@@ -135,23 +135,7 @@ def vm_class(request):
135
135
assert False , "Unsupported VM: {0}" .format (request .param )
136
136
137
137
138
- def test_vm_fixtures (fixture , vm_class ):
139
- chaindb = ChainDB (get_db_backend ())
140
- header = BlockHeader (
141
- coinbase = fixture ['env' ]['currentCoinbase' ],
142
- difficulty = fixture ['env' ]['currentDifficulty' ],
143
- block_number = fixture ['env' ]['currentNumber' ],
144
- gas_limit = fixture ['env' ]['currentGasLimit' ],
145
- timestamp = fixture ['env' ]['currentTimestamp' ],
146
- )
147
- vm = vm_class (header = header , chaindb = chaindb )
148
- vm_state = vm .state
149
- with vm_state .state_db () as state_db :
150
- setup_state_db (fixture ['pre' ], state_db )
151
- code = state_db .get_code (fixture ['exec' ]['address' ])
152
- # Update state_root manually
153
- vm .block .header .state_root = vm_state .state_root
154
-
138
+ def fixture_to_computation (fixture , code , vm ):
155
139
message = Message (
156
140
to = fixture ['exec' ]['address' ],
157
141
sender = fixture ['exec' ]['caller' ],
@@ -164,11 +148,52 @@ def test_vm_fixtures(fixture, vm_class):
164
148
origin = fixture ['exec' ]['origin' ],
165
149
gas_price = fixture ['exec' ]['gasPrice' ],
166
150
)
167
- computation = vm .state .get_computation (message , transaction_context ).apply_computation (
151
+ return vm .state .get_computation (message , transaction_context ).apply_computation (
168
152
vm .state ,
169
153
message ,
170
154
transaction_context ,
171
155
)
156
+
157
+
158
+ def fixture_to_bytecode_computation (fixture , code , vm ):
159
+ return vm .execute_bytecode (
160
+ origin = fixture ['exec' ]['origin' ],
161
+ gas_price = fixture ['exec' ]['gasPrice' ],
162
+ gas = fixture ['exec' ]['gas' ],
163
+ to = fixture ['exec' ]['address' ],
164
+ sender = fixture ['exec' ]['caller' ],
165
+ value = fixture ['exec' ]['value' ],
166
+ data = fixture ['exec' ]['data' ],
167
+ code = code ,
168
+ )
169
+
170
+
171
+ @pytest .mark .parametrize (
172
+ 'computation_getter' ,
173
+ (
174
+ fixture_to_bytecode_computation ,
175
+ fixture_to_computation ,
176
+ ),
177
+ )
178
+ def test_vm_fixtures (fixture , vm_class , computation_getter ):
179
+ chaindb = ChainDB (get_db_backend ())
180
+ header = BlockHeader (
181
+ coinbase = fixture ['env' ]['currentCoinbase' ],
182
+ difficulty = fixture ['env' ]['currentDifficulty' ],
183
+ block_number = fixture ['env' ]['currentNumber' ],
184
+ gas_limit = fixture ['env' ]['currentGasLimit' ],
185
+ timestamp = fixture ['env' ]['currentTimestamp' ],
186
+ )
187
+ vm = vm_class (header = header , chaindb = chaindb )
188
+ vm_state = vm .state
189
+ with vm_state .state_db () as state_db :
190
+ setup_state_db (fixture ['pre' ], state_db )
191
+ code = state_db .get_code (fixture ['exec' ]['address' ])
192
+ # Update state_root manually
193
+ vm .block .header .state_root = vm_state .state_root
194
+
195
+ computation = computation_getter (fixture , code , vm )
196
+
172
197
# Update state_root manually
173
198
vm .block .header .state_root = computation .vm_state .state_root
174
199
0 commit comments