From 2d47ed2918ca1baa6f02a61b1ae45935529e0223 Mon Sep 17 00:00:00 2001 From: redshiftzero Date: Fri, 5 Apr 2019 12:01:20 -0700 Subject: [PATCH 1/2] test: missing constructor function should not ignore constructor args --- .../contracts/test_contract_constructor_encoding.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/core/contracts/test_contract_constructor_encoding.py b/tests/core/contracts/test_contract_constructor_encoding.py index edd7383992..10e9861e23 100644 --- a/tests/core/contracts/test_contract_constructor_encoding.py +++ b/tests/core/contracts/test_contract_constructor_encoding.py @@ -20,6 +20,19 @@ def test_contract_constructor_abi_encoding_with_constructor_with_no_args(SimpleC assert deploy_data == SIMPLE_CONSTRUCTOR_CODE +@pytest.mark.parametrize( + 'args,kwargs', + ( + (None, 'kwarg-is-ignored'), + ('arg-is-ignored', None), + ), +) +def test_contract_error_if_additional_args_are_supplied_with_no_constructor_fn(MathContract, + args, kwargs): + with pytest.raises(TypeError, match="Constructor args"): + MathContract._encode_constructor_data(args, kwargs) + + @pytest.mark.parametrize( 'arguments', ( From 1591c2051611460a9bea860dd95ffd7a0caf2140 Mon Sep 17 00:00:00 2001 From: redshiftzero Date: Fri, 5 Apr 2019 12:04:56 -0700 Subject: [PATCH 2/2] bug: raise exception instead of silently ignoring unnecessary args --- web3/contract.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/web3/contract.py b/web3/contract.py index 6138bb7c17..a3c23dba9b 100644 --- a/web3/contract.py +++ b/web3/contract.py @@ -474,6 +474,10 @@ def _encode_constructor_data(cls, args=None, kwargs=None): encode_abi(cls.web3, constructor_abi, arguments, data=cls.bytecode) ) else: + if args is not None or kwargs is not None: + msg = "Constructor args were provided, but no constructor function was provided." + raise TypeError(msg) + deploy_data = to_hex(cls.bytecode) return deploy_data