Trident

Struct Trident 

Source
pub struct Trident { /* private fields */ }

Implementations§

Source§

impl Trident

Source

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 transaction
  • transaction_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());
Source

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
Source

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
Source

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
Source

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
Source

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
Source

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 stored
  • account - The account data to set
Source

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

Source

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

Source

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 retrieve
  • discriminator_size - Number of bytes to skip before deserializing
§Returns

Some(T) if deserialization succeeds, None otherwise

Source

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

Source

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

Source

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

Source

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 airdrop
  • amount - The number of lamports to airdrop
Source

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)

Source

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 address
  • program_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);
}
Source

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 address
  • program_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

Source

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 account
  • to_pubkey - The public key of the new account to create
  • lamports - The number of lamports to transfer to the new account
  • space - The number of bytes to allocate for the account data
  • owner - The program that will own the new account
§Returns

An instruction that needs to be executed with process_transaction

Source

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 for
  • space - 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

Source

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 assign
  • owner - 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

Source

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 from
  • to - The public key of the account to transfer to
  • amount - The number of lamports to transfer
§Returns

An instruction that needs to be executed with process_transaction

Source§

impl Trident

Source

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 metric
  • value - The value to record in the histogram
§Note

Metrics are only recorded when the FUZZING_METRICS environment variable is set

Source

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 metric
  • value - The value to add to the accumulator
§Note

Metrics are only recorded when the FUZZING_METRICS environment variable is set

Source

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 track
  • account_name - A descriptive name for the account
§Note

Account tracking is only enabled when the FUZZING_REGRESSION environment variable is set

Source§

impl Trident

Source

pub fn random_from_range<T, R>(&mut self, range: R) -> T
where 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);
Source

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

Source

pub fn random_string(&mut self, length: usize) -> String

Generates a random string of the specified length

Creates a random string containing alphanumeric characters, useful for generating test data like names, symbols, or URIs.

§Arguments
  • length - The desired length of the generated string
§Returns

A random string of the specified length

Source

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
Source

pub fn random_bool(&mut self) -> bool

Generates a random boolean value

Creates a random boolean value, useful for testing with boolean inputs.

§Returns

A random boolean value

§Example
let random_bool = trident.random_bool();
Source

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§

Source§

impl Default for Trident

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more