Skip to content

Commit c7bbd24

Browse files
authored
init commit of async contract (#2377)
Create Base/Async structure for ContractFunctions, ContractEvents, Contract, ContractConstructor, ContractFunction, ContractEvent, ContractCaller classes
1 parent 6473a54 commit c7bbd24

File tree

5 files changed

+993
-362
lines changed

5 files changed

+993
-362
lines changed

tests/core/contracts/conftest.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
from eth_utils import (
66
event_signature_to_log_topic,
77
)
8+
from eth_utils.toolz import (
9+
identity,
10+
)
11+
import pytest_asyncio
812

13+
from web3 import Web3
914
from web3._utils.module_testing.emitter_contract import (
1015
CONTRACT_EMITTER_ABI,
1116
CONTRACT_EMITTER_CODE,
@@ -46,6 +51,15 @@
4651
REVERT_CONTRACT_BYTECODE,
4752
REVERT_CONTRACT_RUNTIME_CODE,
4853
)
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+
)
4963

5064
CONTRACT_NESTED_TUPLE_SOURCE = """
5165
pragma solidity >=0.4.19 <0.6.0;
@@ -1036,3 +1050,39 @@ def estimateGas(request):
10361050
@pytest.fixture
10371051
def buildTransaction(request):
10381052
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)

web3/_utils/module_testing/web3_module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def test_solidityKeccak(
179179
self, w3: "Web3", types: Sequence[TypeStr], values: Sequence[Any], expected: HexBytes
180180
) -> None:
181181
if isinstance(expected, type) and issubclass(expected, Exception):
182-
with pytest.raises(expected): # type: ignore
182+
with pytest.raises(expected):
183183
w3.solidityKeccak(types, values)
184184
return
185185

0 commit comments

Comments
 (0)