Skip to main content

Crate crucible_test_context

Crate crucible_test_context 

Source

Re-exports§

pub use schema::register_account_schemas;
pub use schema::AccountSchema;
pub use coverage::build_cached_analysis;
pub use coverage::extract_functions;
pub use coverage::generate_bytecode_lcov;
pub use coverage::generate_coverage_html;
pub use coverage::generate_coverage_html_cached;
pub use coverage::generate_source_lcov;
pub use coverage::build_dwarf_source_map;
pub use coverage::DwarfSourceMap;
pub use coverage::SourceLocation;
pub use coverage::CachedFunctionInfo;
pub use coverage::CachedProgramAnalysis;
pub use coverage::CoverageStats;
pub use coverage::CoverageWriteStats;
pub use coverage::FunctionInfo;
pub use coverage::ReachableAnalysis;
pub use litesvm;
pub use serde_json;

Modules§

coverage
Coverage analysis and visualization for BPF programs.
fuzz_types
schema
Account schema registry for semantic field-level diffs.
snapshot
Dirty account tracking and snapshot/restore for fast fuzzing iterations.

Macros§

fuzz_assert
Assert a condition is true
fuzz_assert_approx_eq
Assert two values are approximately equal within a delta (absolute difference)
fuzz_assert_eq
Assert two values are equal
fuzz_assert_ge
Assert a >= b
fuzz_assert_gt
Assert a > b
fuzz_assert_le
Assert a <= b
fuzz_assert_lt
Assert a < b
fuzz_assert_ne
Assert two values are not equal

Structs§

ActionRecord
Record of a single action execution for crash metadata
CrashMetadata
Complete crash metadata for .meta.json files
EmptyInvocationCallback
Empty callback that does nothing - used during setup to avoid DefaultRegisterTracingCallback trying to find .so files on disk for built-in programs.
FieldDelta
A single field-level semantic diff (used by schema registry for rich crash output).
FxBuildHasher
An implementation of BuildHasher that produces FxHashers.
GenericAccountBuilder
InstructionBuilder
MintAccountBuilder
MockPythOracleBuilder
Builder for creating mock Pyth price feed accounts
PriceFeedMessage
Pyth price feed message containing price data
PriceUpdateV2
Pyth PriceUpdateV2 account structure (Pyth Solana Receiver format)
ProgramBuilder
ProgramData
Stores program data for reloading into debuggable SVMs
TestContext
TokenAccountBuilder
TransactionBuilder
TxError
Error type for TxOutcome::into_result()

Enums§

TxOutcome
Parsed transaction outcome from litesvm execution
VerificationLevel
Pyth verification level for price updates

Constants§

DEFAULT_PYTH_RECEIVER_ID
Default Pyth Solana Receiver program ID rec5EKMGg6MxZYaMdyBps2bnnCNHi6KCYuQedA7GsAuW
PYTH_DISCRIMINATOR
PriceUpdateV2 discriminator: sha256(“account:PriceUpdateV2”)[0..8]

Statics§

TOTAL_ACTIONS_DISPATCHED
Global counter of total actions dispatched across all iterations. Used with TOTAL_EXECUTIONS to compute average actions per execution.
TOTAL_ACTIONS_SUCCEEDED
Global counter of total actions that succeeded across all iterations. Used by monitor to display success rate (ok/total).
TOTAL_ACTION_VARIANTS
Total number of action variants available (set once at startup). Used by monitor to display “discovered: N/M actions”.

Traits§

AccountBuilderBase
IntoActionSuccess
Trait to normalize action return values to success/failure. Allows actions to return either () (always success) or Result<(), E> (success/failure).
InvocationInspectCallback

Functions§

