Skip to content

Commit

Permalink
Init commit of async contract:
Browse files Browse the repository at this point in the history
- ContractEvents/ContractEvent Async
- fixed broken test
- linting
  • Loading branch information
dbfreem authored and fselmo committed May 25, 2022
1 parent 1bd1d0c commit c1cb4e3
Show file tree
Hide file tree
Showing 4 changed files with 947 additions and 337 deletions.
50 changes: 50 additions & 0 deletions tests/core/contracts/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
from eth_utils import (
event_signature_to_log_topic,
)
from eth_utils.toolz import (
identity,
)
import pytest_asyncio

from web3 import Web3
from web3._utils.module_testing.emitter_contract import (
CONTRACT_EMITTER_ABI,
CONTRACT_EMITTER_CODE,
Expand Down Expand Up @@ -46,6 +51,15 @@
REVERT_CONTRACT_BYTECODE,
REVERT_CONTRACT_RUNTIME_CODE,
)
from web3.contract import (
AsyncContract,
)
from web3.eth import (
AsyncEth,
)
from web3.providers.eth_tester.main import (
AsyncEthereumTesterProvider,
)

CONTRACT_NESTED_TUPLE_SOURCE = """
pragma solidity >=0.4.19 <0.6.0;
Expand Down Expand Up @@ -1036,3 +1050,39 @@ def estimateGas(request):
@pytest.fixture
def buildTransaction(request):
return functools.partial(invoke_contract, api_call_desig='buildTransaction')


@pytest_asyncio.fixture()
async def async_deploy(web3, Contract, apply_func=identity, args=None):
args = args or []
deploy_txn = await Contract.constructor(*args).transact()
deploy_receipt = await web3.eth.wait_for_transaction_receipt(deploy_txn)
assert deploy_receipt is not None
address = apply_func(deploy_receipt['contractAddress'])
contract = Contract(address=address)
assert contract.address == address
assert len(await web3.eth.get_code(contract.address)) > 0
return contract


@pytest_asyncio.fixture()
async def async_w3():
provider = AsyncEthereumTesterProvider()
w3 = Web3(provider, modules={'eth': [AsyncEth]},
middlewares=provider.middlewares)
w3.eth.default_account = await w3.eth.coinbase
return w3


@pytest_asyncio.fixture()
def AsyncMathContract(async_w3, MATH_ABI, MATH_CODE, MATH_RUNTIME):
contract = AsyncContract.factory(async_w3,
abi=MATH_ABI,
bytecode=MATH_CODE,
bytecode_runtime=MATH_RUNTIME)
return contract


@pytest_asyncio.fixture()
async def async_math_contract(async_w3, AsyncMathContract, address_conversion_func):
return await async_deploy(async_w3, AsyncMathContract, address_conversion_func)
Loading

0 comments on commit c1cb4e3

Please sign in to comment.