Skip to content

Commit 2020b55

Browse files
dbfreemkclowes
andauthored
Fix for HypothesisDeprecationWarning in CircleCI #1729 (#2228)
* Added conftest.py to test/core/utilities and moved web3 fixture to it Moved fixtures into test_contract_topic_filter.py Both of these were to fix HypothesisDeprecationWarning while running test Co-authored-by: kclowes <kclowes@users.noreply.github.com>
1 parent 9c117ab commit 2020b55

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

newsfragments/1729.misc.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove HypothesisDeprecationWarnings in tests

tests/core/filtering/test_contract_topic_filters.py

+81
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,87 @@
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(autouse=True)
37+
def wait_for_mining_start(web3, wait_for_block):
38+
wait_for_block(web3)
39+
40+
41+
@pytest.fixture(scope="module")
42+
def EMITTER_CODE():
43+
return CONTRACT_EMITTER_CODE
44+
45+
46+
@pytest.fixture(scope="module")
47+
def EMITTER_RUNTIME():
48+
return CONTRACT_EMITTER_RUNTIME
49+
50+
51+
@pytest.fixture(scope="module")
52+
def EMITTER_ABI():
53+
return CONTRACT_EMITTER_ABI
54+
55+
56+
@pytest.fixture(scope="module")
57+
def EMITTER(EMITTER_CODE,
58+
EMITTER_RUNTIME,
59+
EMITTER_ABI):
60+
return {
61+
'bytecode': EMITTER_CODE,
62+
'bytecode_runtime': EMITTER_RUNTIME,
63+
'abi': EMITTER_ABI,
64+
}
65+
66+
67+
@pytest.fixture(scope="module")
68+
def Emitter(web3, EMITTER):
69+
return web3.eth.contract(**EMITTER)
70+
71+
72+
@pytest.fixture(scope="module")
73+
def emitter(web3, Emitter, wait_for_transaction, wait_for_block, address_conversion_func):
74+
wait_for_block(web3)
75+
deploy_txn_hash = Emitter.constructor().transact({
76+
'from': web3.eth.coinbase,
77+
'gas': 1000000,
78+
'maxFeePerGas': 10 ** 9,
79+
'maxPriorityFeePerGas': 10 ** 9,
80+
})
81+
deploy_receipt = wait_for_transaction(web3, deploy_txn_hash)
82+
contract_address = address_conversion_func(deploy_receipt['contractAddress'])
83+
84+
bytecode = web3.eth.get_code(contract_address)
85+
assert bytecode == Emitter.bytecode_runtime
86+
_emitter = Emitter(address=contract_address)
87+
assert _emitter.address == contract_address
88+
return _emitter
89+
990

1091
def not_empty_string(x):
1192
return x != ''

tests/core/utilities/conftest.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pytest
2+
3+
from web3.main import (
4+
Web3,
5+
)
6+
from web3.providers.eth_tester import (
7+
EthereumTesterProvider,
8+
)
9+
10+
11+
@pytest.fixture(scope="module")
12+
def web3():
13+
provider = EthereumTesterProvider()
14+
return Web3(provider)

0 commit comments

Comments
 (0)