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 assert!(r.is_success());
60 }
61
62 fn run(
63 bytecode: &[u8],
64 inspector: impl Inspector<
65 Context<BlockEnv, TxEnv, CfgEnv, BenchmarkDB, Journal<BenchmarkDB>, ()>,
66 EthInterpreter,
67 >,
68 ) -> context::result::ExecutionResult {
69 let bytecode = Bytecode::new_raw(bytecode.to_vec().into());
70 let ctx = Context::mainnet().with_db(BenchmarkDB::new_bytecode(bytecode));
71 let mut evm = ctx.build_mainnet_with_inspector(inspector);
72 evm.inspect_one_tx(
73 TxEnv::builder()
74 .caller(BENCH_CALLER)
75 .kind(TxKind::Call(BENCH_TARGET))
76 .gas_limit(21100)
77 .build()
78 .unwrap(),
79 )
80 .unwrap()
81 }
82}