Skip to content

Commit 037be8d

Browse files
authored
chore(test): don't use EvmInternals::new (#17188)
1 parent d026630 commit 037be8d

File tree

1 file changed

+40
-24
lines changed

1 file changed

+40
-24
lines changed

crates/engine/tree/src/tree/precompile_cache.rs

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ mod tests {
241241
use std::hash::DefaultHasher;
242242

243243
use super::*;
244-
use reth_evm::EvmInternals;
244+
use reth_evm::{EthEvmFactory, Evm, EvmEnv, EvmFactory};
245245
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;
248248

249249
#[test]
250250
fn test_cache_key_ref_hash() {
@@ -290,6 +290,7 @@ mod tests {
290290

291291
#[test]
292292
fn test_precompile_cache_map_separate_addresses() {
293+
let mut evm = EthEvmFactory::default().create_evm(EmptyDB::default(), EvmEnv::default());
293294
let input_data = b"same_input";
294295
let gas_limit = 100_000;
295296

@@ -337,41 +338,56 @@ mod tests {
337338
None,
338339
);
339340

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+
340347
// 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 {
345350
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()
348355
})
356+
.unwrap()
357+
.result
358+
.into_output()
349359
.unwrap();
350-
assert_eq!(result1.bytes.as_ref(), b"output_from_precompile_1");
360+
assert_eq!(result1.as_ref(), b"output_from_precompile_1");
351361

352362
// first invocation of precompile2 with the same input (should be a cache miss)
353363
// 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 {
358366
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()
361371
})
372+
.unwrap()
373+
.result
374+
.into_output()
362375
.unwrap();
363-
assert_eq!(result2.bytes.as_ref(), b"output_from_precompile_2");
376+
assert_eq!(result2.as_ref(), b"output_from_precompile_2");
364377

365378
// 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 {
370381
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()
373386
})
387+
.unwrap()
388+
.result
389+
.into_output()
374390
.unwrap();
375-
assert_eq!(result3.bytes.as_ref(), b"output_from_precompile_1");
391+
assert_eq!(result3.as_ref(), b"output_from_precompile_1");
376392
}
377393
}

0 commit comments

Comments
 (0)