|
6 | 6 | strategies as st,
|
7 | 7 | )
|
8 | 8 |
|
| 9 | +from web3 import Web3 |
| 10 | +from web3._utils.module_testing.emitter_contract import ( |
| 11 | + CONTRACT_EMITTER_ABI, |
| 12 | + CONTRACT_EMITTER_CODE, |
| 13 | + CONTRACT_EMITTER_RUNTIME, |
| 14 | +) |
| 15 | +from web3.middleware import ( |
| 16 | + local_filter_middleware, |
| 17 | +) |
| 18 | +from web3.providers.eth_tester import ( |
| 19 | + EthereumTesterProvider, |
| 20 | +) |
| 21 | + |
| 22 | + |
| 23 | +@pytest.fixture( |
| 24 | + scope='module', |
| 25 | + params=[True, False], |
| 26 | + ids=["local_filter_middleware", "node_based_filter"]) |
| 27 | +def web3(request): |
| 28 | + use_filter_middleware = request.param |
| 29 | + provider = EthereumTesterProvider() |
| 30 | + w3 = Web3(provider) |
| 31 | + if use_filter_middleware: |
| 32 | + w3.middleware_onion.add(local_filter_middleware) |
| 33 | + return w3 |
| 34 | + |
| 35 | + |
| 36 | +@pytest.fixture(autouse=True) |
| 37 | +def wait_for_mining_start(web3, wait_for_block): |
| 38 | + wait_for_block(web3) |
| 39 | + |
| 40 | + |
| 41 | +@pytest.fixture(scope="module") |
| 42 | +def EMITTER_CODE(): |
| 43 | + return CONTRACT_EMITTER_CODE |
| 44 | + |
| 45 | + |
| 46 | +@pytest.fixture(scope="module") |
| 47 | +def EMITTER_RUNTIME(): |
| 48 | + return CONTRACT_EMITTER_RUNTIME |
| 49 | + |
| 50 | + |
| 51 | +@pytest.fixture(scope="module") |
| 52 | +def EMITTER_ABI(): |
| 53 | + return CONTRACT_EMITTER_ABI |
| 54 | + |
| 55 | + |
| 56 | +@pytest.fixture(scope="module") |
| 57 | +def EMITTER(EMITTER_CODE, |
| 58 | + EMITTER_RUNTIME, |
| 59 | + EMITTER_ABI): |
| 60 | + return { |
| 61 | + 'bytecode': EMITTER_CODE, |
| 62 | + 'bytecode_runtime': EMITTER_RUNTIME, |
| 63 | + 'abi': EMITTER_ABI, |
| 64 | + } |
| 65 | + |
| 66 | + |
| 67 | +@pytest.fixture(scope="module") |
| 68 | +def Emitter(web3, EMITTER): |
| 69 | + return web3.eth.contract(**EMITTER) |
| 70 | + |
| 71 | + |
| 72 | +@pytest.fixture(scope="module") |
| 73 | +def emitter(web3, Emitter, wait_for_transaction, wait_for_block, address_conversion_func): |
| 74 | + wait_for_block(web3) |
| 75 | + deploy_txn_hash = Emitter.constructor().transact({ |
| 76 | + 'from': web3.eth.coinbase, |
| 77 | + 'gas': 1000000, |
| 78 | + 'maxFeePerGas': 10 ** 9, |
| 79 | + 'maxPriorityFeePerGas': 10 ** 9, |
| 80 | + }) |
| 81 | + deploy_receipt = wait_for_transaction(web3, deploy_txn_hash) |
| 82 | + contract_address = address_conversion_func(deploy_receipt['contractAddress']) |
| 83 | + |
| 84 | + bytecode = web3.eth.get_code(contract_address) |
| 85 | + assert bytecode == Emitter.bytecode_runtime |
| 86 | + _emitter = Emitter(address=contract_address) |
| 87 | + assert _emitter.address == contract_address |
| 88 | + return _emitter |
| 89 | + |
9 | 90 |
|
10 | 91 | def not_empty_string(x):
|
11 | 92 | return x != ''
|
|
0 commit comments