Invariant Checks#
Trident allows you to (optionally) specify Invariant Checks for each Instruction.
The Invariant Check will be called after the Instruction was successfully invoked. Within the Invariant Check you can compare the contents of Accounts before and after the Instruction was called.
Important
Returning error in the Invariant Check is considered as detected undesired behavior (i.e. issue/crash detected).
fn check(
&self,
_pre_ix: &[SnapshotAccount],
post_ix: &[SnapshotAccount],
_ix_data: Self::IxData,
) -> Result<(), FuzzingError> {
if let Ok(hello_world_account) =
hello_world::StoreHelloWorld::try_deserialize(&mut post_ix[1].data())
{
if hello_world_account.input == 253 {
return Err(FuzzingError::Custom(1));
}
}
Ok(())
}
Important
Order of accounts within the array is the same as the order of accounts on the instruction input of your program.
Account Deserialization#
The SnapshotAccount
provides methods to obtain parts of the account (e.g. address, its data, owner etc.). If you want to deserialize data into struct defined within your program (or within for example anchor-spl
), you can use approach from source code above, meaning utilze try_deserialize
generated by anchor within your program.
Tip
Consider checking the Examples section for more tips.