|
8 | 8 | print_logs, |
9 | 9 | ) |
10 | 10 |
|
| 11 | +from utils_logs import ( |
| 12 | + LogHandler |
| 13 | +) |
| 14 | + |
11 | 15 |
|
12 | | -MAX_UINT = 2**256 |
13 | | -fake_address = 0x03432 |
14 | 16 | print_the_logs = False |
| 17 | + |
| 18 | +MAX_UINT = 2**256 - 1 |
| 19 | +fake_address = 0x03432 |
15 | 20 | passphrase = '0' |
16 | 21 | fixture_decimals = [18, 1] |
17 | 22 |
|
|
51 | 56 | } |
52 | 57 | ] |
53 | 58 |
|
| 59 | +token_events = { |
| 60 | + 'deploy': 'Deployed', |
| 61 | + 'setup': 'Setup', |
| 62 | + 'transfer': 'Transfer', |
| 63 | + 'approve': 'Approval', |
| 64 | + 'burn': 'Burnt' |
| 65 | +} |
| 66 | + |
54 | 67 |
|
55 | 68 | # auction_supply = initial_supply - reduce((lambda x, y: x + y), prealloc) |
56 | 69 |
|
@@ -155,6 +168,25 @@ def get(arguments, transaction=None, token_type='CustomToken', decimals=18): |
155 | 168 | return get |
156 | 169 |
|
157 | 170 |
|
| 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 | + |
158 | 190 | @pytest.fixture() |
159 | 191 | def token_contract( |
160 | 192 | chain, |
@@ -208,10 +240,18 @@ def get(txn_hash): |
208 | 240 |
|
209 | 241 |
|
210 | 242 | @pytest.fixture |
211 | | -def create_contract(chain): |
| 243 | +def create_contract(chain, event_handler): |
212 | 244 | def get(contract_type, arguments, transaction=None): |
213 | 245 | deploy_txn_hash = contract_type.deploy(transaction=transaction, args=arguments) |
214 | 246 | contract_address = chain.wait.for_contract_address(deploy_txn_hash) |
215 | 247 | 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 | + |
216 | 256 | return contract |
217 | 257 | return get |
0 commit comments