Skip to content

Commit fd7c0ae

Browse files
committed
eip-7748: add tests for stale data happening in the same block as the one converting accounts
Signed-off-by: Ignacio Hagopian <[email protected]>
1 parent 55af989 commit fd7c0ae

File tree

1 file changed

+47
-16
lines changed

1 file changed

+47
-16
lines changed

tests/verkle/eip7748/modified_accounts.py

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,43 @@
3131
"tx_send_value",
3232
[True, False],
3333
)
34+
@pytest.mark.parametrize(
35+
"modification_overlap_conversion",
36+
[True, False],
37+
)
3438
def test_modified_contract(
35-
blockchain_test: BlockchainTestFiller, storage_slot_write: int, tx_send_value: bool
39+
blockchain_test: BlockchainTestFiller,
40+
storage_slot_write: int,
41+
tx_send_value: bool,
42+
modification_overlap_conversion: bool,
3643
):
3744
"""
3845
Test converting a modified contract where a previous transaction writes to:
3946
- Existing storage slots (i.e., storage slots that must not be converted (stale))
4047
- New storage slots (i.e., storage slots that must not be converted (not overriden with zeros))
4148
- Basic data (i.e., balance/nonce which must not be converted (stale))
49+
The conversion transaction can be in the same block or previous block as the conversion.
4250
"""
43-
_convert_modified_account(blockchain_test, tx_send_value, ContractSetup(storage_slot_write))
51+
_convert_modified_account(
52+
blockchain_test,
53+
tx_send_value,
54+
ContractSetup(storage_slot_write),
55+
modification_overlap_conversion,
56+
)
4457

4558

4659
@pytest.mark.valid_from("EIP6800Transition")
60+
@pytest.mark.parametrize(
61+
"modification_overlap_conversion",
62+
[True, False],
63+
)
4764
def test_modified_eoa(
48-
blockchain_test: BlockchainTestFiller,
65+
blockchain_test: BlockchainTestFiller, modification_overlap_conversion: bool
4966
):
5067
"""
51-
Test converting a modified EOA.
68+
Test converting a modified EOA in the same block or previous block as the conversion.
5269
"""
53-
_convert_modified_account(blockchain_test, True, None)
70+
_convert_modified_account(blockchain_test, True, None, modification_overlap_conversion)
5471

5572

5673
class ContractSetup:
@@ -62,18 +79,24 @@ def _convert_modified_account(
6279
blockchain_test: BlockchainTestFiller,
6380
tx_send_value: bool,
6481
contract_setup: Optional[ContractSetup],
82+
modification_overlap_conversion: bool,
6583
):
6684
pre_state = {}
6785
pre_state[TestAddress] = Account(balance=1000000000000000000000)
6886

69-
# TODO(hack): today the testing-framework does not support us signaling that we want to
70-
# put the `ConversionTx(tx, **0**)` at the first block after genesis. To simulate that, we have
71-
# to do this here so we "shift" the target account to the second block in the fork.
72-
# If this is ever supported, remove this.
73-
for i in range(stride):
74-
pre_state[accounts[i]] = Account(balance=100 + 1000 * i)
75-
76-
target_account = accounts[stride]
87+
expected_conversion_blocks = 1
88+
accounts_idx = 0
89+
if not modification_overlap_conversion:
90+
expected_conversion_blocks = 2
91+
# TODO(hack): today the testing-framework does not support us signaling that we want to
92+
# put the `ConversionTx(tx, **0**)` at the first block after genesis. To simulate that, we have
93+
# to do this here so we "shift" the target account to the second block in the fork.
94+
# If this is ever supported, remove this.
95+
for i in range(stride):
96+
pre_state[accounts[accounts_idx]] = Account(balance=100 + 1000 * i)
97+
accounts_idx += 1
98+
99+
target_account = accounts[accounts_idx]
77100
if contract_setup is not None:
78101
pre_state[target_account] = Account(
79102
balance=1_000,
@@ -86,18 +109,24 @@ def _convert_modified_account(
86109
storage={0: 100, 300: 200},
87110
)
88111
else:
89-
pre_state[target_account] = Account(balance=1_000, nonce=0)
112+
pre_state[target_account] = Account(balance=10_000, nonce=0)
90113

91114
tx = Transaction(
92115
ty=0x0,
93116
chain_id=0x01,
94117
to=target_account,
95-
value=100 if tx_send_value else 0,
118+
value=500 if tx_send_value else 0,
96119
gas_limit=100_000,
97120
gas_price=10,
98121
)
99122

100-
_state_conversion(blockchain_test, pre_state, stride, 2, [ConversionTx(tx, 0)])
123+
_state_conversion(
124+
blockchain_test,
125+
pre_state,
126+
stride,
127+
expected_conversion_blocks,
128+
[ConversionTx(tx, 0)],
129+
)
101130

102131

103132
@pytest.mark.valid_from("EIP6800Transition")
@@ -116,6 +145,8 @@ def test_modified_eoa_conversion_units(blockchain_test: BlockchainTestFiller):
116145
pre_state[accounts[i]] = Account(balance=100 + 1000 * i)
117146

118147
txs = []
148+
# Add stride+3 extra EOAs, and invalidate the first stride ones. This is to check that
149+
# the conversion units are properly counted, and the last 3 aren't converted in that block.
119150
for i in range(stride + 3):
120151
pre_state[accounts[stride + i]] = Account(balance=1_000, nonce=0)
121152
if i < stride:

0 commit comments

Comments
 (0)