14
14
from eth .tools .factories .transaction import (
15
15
new_dynamic_fee_transaction , new_transaction ,
16
16
)
17
- from eth .vm .message import Message
18
17
19
18
FOUR_TXN_GAS_LIMIT = 21000 * 4
20
19
57
56
)
58
57
59
58
60
- def _configure_mining_chain (name , request ):
59
+ def _configure_mining_chain (name , genesis_vm , vm_under_test ):
61
60
return MiningChain .configure (
62
61
__name__ = name ,
63
62
vm_configuration = (
64
63
(
65
64
constants .GENESIS_BLOCK_NUMBER ,
66
- BerlinVM .configure (consensus_class = NoProofConsensus ),
65
+ genesis_vm .configure (consensus_class = NoProofConsensus ),
67
66
),
68
67
(
69
68
constants .GENESIS_BLOCK_NUMBER + 1 ,
70
- request . param .configure (consensus_class = NoProofConsensus ),
69
+ vm_under_test .configure (consensus_class = NoProofConsensus ),
71
70
),
72
71
),
73
72
chain_id = 1337 ,
@@ -77,7 +76,9 @@ def _configure_mining_chain(name, request):
77
76
# VMs starting at London
78
77
@pytest .fixture (params = MAINNET_VMS [9 :])
79
78
def london_plus_miner (request , base_db , genesis_state ):
80
- klass = _configure_mining_chain ('LondonAt1' , request )
79
+ vm_under_test = request .param
80
+
81
+ klass = _configure_mining_chain ('LondonAt1' , BerlinVM , vm_under_test )
81
82
header_fields = dict (
82
83
difficulty = 1 ,
83
84
gas_limit = 21000 * 2 , # block limit is hit with two transactions
@@ -90,7 +91,9 @@ def london_plus_miner(request, base_db, genesis_state):
90
91
# VMs up to, but not including, London
91
92
@pytest .fixture (params = MAINNET_VMS [0 :9 ])
92
93
def pre_london_miner (request , base_db , genesis_state ):
93
- klass = _configure_mining_chain ('EndsBeforeLondon' , request )
94
+ vm_under_test = request .param
95
+
96
+ klass = _configure_mining_chain ('EndsBeforeLondon' , MAINNET_VMS [0 ], vm_under_test )
94
97
header_fields = dict (
95
98
difficulty = 1 ,
96
99
gas_limit = 100000 , # arbitrary, just enough for testing
@@ -145,41 +148,37 @@ def test_base_fee_evolution(
145
148
EIP_3541_CREATE_AND_CREATE2_REVERT_TEST_CASES
146
149
)
147
150
def test_revert_on_reserved_0xEF_byte_for_CREATE_and_CREATE2_post_london (
148
- london_plus_miner , transaction_context , funded_address , code , data ,
151
+ london_plus_miner , funded_address , code , data ,
149
152
):
150
153
chain = london_plus_miner
151
- state = chain .get_vm (). state
154
+ vm = chain .get_vm ()
152
155
153
156
# test positive case from https://eips.ethereum.org/EIPS/eip-3541#test-cases
154
- create_message = Message (
157
+ successful_create_computation = vm .execute_bytecode (
158
+ origin = funded_address ,
155
159
to = funded_address ,
156
160
sender = funded_address ,
157
161
value = 0 ,
158
162
code = code ,
159
163
data = decode_hex ("0x60fe60005360016000f3" ),
160
164
gas = 400000 ,
161
- )
162
-
163
- successful_create_computation = state .computation_class .apply_create_message (
164
- state , create_message , transaction_context
165
+ gas_price = 1 ,
165
166
)
166
167
167
168
assert successful_create_computation .is_success
168
- # gas used varies between 32261 and 32270 depending on test case
169
+ # assert only the appropriate gas is consumed, not all the gas. This falls within a range
169
170
assert 32261 <= successful_create_computation .get_gas_used () <= 32270
170
171
171
172
# test parameterized negative cases
172
- reverted_create_message = Message (
173
+ revert_create_computation = vm .execute_bytecode (
174
+ origin = funded_address ,
173
175
to = funded_address ,
174
176
sender = funded_address ,
175
177
value = 0 ,
176
178
code = code ,
177
179
data = data ,
178
180
gas = 40000 ,
179
- )
180
-
181
- revert_create_computation = state .computation_class .apply_create_message (
182
- state , reverted_create_message , transaction_context
181
+ gas_price = 1 ,
183
182
)
184
183
185
184
assert revert_create_computation .is_error
@@ -275,32 +274,30 @@ def test_state_revert_on_reserved_0xEF_byte_for_create_transaction_post_london(
275
274
assert "0xef" in repr (reverted_computation .error ).lower ()
276
275
277
276
assert reverted_computation .get_nonce (funded_address ) == 1 # assert nonce is still 1
278
- # reverted txn only consumes gas:
279
- assert end_balance == new_balance - mined_header .gas_used
277
+ # reverted txn consumes the gas:
278
+ assert mined_header .gas_used == 60000
279
+ assert end_balance == new_balance - 60000
280
280
281
281
282
282
@pytest .mark .parametrize (
283
283
"code, data" ,
284
284
EIP_3541_CREATE_AND_CREATE2_REVERT_TEST_CASES
285
285
)
286
286
def test_state_does_not_revert_on_reserved_0xEF_byte_for_CREATE_and_CREATE2_pre_london (
287
- pre_london_miner , transaction_context , funded_address , code , data ,
287
+ pre_london_miner , funded_address , code , data ,
288
288
):
289
289
chain = pre_london_miner
290
290
vm = chain .get_vm ()
291
- state = vm .state
292
291
293
- create_message = Message (
292
+ computation = vm .execute_bytecode (
293
+ origin = funded_address ,
294
294
to = funded_address ,
295
295
sender = funded_address ,
296
296
value = 0 ,
297
297
code = code ,
298
298
data = data ,
299
299
gas = 40000 ,
300
- )
301
-
302
- computation = state .computation_class .apply_create_message (
303
- state , create_message , transaction_context
300
+ gas_price = 1 ,
304
301
)
305
302
306
303
if computation .is_error :
@@ -311,7 +308,7 @@ def test_state_does_not_revert_on_reserved_0xEF_byte_for_CREATE_and_CREATE2_pre_
311
308
312
309
else :
313
310
assert computation .is_success
314
- # gas used varies between 32670 and 38470 depending on test case
311
+ # assert only the appropriate gas is consumed, not all the gas. This falls within a range
315
312
assert 32261 <= computation .get_gas_used () <= 38470
316
313
assert computation .get_gas_refund () == 0
317
314
0 commit comments