Skip to content

AyncENS/Contract #2370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ens/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from .main import (
ENS,
AsyncENS
)

from .exceptions import (
Expand Down
356 changes: 337 additions & 19 deletions ens/main.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions newsfragments/2318.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In ENS the contract function to resolve an ENS address was being called twice in error. One of those calls was removed.
52 changes: 52 additions & 0 deletions tests/core/contracts/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
from eth_utils import (
event_signature_to_log_topic,
)
from eth_utils.toolz import (
identity,
)

from ens import (
AsyncENS,
)
from web3 import Web3
from web3._utils.module_testing.emitter_contract import (
CONTRACT_EMITTER_ABI,
CONTRACT_EMITTER_CODE,
Expand Down Expand Up @@ -46,6 +53,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 +1052,39 @@ def estimateGas(request):
@pytest.fixture
def buildTransaction(request):
return functools.partial(invoke_contract, api_call_desig='buildTransaction')


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.fixture()
async def async_w3():
provider = AsyncEthereumTesterProvider()
w3 = Web3(provider, modules={'eth': [AsyncEth]},
middlewares=provider.middlewares)
w3.ens = AsyncENS.fromWeb3(w3)
w3.eth.default_account = await w3.eth.coinbase
return w3


@pytest.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.fixture()
async def async_math_contract(async_w3, AsyncMathContract, address_conversion_func):
return await async_deploy(async_w3, AsyncMathContract, address_conversion_func)
6 changes: 6 additions & 0 deletions tests/core/contracts/test_contract_call_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,3 +879,9 @@ def test_call_revert_contract(revert_contract):
# which does not contain the revert reason. Avoid that by giving a gas
# value.
revert_contract.functions.revertWithMessage().call({'gas': 100000})


@pytest.mark.asyncio
async def test_async_call_no_args(async_math_contract):
result = await async_math_contract.functions.return13().call()
assert result == 13
Loading