Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1193 bugfix: don't silently ignore constructor args when no constructor function is provided #1316

Merged
merged 2 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/core/contracts/test_contract_constructor_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
(
Expand Down
4 changes: 4 additions & 0 deletions web3/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down