Skip to content

Commit

Permalink
fix all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita committed Dec 25, 2024
1 parent 125daa2 commit 8e46f98
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 142 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ alloy-rpc-types-eth = "0.8"
alloy-rpc-types-trace = "0.8"
alloy-sol-types = "0.8"
alloy-primitives = { version = "0.8", features = ["map"] }
revm = { git = "https://github.com/bluealloy/revm.git", rev = "a0e82657", default-features = false, features = [
revm = { git = "https://github.com/bluealloy/revm.git", rev = "d0a65323", default-features = false, features = [
"std",
] }
revm-inspector = { git = "https://github.com/bluealloy/revm.git", rev = "a0e82657", default-features = false, features = [
revm-inspector = { git = "https://github.com/bluealloy/revm.git", rev = "d0a65323", default-features = false, features = [
"std",
] }

Expand All @@ -55,7 +55,7 @@ boa_gc = { version = "0.19", optional = true }

[dev-dependencies]
snapbox = { version = "0.6", features = ["term-svg"] }
revm-database = { git = "https://github.com/bluealloy/revm.git", rev = "a0e82657", default-features = false, features = [
revm-database = { git = "https://github.com/bluealloy/revm.git", rev = "d0a65323", default-features = false, features = [
"std",
] }

Expand Down
2 changes: 2 additions & 0 deletions src/tracing/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl CallTraceArena {
kind: PushTraceKind,
new_trace: CallTrace,
) -> usize {
println!("entry: {:?} kind {kind:?}, new_trace: {new_trace:?}", entry);
loop {
match new_trace.depth {
// The entry node, just update it
Expand Down Expand Up @@ -91,6 +92,7 @@ impl CallTraceArena {
}

/// How to push a trace into the arena
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum PushTraceKind {
/// This will _only_ push the trace into the arena.
PushOnly,
Expand Down
18 changes: 9 additions & 9 deletions src/tracing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ impl TracingInspector {
// // only if this is _not_ the root call
// return self.is_deep() && value.is_zero();
//}
self.is_deep()
let _ = self.is_deep();
false
}

/// Returns the currently active call trace.
Expand Down Expand Up @@ -494,23 +495,23 @@ impl TracingInspector {
if self.config.record_state_diff {
let op = step.op.get();

let journal_entry = context.journal_ext().last_journal().last().cloned();
let journal_entry = context.journal_ext().last_journal().last();

step.storage_change = match (op, journal_entry) {
(
opcode::SLOAD | opcode::SSTORE,
Some(JournalEntry::StorageChanged { address, key, had_value }),
) => {
// SAFETY: (Address,key) exists if part if StorageChange
//TODO let value =
// context.journal_ext().state[address].storage[key].present_value();
let value = U256::ZERO;
let value =
context.journal_ext().evm_state()[address].storage[&key].present_value();
let reason = match op {
opcode::SLOAD => StorageChangeReason::SLOAD,
opcode::SSTORE => StorageChangeReason::SSTORE,
_ => unreachable!(),
};
let change = StorageChange { key, value, had_value: Some(had_value), reason };
let change =
StorageChange { key: *key, value, had_value: Some(*had_value), reason };
Some(change)
}
_ => None,
Expand Down Expand Up @@ -541,7 +542,6 @@ where
#[inline]
fn step_end(&mut self, interp: &mut Interpreter<EthInterpreter>, context: &mut CTX) {
if self.config.record_steps {
// TODO(rakita) fix this
self.fill_step_on_step_end(interp, context);
}
}
Expand Down Expand Up @@ -616,7 +616,7 @@ where

fn create_end(
&mut self,
context: &mut CTX,
_context: &mut CTX,
_inputs: &CreateInputs,
outcome: &mut CreateOutcome,
) {
Expand Down Expand Up @@ -651,7 +651,7 @@ where

fn eofcreate_end(
&mut self,
context: &mut CTX,
_context: &mut CTX,
_inputs: &EOFCreateInputs,
outcome: &mut CreateOutcome,
) {
Expand Down
19 changes: 10 additions & 9 deletions tests/it/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ fn test_parity_selfdestruct(spec_id: SpecId) {
db.insert_account_info(deployer, AccountInfo { balance: value, ..Default::default() });
});

context.modify_tx(|tx| tx.value = value);
let output = deploy_contract(&mut context, code.into(), deployer, spec_id);
let addr = output.created_address().unwrap();

Expand Down Expand Up @@ -170,14 +171,14 @@ fn test_parity_call_selfdestruct() {
let deployer = address!("341348115259a8bf69f1f50101c227fced83bac6");
let value = U256::from(69);

// let mut evm = TestEvm::new_with_spec_id(SpecId::LONDON);
// evm.db.insert_account_info(deployer, AccountInfo { balance: value, ..Default::default() });
// evm.env.tx.caller = deployer;
// evm.env.tx.value = value;

let mut context =
Context::default().with_db(CacheDB::<EmptyDB>::default()).modify_db_chained(|db| {
let mut context = Context::default()
.with_db(CacheDB::<EmptyDB>::default())
.modify_db_chained(|db| {
db.insert_account_info(deployer, AccountInfo { balance: value, ..Default::default() });
})
.modify_tx_chained(|tx| {
tx.caller = deployer;
tx.value = value;
});

let to = deploy_contract(&mut context, code.into(), deployer, SpecId::LONDON)
Expand All @@ -192,7 +193,7 @@ fn test_parity_call_selfdestruct() {
gas_limit: 100000000,
transact_to: TransactTo::Call(to),
data: input.to_vec().into(),
nonce: 1,
nonce: 0,
..Default::default()
};
});
Expand Down Expand Up @@ -329,7 +330,7 @@ fn test_parity_delegatecall_selfdestruct() {
gas_limit: 1000000,
transact_to: TransactTo::Call(delegate_addr),
data: input_data.into(),
nonce: 2,
nonce: 0,
..Default::default()
});

Expand Down
2 changes: 1 addition & 1 deletion tests/it/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn test_internal_transfers() {
let code = hex!("608060405234801561001057600080fd5b5060ef8061001f6000396000f3fe608060405260043610601c5760003560e01c8063830c29ae146021575b600080fd5b6030602c366004608b565b6032565b005b600080826001600160a01b03163460405160006040518083038185875af1925050503d8060008114607e576040519150601f19603f3d011682016040523d82523d6000602084013e6083565b606091505b505050505050565b600060208284031215609c57600080fd5b81356001600160a01b038116811460b257600080fd5b939250505056fea26469706673582212201654bdbf09c088897c9b02f3ba9df280b136ef99c3a05ca5a21d9a10fd912d3364736f6c634300080d0033");
let deployer = Address::ZERO;

let mut db = CacheDB::new(EmptyDB::default());
let db = CacheDB::new(EmptyDB::default());

let mut context = Context::default()
.with_db(db)
Expand Down
126 changes: 8 additions & 118 deletions tests/it/utils.rs
Original file line number Diff line number Diff line change
@@ -1,125 +1,18 @@
use alloy_primitives::{Address, Bytes, U256};
use alloy_primitives::{Address, Bytes};
use colorchoice::ColorChoice;
use revm::{
context::{BlockEnv, CfgEnv, TxEnv},
context_interface::{
result::{EVMError, ExecutionResult, HaltReason, InvalidTransaction, ResultAndState},
DatabaseGetter, TransactTo,
},
database_interface::EmptyDB,
handler::EthHandler,
interpreter::interpreter::EthInterpreter,
specification::hardfork::SpecId,
Context, Database, DatabaseCommit, Evm, EvmCommit, EvmExec, JournaledState, MainEvm,
Context, Database, DatabaseCommit, Evm, EvmCommit, EvmExec, JournaledState,
};
use revm_database::CacheDB;
use revm_inspector::{
inspector_handler, GetInspector, Inspector, InspectorContext, InspectorHandler,
InspectorMainEvm,
};
use revm_inspectors::tracing::{
TraceWriter, TraceWriterConfig, TracingInspector, TracingInspectorConfig,
};
use std::convert::Infallible;

// type TestDb = CacheDB<EmptyDB>;

// #[derive(Clone, Debug)]
// pub struct TestEvm {
// pub context: Context<BlockEnv, TxEnv, CfgEnv, CacheDB<EmptyDB>>,
// }

// impl Default for TestEvm {
// fn default() -> Self {
// Self::new()
// }
// }

// impl TestEvm {
// pub fn new() -> Self {
// let context = Context::default()
// .modify_block_chained(|b| {
// b.gas_limit = U256::MAX;
// })
// .modify_tx_chained(|tx| {
// tx.gas_limit = u64::MAX;
// tx.gas_price = U256::ZERO;
// })
// .with_db(CacheDB::new(EmptyDB::default()))
// .modify_cfg_chained(|cfg| {
// cfg.spec = SpecId::CANCUN;
// });

// Self { context }
// }

// pub fn new_with_spec_id(spec_id: SpecId) -> Self {
// let mut evm = Self::new();
// evm.context.modify_cfg(|cfg| cfg.spec = spec_id);
// evm
// }

// pub fn env_with_tx(&self, tx_env: TxEnv) -> EnvWithHandlerCfg {
// let mut env = self.env.clone();
// env.tx = tx_env;
// env
// }

// pub fn simple_deploy(&mut self, data: Bytes) -> Address {
// self.deploy(data, TracingInspector::new(TracingInspectorConfig::default_geth()))
// .expect("failed to deploy contract")
// }

// pub fn deploy<I: for<'a> GetInspector<&'a mut TestDb>>(
// &mut self,
// data: Bytes,
// inspector: I,
// ) -> Result<Address, EVMError<Infallible>> {
// let (_, address) = self.try_deploy(data, inspector)?;
// Ok(address.expect("failed to deploy contract"))
// }

// pub fn try_deploy<I: for<'a> GetInspector<&'a mut TestDb>>(
// &mut self,
// data: Bytes,
// inspector: I,
// ) -> Result<(ExecutionResult, Option<Address>), EVMError<Infallible>> {
// self.env.tx.data = data;
// self.env.tx.transact_to = TransactTo::Create;

// let (ResultAndState { result, state }, env) = self.inspect(inspector)?;
// self.db.commit(state);
// self.env = env;
// match &result {
// ExecutionResult::Success { output, .. } => {
// let address = output.address().copied();
// Ok((result, address))
// }
// _ => Ok((result, None)),
// }
// }

// pub fn call<I: for<'a> GetInspector<&'a mut TestDb>>(
// &mut self,
// address: Address,
// data: Bytes,
// inspector: I,
// ) -> Result<ExecutionResult, EVMError<Infallible>> {
// self.env.tx.data = data;
// self.env.tx.transact_to = TransactTo::Call(address);
// let (ResultAndState { result, state }, env) = self.inspect(inspector)?;
// self.db.commit(state);
// self.env = env;
// Ok(result)
// }

// pub fn inspect<I: for<'a> GetInspector<&'a mut TestDb>>(
// &mut self,
// inspector: I,
// ) -> Result<(ResultAndState, EnvWithHandlerCfg), EVMError<Infallible>> {
// inspect(&mut self.db, self.env.clone(), inspector)
// }
// }
use revm_inspector::{inspector_handler, GetInspector, InspectorContext, InspectorMainEvm};
use revm_inspectors::tracing::{TraceWriter, TraceWriterConfig, TracingInspector};

pub type ContextDb<DB> = Context<BlockEnv, TxEnv, CfgEnv, DB, JournaledState<DB>, ()>;

Expand Down Expand Up @@ -161,13 +54,10 @@ pub fn deploy_contract<DB: Database + DatabaseCommit>(
spec: SpecId,
) -> ExecutionResult<HaltReason> {
context.modify_tx(|tx| {
*tx = TxEnv {
caller: deployer,
gas_limit: 1000000,
transact_to: TransactTo::Create,
data: code,
..Default::default()
};
tx.caller = deployer;
tx.gas_limit = 1000000;
tx.transact_to = TransactTo::Create;
tx.data = code;
});
context.modify_cfg(|cfg| cfg.spec = spec);

Expand Down
4 changes: 2 additions & 2 deletions tests/it/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use alloy_primitives::{address, b256, bytes, hex, Address, B256, U256};
use alloy_sol_types::{sol, SolCall};
use colorchoice::ColorChoice;
use revm::{
context_interface::{DatabaseGetter, TransactTo, TransactionGetter},
context_interface::{DatabaseGetter, TransactTo},
database_interface::EmptyDB,
specification::hardfork::SpecId,
Context, DatabaseCommit,
Expand Down Expand Up @@ -34,7 +34,7 @@ fn test_trace_printing() {
&mut context,
CREATION_CODE.parse().unwrap(),
Address::default(),
SpecId::LONDON,
SpecId::CANCUN,
&mut tracer,
)
.created_address()
Expand Down

0 comments on commit 8e46f98

Please sign in to comment.