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