Skip to content

Commit 5aeb7f2

Browse files
committed
Make old contract state test more stable
1 parent a6ed522 commit 5aeb7f2

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

web3/_utils/module_testing/eth_module.py

+12-17
Original file line numberDiff line numberDiff line change
@@ -4663,35 +4663,30 @@ def test_eth_call_old_contract_state(
46634663
math_contract: "Contract",
46644664
keyfile_account_address: ChecksumAddress,
46654665
) -> None:
4666-
start_block = w3.eth.get_block("latest")
4667-
block_num = start_block["number"]
4668-
block_hash = start_block["hash"]
4666+
latest_block = w3.eth.get_block("latest")
4667+
block_num = latest_block["number"]
4668+
block_hash = latest_block["hash"]
46694669

4670-
math_contract.functions.incrementCounter().transact(
4671-
{"from": keyfile_account_address}
4670+
latest_call_result = math_contract.functions.counter().call(
4671+
block_identifier="latest"
46724672
)
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
46814673
block_hash_call_result = math_contract.functions.counter().call(
46824674
block_identifier=block_hash
46834675
)
46844676
block_num_call_result = math_contract.functions.counter().call(
46854677
block_identifier=block_num
46864678
)
4687-
latest_call_result = math_contract.functions.counter().call(
4688-
block_identifier="latest"
4689-
)
46904679
default_call_result = math_contract.functions.counter().call()
4680+
4681+
# send and wait 1 second to mine
4682+
math_contract.functions.incrementCounter().transact(
4683+
{"from": keyfile_account_address}
4684+
)
4685+
time.sleep(1)
4686+
46914687
pending_call_result = math_contract.functions.counter().call(
46924688
block_identifier="pending"
46934689
)
4694-
46954690
assert block_hash_call_result == 0
46964691
assert block_num_call_result == 0
46974692
assert latest_call_result == 0

0 commit comments

Comments
 (0)