Skip to content
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

Fixes emitter fixture scoping issues #1780

Merged
merged 3 commits into from
Oct 29, 2020
Merged
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
4 changes: 2 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _wait_for_miner_start(web3, timeout=60):
return _wait_for_miner_start


@pytest.fixture()
@pytest.fixture(scope="module")
def wait_for_block():
def _wait_for_block(web3, block_number=1, timeout=None):
if not timeout:
Expand All @@ -79,7 +79,7 @@ def _wait_for_block(web3, block_number=1, timeout=None):
return _wait_for_block


@pytest.fixture()
@pytest.fixture(scope="module")
def wait_for_transaction():
def _wait_for_transaction(web3, txn_hash, timeout=120):
poll_delay_counter = PollDelayCounter()
Expand Down
3 changes: 3 additions & 0 deletions newsfragments/1780.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Specify 'module' scope for 'wait_for_block' and 'wait_for_transaction' fixtures. Specify 'module'
scope for emitter fixtures ('emitter', 'Emitter', 'EMITTER', 'EMITTER_ABI', 'EMITTER_RUNTIME',
'EMITTER_CODE') and 'web3(request)'in test_contract_data_filters.py.
5 changes: 1 addition & 4 deletions tests/core/contracts/test_contract_buildTransaction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import pytest

from eth_utils.toolz import (
Expand All @@ -10,8 +8,7 @@
ValidationError,
)

# Ignore warning in pyethereum 1.6 - will go away with the upgrade
pytestmark = pytest.mark.filterwarnings("ignore:implicit cast from 'char *'")
# -*- coding: utf-8 -*-


@pytest.fixture()
Expand Down
74 changes: 74 additions & 0 deletions tests/core/filtering/test_contract_data_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,80 @@
strategies as st,
)

from web3 import Web3
from web3._utils.module_testing.emitter_contract import (
CONTRACT_EMITTER_ABI,
CONTRACT_EMITTER_CODE,
CONTRACT_EMITTER_RUNTIME,
)
from web3.middleware import (
local_filter_middleware,
)
from web3.providers.eth_tester import (
EthereumTesterProvider,
)


@pytest.fixture(
scope="module",
params=[True, False],
ids=["local_filter_middleware", "node_based_filter"])
def web3(request):
use_filter_middleware = request.param
provider = EthereumTesterProvider()
w3 = Web3(provider)
if use_filter_middleware:
w3.middleware_onion.add(local_filter_middleware)
return w3


@pytest.fixture(scope="module")
def EMITTER_CODE():
return CONTRACT_EMITTER_CODE


@pytest.fixture(scope="module")
def EMITTER_RUNTIME():
return CONTRACT_EMITTER_RUNTIME


@pytest.fixture(scope="module")
def EMITTER_ABI():
return CONTRACT_EMITTER_ABI


@pytest.fixture(scope="module")
def EMITTER(EMITTER_CODE,
EMITTER_RUNTIME,
EMITTER_ABI):
return {
'bytecode': EMITTER_CODE,
'bytecode_runtime': EMITTER_RUNTIME,
'abi': EMITTER_ABI,
}


@pytest.fixture(scope="module")
def Emitter(web3, EMITTER):
return web3.eth.contract(**EMITTER)


@pytest.fixture(scope="module")
def emitter(web3, Emitter, wait_for_transaction, wait_for_block, address_conversion_func):
wait_for_block(web3)
deploy_txn_hash = Emitter.constructor().transact({
'from': web3.eth.coinbase,
'gas': 1000000,
'gasPrice': 1})
deploy_receipt = wait_for_transaction(web3, deploy_txn_hash)
contract_address = address_conversion_func(deploy_receipt['contractAddress'])

bytecode = web3.eth.getCode(contract_address)
assert bytecode == Emitter.bytecode_runtime
_emitter = Emitter(address=contract_address)
assert _emitter.address == contract_address
return _emitter


def not_empty_string(x):
return x != ''
Expand Down
3 changes: 0 additions & 3 deletions tests/core/filtering/test_contract_on_event_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
is_address,
)

# Ignore warning in pyethereum 1.6 - will go away with the upgrade
pytestmark = pytest.mark.filterwarnings("ignore:implicit cast from 'char *'")


@pytest.mark.parametrize('call_as_instance', (True, False))
def test_create_filter_address_parameter(web3, emitter, Emitter, call_as_instance):
Expand Down