11import pytest
22
3+ from typing import Optional
34from ethereum_test_tools import BlockchainTestFiller , Transaction , Account , TestAddress
45from ethereum_test_tools .vm .opcode import Opcodes as Op
56from .utils import stride , _state_conversion , accounts , ConversionTx
2728 ],
2829)
2930@pytest .mark .parametrize (
30- "stale_basic_data " ,
31+ "tx_send_value " ,
3132 [True , False ],
3233)
3334def test_modified_contract (
3435 blockchain_test : BlockchainTestFiller ,
3536 storage_slot_write : int ,
36- stale_basic_data : bool ,
37+ tx_send_value : bool ,
3738):
3839 """
39- Test converting a contract where a previous transaction writes to:
40+ Test converting a modified contract where a previous transaction writes to:
4041 - Existing storage slots (i.e., storage slots that must not be converted (stale))
4142 - New storage slots (i.e., storage slots that must not be converted (not overriden with zeros))
4243 - Basic data (i.e., balance/nonce which must not be converted (stale))
4344 """
45+ _convert_modified_account (blockchain_test , tx_send_value , ContractSetup (storage_slot_write ))
46+
47+
48+ @pytest .mark .valid_from ("EIP6800Transition" )
49+ def test_modified_eoa (
50+ blockchain_test : BlockchainTestFiller ,
51+ ):
52+ """
53+ Test converting a modified EOA.
54+ """
55+ _convert_modified_account (blockchain_test , True , None )
56+
57+
58+ class ContractSetup :
59+ def __init__ (self , storage_slot_write : Optional [int ]):
60+ self .storage_slot_write = storage_slot_write
61+
62+
63+ def _convert_modified_account (
64+ blockchain_test : BlockchainTestFiller ,
65+ tx_send_value : bool ,
66+ contract_setup : Optional [ContractSetup ],
67+ ):
4468 pre_state = {}
4569 pre_state [TestAddress ] = Account (balance = 1000000000000000000000 )
4670
@@ -52,21 +76,25 @@ def test_modified_contract(
5276 pre_state [accounts [i ]] = Account (balance = 100 + 1000 * i )
5377
5478 target_account = accounts [stride ]
55- pre_state [target_account ] = Account (
56- balance = 1_000 ,
57- nonce = 0 ,
58- code = Op .SSTORE (storage_slot_write , 9999 ) if storage_slot_write is not None else [],
59- storage = {
60- 0 : 100 ,
61- 300 : 200 ,
62- },
63- )
79+ if contract_setup is not None :
80+ pre_state [target_account ] = Account (
81+ balance = 1_000 ,
82+ nonce = 0 ,
83+ code = (
84+ Op .SSTORE (contract_setup .storage_slot_write , 9999 )
85+ if contract_setup .storage_slot_write is not None
86+ else []
87+ ),
88+ storage = {0 : 100 , 300 : 200 },
89+ )
90+ else :
91+ pre_state [target_account ] = Account (balance = 1_000 , nonce = 0 )
6492
6593 tx = Transaction (
6694 ty = 0x0 ,
6795 chain_id = 0x01 ,
6896 to = target_account ,
69- value = 100 if stale_basic_data else 0 ,
97+ value = 100 if tx_send_value else 0 ,
7098 gas_limit = 100_000 ,
7199 gas_price = 10 ,
72100 )
0 commit comments