Skip to content

Commit d3c23f8

Browse files
authored
Merge pull request #1780 from tmckenzie51/tiffany/emitter-scope
Fixes emitter fixture scoping issues
2 parents 39b8a38 + 8eed796 commit d3c23f8

File tree

5 files changed

+80
-9
lines changed

5 files changed

+80
-9
lines changed

conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _wait_for_miner_start(web3, timeout=60):
6464
return _wait_for_miner_start
6565

6666

67-
@pytest.fixture()
67+
@pytest.fixture(scope="module")
6868
def wait_for_block():
6969
def _wait_for_block(web3, block_number=1, timeout=None):
7070
if not timeout:
@@ -79,7 +79,7 @@ def _wait_for_block(web3, block_number=1, timeout=None):
7979
return _wait_for_block
8080

8181

82-
@pytest.fixture()
82+
@pytest.fixture(scope="module")
8383
def wait_for_transaction():
8484
def _wait_for_transaction(web3, txn_hash, timeout=120):
8585
poll_delay_counter = PollDelayCounter()

newsfragments/1780.misc.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Specify 'module' scope for 'wait_for_block' and 'wait_for_transaction' fixtures. Specify 'module'
2+
scope for emitter fixtures ('emitter', 'Emitter', 'EMITTER', 'EMITTER_ABI', 'EMITTER_RUNTIME',
3+
'EMITTER_CODE') and 'web3(request)'in test_contract_data_filters.py.

tests/core/contracts/test_contract_buildTransaction.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
import pytest
42

53
from eth_utils.toolz import (
@@ -10,8 +8,7 @@
108
ValidationError,
119
)
1210

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

1613

1714
@pytest.fixture()

tests/core/filtering/test_contract_data_filters.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,80 @@
66
strategies as st,
77
)
88

9+
from web3 import Web3
10+
from web3._utils.module_testing.emitter_contract import (
11+
CONTRACT_EMITTER_ABI,
12+
CONTRACT_EMITTER_CODE,
13+
CONTRACT_EMITTER_RUNTIME,
14+
)
15+
from web3.middleware import (
16+
local_filter_middleware,
17+
)
18+
from web3.providers.eth_tester import (
19+
EthereumTesterProvider,
20+
)
21+
22+
23+
@pytest.fixture(
24+
scope="module",
25+
params=[True, False],
26+
ids=["local_filter_middleware", "node_based_filter"])
27+
def web3(request):
28+
use_filter_middleware = request.param
29+
provider = EthereumTesterProvider()
30+
w3 = Web3(provider)
31+
if use_filter_middleware:
32+
w3.middleware_onion.add(local_filter_middleware)
33+
return w3
34+
35+
36+
@pytest.fixture(scope="module")
37+
def EMITTER_CODE():
38+
return CONTRACT_EMITTER_CODE
39+
40+
41+
@pytest.fixture(scope="module")
42+
def EMITTER_RUNTIME():
43+
return CONTRACT_EMITTER_RUNTIME
44+
45+
46+
@pytest.fixture(scope="module")
47+
def EMITTER_ABI():
48+
return CONTRACT_EMITTER_ABI
49+
50+
51+
@pytest.fixture(scope="module")
52+
def EMITTER(EMITTER_CODE,
53+
EMITTER_RUNTIME,
54+
EMITTER_ABI):
55+
return {
56+
'bytecode': EMITTER_CODE,
57+
'bytecode_runtime': EMITTER_RUNTIME,
58+
'abi': EMITTER_ABI,
59+
}
60+
61+
62+
@pytest.fixture(scope="module")
63+
def Emitter(web3, EMITTER):
64+
return web3.eth.contract(**EMITTER)
65+
66+
67+
@pytest.fixture(scope="module")
68+
def emitter(web3, Emitter, wait_for_transaction, wait_for_block, address_conversion_func):
69+
wait_for_block(web3)
70+
deploy_txn_hash = Emitter.constructor().transact({
71+
'from': web3.eth.coinbase,
72+
'gas': 1000000,
73+
'gasPrice': 1})
74+
deploy_receipt = wait_for_transaction(web3, deploy_txn_hash)
75+
contract_address = address_conversion_func(deploy_receipt['contractAddress'])
76+
77+
bytecode = web3.eth.getCode(contract_address)
78+
assert bytecode == Emitter.bytecode_runtime
79+
_emitter = Emitter(address=contract_address)
80+
assert _emitter.address == contract_address
81+
return _emitter
82+
983

1084
def not_empty_string(x):
1185
return x != ''

tests/core/filtering/test_contract_on_event_filtering.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
is_address,
55
)
66

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

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

0 commit comments

Comments
 (0)