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
        })
    def _set_function_info(self):
        if not self.abi:
            self.abi = find_matching_fn_abi(self.contract_abi,
                                            self.function_identifier,
                                            self.args, self.kwargs)
        if self.function_identifier is FallbackFn:
            self.selector = encode_hex(b'')
        elif is_text(self.function_identifier):
            self.selector = encode_hex(function_abi_to_4byte_selector(
                self.abi))
        else:
            raise TypeError("Unsupported function identifier")

        self.arguments = merge_args_and_kwargs(self.abi, self.args,
                                               self.kwargs)
    def _encode_data_in_transaction(self, *args, **kwargs):
        constructor_abi = get_constructor_abi(self.abi)

        if constructor_abi:
            if not args:
                args = tuple()
            if not kwargs:
                kwargs = {}

            arguments = merge_args_and_kwargs(constructor_abi, args, kwargs)
            data = add_0x_prefix(
                encode_abi(self.web3,
                           constructor_abi,
                           arguments,
                           data=self.bytecode))
        else:
            data = to_hex(self.bytecode)

        return data
    def _encode_constructor_data(cls, args=None, kwargs=None):
        constructor_abi = get_constructor_abi(cls.abi)

        if constructor_abi:
            if args is None:
                args = tuple()
            if kwargs is None:
                kwargs = {}

            arguments = merge_args_and_kwargs(constructor_abi, args, kwargs)

            deploy_data = add_0x_prefix(
                encode_abi(cls.web3,
                           constructor_abi,
                           arguments,
                           data=cls.bytecode))
        else:
            deploy_data = to_hex(cls.bytecode)

        return deploy_data
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)

    _, aligned_fn_arguments = get_aligned_abi_inputs(fn_abi, fn_arguments)

    return fn_abi, fn_selector, aligned_fn_arguments
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_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_allowed_when_duplicate_named_inputs():
    actual = merge_args_and_kwargs(DUPLICATE_NAMES_FUNCTION_ABI, (1, 2, 3), {})
    assert actual == (1, 2, 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
        })