|
1 | 1 | import json
|
2 | 2 | import math
|
| 3 | +import time |
3 | 4 | import pytest
|
4 | 5 | from random import (
|
5 | 6 | randint,
|
@@ -4663,35 +4664,30 @@ def test_eth_call_old_contract_state(
|
4663 | 4664 | math_contract: "Contract",
|
4664 | 4665 | keyfile_account_address: ChecksumAddress,
|
4665 | 4666 | ) -> 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"] |
4669 | 4670 |
|
4670 |
| - math_contract.functions.incrementCounter().transact( |
4671 |
| - {"from": keyfile_account_address} |
| 4671 | + latest_call_result = math_contract.functions.counter().call( |
| 4672 | + block_identifier="latest" |
4672 | 4673 | )
|
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 |
4681 | 4674 | block_hash_call_result = math_contract.functions.counter().call(
|
4682 | 4675 | block_identifier=block_hash
|
4683 | 4676 | )
|
4684 | 4677 | block_num_call_result = math_contract.functions.counter().call(
|
4685 | 4678 | block_identifier=block_num
|
4686 | 4679 | )
|
4687 |
| - latest_call_result = math_contract.functions.counter().call( |
4688 |
| - block_identifier="latest" |
4689 |
| - ) |
4690 | 4680 | 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 | + |
4691 | 4688 | pending_call_result = math_contract.functions.counter().call(
|
4692 | 4689 | block_identifier="pending"
|
4693 | 4690 | )
|
4694 |
| - |
4695 | 4691 | assert block_hash_call_result == 0
|
4696 | 4692 | assert block_num_call_result == 0
|
4697 | 4693 | assert latest_call_result == 0
|
|
0 commit comments