forked from ethereum/web3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_contract_attributes.py
48 lines (37 loc) · 1.41 KB
/
test_contract_attributes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import pytest
from web3.exceptions import (
ABIEventFunctionNotFound,
ABIFunctionNotFound,
)
@pytest.fixture()
def abi():
return '''[{"anonymous":false,"inputs":[{"indexed":false,"name":"value","type":"uint256"}],"name":"Increased","type":"function"}, {"anonymous":false,"inputs":[{"indexed":false,"name":"value","type":"uint256"}],"name":"Increased","type":"event"}]''' # noqa: E501
@pytest.mark.parametrize(
'attribute',
('functions', 'events', 'caller')
)
def test_getattr(web3, abi, attribute):
contract = web3.eth.contract(abi=abi)
contract_attribute = getattr(contract, attribute)
assert getattr(contract_attribute, "Increased")
@pytest.mark.parametrize(
'attribute,error', (
('functions', ABIFunctionNotFound),
('events', ABIEventFunctionNotFound),
('caller', ABIFunctionNotFound),
)
)
def test_getattr_raises_error(web3, abi, attribute, error):
contract = web3.eth.contract(abi=abi)
contract_attribute = getattr(contract, attribute)
with pytest.raises(error):
getattr(contract_attribute, "Decreased")
@pytest.mark.parametrize(
'attribute',
('functions', 'events', 'caller')
)
def test_hasattr(web3, abi, attribute):
contract = web3.eth.contract(abi=abi)
contract_attribute = getattr(contract, attribute)
assert hasattr(contract_attribute, "Increased") is True
assert hasattr(contract_attribute, "Decreased") is False