-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from pipermerriam/piper/fancier-contract-objects
Add additional compiler fields to Contract object.
- Loading branch information
Showing
14 changed files
with
401 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import pytest | ||
import warnings | ||
import sys | ||
|
||
from web3.contract import ( | ||
Contract, | ||
) | ||
|
||
|
||
ABI = [ | ||
{ | ||
"constant": False, | ||
"inputs": [], | ||
"name": "func_1", | ||
"outputs": [], | ||
"type": "function", | ||
}, | ||
] | ||
|
||
ADDRESS = '0x0000000000000000000000000000000000000000' | ||
|
||
|
||
class ContactClassForTest(Contract): | ||
web3 = True | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'args,kwargs,expected', | ||
( | ||
((ABI,), {}, {'abi': ABI}), | ||
((ABI,), {'abi': ABI}, TypeError), | ||
((ABI, ADDRESS), {}, {'abi': ABI, 'address': ADDRESS}), | ||
( | ||
(ABI, ADDRESS), | ||
{'code': '0x1', 'code_runtime': '0x2'}, | ||
{'abi': ABI, 'address': ADDRESS, 'bytecode': '0x1', 'bytecode_runtime': '0x2'}), | ||
( | ||
(ABI, ADDRESS, '0x1', '0x2', '0x3'), | ||
{}, | ||
{'abi': ABI, 'address': ADDRESS, 'bytecode': '0x1', 'bytecode_runtime': '0x2', 'source': '0x3'}, | ||
), | ||
( | ||
tuple(), | ||
{'abi': ABI, 'address': ADDRESS, 'code': '0x1', 'code_runtime': '0x2', 'source': '0x3'}, | ||
{'abi': ABI, 'address': ADDRESS, 'bytecode': '0x1', 'bytecode_runtime': '0x2', 'source': '0x3'}, | ||
), | ||
((ABI, ADDRESS), {'abi': ABI}, TypeError), | ||
((ABI, ADDRESS), {'address': ADDRESS}, TypeError), | ||
((ADDRESS,), {}, {'address': ADDRESS}), | ||
) | ||
) | ||
def test_process_legacy_constructor_signature(args, kwargs, expected): | ||
|
||
if isinstance(expected, type) and issubclass(expected, Exception): | ||
with pytest.raises(expected): | ||
ContactClassForTest(*args, **kwargs) | ||
return | ||
|
||
actual = ContactClassForTest(*args, **kwargs) | ||
for key, value in expected.items(): | ||
assert getattr(actual, key) == value | ||
|
||
|
||
@pytest.mark.skipif(sys.version_info.major == 2, reason="Python2 fails weirdly on this test") | ||
def test_deprecated_properties(): | ||
instance = ContactClassForTest(ABI, ADDRESS, '0x1', '0x2', source='0x3') | ||
|
||
with pytest.warns(DeprecationWarning): | ||
instance.source | ||
|
||
with pytest.warns(DeprecationWarning): | ||
instance.code | ||
|
||
with pytest.warns(DeprecationWarning): | ||
instance.code_runtime | ||
|
||
|
||
@pytest.mark.skipif(sys.version_info.major == 2, reason="Python2 fails weirdly on this test") | ||
def test_deprecated_instantiation(): | ||
with pytest.warns(Warning) as record: | ||
ContactClassForTest(ADDRESS) | ||
ContactClassForTest(address=ADDRESS) | ||
warnings.warn(Warning('test')) | ||
|
||
assert len(record) == 1 | ||
|
||
with pytest.warns(DeprecationWarning): | ||
ContactClassForTest() # no address | ||
|
||
with pytest.warns(DeprecationWarning): | ||
ContactClassForTest(ABI, ADDRESS) # no address | ||
|
||
with pytest.warns(DeprecationWarning): | ||
ContactClassForTest(ABI) # no address | ||
|
||
with pytest.warns(DeprecationWarning): | ||
ContactClassForTest(code='0x1') # no address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from web3.utils.empty import ( | ||
empty, | ||
) | ||
|
||
|
||
def test_empty_object_is_falsy(): | ||
assert bool(empty) is False | ||
assert not empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.