1#![cfg_attr(not(test), warn(unused_crate_dependencies))]
6#![cfg_attr(not(feature = "std"), no_std)]
7
8mod count_inspector;
9#[cfg(feature = "tracer")]
10mod eip3155;
11mod either;
12mod gas;
13pub mod handler;
15mod inspect;
16mod inspector;
17mod mainnet_inspect;
18mod noop;
19mod traits;
20
21#[cfg(test)]
22mod inspector_tests;
23
24pub mod inspectors {
26 #[cfg(feature = "tracer")]
27 pub use super::eip3155::TracerEip3155;
28 pub use super::gas::GasInspector;
29}
30
31pub use count_inspector::CountInspector;
32pub use handler::{inspect_instructions, InspectorHandler};
33pub use inspect::{InspectCommitEvm, InspectEvm, InspectSystemCallEvm};
34pub use inspector::*;
35pub use noop::NoOpInspector;
36pub use traits::*;
37
38#[cfg(test)]
39mod tests {
40 use super::*;
41 use ::handler::{MainBuilder, MainContext};
42 use context::{BlockEnv, CfgEnv, Context, Journal, TxEnv};
43 use database::{BenchmarkDB, BENCH_CALLER, BENCH_TARGET};
44 use interpreter::{interpreter::EthInterpreter, InstructionResult, InterpreterTypes};
45 use primitives::TxKind;
46 use state::{bytecode::opcode, Bytecode};
47
48 struct HaltInspector;
49 impl<CTX, INTR: InterpreterTypes> Inspector<CTX, INTR> for HaltInspector {
50 fn step(&mut self, interp: &mut interpreter::Interpreter<INTR>, _context: &mut CTX) {
51 interp.halt(InstructionResult::Stop);
52 }
53 }
54
55 #[test]
56 fn test_step_halt() {
57 let bytecode = [opcode::INVALID];
58 let r = run(&bytecode, HaltInspector);
59 dbg!(&r);
60 assert!(r.is_success());
61 }
62
63 fn run(
64 bytecode: &[u8],
65 inspector: impl Inspector<
66 Context<BlockEnv, TxEnv, CfgEnv, BenchmarkDB, Journal<BenchmarkDB>, ()>,
67 EthInterpreter,
68 >,
69 ) -> context::result::ExecutionResult {
70 let bytecode = Bytecode::new_raw(bytecode.to_vec().into());
71 let ctx = Context::mainnet().with_db(BenchmarkDB::new_bytecode(bytecode));
72 let mut evm = ctx.build_mainnet_with_inspector(inspector);
73 evm.inspect_one_tx(
74 TxEnv::builder()
75 .caller(BENCH_CALLER)
76 .kind(TxKind::Call(BENCH_TARGET))
77 .gas_limit(21100)
78 .build()
79 .unwrap(),
80 )
81 .unwrap()
82 }
83}