Function soroban_sdk::testutils::arbitrary::fuzz_catch_panic
source · pub fn fuzz_catch_panic<F, R>(f: F) -> Result<R>where
F: FnOnce() -> R,
Available on crate feature
testutils
only.Expand description
Catch panics within a fuzz test.
The cargo-fuzz
test harness turns panics into test failures,
immediately aborting the process.
This function catches panics while temporarily disabling the
cargo-fuzz
panic handler.
Example
use soroban_sdk::{Address, Env};
use soroban_sdk::testutils::arbitrary::{Arbitrary, SorobanArbitrary};
#[derive(Arbitrary, Debug)]
struct FuzzDeposit {
deposit_amount: i128,
deposit_address: <Address as SorobanArbitrary>::Prototype,
}
fuzz_target!(|input: FuzzDeposit| {
let env = Env::default();
let contract = ExampleContract::new(env, &env.register_contract(None, ExampleContract {}));
let addresses: Address = input.deposit_address.into_val(&env);
let r = fuzz_catch_panic(|| {
contract.deposit(deposit_address, input.deposit_amount);
});
});