Skip to content

Commit 0a39b5b

Browse files
committed
add stride stale contract storage slots
Signed-off-by: Ignacio Hagopian <[email protected]>
1 parent 06f3ba3 commit 0a39b5b

File tree

1 file changed

+75
-4
lines changed

1 file changed

+75
-4
lines changed

Diff for: tests/verkle/eip7748/modified_accounts.py

+75-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22

3+
from itertools import chain
34
from typing import Optional
45
from ethereum_test_tools import BlockchainTestFiller, Transaction, Account, TestAddress
56
from ethereum_test_tools.vm.opcode import Opcodes as Op
@@ -32,9 +33,7 @@
3233
[True, False],
3334
)
3435
def test_modified_contract(
35-
blockchain_test: BlockchainTestFiller,
36-
storage_slot_write: int,
37-
tx_send_value: bool,
36+
blockchain_test: BlockchainTestFiller, storage_slot_write: int, tx_send_value: bool
3837
):
3938
"""
4039
Test converting a modified contract where a previous transaction writes to:
@@ -99,4 +98,76 @@ def _convert_modified_account(
9998
gas_price=10,
10099
)
101100

102-
_state_conversion(blockchain_test, pre_state, stride, 1, [ConversionTx(tx, 0)])
101+
_state_conversion(blockchain_test, pre_state, stride, 2, [ConversionTx(tx, 0)])
102+
103+
104+
@pytest.mark.valid_from("EIP6800Transition")
105+
def test_modified_eoa_conversion_units(blockchain_test: BlockchainTestFiller):
106+
"""
107+
Test stale EOA are properly counted as used conversion units.
108+
"""
109+
pre_state = {}
110+
pre_state[TestAddress] = Account(balance=1000000000000000000000)
111+
112+
# TODO(hack): today the testing-framework does not support us signaling that we want to
113+
# put the `ConversionTx(tx, **0**)` at the first block after genesis. To simulate that, we have
114+
# to do this here so we "shift" the target account to the second block in the fork.
115+
# If this is ever supported, remove this.
116+
for i in range(stride):
117+
pre_state[accounts[i]] = Account(balance=100 + 1000 * i)
118+
119+
txs = []
120+
for i in range(stride + 3):
121+
pre_state[accounts[stride + i]] = Account(balance=1_000, nonce=0)
122+
if i < stride:
123+
tx = Transaction(
124+
ty=0x0,
125+
chain_id=0x01,
126+
nonce=i,
127+
to=accounts[stride + i],
128+
value=100,
129+
gas_limit=100_000,
130+
gas_price=10,
131+
)
132+
txs.append(ConversionTx(tx, 0))
133+
134+
_state_conversion(blockchain_test, pre_state, stride, 3, txs)
135+
136+
137+
@pytest.mark.valid_from("EIP6800Transition")
138+
def test_modified_contract_conversion_units(blockchain_test: BlockchainTestFiller):
139+
"""
140+
Test stale contract storage slots are properly counted as used conversion units.
141+
"""
142+
pre_state = {}
143+
pre_state[TestAddress] = Account(balance=1000000000000000000000)
144+
145+
# TODO(hack): today the testing-framework does not support us signaling that we want to
146+
# put the `ConversionTx(tx, **0**)` at the first block after genesis. To simulate that, we have
147+
# to do this here so we "shift" the target account to the second block in the fork.
148+
# If this is ever supported, remove this.
149+
for i in range(stride):
150+
pre_state[accounts[i]] = Account(balance=100 + 1000 * i)
151+
152+
target_account = accounts[stride]
153+
pre_state[target_account] = Account(
154+
balance=1_000,
155+
nonce=0,
156+
code=sum([Op.SSTORE(ss, 10_000 + i) for i, ss in enumerate(range(stride))]),
157+
storage={ss: 100 + i for i, ss in enumerate(range(stride))},
158+
)
159+
for i in range(3):
160+
pre_state[accounts[stride + 1 + i]] = Account(balance=1_000 + i, nonce=0)
161+
162+
# Send tx that writes all existing storage slots.
163+
tx = Transaction(
164+
ty=0x0,
165+
chain_id=0x01,
166+
nonce=0,
167+
to=target_account,
168+
value=100,
169+
gas_limit=100_000,
170+
gas_price=10,
171+
)
172+
173+
_state_conversion(blockchain_test, pre_state, stride, 3, [ConversionTx(tx, 0)])

0 commit comments

Comments
 (0)