1
1
import pytest
2
2
3
+ from typing import Optional
3
4
from ethereum_test_tools import BlockchainTestFiller , Transaction , Account , TestAddress
4
5
from ethereum_test_tools .vm .opcode import Opcodes as Op
5
6
from .utils import stride , _state_conversion , accounts , ConversionTx
27
28
],
28
29
)
29
30
@pytest .mark .parametrize (
30
- "stale_basic_data " ,
31
+ "tx_send_value " ,
31
32
[True , False ],
32
33
)
33
34
def test_modified_contract (
34
35
blockchain_test : BlockchainTestFiller ,
35
36
storage_slot_write : int ,
36
- stale_basic_data : bool ,
37
+ tx_send_value : bool ,
37
38
):
38
39
"""
39
- Test converting a contract where a previous transaction writes to:
40
+ Test converting a modified contract where a previous transaction writes to:
40
41
- Existing storage slots (i.e., storage slots that must not be converted (stale))
41
42
- New storage slots (i.e., storage slots that must not be converted (not overriden with zeros))
42
43
- Basic data (i.e., balance/nonce which must not be converted (stale))
43
44
"""
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
+ ):
44
68
pre_state = {}
45
69
pre_state [TestAddress ] = Account (balance = 1000000000000000000000 )
46
70
@@ -52,21 +76,25 @@ def test_modified_contract(
52
76
pre_state [accounts [i ]] = Account (balance = 100 + 1000 * i )
53
77
54
78
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 )
64
92
65
93
tx = Transaction (
66
94
ty = 0x0 ,
67
95
chain_id = 0x01 ,
68
96
to = target_account ,
69
- value = 100 if stale_basic_data else 0 ,
97
+ value = 100 if tx_send_value else 0 ,
70
98
gas_limit = 100_000 ,
71
99
gas_price = 10 ,
72
100
)
0 commit comments