Beispiel #1
0
def get_function_info(fn_name,
                      contract_abi=None,
                      fn_abi=None,
                      args=None,
                      kwargs=None):
    if args is None:
        args = tuple()
    if kwargs is None:
        kwargs = {}

    if fn_abi is None:
        fn_abi = find_matching_fn_abi(contract_abi, fn_name, args, kwargs)

    fn_selector = encode_hex(function_abi_to_4byte_selector(fn_abi))

    fn_arguments = merge_args_and_kwargs(fn_abi, args, kwargs)

    return fn_abi, fn_selector, fn_arguments
def test_args_allowed_when_duplicate_named_inputs():
    actual = merge_args_and_kwargs(DUPLICATE_NAMES_FUNCTION_ABI, (1, 2, 3), {})
    assert actual == (1, 2, 3)
def test_kwargs_allowed_if_no_intersections_with_duplicate_input_names():
    with pytest.raises(TypeError):
        merge_args_and_kwargs(DUPLICATE_NAMES_FUNCTION_ABI, (1,), {'a': 2, 'b': 3})
def test_args_works_when_merging_with_unnamed_inputs():
    actual = merge_args_and_kwargs(GENERATED_FUNCTION_ABI, (1, 2), {})
    assert actual == (1, 2)
def test_kwargs_is_disallowed_when_merging_with_unnamed_inputs():
    with pytest.raises(TypeError):
        merge_args_and_kwargs(GENERATED_FUNCTION_ABI, tuple(), {'x': 1, 'y': 2})
def test_merging_of_args_and_kwargs_with_no_inputs():
    actual = merge_args_and_kwargs(NO_INPUTS_FUNCTION_ABI, tuple(), {})
    assert actual == tuple()
def test_merging_of_args_and_kwargs(args, kwargs, expected_args):
    actual_args = merge_args_and_kwargs(FUNCTION_ABI, args, kwargs)
    assert actual_args == expected_args
def test_error_when_invalid_args_kwargs_combo_provided():
    with pytest.raises(TypeError):
        merge_args_and_kwargs(GENERATED_FUNCTION_ABI, (1, 2,), {'a': 1, 'b': 2})