Skip to content

Commit f56b684

Browse files
committed
Simplify old contract state test
1 parent f19eb42 commit f56b684

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

web3/_utils/module_testing/eth_module.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4645,38 +4645,37 @@ def test_eth_call_old_contract_state(
46454645
block_hash = current_block["hash"]
46464646

46474647
default_call_result = math_contract.functions.counter().call()
4648-
pre_state_change_latest = math_contract.functions.counter().call(
4648+
latest_call_result = math_contract.functions.counter().call(
46494649
block_identifier="latest"
46504650
)
46514651

4652-
# increment counter and wait 1 second to "mine" txn
4652+
# increment counter and get tx receipt
46534653
tx_hash = math_contract.functions.incrementCounter().transact(
46544654
{"from": keyfile_account_address}
46554655
)
4656-
w3.eth.wait_for_transaction_receipt(tx_hash)
4657-
# assert block number increased
4658-
assert w3.eth.get_block("latest")["number"] == block_num + 1
4656+
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
46594657

4658+
# get new state value
4659+
post_state_block_num_call_result = math_contract.functions.counter().call(
4660+
block_identifier=tx_receipt["blockNumber"]
4661+
)
4662+
4663+
# call old state values with different block identifiers
46604664
block_hash_call_result = math_contract.functions.counter().call(
46614665
block_identifier=block_hash
46624666
)
4663-
block_num_call_result = math_contract.functions.counter().call(
4667+
pre_state_block_num_call_result = math_contract.functions.counter().call(
46644668
block_identifier=block_num
46654669
)
46664670

4667-
# assert old state values
4671+
# assert old state values before incrementing counter
4672+
assert pre_state_block_num_call_result == post_state_block_num_call_result - 1
46684673
assert (
4669-
block_hash_call_result
4670-
== block_num_call_result
4674+
pre_state_block_num_call_result
4675+
== block_hash_call_result
46714676
== default_call_result
4672-
== pre_state_change_latest
4673-
)
4674-
4675-
# assert new state value
4676-
post_state_change_latest = math_contract.functions.counter().call(
4677-
block_identifier="latest"
4677+
== latest_call_result
46784678
)
4679-
assert post_state_change_latest == pre_state_change_latest + 1
46804679

46814680
def test_eth_uninstall_filter(self, w3: "Web3") -> None:
46824681
filter = w3.eth.filter({})

0 commit comments

Comments
 (0)