Skip to content

Commit

Permalink
Generalize machine run/step in call stack (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorpaas authored Nov 20, 2023
1 parent dbf6a10 commit 0e81a49
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 189 deletions.
47 changes: 19 additions & 28 deletions jsontests/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use evm::backend::in_memory::{
};
use evm::standard::{Config, Etable, Gasometer, Invoker, TransactArgs};
use evm::utils::u256_to_h256;
use evm::{Capture, RuntimeState};
use evm::{Capture, GasedMachine};
use primitive_types::U256;
use std::collections::{BTreeMap, BTreeSet};

Expand Down Expand Up @@ -59,7 +59,7 @@ pub fn run_test(_filename: &str, _test_name: &str, test: Test, debug: bool) -> R
.collect::<BTreeMap<_, _>>();

let etable = Etable::runtime();
let invoker = Invoker::new(&config);
let invoker = Invoker::<_, Gasometer, _, _, _>::new(&config, &etable);
let args = TransactArgs::Call {
caller: test.transaction.sender,
address: test.transaction.to,
Expand Down Expand Up @@ -93,36 +93,27 @@ pub fn run_test(_filename: &str, _test_name: &str, test: Test, debug: bool) -> R
let mut step_backend = run_backend.clone();

// Run
let run_result = evm::transact::<RuntimeState, Gasometer, _, _, _, _>(
args.clone(),
Some(4),
&mut run_backend,
&invoker,
&etable,
);
let run_result = evm::transact(args.clone(), Some(4), &mut run_backend, &invoker);
run_backend.layers[0].clear_pending();

// Step
if debug {
let _step_result = evm::HeapTransact::<RuntimeState, Gasometer, _, _, _>::new(
args,
&invoker,
&mut step_backend,
)
.and_then(|mut stepper| loop {
{
let machine = stepper.last_machine()?;
println!(
"pc: {}, opcode: {:?}, gas: 0x{:x}",
machine.machine.position(),
machine.machine.peek_opcode(),
machine.gasometer.gas(),
);
}
if let Err(Capture::Exit(result)) = stepper.step(&etable) {
break result;
}
});
let _step_result = evm::HeapTransact::new(args, &invoker, &mut step_backend).and_then(
|mut stepper| loop {
{
let machine: &GasedMachine<_, Gasometer> = stepper.last_machine()?;
println!(
"pc: {}, opcode: {:?}, gas: 0x{:x}",
machine.machine.position(),
machine.machine.peek_opcode(),
machine.gasometer.gas(),
);
}
if let Err(Capture::Exit(result)) = stepper.step() {
break result;
}
},
);
step_backend.layers[0].clear_pending();
}

Expand Down
Loading

0 comments on commit 0e81a49

Please sign in to comment.