Skip to content

Commit b0598af

Browse files
committed
Make old contract state test more stable
1 parent 3c8c98f commit b0598af

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

web3/_utils/module_testing/eth_module.py

+13-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import math
3+
import time
34
import pytest
45
from random import (
56
randint,
@@ -4663,35 +4664,30 @@ def test_eth_call_old_contract_state(
46634664
math_contract: "Contract",
46644665
keyfile_account_address: ChecksumAddress,
46654666
) -> None:
4666-
start_block = w3.eth.get_block("latest")
4667-
block_num = start_block["number"]
4668-
block_hash = start_block["hash"]
4667+
latest_block = w3.eth.get_block("latest")
4668+
block_num = latest_block["number"]
4669+
block_hash = latest_block["hash"]
46694670

4670-
math_contract.functions.incrementCounter().transact(
4671-
{"from": keyfile_account_address}
4671+
latest_call_result = math_contract.functions.counter().call(
4672+
block_identifier="latest"
46724673
)
4673-
4674-
# This isn't an incredibly convincing test since we can't mine, and
4675-
# the default resolved block is latest, So if block_identifier was ignored
4676-
# we would get the same result. For now, we mostly depend on core tests.
4677-
# Ideas to improve this test:
4678-
# - Enable on-demand mining in more clients
4679-
# - Increment the math contract in all of the fixtures, and check the
4680-
# value in an old block
46814674
block_hash_call_result = math_contract.functions.counter().call(
46824675
block_identifier=block_hash
46834676
)
46844677
block_num_call_result = math_contract.functions.counter().call(
46854678
block_identifier=block_num
46864679
)
4687-
latest_call_result = math_contract.functions.counter().call(
4688-
block_identifier="latest"
4689-
)
46904680
default_call_result = math_contract.functions.counter().call()
4681+
4682+
# send and wait 1 second to mine
4683+
math_contract.functions.incrementCounter().transact(
4684+
{"from": keyfile_account_address}
4685+
)
4686+
time.sleep(1)
4687+
46914688
pending_call_result = math_contract.functions.counter().call(
46924689
block_identifier="pending"
46934690
)
4694-
46954691
assert block_hash_call_result == 0
46964692
assert block_num_call_result == 0
46974693
assert latest_call_result == 0

0 commit comments

Comments
 (0)