|
5 | 5 | from eth_utils import (
|
6 | 6 | event_signature_to_log_topic,
|
7 | 7 | )
|
| 8 | +from eth_utils.toolz import ( |
| 9 | + identity, |
| 10 | +) |
| 11 | +import pytest_asyncio |
8 | 12 |
|
| 13 | +from web3 import Web3 |
9 | 14 | from web3._utils.module_testing.emitter_contract import (
|
10 | 15 | CONTRACT_EMITTER_ABI,
|
11 | 16 | CONTRACT_EMITTER_CODE,
|
|
46 | 51 | REVERT_CONTRACT_BYTECODE,
|
47 | 52 | REVERT_CONTRACT_RUNTIME_CODE,
|
48 | 53 | )
|
| 54 | +from web3.contract import ( |
| 55 | + AsyncContract, |
| 56 | +) |
| 57 | +from web3.eth import ( |
| 58 | + AsyncEth, |
| 59 | +) |
| 60 | +from web3.providers.eth_tester.main import ( |
| 61 | + AsyncEthereumTesterProvider, |
| 62 | +) |
49 | 63 |
|
50 | 64 | CONTRACT_NESTED_TUPLE_SOURCE = """
|
51 | 65 | pragma solidity >=0.4.19 <0.6.0;
|
@@ -1036,3 +1050,39 @@ def estimateGas(request):
|
1036 | 1050 | @pytest.fixture
|
1037 | 1051 | def buildTransaction(request):
|
1038 | 1052 | return functools.partial(invoke_contract, api_call_desig='buildTransaction')
|
| 1053 | + |
| 1054 | + |
| 1055 | +@pytest_asyncio.fixture() |
| 1056 | +async def async_deploy(web3, Contract, apply_func=identity, args=None): |
| 1057 | + args = args or [] |
| 1058 | + deploy_txn = await Contract.constructor(*args).transact() |
| 1059 | + deploy_receipt = await web3.eth.wait_for_transaction_receipt(deploy_txn) |
| 1060 | + assert deploy_receipt is not None |
| 1061 | + address = apply_func(deploy_receipt['contractAddress']) |
| 1062 | + contract = Contract(address=address) |
| 1063 | + assert contract.address == address |
| 1064 | + assert len(await web3.eth.get_code(contract.address)) > 0 |
| 1065 | + return contract |
| 1066 | + |
| 1067 | + |
| 1068 | +@pytest_asyncio.fixture() |
| 1069 | +async def async_w3(): |
| 1070 | + provider = AsyncEthereumTesterProvider() |
| 1071 | + w3 = Web3(provider, modules={'eth': [AsyncEth]}, |
| 1072 | + middlewares=provider.middlewares) |
| 1073 | + w3.eth.default_account = await w3.eth.coinbase |
| 1074 | + return w3 |
| 1075 | + |
| 1076 | + |
| 1077 | +@pytest_asyncio.fixture() |
| 1078 | +def AsyncMathContract(async_w3, MATH_ABI, MATH_CODE, MATH_RUNTIME): |
| 1079 | + contract = AsyncContract.factory(async_w3, |
| 1080 | + abi=MATH_ABI, |
| 1081 | + bytecode=MATH_CODE, |
| 1082 | + bytecode_runtime=MATH_RUNTIME) |
| 1083 | + return contract |
| 1084 | + |
| 1085 | + |
| 1086 | +@pytest_asyncio.fixture() |
| 1087 | +async def async_math_contract(async_w3, AsyncMathContract, address_conversion_func): |
| 1088 | + return await async_deploy(async_w3, AsyncMathContract, address_conversion_func) |
0 commit comments