pub struct Trident { /* private fields */ }Implementations§
Source§impl Trident
impl Trident
Sourcepub fn process_transaction(
&mut self,
instructions: &[Instruction],
log_as: Option<&str>,
) -> TransactionResult
pub fn process_transaction( &mut self, instructions: &[Instruction], log_as: Option<&str>, ) -> TransactionResult
Processes a transaction containing one or more instructions
This method executes the provided instructions as a single transaction and returns the result including success/failure status and transaction logs. It also handles fuzzing metrics collection when enabled via environment variables.
§Arguments
instructions- A slice of instructions to execute in the transactiontransaction_name- A descriptive name for the transaction (used in metrics)
§Returns
A TransactionResult containing the execution result and logs
§Example
let instructions = vec![system_instruction::transfer(&from, &to, 1000)];
let result = trident.process_transaction(&instructions, Some("Transfer SOL"));
assert!(result.is_success());Sourcepub fn deploy_program(&mut self, program: TridentProgram)
pub fn deploy_program(&mut self, program: TridentProgram)
Deploys a binary program to the SVM runtime
This method deploys a compiled Solana program (BPF/SBF) to the runtime, making it available for instruction execution.
§Arguments
program- The compiled program to deploy
Sourcepub fn warp_to_epoch(&mut self, warp_epoch: u64)
pub fn warp_to_epoch(&mut self, warp_epoch: u64)
Warps the blockchain clock to a specific epoch
This method updates the system clock sysvar to simulate time progression to the specified epoch, useful for testing time-dependent program logic.
§Arguments
warp_epoch- The target epoch to warp to
Sourcepub fn warp_to_slot(&mut self, warp_slot: u64)
pub fn warp_to_slot(&mut self, warp_slot: u64)
Warps the blockchain clock to a specific slot
This method updates the system clock sysvar to simulate progression to the specified slot number.
§Arguments
warp_slot- The target slot number to warp to
Sourcepub fn warp_to_timestamp(&mut self, warp_timestamp: i64)
pub fn warp_to_timestamp(&mut self, warp_timestamp: i64)
Warps the blockchain clock to a specific Unix timestamp
This method updates the system clock sysvar to simulate time progression to the specified Unix timestamp.
§Arguments
warp_timestamp- The target Unix timestamp to warp to
Sourcepub fn forward_in_time(&mut self, seconds: i64)
pub fn forward_in_time(&mut self, seconds: i64)
Advances the blockchain clock by a specified number of seconds
This method increments the current Unix timestamp by the given number of seconds, useful for testing time-based program behavior.
§Arguments
seconds- The number of seconds to advance the clock
Sourcepub fn set_account_custom(
&mut self,
address: &Pubkey,
account: &AccountSharedData,
)
pub fn set_account_custom( &mut self, address: &Pubkey, account: &AccountSharedData, )
Sets a custom account state at the specified address
This method allows you to manually set account data, lamports, and owner for any public key, useful for setting up test scenarios.
§Arguments
address- The public key where the account should be storedaccount- The account data to set
Sourcepub fn payer(&self) -> Keypair
pub fn payer(&self) -> Keypair
Returns the default payer keypair for transactions
This keypair is used to pay transaction fees and sign transactions when no other payer is specified.
§Returns
The default payer keypair
Sourcepub fn get_account(&mut self, key: &Pubkey) -> AccountSharedData
pub fn get_account(&mut self, key: &Pubkey) -> AccountSharedData
Retrieves account data for the specified public key
Returns the account data including lamports, owner, and data bytes. If the account doesn’t exist, returns a default empty account.
§Arguments
key- The public key of the account to retrieve
§Returns
The account data or a default account if not found
Sourcepub fn get_account_with_type<T: BorshDeserialize>(
&mut self,
key: &Pubkey,
discriminator_size: usize,
) -> Option<T>
pub fn get_account_with_type<T: BorshDeserialize>( &mut self, key: &Pubkey, discriminator_size: usize, ) -> Option<T>
Retrieves and deserializes account data as a specific type
This method fetches account data and attempts to deserialize it using Borsh, skipping the specified discriminator bytes at the beginning.
§Arguments
key- The public key of the account to retrievediscriminator_size- Number of bytes to skip before deserializing
§Returns
Some(T) if deserialization succeeds, None otherwise
Sourcepub fn get_current_timestamp(&self) -> i64
pub fn get_current_timestamp(&self) -> i64
Gets the current Unix timestamp from the blockchain clock
Returns the current timestamp as stored in the Clock sysvar.
§Returns
The current Unix timestamp in seconds
Sourcepub fn get_last_blockhash(&self) -> Hash
pub fn get_last_blockhash(&self) -> Hash
Gets the last blockhash (not implemented for TridentSVM)
§Panics
This method always panics as it’s not yet implemented for TridentSVM
Sourcepub fn get_sysvar<T: Sysvar>(&self) -> T
pub fn get_sysvar<T: Sysvar>(&self) -> T
Retrieves a system variable (sysvar) of the specified type
System variables contain blockchain state information like clock, rent, and epoch schedule data.
§Returns
The requested sysvar data
Sourcepub fn airdrop(&mut self, address: &Pubkey, amount: u64)
pub fn airdrop(&mut self, address: &Pubkey, amount: u64)
Airdrops SOL to the specified address
This method adds the specified amount of lamports to the target account. If the account doesn’t exist, it will be created with the airdropped amount.
§Arguments
address- The public key to receive the airdropamount- The number of lamports to airdrop
Sourcepub fn get_program_data_address_v3(&self, program_address: &Pubkey) -> Pubkey
pub fn get_program_data_address_v3(&self, program_address: &Pubkey) -> Pubkey
Derives the program data address for an upgradeable program
This method finds the program data account address for an upgradeable BPF loader program by deriving a Program Derived Address (PDA) using the program’s address as a seed.
§Arguments
program_address- The public key of the upgradeable program
§Returns
The derived program data address (PDA)
Sourcepub fn create_program_address(
&self,
seeds: &[&[u8]],
program_id: &Pubkey,
) -> Option<Pubkey>
pub fn create_program_address( &self, seeds: &[&[u8]], program_id: &Pubkey, ) -> Option<Pubkey>
Creates a program address (PDA) from seeds and a program ID
This method attempts to create a valid program-derived address using the provided
seeds and program ID. Unlike find_program_address, this does not search for a
valid bump seed and will return None if the provided seeds don’t produce a valid PDA.
§Arguments
seeds- Array of seed byte slices used to derive the addressprogram_id- The program ID to use for derivation
§Returns
Some(Pubkey) if the seeds produce a valid PDA, None otherwise
§Example
let seeds = &[b"my-seed", &[bump_seed]];
if let Some(pda) = trident.create_program_address(seeds, &program_id) {
println!("Created PDA: {}", pda);
}Sourcepub fn find_program_address(
&self,
seeds: &[&[u8]],
program_id: &Pubkey,
) -> (Pubkey, u8)
pub fn find_program_address( &self, seeds: &[&[u8]], program_id: &Pubkey, ) -> (Pubkey, u8)
Finds a valid program address (PDA) and its bump seed
This method searches for a valid program-derived address by trying different bump seeds (starting from 255 and counting down) until a valid PDA is found. This is the canonical way to derive PDAs in Solana programs.
§Arguments
seeds- Array of seed byte slices used to derive the addressprogram_id- The program ID to use for derivation
§Returns
A tuple containing the derived PDA and the bump seed used to generate it
§Example
let seeds = &[b"my-seed", user_pubkey.as_ref()];
let (pda, bump) = trident.find_program_address(seeds, &program_id);
println!("Found PDA: {} with bump: {}", pda, bump);Source§impl Trident
impl Trident
Sourcepub fn create_account(
&mut self,
from_pubkey: &Pubkey,
to_pubkey: &Pubkey,
lamports: u64,
space: u64,
owner: &Pubkey,
) -> Instruction
pub fn create_account( &mut self, from_pubkey: &Pubkey, to_pubkey: &Pubkey, lamports: u64, space: u64, owner: &Pubkey, ) -> Instruction
Creates a new account
Generates a system program create_account instruction to allocate space and assign ownership of a new account.
§Arguments
from_pubkey- The public key of the account funding the new accountto_pubkey- The public key of the new account to createlamports- The number of lamports to transfer to the new accountspace- The number of bytes to allocate for the account dataowner- The program that will own the new account
§Returns
An instruction that needs to be executed with process_transaction
Sourcepub fn allocate(&mut self, address: &Pubkey, space: u64) -> Instruction
pub fn allocate(&mut self, address: &Pubkey, space: u64) -> Instruction
Allocates space for an account
Generates a system program allocate instruction to allocate the specified number of bytes for an account’s data.
§Arguments
address- The public key of the account to allocate space forspace- The number of bytes to allocate
§Returns
An instruction that needs to be executed with process_transaction
§Note
This will succeed on PDAs in Trident, but would fail on-chain outside of a program invocation since PDAs cannot sign transactions
Sourcepub fn assign(&mut self, address: &Pubkey, owner: &Pubkey) -> Instruction
pub fn assign(&mut self, address: &Pubkey, owner: &Pubkey) -> Instruction
Assigns an account to a program
Generates a system program assign instruction to change the owner of an account to the specified program.
§Arguments
address- The public key of the account to assignowner- The public key of the program that will own the account
§Returns
An instruction that needs to be executed with process_transaction
§Note
This will succeed on PDAs in Trident, but would fail on-chain outside of a program invocation since PDAs cannot sign transactions
Sourcepub fn transfer(
&mut self,
from: &Pubkey,
to: &Pubkey,
amount: u64,
) -> Instruction
pub fn transfer( &mut self, from: &Pubkey, to: &Pubkey, amount: u64, ) -> Instruction
Transfers SOL from one account to another
Generates a system program transfer instruction to move the specified amount of lamports from the source to destination account.
§Arguments
from- The public key of the account to transfer fromto- The public key of the account to transfer toamount- The number of lamports to transfer
§Returns
An instruction that needs to be executed with process_transaction
Source§impl Trident
impl Trident
Sourcepub fn record_histogram(&mut self, metric_name: &str, value: f64)
pub fn record_histogram(&mut self, metric_name: &str, value: f64)
Records a value in a histogram metric
Histogram metrics track the distribution of values over time, useful for measuring performance characteristics like execution times, gas usage, or other numerical distributions.
§Arguments
metric_name- Name of the histogram metricvalue- The value to record in the histogram
§Note
Metrics are only recorded when the FUZZING_METRICS environment variable is set
Sourcepub fn record_accumulator(&mut self, metric_name: &str, value: f64)
pub fn record_accumulator(&mut self, metric_name: &str, value: f64)
Records a value in an accumulator metric
Accumulator metrics sum up values over time, useful for tracking totals like total gas consumed, total tokens transferred, etc.
§Arguments
metric_name- Name of the accumulator metricvalue- The value to add to the accumulator
§Note
Metrics are only recorded when the FUZZING_METRICS environment variable is set
Sourcepub fn track_account_regression(&mut self, account: &Pubkey, account_name: &str)
pub fn track_account_regression(&mut self, account: &Pubkey, account_name: &str)
Tracks account state for regression testing
This method captures the current state of an account for regression analysis, allowing you to detect when account states change unexpectedly between fuzzing runs.
§Arguments
account- The public key of the account to trackaccount_name- A descriptive name for the account
§Note
Account tracking is only enabled when the FUZZING_REGRESSION environment variable is set
Source§impl Trident
impl Trident
Sourcepub fn random_from_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
pub fn random_from_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Generates a random value within the specified range
This method uses the internal RNG to generate a random value of type T within the given range. The range can be inclusive or exclusive.
§Arguments
range- The range to sample from (e.g., 0..10, 0..=9)
§Returns
A random value of type T within the specified range
§Example
let random_u64 = trident.random_from_range(1..=100);
let random_f64 = trident.random_from_range(0.0..1.0);Sourcepub fn random_pubkey(&mut self) -> Pubkey
pub fn random_pubkey(&mut self) -> Pubkey
Generates a random Solana public key
Creates a cryptographically random 32-byte public key, useful for generating test accounts and addresses.
§Returns
A randomly generated Pubkey
Sourcepub fn random_string(&mut self, length: usize) -> String
pub fn random_string(&mut self, length: usize) -> String
Sourcepub fn random_bytes(&mut self, bytes: &mut [u8])
pub fn random_bytes(&mut self, bytes: &mut [u8])
Fills a byte slice with random data
This method fills the provided mutable byte slice with cryptographically random data, useful for generating random seeds, nonces, or other binary data.
§Arguments
bytes- A mutable byte slice to fill with random data
Sourcepub fn random_bool(&mut self) -> bool
pub fn random_bool(&mut self) -> bool
Sourcepub fn random_keypair(&mut self) -> Keypair
pub fn random_keypair(&mut self) -> Keypair
Generates a random Solana keypair
Creates a cryptographically secure random Ed25519 keypair, useful for generating test signers, authority accounts, and testing signature verification.
§Returns
A randomly generated Keypair with a valid public/private key pair
§Example
let signer = trident.random_keypair();
let authority = trident.random_keypair();Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Trident
impl RefUnwindSafe for Trident
impl Send for Trident
impl Sync for Trident
impl Unpin for Trident
impl UnwindSafe for Trident
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more