Skip to content

Commit f03a10c

Browse files
Add tests for verifying token events.
1 parent 72760c6 commit f03a10c

File tree

3 files changed

+304
-34
lines changed

3 files changed

+304
-34
lines changed

tests/fixtures.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88
print_logs,
99
)
1010

11+
from utils_logs import (
12+
LogHandler
13+
)
14+
1115

12-
MAX_UINT = 2**256
13-
fake_address = 0x03432
1416
print_the_logs = False
17+
18+
MAX_UINT = 2**256 - 1
19+
fake_address = 0x03432
1520
passphrase = '0'
1621
fixture_decimals = [18, 1]
1722

@@ -51,6 +56,14 @@
5156
}
5257
]
5358

59+
token_events = {
60+
'deploy': 'Deployed',
61+
'setup': 'Setup',
62+
'transfer': 'Transfer',
63+
'approve': 'Approval',
64+
'burn': 'Burnt'
65+
}
66+
5467

5568
# auction_supply = initial_supply - reduce((lambda x, y: x + y), prealloc)
5669

@@ -155,6 +168,25 @@ def get(arguments, transaction=None, token_type='CustomToken', decimals=18):
155168
return get
156169

157170

171+
@pytest.fixture()
172+
def event_handler(chain, web3):
173+
def get_event_handler(contract=None, address=None, abi=None):
174+
if contract:
175+
# Get contract factory name from contract instance
176+
# TODO is there an actual API for this??
177+
comp_target = contract.metadata['settings']['compilationTarget']
178+
name = comp_target[list(comp_target.keys())[0]]
179+
180+
abi = chain.provider.get_base_contract_factory(name).abi
181+
address = contract.address
182+
183+
if address and abi:
184+
return LogHandler(web3, address, abi)
185+
else:
186+
raise Exception('event_handler called without a contract instance')
187+
return get_event_handler
188+
189+
158190
@pytest.fixture()
159191
def token_contract(
160192
chain,
@@ -208,10 +240,18 @@ def get(txn_hash):
208240

209241

210242
@pytest.fixture
211-
def create_contract(chain):
243+
def create_contract(chain, event_handler):
212244
def get(contract_type, arguments, transaction=None):
213245
deploy_txn_hash = contract_type.deploy(transaction=transaction, args=arguments)
214246
contract_address = chain.wait.for_contract_address(deploy_txn_hash)
215247
contract = contract_type(address=contract_address)
248+
249+
# Check deploy event if not proxy contract
250+
if len(arguments) > 0:
251+
ev_handler = event_handler(contract)
252+
if ev_handler:
253+
ev_handler.add(deploy_txn_hash, token_events['deploy'])
254+
ev_handler.check()
255+
216256
return contract
217257
return get

0 commit comments

Comments
 (0)