backfill_action_params
Backfill the params for a specific action record in the history.
build_crash_metadata
Build crash metadata from current state
clear_action_history
Clear the action history (called at start of each iteration)
clear_iteration_state
Clear all per-iteration state: action history + violation tracking. Convenience wrapper — call at the start of each fuzzing iteration.
clear_violation_tracking
Clear all violation tracking state (called at start of each iteration)
compute_svm_debug_hash
Hash SVM state for tracked accounts. Returns (hash, clock_slot). Accounts sorted by (lamports, data_len, data_hash) for cross-run stability.
format_action_sequence
Print the action sequence to stderr (for debugging crashes) Format the current action sequence from TLS history into a string. Must be called on the same thread that executed the actions (reads TLS).
format_all_actions_oneline
Format ALL actions in the current history as one-line descriptions, newline-separated. Used by stateful mode to store the full chain description in a single action_desc field.
format_json_value
Format a JSON value for display (compact format)
format_last_action_oneline
Format the most recent action from TLS history as a one-line summary. e.g. “action_deposit(user=0, amount=500) -> OK” Returns empty string if no action in history.
get_action_history
Get a copy of the action history
get_current_instruction
Get the current Anchor instruction name
get_current_iteration
Get the current iteration number
get_current_test_name
Get the current test name
get_first_action_success
Check if the first action in history succeeded. Avoids cloning the entire history Vec — O(1) instead of O(n).
get_iteration_dispatch_count
Get the per-iteration dispatch count (call after fn_name). Returns at least 1 to avoid zero-counting iterations.
get_registered_discriminators
Get all registered discriminators (for debugging)
get_send_batch_timers
Get send_batch sub-phase timers: (pre_ns, svm_ns, post_ns).
get_send_tx_breakdown
Get send_transaction sub-breakdown: (blockhash_ns, sign_ns, exec_ns).
get_violation_action_index
Get the action index that triggered the violation (if any)
has_variant_succeeded
Check if a given action variant index has ever succeeded.
has_violation
Check if a violation has been recorded (without consuming it)
increment_action_count
Increment the global action counter by one. Also increments the thread-local per-iteration counter for accurate multicore exec/sec reporting (global atomic has cross-thread noise).
increment_action_success_count
Increment the global succeeded action counter by one.
is_corpus_loading
Check if corpus loading is in progress.
is_debug_replay
Check FUZZ_DEBUG_REPLAY env var (cached per-thread).
is_stateful_chain_mode
Check if stateful chain mode is active.
lookup_instruction_by_discriminator
Look up instruction name from discriminator bytes at the start of instruction data. Automatically uses the correct discriminator length (4 or 8 bytes). Returns None if discriminator is not registered or if the data is too short. Lock-free after initialization.
mark_variant_succeeded
Mark an action variant index as having succeeded at least once.
parse_action_desc
Parse an action description string like “withdraw(authority=null, lamports=5) -> OK” back into an ActionRecord. Used by stateful mode to reconstruct full crash metadata from pool descriptions.
parse_error_code
Parse litesvm TransactionError to extract error code. Extracts Custom(N) error codes from InstructionError variants.
parse_instruction_index
Parse litesvm TransactionError to extract instruction index.
print_action_sequence
push_action_record
Push an action record to the history and update cumulative stats.
push_action_record_lite
Lite action record: only records name and success, defers JSON params. Avoids serde_json::Value allocation on every action of every iteration. The params field is set to null and should be backfilled via backfill_action_params only when needed (crash/violation).
record_violation
Record an invariant violation (used by fuzz_assert! macros)
register_instruction_discriminators
Register instruction discriminators for per-instruction coverage tracking. Call this once at harness initialization with discriminators from the program’s IDL. Supports variable-length discriminators (4 bytes for bincode, 8 bytes for Anchor). Subsequent calls are ignored (OnceLock can only be set once).
reset_iteration_dispatch_count
Reset the per-iteration dispatch counter (call before fn_name).
reset_send_batch_timers
Reset send_batch sub-phase accumulators (call before fn_name).
set_corpus_loading
Set corpus loading flag (suppresses monitor output during loading).
set_current_iteration
Set the current iteration number
set_current_test_name
Set the current test name (called at test start)
set_last_error_code
Set the last error code from a transaction result (called by tx_result_to_outcome)
set_stateful_chain_mode
Set stateful chain mode flag. When true, invariant test loops break on first action failure (failed actions produce dead-end states in stateful mode).
set_total_actions
Set the total number of actions in the current sequence (for early exit tracking)
set_violation_action_index
Record which action index triggered a violation (only records first violation)
succeeded_variant_count
Get the number of action variants that have ever succeeded.
take_violation
Take the current violation (clearing it). Returns Some if violated.
tx_result_to_outcome
Convert litesvm transaction result to TxOutcome
write_crash_metadata
Write crash metadata to a .meta.json file and save input bytes for replay
write_crash_metadata_for_id
Write crash metadata for a known crash ID (used by tmin to update metadata in place)
write_crash_metadata_with_actions
Write crash metadata with an explicit full action chain (for stateful mode). If full_actions is Some, it overrides the TLS action history.

Type Aliases§

FastHashMap
Type alias for fast HashMap (uses FxHash)
FastHashSet
Type alias for fast HashSet (uses FxHash)
FxHashMap
Type alias for a hash map that uses the Fx hashing algorithm.
FxHashSet
Type alias for a hash set that uses the Fx hashing algorithm.