Skip to content

Commit 0354ccd

Browse files
committed
eip7748: cover tx revertions in tx generating stale data accounts
Signed-off-by: Ignacio Hagopian <[email protected]>
1 parent fd7c0ae commit 0354ccd

File tree

1 file changed

+49
-13
lines changed

1 file changed

+49
-13
lines changed

tests/verkle/eip7748/modified_accounts.py

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@
99
REFERENCE_SPEC_VERSION = "TODO"
1010

1111

12+
class StaleAccountTx:
13+
"""
14+
Class to represent a transaction that modifies an account to be converted, making it completely/partially stale.
15+
It can be configured to:
16+
- be in the same block as the conversion transaction or in a previous block
17+
- revert or not revert
18+
"""
19+
20+
def __init__(self, same_block_as_conversion: bool, revert: bool):
21+
self.same_block_as_conversion = same_block_as_conversion
22+
self.revert = revert
23+
24+
1225
@pytest.mark.valid_from("EIP6800Transition")
1326
@pytest.mark.parametrize(
1427
"storage_slot_write",
@@ -32,14 +45,23 @@
3245
[True, False],
3346
)
3447
@pytest.mark.parametrize(
35-
"modification_overlap_conversion",
36-
[True, False],
48+
"tx_stale_account_config",
49+
[
50+
StaleAccountTx(False, False),
51+
StaleAccountTx(True, False),
52+
StaleAccountTx(True, True),
53+
],
54+
ids=[
55+
"Tx generating stale account in previous block",
56+
"Tx generating stale account in the same block",
57+
"Reverted tx generating stale account in the same block",
58+
],
3759
)
3860
def test_modified_contract(
3961
blockchain_test: BlockchainTestFiller,
4062
storage_slot_write: int,
4163
tx_send_value: bool,
42-
modification_overlap_conversion: bool,
64+
tx_stale_account_config: StaleAccountTx,
4365
):
4466
"""
4567
Test converting a modified contract where a previous transaction writes to:
@@ -52,22 +74,29 @@ def test_modified_contract(
5274
blockchain_test,
5375
tx_send_value,
5476
ContractSetup(storage_slot_write),
55-
modification_overlap_conversion,
77+
tx_stale_account_config,
5678
)
5779

5880

5981
@pytest.mark.valid_from("EIP6800Transition")
6082
@pytest.mark.parametrize(
61-
"modification_overlap_conversion",
62-
[True, False],
83+
"tx_stale_account_config",
84+
[
85+
StaleAccountTx(False, False),
86+
StaleAccountTx(True, False),
87+
],
88+
ids=[
89+
"Tx generating stale account in previous block",
90+
"Tx generating stale account in the same block",
91+
],
6392
)
6493
def test_modified_eoa(
65-
blockchain_test: BlockchainTestFiller, modification_overlap_conversion: bool
94+
blockchain_test: BlockchainTestFiller, tx_stale_account_config: StaleAccountTx
6695
):
6796
"""
6897
Test converting a modified EOA in the same block or previous block as the conversion.
6998
"""
70-
_convert_modified_account(blockchain_test, True, None, modification_overlap_conversion)
99+
_convert_modified_account(blockchain_test, True, None, tx_stale_account_config)
71100

72101

73102
class ContractSetup:
@@ -79,14 +108,14 @@ def _convert_modified_account(
79108
blockchain_test: BlockchainTestFiller,
80109
tx_send_value: bool,
81110
contract_setup: Optional[ContractSetup],
82-
modification_overlap_conversion: bool,
111+
tx_stale_account_config: StaleAccountTx,
83112
):
84113
pre_state = {}
85114
pre_state[TestAddress] = Account(balance=1000000000000000000000)
86115

87116
expected_conversion_blocks = 1
88117
accounts_idx = 0
89-
if not modification_overlap_conversion:
118+
if not tx_stale_account_config.same_block_as_conversion:
90119
expected_conversion_blocks = 2
91120
# TODO(hack): today the testing-framework does not support us signaling that we want to
92121
# put the `ConversionTx(tx, **0**)` at the first block after genesis. To simulate that, we have
@@ -102,13 +131,20 @@ def _convert_modified_account(
102131
balance=1_000,
103132
nonce=0,
104133
code=(
105-
Op.SSTORE(contract_setup.storage_slot_write, 9999)
106-
if contract_setup.storage_slot_write is not None
107-
else []
134+
(
135+
Op.SSTORE(contract_setup.storage_slot_write, 9999)
136+
if contract_setup.storage_slot_write is not None
137+
else Op.RETURN
138+
)
139+
+ Op.REVERT
140+
if tx_stale_account_config.revert
141+
else Op.RETURN
108142
),
109143
storage={0: 100, 300: 200},
110144
)
111145
else:
146+
if tx_stale_account_config.revert:
147+
raise Exception("Invalid test case -- EOA transfers can't revert")
112148
pre_state[target_account] = Account(balance=10_000, nonce=0)
113149

114150
tx = Transaction(

0 commit comments

Comments
 (0)