pub struct AddressStorage { /* private fields */ }Expand description
A storage container for managing and tracking public key addresses
AddressStorage provides a convenient way to store and retrieve addresses during fuzz testing.
It can generate random addresses or derive PDAs, and allows you to randomly select from stored addresses.
Implementations§
Source§impl AddressStorage
impl AddressStorage
Sourcepub fn insert(
&mut self,
trident: &mut Trident,
seeds: Option<PdaSeeds<'_>>,
) -> Pubkey
pub fn insert( &mut self, trident: &mut Trident, seeds: Option<PdaSeeds<'_>>, ) -> Pubkey
Inserts a new address into storage
Generates a new address (either a PDA or random keypair) and stores it. If PDA seeds are provided, attempts to derive a PDA. If derivation fails or no seeds are provided, generates a random keypair address.
§Arguments
trident- The Trident instance for random number generationseeds- Optional PDA seeds for deriving a program-derived address
§Returns
The newly created and stored address
Sourcepub fn insert_with_address(&mut self, address: Pubkey)
pub fn insert_with_address(&mut self, address: Pubkey)
Inserts an existing address into storage
Stores a pre-existing address without generating a new one. Useful when you need to track addresses created elsewhere.
§Arguments
address- The address to store
Sourcepub fn get(&self, trident: &mut Trident) -> Option<Pubkey>
pub fn get(&self, trident: &mut Trident) -> Option<Pubkey>
Retrieves a random address from storage
Randomly selects one of the stored addresses using Trident’s RNG. This is useful for fuzzing operations that need to work with previously created accounts.
§Arguments
trident- The Trident instance for random number generation
§Returns
Some(Pubkey)- A randomly selected address from storageNone- If the storage is empty
Sourcepub fn get_except(
&self,
trident: &mut Trident,
except_addresses: &[Pubkey],
) -> Option<Pubkey>
pub fn get_except( &self, trident: &mut Trident, except_addresses: &[Pubkey], ) -> Option<Pubkey>
Retrieves a random address from storage, excluding specified addresses
Randomly selects one of the stored addresses using Trident’s RNG, ensuring the selected address is not in the exclusion list. This is useful for fuzzing operations that need distinct accounts (e.g., sender and receiver must be different).
§Arguments
trident- The Trident instance for random number generationexcept_addresses- Slice of addresses to exclude from selection
§Returns
Some(Pubkey)- A randomly selected address that is not in the exclusion listNone- If storage is empty or all addresses are in the exclusion list
§Examples
let sender = storage.get(&mut trident)?;
// Get a different address for receiver
let receiver = storage.get_except(&mut trident, &[sender])?;Trait Implementations§
Auto Trait Implementations§
impl Freeze for AddressStorage
impl RefUnwindSafe for AddressStorage
impl Send for AddressStorage
impl Sync for AddressStorage
impl Unpin for AddressStorage
impl UnwindSafe for AddressStorage
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