thruput_native_exec/lib.rs
1//! Native execution environment for testing Thruput contracts in-process.
2//!
3//! The entry point is [`test_environment::TestEnvironment`], an in-memory
4//! Thruput instance against which tests run mocked transactions and
5//! assert on their results.
6#![warn(missing_docs)]
7
8/// Report a failure detected inside a `Drop` impl without risking a SIGABRT.
9///
10/// Panicking while the thread is *already* unwinding (e.g. a test assertion
11/// just failed) aborts the whole process, replacing the original failure
12/// message with an opaque SIGABRT. So when a panic is already in flight we log
13/// to stderr instead; otherwise we panic normally, since a Drop-time invariant
14/// violation with no prior panic is a real bug worth surfacing loudly.
15#[track_caller]
16pub(crate) fn drop_failure(args: core::fmt::Arguments<'_>) {
17 if std::thread::panicking() {
18 eprintln!(
19 "[native-exec] error during Drop suppressed to preserve the \
20 in-flight panic: {args}"
21 );
22 } else {
23 panic!("{args}");
24 }
25}
26
27/// Fluent builders for configuring and executing invocation frames.
28pub mod frame_builder;
29/// Per-frame results (status, buffers, trace, events) and their assertions.
30pub mod frame_result;
31/// The mocked syscall entrypoint bridging guest syscalls to the test FFI.
32pub mod host_fn_error;
33/// Panic payloads and the panic hook that classify frame unwinds.
34pub mod invoke_error;
35pub use host_fn_error::perform_mocked_syscall;
36/// Mock contracts: native closures registered as contract entrypoints.
37pub mod mock_contract;
38/// The mocked transaction handler and its invocation-frame state machine.
39pub mod mock_transaction_handler;
40/// The chain's execution parameters, and a builder for non-default ones.
41pub mod network_config;
42/// The rv32 stack-usage record the test FFI keeps per rv32 invocation.
43pub mod rv32_stack_usage;
44/// The in-process thruput test environment.
45pub mod test_environment;
46/// Optional builder for a test environment with non-default settings.
47pub mod test_environment_builder;
48/// Small conveniences for writing tests (deterministic named addresses).
49pub mod test_helpers;
50/// Whole-transaction results (root frame + commit outcome) and assertions.
51pub mod transact_result;
52/// Builder for configuring a mocked transaction before executing it.
53pub mod transaction_builder;
54/// Handler for executing full signed transactions against the environment.
55pub mod transaction_handler;
56/// Typed outcome of a two-phase transaction commit.
57pub mod try_commit_result;
58pub use try_commit_result::TryCommitResult;
59
60#[cfg(target_arch = "riscv32")]
61compile_error!("The `native_exec` crate cannot be compiled for rv32.");