Skip to content

Commit c7b9771

Browse files
reedsafselmo
andauthored
[V6] geth --dev test fixture setup (#3209)
* WIP: Generate geth fixture for shanghai with clique consensus * Initial squashed commits for getting ``geth --dev`` test fixture working: - Quicker timeout for unmined wait-for-txn-receipt tests - Update default fees test for geth --dev mode - Get rid of all miner start() and stop() references - Run integration tests with --dev flag - Test refactoring for ``geth --dev`` test fixture setup - Remove PoW related endpoint tests; TODO: remove / deprecate endpoints - Support latest geth versions - Update geth version in circleCI config + peripherally related changes - Turn on PoS block identifier tests - get geth --dev test suite working * Updates towards ``geth --dev`` test fixture: - Flaky for replace transaction - Fix typing - Loosen assertions on gas - Nonce value fix - Loosen asserts for default maxFeePerGas and maxPriorityFeePerGas tests * ``geth --dev`` test fixture tweaks: - Add @flaky to tests that expect mining at certain times - This isn't ideal. Perhaps we can increase the ``dev.period`` (mining interval) to make these tests a bit more reliable and hopefully the other tests are unaffected. - Update benchmark to run with ``geth --dev`` setup - Put back old state of get_logs_without_logs for eth_tester * More work towards ``geth --dev`` test fixture: - Try with --dev.period=5 - Remove assert from test_eth_new_block_filter - Remove sleep from test_web3_client_version - Try without flaky - Fixes test_eth_send_transaction_with_nonce without the need for retries. - Retries were causing transactions to be sent with the same nonce, which in turn requires more gas to go through. Running the test once fixes this issue. - Obtain the transaction count providing the 'pending' argument. - Fix test_eth_send_transaction_no_max_fee * Additional cleanup for ``geth --dev`` test fixture * Sync with feedback in #3191 for ``geth --dev`` test fixture --------- Co-authored-by: fselmo <[email protected]>
1 parent 34e0409 commit c7b9771

25 files changed

+171
-343
lines changed

.circleci/config.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2.1
33
parameters:
44
geth_version:
55
# update default value when updating geth integration test fixture
6-
default: "v1.11.6"
6+
default: "v1.13.9"
77
type: string
88
pygeth_version:
99
# update default value when updating geth integration test fixture
@@ -107,7 +107,6 @@ geth_steps: &geth_steps
107107
fi
108108
sudo ln -s /home/circleci/.py-geth/geth-<< pipeline.parameters.geth_version >>/bin/geth /usr/local/bin/geth
109109
geth version
110-
geth makedag 0 $HOME/.ethash
111110
- run:
112111
name: run tox
113112
command: python -m tox -r
@@ -148,7 +147,6 @@ geth_custom_steps: &geth_custom_steps
148147
sudo apt-get update;
149148
sudo apt-get install -y build-essential;
150149
./custom_geth version
151-
./custom_geth makedag 0 $HOME/.ethash
152150
- run:
153151
name: run tox
154152
command: python -m tox -r

docs/contributing.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,13 @@ Geth Fixtures
373373

374374
.. code:: sh
375375
376-
$ python -m geth.install v1.11.6
376+
$ python -m geth.install v1.13.9
377377
378378
2. Specify the Geth binary and run the fixture creation script (from within the web3.py directory):
379379

380380
.. code:: sh
381381
382-
$ GETH_BINARY=~/.py-geth/geth-v1.11.6/bin/geth python ./tests/integration/generate_fixtures/go_ethereum.py ./tests/integration/geth-1.11.6-fixture
382+
$ GETH_BINARY=~/.py-geth/geth-v1.13.9/bin/geth python ./tests/integration/generate_fixtures/go_ethereum.py ./tests/integration/geth-1.13.9-fixture
383383
384384
3. The output of this script is your fixture, a zip file, which is now stored in ``/tests/integration/``.
385385
Update the ``/tests/integration/go_ethereum/conftest.py`` and

newsfragments/3191.internal.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Create test fixture for latest ``geth`` version. Run tests with ``geth`` in ``--dev`` mode.

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
extras_require = {
88
"tester": [
99
"eth-tester[py-evm]==v0.9.1-b.1",
10-
"py-geth>=3.11.0",
10+
"py-geth>=3.14.0",
1111
],
1212
"linter": [
1313
"black>=22.1.0",

tests/core/mining-module/conftest.py

-11
This file was deleted.

tests/core/mining-module/test_miner_hashrate.py

-11
This file was deleted.

tests/core/mining-module/test_miner_setExtra.py

-39
This file was deleted.

tests/core/mining-module/test_miner_setGasPrice.py

-28
This file was deleted.

tests/core/mining-module/test_miner_start.py

-34
This file was deleted.

tests/core/mining-module/test_miner_stop.py

-27
This file was deleted.

tests/core/mining-module/test_setEtherBase.py

-6
This file was deleted.

tests/integration/generate_fixtures/common.py

+12-30
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
from web3 import (
1616
constants,
1717
)
18-
from web3.exceptions import (
19-
TransactionNotFound,
20-
)
2118

2219
# use same coinbase value as in `web3.py/tests/integration/common.py`
2320
COINBASE = "0xdc544d1aa88ff8bbd2f2aec754b1f1e99e1812fd"
@@ -26,6 +23,7 @@
2623
KEYFILE_DATA = '{"address":"dc544d1aa88ff8bbd2f2aec754b1f1e99e1812fd","crypto":{"cipher":"aes-128-ctr","ciphertext":"52e06bc9397ea9fa2f0dae8de2b3e8116e92a2ecca9ad5ff0061d1c449704e98","cipherparams":{"iv":"aa5d0a5370ef65395c1a6607af857124"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"9fdf0764eb3645ffc184e166537f6fe70516bf0e34dc7311dea21f100f0c9263"},"mac":"4e0b51f42b865c15c485f4faefdd1f01a38637e5247f8c75ffe6a8c0eba856f6"},"id":"5a6124e0-10f1-4c1c-ae3e-d903eacb740a","version":3}' # noqa: E501
2724

2825
KEYFILE_PW = "web3py-test"
26+
KEYFILE_PW_TXT = "pw.txt"
2927
KEYFILE_FILENAME = "UTC--2017-08-24T19-42-47.517572178Z--dc544d1aa88ff8bbd2f2aec754b1f1e99e1812fd" # noqa: E501
3028

3129
RAW_TXN_ACCOUNT = "0x39EEed73fb1D3855E90Cbd42f348b3D7b340aAA6"
@@ -40,20 +38,22 @@
4038
"config": {
4139
"chainId": 131277322940537, # the string 'web3py' as an integer
4240
"homesteadBlock": 0,
43-
"byzantiumBlock": 0,
44-
"constantinopleBlock": 0,
4541
"eip150Block": 0,
4642
"eip155Block": 0,
4743
"eip158Block": 0,
48-
"istanbulBlock": 0,
44+
"byzantiumBlock": 0,
45+
"constantinopleBlock": 0,
4946
"petersburgBlock": 0,
47+
"istanbulBlock": 0,
5048
"berlinBlock": 0,
5149
"londonBlock": 0,
5250
"arrowGlacierBlock": 0,
5351
"grayGlacierBlock": 0,
5452
"shanghaiTime": 0,
53+
"terminalTotalDifficulty": 0,
54+
"terminalTotalDifficultyPassed": True,
5555
},
56-
"nonce": "0x0000000000000042",
56+
"nonce": "0x0",
5757
"alloc": {
5858
COINBASE: {"balance": "1000000000000000000000000000"},
5959
UNLOCKABLE_ACCOUNT: {"balance": "1000000000000000000000000000"},
@@ -65,7 +65,7 @@
6565
"0000000000000000000000000000000000000005": {"balance": "1"},
6666
"0000000000000000000000000000000000000006": {"balance": "1"},
6767
},
68-
"timestamp": "0x00",
68+
"timestamp": "0x0",
6969
"parentHash": constants.HASH_ZERO,
7070
"extraData": "0x3535353535353535353535353535353535353535353535353535353535353535",
7171
"gasLimit": "0x3b9aca00", # 1,000,000,000
@@ -172,6 +172,9 @@ def get_geth_process(
172172
geth_binary,
173173
"--datadir",
174174
datadir,
175+
"--dev",
176+
"--dev.period",
177+
"1",
175178
"--ipcpath",
176179
ipc_path,
177180
"--nodiscover",
@@ -210,43 +213,22 @@ def mine_block(w3):
210213
origin_block_number = w3.eth.block_number
211214

212215
start_time = time.time()
213-
w3.geth.miner.start(1)
214216
while time.time() < start_time + 120:
215217
block_number = w3.eth.block_number
216218
if block_number > origin_block_number:
217-
w3.geth.miner.stop()
218219
return block_number
219220
else:
220221
time.sleep(0.1)
221222
else:
222223
raise ValueError("No block mined during wait period")
223224

224225

225-
def mine_transaction_hash(w3, txn_hash):
226-
start_time = time.time()
227-
w3.geth.miner.start(1)
228-
while time.time() < start_time + 120:
229-
try:
230-
receipt = w3.eth.get_transaction_receipt(txn_hash)
231-
except TransactionNotFound:
232-
continue
233-
if receipt is not None:
234-
w3.geth.miner.stop()
235-
return receipt
236-
else:
237-
time.sleep(0.1)
238-
else:
239-
raise ValueError(
240-
"Math contract deploy transaction not mined during wait period"
241-
)
242-
243-
244226
def deploy_contract(w3, name, factory):
245227
name = name.upper()
246228
w3.geth.personal.unlock_account(w3.eth.coinbase, KEYFILE_PW)
247229
deploy_txn_hash = factory.constructor().transact({"from": w3.eth.coinbase})
248230
print(f"{name}_CONTRACT_DEPLOY_HASH: {deploy_txn_hash}")
249-
deploy_receipt = mine_transaction_hash(w3, deploy_txn_hash)
231+
deploy_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn_hash)
250232
print(f"{name}_CONTRACT_DEPLOY_TRANSACTION_MINED")
251233
contract_address = deploy_receipt["contractAddress"]
252234
assert is_checksum_address(contract_address)

0 commit comments

Comments
 (0)