Skip to content

Commit

Permalink
Make old contract state test more stable
Browse files Browse the repository at this point in the history
  • Loading branch information
fselmo committed Apr 16, 2024
1 parent 3c8c98f commit b0598af
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import math
import time
import pytest
from random import (
randint,
Expand Down Expand Up @@ -4663,35 +4664,30 @@ def test_eth_call_old_contract_state(
math_contract: "Contract",
keyfile_account_address: ChecksumAddress,
) -> None:
start_block = w3.eth.get_block("latest")
block_num = start_block["number"]
block_hash = start_block["hash"]
latest_block = w3.eth.get_block("latest")
block_num = latest_block["number"]
block_hash = latest_block["hash"]

math_contract.functions.incrementCounter().transact(
{"from": keyfile_account_address}
latest_call_result = math_contract.functions.counter().call(
block_identifier="latest"
)

# This isn't an incredibly convincing test since we can't mine, and
# the default resolved block is latest, So if block_identifier was ignored
# we would get the same result. For now, we mostly depend on core tests.
# Ideas to improve this test:
# - Enable on-demand mining in more clients
# - Increment the math contract in all of the fixtures, and check the
# value in an old block
block_hash_call_result = math_contract.functions.counter().call(
block_identifier=block_hash
)
block_num_call_result = math_contract.functions.counter().call(
block_identifier=block_num
)
latest_call_result = math_contract.functions.counter().call(
block_identifier="latest"
)
default_call_result = math_contract.functions.counter().call()

# send and wait 1 second to mine
math_contract.functions.incrementCounter().transact(
{"from": keyfile_account_address}
)
time.sleep(1)

pending_call_result = math_contract.functions.counter().call(
block_identifier="pending"
)

assert block_hash_call_result == 0
assert block_num_call_result == 0
assert latest_call_result == 0
Expand Down

0 comments on commit b0598af

Please sign in to comment.