Skip to content

Commit cbba343

Browse files
committed
Additional cleanup for geth --dev`` test fixture
1 parent fd4eab0 commit cbba343

File tree

6 files changed

+39
-5
lines changed

6 files changed

+39
-5
lines changed

tests/integration/generate_fixtures/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
"timestamp": "0x0",
6969
"parentHash": constants.HASH_ZERO,
7070
"extraData": "0x3535353535353535353535353535353535353535353535353535353535353535",
71-
"difficulty": "0x1",
72-
"gasLimit": "0x1c9c380",
71+
"gasLimit": "0x3b9aca00", # 1,000,000,000
72+
"difficulty": "0x10000",
7373
"mixhash": constants.HASH_ZERO,
7474
"coinbase": COINBASE,
7575
}

tests/integration/generate_fixtures/go_ethereum.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,18 @@ def get_geth_process(geth_binary, datadir, genesis_file_path, geth_port, keyfile
8585

8686
run_geth_command = (
8787
geth_binary,
88-
"--datadir", # data dir for the db
88+
"--datadir",
8989
datadir,
9090
"--dev",
9191
"--dev.period",
9292
"1",
9393
"--port",
9494
geth_port,
95+
"--miner.etherbase",
96+
common.COINBASE[2:],
9597
"--password",
9698
keyfile_pw,
97-
"--rpc.enabledeprecatedpersonal", # Enables the (deprecated) personal namespace
99+
"--rpc.enabledeprecatedpersonal",
98100
)
99101

100102
popen_proc = subprocess.Popen(
935 Bytes
Binary file not shown.

tests/integration/go_ethereum/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def base_geth_command_arguments(geth_binary, datadir):
9696
str(datadir),
9797
"--dev",
9898
"--dev.period",
99-
"5",
99+
"5", # dev.period > 1 for tests which require pending blocks
100100
"--password",
101101
os.path.join(datadir, "keystore", "pw.txt"),
102102
)

web3/_utils/module_testing/eth_module.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
)
6464
from web3._utils.module_testing.utils import (
6565
RequestMocker,
66+
flaky_geth_dev_mining,
6667
)
6768
from web3._utils.type_conversion import (
6869
to_hex_if_bytes,
@@ -2070,6 +2071,7 @@ async def test_async_eth_sign_ens_names(
20702071
assert is_bytes(signature)
20712072
assert len(signature) == 32 + 32 + 1
20722073

2074+
@flaky_geth_dev_mining
20732075
@pytest.mark.asyncio
20742076
async def test_async_eth_replace_transaction_legacy(
20752077
self, async_w3: "AsyncWeb3", async_unlocked_account_dual_type: ChecksumAddress
@@ -2097,6 +2099,7 @@ async def test_async_eth_replace_transaction_legacy(
20972099
assert replace_txn["gas"] == 21000
20982100
assert replace_txn["gasPrice"] == txn_params["gasPrice"]
20992101

2102+
@flaky_geth_dev_mining
21002103
@pytest.mark.asyncio
21012104
async def test_async_eth_replace_transaction(
21022105
self, async_w3: "AsyncWeb3", async_unlocked_account_dual_type: ChecksumAddress
@@ -2131,6 +2134,7 @@ async def test_async_eth_replace_transaction(
21312134
assert replace_txn["maxFeePerGas"] == three_gwei_in_wei
21322135
assert replace_txn["maxPriorityFeePerGas"] == two_gwei_in_wei
21332136

2137+
@flaky_geth_dev_mining
21342138
@pytest.mark.asyncio
21352139
async def test_async_eth_replace_transaction_underpriced(
21362140
self, async_w3: "AsyncWeb3", async_unlocked_account_dual_type: ChecksumAddress
@@ -2152,6 +2156,7 @@ async def test_async_eth_replace_transaction_underpriced(
21522156
with pytest.raises(ValueError, match="replacement transaction underpriced"):
21532157
await async_w3.eth.replace_transaction(txn_hash, txn_params)
21542158

2159+
@flaky_geth_dev_mining
21552160
@pytest.mark.asyncio
21562161
async def test_async_eth_replace_transaction_non_existing_transaction(
21572162
self, async_w3: "AsyncWeb3", async_unlocked_account_dual_type: ChecksumAddress
@@ -2172,6 +2177,7 @@ async def test_async_eth_replace_transaction_non_existing_transaction(
21722177
txn_params,
21732178
)
21742179

2180+
@flaky_geth_dev_mining
21752181
@pytest.mark.asyncio
21762182
async def test_async_eth_replace_transaction_already_mined(
21772183
self, async_w3: "AsyncWeb3", async_unlocked_account_dual_type: ChecksumAddress
@@ -2192,6 +2198,7 @@ async def test_async_eth_replace_transaction_already_mined(
21922198
with pytest.raises(ValueError, match="Supplied transaction with hash"):
21932199
await async_w3.eth.replace_transaction(txn_hash, txn_params)
21942200

2201+
@flaky_geth_dev_mining
21952202
@pytest.mark.asyncio
21962203
async def test_async_eth_replace_transaction_incorrect_nonce(
21972204
self, async_w3: "AsyncWeb3", async_unlocked_account: ChecksumAddress
@@ -2213,6 +2220,7 @@ async def test_async_eth_replace_transaction_incorrect_nonce(
22132220
with pytest.raises(ValueError):
22142221
await async_w3.eth.replace_transaction(txn_hash, txn_params)
22152222

2223+
@flaky_geth_dev_mining
22162224
@pytest.mark.asyncio
22172225
async def test_async_eth_replace_transaction_gas_price_too_low(
22182226
self, async_w3: "AsyncWeb3", async_unlocked_account_dual_type: ChecksumAddress
@@ -2230,6 +2238,7 @@ async def test_async_eth_replace_transaction_gas_price_too_low(
22302238
with pytest.raises(ValueError):
22312239
await async_w3.eth.replace_transaction(txn_hash, txn_params)
22322240

2241+
@flaky_geth_dev_mining
22332242
@pytest.mark.asyncio
22342243
async def test_async_eth_replace_transaction_gas_price_defaulting_minimum(
22352244
self, async_w3: "AsyncWeb3", async_unlocked_account: ChecksumAddress
@@ -2253,6 +2262,7 @@ async def test_async_eth_replace_transaction_gas_price_defaulting_minimum(
22532262
gas_price * 1.125
22542263
) # minimum gas price
22552264

2265+
@flaky_geth_dev_mining
22562266
@pytest.mark.asyncio
22572267
async def test_async_eth_replace_transaction_gas_price_defaulting_strategy_higher(
22582268
self, async_w3: "AsyncWeb3", async_unlocked_account: ChecksumAddress
@@ -2281,6 +2291,7 @@ def higher_gas_price_strategy(async_w3: "AsyncWeb3", txn: TxParams) -> Wei:
22812291
) # Strategy provides higher gas price
22822292
async_w3.eth.set_gas_price_strategy(None) # reset strategy
22832293

2294+
@flaky_geth_dev_mining
22842295
@pytest.mark.asyncio
22852296
async def test_async_eth_replace_transaction_gas_price_defaulting_strategy_lower(
22862297
self, async_w3: "AsyncWeb3", async_unlocked_account: ChecksumAddress
@@ -3254,6 +3265,7 @@ def gas_price_strategy(_w3: "Web3", _txn: TxParams) -> str:
32543265
assert txn["gasPrice"] == two_gwei_in_wei
32553266
w3.eth.set_gas_price_strategy(None) # reset strategy
32563267

3268+
@flaky_geth_dev_mining
32573269
def test_eth_replace_transaction_legacy(
32583270
self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress
32593271
) -> None:
@@ -3282,6 +3294,7 @@ def test_eth_replace_transaction_legacy(
32823294
assert replace_txn["gas"] == 21000
32833295
assert replace_txn["gasPrice"] == txn_params["gasPrice"]
32843296

3297+
@flaky_geth_dev_mining
32853298
def test_eth_replace_transaction(
32863299
self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress
32873300
) -> None:
@@ -3315,6 +3328,7 @@ def test_eth_replace_transaction(
33153328
assert replace_txn["maxFeePerGas"] == three_gwei_in_wei
33163329
assert replace_txn["maxPriorityFeePerGas"] == two_gwei_in_wei
33173330

3331+
@flaky_geth_dev_mining
33183332
def test_eth_replace_transaction_underpriced(
33193333
self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress
33203334
) -> None:
@@ -3335,6 +3349,7 @@ def test_eth_replace_transaction_underpriced(
33353349
with pytest.raises(ValueError, match="replacement transaction underpriced"):
33363350
w3.eth.replace_transaction(txn_hash, txn_params)
33373351

3352+
@flaky_geth_dev_mining
33383353
def test_eth_replace_transaction_non_existing_transaction(
33393354
self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress
33403355
) -> None:
@@ -3354,6 +3369,7 @@ def test_eth_replace_transaction_non_existing_transaction(
33543369
txn_params,
33553370
)
33563371

3372+
@flaky_geth_dev_mining
33573373
def test_eth_replace_transaction_already_mined(
33583374
self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress
33593375
) -> None:
@@ -3373,6 +3389,7 @@ def test_eth_replace_transaction_already_mined(
33733389
with pytest.raises(ValueError, match="Supplied transaction with hash"):
33743390
w3.eth.replace_transaction(txn_hash, txn_params)
33753391

3392+
@flaky_geth_dev_mining
33763393
def test_eth_replace_transaction_incorrect_nonce(
33773394
self, w3: "Web3", unlocked_account: ChecksumAddress
33783395
) -> None:
@@ -3393,6 +3410,7 @@ def test_eth_replace_transaction_incorrect_nonce(
33933410
with pytest.raises(ValueError):
33943411
w3.eth.replace_transaction(txn_hash, txn_params)
33953412

3413+
@flaky_geth_dev_mining
33963414
def test_eth_replace_transaction_gas_price_too_low(
33973415
self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress
33983416
) -> None:
@@ -3409,6 +3427,7 @@ def test_eth_replace_transaction_gas_price_too_low(
34093427
with pytest.raises(ValueError):
34103428
w3.eth.replace_transaction(txn_hash, txn_params)
34113429

3430+
@flaky_geth_dev_mining
34123431
def test_eth_replace_transaction_gas_price_defaulting_minimum(
34133432
self, w3: "Web3", unlocked_account: ChecksumAddress
34143433
) -> None:
@@ -3431,6 +3450,7 @@ def test_eth_replace_transaction_gas_price_defaulting_minimum(
34313450
gas_price * 1.125
34323451
) # minimum gas price
34333452

3453+
@flaky_geth_dev_mining
34343454
def test_eth_replace_transaction_gas_price_defaulting_strategy_higher(
34353455
self, w3: "Web3", unlocked_account: ChecksumAddress
34363456
) -> None:
@@ -3458,6 +3478,7 @@ def higher_gas_price_strategy(w3: "Web3", txn: TxParams) -> Wei:
34583478
) # Strategy provides higher gas price
34593479
w3.eth.set_gas_price_strategy(None) # reset strategy
34603480

3481+
@flaky_geth_dev_mining
34613482
def test_eth_replace_transaction_gas_price_defaulting_strategy_lower(
34623483
self, w3: "Web3", unlocked_account: ChecksumAddress
34633484
) -> None:

web3/_utils/module_testing/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
cast,
1111
)
1212

13+
from flaky import (
14+
flaky,
15+
)
1316
from toolz import (
1417
merge,
1518
)
@@ -30,6 +33,14 @@
3033
)
3134

3235

36+
"""
37+
flaky_geth_dev_mining decorator for tests requiring a pending block
38+
for the duration of the test. This behavior can be flaky
39+
due to timing of the test running as a block is mined.
40+
"""
41+
flaky_geth_dev_mining = flaky(max_runs=3)
42+
43+
3344
class RequestMocker:
3445
"""
3546
Context manager to mock requests made by a web3 instance. This is meant to be used

0 commit comments

Comments
 (0)