@@ -241,10 +241,10 @@ mod tests {
241
241
use std:: hash:: DefaultHasher ;
242
242
243
243
use super :: * ;
244
- use reth_evm:: EvmInternals ;
244
+ use reth_evm:: { EthEvmFactory , Evm , EvmEnv , EvmFactory } ;
245
245
use reth_revm:: db:: EmptyDB ;
246
- use revm:: { context:: JournalTr , precompile:: PrecompileOutput , Journal } ;
247
- use revm_primitives:: { hardfork:: SpecId , U256 } ;
246
+ use revm:: { context:: TxEnv , precompile:: PrecompileOutput } ;
247
+ use revm_primitives:: hardfork:: SpecId ;
248
248
249
249
#[ test]
250
250
fn test_cache_key_ref_hash ( ) {
@@ -290,6 +290,7 @@ mod tests {
290
290
291
291
#[ test]
292
292
fn test_precompile_cache_map_separate_addresses ( ) {
293
+ let mut evm = EthEvmFactory :: default ( ) . create_evm ( EmptyDB :: default ( ) , EvmEnv :: default ( ) ) ;
293
294
let input_data = b"same_input" ;
294
295
let gas_limit = 100_000 ;
295
296
@@ -337,41 +338,56 @@ mod tests {
337
338
None ,
338
339
) ;
339
340
341
+ let precompile1_address = Address :: with_last_byte ( 1 ) ;
342
+ let precompile2_address = Address :: with_last_byte ( 2 ) ;
343
+
344
+ evm. precompiles_mut ( ) . apply_precompile ( & precompile1_address, |_| Some ( wrapped_precompile1) ) ;
345
+ evm. precompiles_mut ( ) . apply_precompile ( & precompile2_address, |_| Some ( wrapped_precompile2) ) ;
346
+
340
347
// first invocation of precompile1 (cache miss)
341
- let result1 = wrapped_precompile1
342
- . call ( PrecompileInput {
343
- data : input_data,
344
- gas : gas_limit,
348
+ let result1 = evm
349
+ . transact_raw ( TxEnv {
345
350
caller : Address :: ZERO ,
346
- value : U256 :: ZERO ,
347
- internals : EvmInternals :: new ( & mut Journal :: < _ > :: new ( EmptyDB :: new ( ) ) ) ,
351
+ gas_limit,
352
+ data : input_data. into ( ) ,
353
+ kind : precompile1_address. into ( ) ,
354
+ ..Default :: default ( )
348
355
} )
356
+ . unwrap ( )
357
+ . result
358
+ . into_output ( )
349
359
. unwrap ( ) ;
350
- assert_eq ! ( result1. bytes . as_ref( ) , b"output_from_precompile_1" ) ;
360
+ assert_eq ! ( result1. as_ref( ) , b"output_from_precompile_1" ) ;
351
361
352
362
// first invocation of precompile2 with the same input (should be a cache miss)
353
363
// if cache was incorrectly shared, we'd get precompile1's result
354
- let result2 = wrapped_precompile2
355
- . call ( PrecompileInput {
356
- data : input_data,
357
- gas : gas_limit,
364
+ let result2 = evm
365
+ . transact_raw ( TxEnv {
358
366
caller : Address :: ZERO ,
359
- value : U256 :: ZERO ,
360
- internals : EvmInternals :: new ( & mut Journal :: < _ > :: new ( EmptyDB :: new ( ) ) ) ,
367
+ gas_limit,
368
+ data : input_data. into ( ) ,
369
+ kind : precompile2_address. into ( ) ,
370
+ ..Default :: default ( )
361
371
} )
372
+ . unwrap ( )
373
+ . result
374
+ . into_output ( )
362
375
. unwrap ( ) ;
363
- assert_eq ! ( result2. bytes . as_ref( ) , b"output_from_precompile_2" ) ;
376
+ assert_eq ! ( result2. as_ref( ) , b"output_from_precompile_2" ) ;
364
377
365
378
// second invocation of precompile1 (should be a cache hit)
366
- let result3 = wrapped_precompile1
367
- . call ( PrecompileInput {
368
- data : input_data,
369
- gas : gas_limit,
379
+ let result3 = evm
380
+ . transact_raw ( TxEnv {
370
381
caller : Address :: ZERO ,
371
- value : U256 :: ZERO ,
372
- internals : EvmInternals :: new ( & mut Journal :: < _ > :: new ( EmptyDB :: new ( ) ) ) ,
382
+ gas_limit,
383
+ data : input_data. into ( ) ,
384
+ kind : precompile1_address. into ( ) ,
385
+ ..Default :: default ( )
373
386
} )
387
+ . unwrap ( )
388
+ . result
389
+ . into_output ( )
374
390
. unwrap ( ) ;
375
- assert_eq ! ( result3. bytes . as_ref( ) , b"output_from_precompile_1" ) ;
391
+ assert_eq ! ( result3. as_ref( ) , b"output_from_precompile_1" ) ;
376
392
}
377
393
}
0 commit comments