pub struct LocalEnvironment { /* private fields */ }Expand description
An clean environment that executes transactions locally. Good for testing and debugging. This environment has the most important SPL programs: spl-token, spl-associated-token-account and spl-memo v1 and v3.
Implementations§
Source§impl LocalEnvironment
impl LocalEnvironment
Sourcepub fn builder() -> LocalEnvironmentBuilder
pub fn builder() -> LocalEnvironmentBuilder
Constructs a builder for a local environment
Sourcepub fn new() -> LocalEnvironment
pub fn new() -> LocalEnvironment
Constructs a clean local environment.
pub fn bank(&mut self) -> &mut Bank
Sourcepub fn advance_blockhash(&self) -> Hash
pub fn advance_blockhash(&self) -> Hash
Advance the bank to the next blockhash.
Trait Implementations§
Source§impl Environment for LocalEnvironment
impl Environment for LocalEnvironment
Source§fn payer(&self) -> Keypair
fn payer(&self) -> Keypair
Returns the keypair used to pay for all transactions. All transaction fees and rent costs are payed for by this keypair.
Source§fn execute_transaction(
&mut self,
tx: Transaction,
) -> EncodedConfirmedTransactionWithStatusMeta
fn execute_transaction( &mut self, tx: Transaction, ) -> EncodedConfirmedTransactionWithStatusMeta
Executes the batch of transactions in the right order and waits for them to be confirmed. The execution results are returned.
Source§fn get_latest_blockhash(&self) -> Hash
fn get_latest_blockhash(&self) -> Hash
Fetch the latest blockhash, for construction of transactions.
Source§fn get_rent_excemption(&self, data: usize) -> u64
fn get_rent_excemption(&self, data: usize) -> u64
Fetch the amount of lamports needed for an account of the given size to be rent excempt.
Source§fn get_account(&self, pubkey: Pubkey) -> Option<Account>
fn get_account(&self, pubkey: Pubkey) -> Option<Account>
Fetch an account. None if the account does not exist.
Source§fn get_recent_blockhash(&self) -> Hash
fn get_recent_blockhash(&self) -> Hash
👎Deprecated since 0.2.0: Please use
get_latest_blockhash() insteadFetch a recent blockhash, for construction of transactions.
Source§fn tx_with_instructions(
&self,
instructions: &[Instruction],
signers: &[&Keypair],
) -> Transaction
fn tx_with_instructions( &self, instructions: &[Instruction], signers: &[&Keypair], ) -> Transaction
Assemble the given instructions into a transaction and sign it. All transactions constructed by this method are signed and payed for by the payer.
Source§fn execute_as_transaction(
&mut self,
instructions: &[Instruction],
signers: &[&Keypair],
) -> EncodedConfirmedTransactionWithStatusMeta
fn execute_as_transaction( &mut self, instructions: &[Instruction], signers: &[&Keypair], ) -> EncodedConfirmedTransactionWithStatusMeta
Assemble the given instructions into a transaction and sign it. All transactions executed by this method are signed and payed for by the payer.
Source§fn execute_as_transaction_debug(
&mut self,
instructions: &[Instruction],
signers: &[&Keypair],
) -> EncodedConfirmedTransactionWithStatusMeta
fn execute_as_transaction_debug( &mut self, instructions: &[Instruction], signers: &[&Keypair], ) -> EncodedConfirmedTransactionWithStatusMeta
Assemble the given instructions into a transaction and sign it. All transactions executed by this method are signed and payed for by the payer.
Prints the transaction before sending it.
Source§fn create_account(
&mut self,
keypair: &Keypair,
lamports: u64,
space: usize,
owner: Pubkey,
)
fn create_account( &mut self, keypair: &Keypair, lamports: u64, space: usize, owner: Pubkey, )
Executes a transaction constructing an empty account with the specified amount of space and lamports, owned by the provided program.
Source§fn create_account_rent_excempt(
&mut self,
keypair: &Keypair,
space: usize,
owner: Pubkey,
)
fn create_account_rent_excempt( &mut self, keypair: &Keypair, space: usize, owner: Pubkey, )
Executes a transaction constructing an empty rent-excempt account with the specified amount of space, owned by the provided program.
Source§fn create_token_mint(
&mut self,
mint: &Keypair,
authority: Pubkey,
freeze_authority: Option<Pubkey>,
decimals: u8,
)
fn create_token_mint( &mut self, mint: &Keypair, authority: Pubkey, freeze_authority: Option<Pubkey>, decimals: u8, )
Executes a transaction constructing a token mint. The account needs to be empty and belong to system for this to work.
Source§fn mint_tokens(
&mut self,
mint: Pubkey,
authority: &Keypair,
account: Pubkey,
amount: u64,
)
fn mint_tokens( &mut self, mint: Pubkey, authority: &Keypair, account: Pubkey, amount: u64, )
Executes a transaction that mints tokens from a mint to an account belonging to that mint.
Source§fn create_token_account(&mut self, account: &Keypair, mint: Pubkey)
fn create_token_account(&mut self, account: &Keypair, mint: Pubkey)
Executes a transaction constructing a token account of the specified mint. The account needs to be empty and belong to system for this to work.
Prefer to use [create_associated_token_account] if you don’t need the provided account to contain the token account.
Source§fn create_associated_token_account(
&mut self,
owner: &Keypair,
mint: Pubkey,
) -> Pubkey
fn create_associated_token_account( &mut self, owner: &Keypair, mint: Pubkey, ) -> Pubkey
Executes a transaction constructing the associated token account of the specified mint belonging to the owner. This will fail if the account already exists.
Source§fn get_or_create_associated_token_account(
&mut self,
owner: &Keypair,
mint: Pubkey,
) -> Pubkey
fn get_or_create_associated_token_account( &mut self, owner: &Keypair, mint: Pubkey, ) -> Pubkey
Executes a transaction constructing the associated token account of the specified mint belonging to the owner.
Source§fn create_account_with_data(&mut self, account: &Keypair, data: Vec<u8>)
fn create_account_with_data(&mut self, account: &Keypair, data: Vec<u8>)
Executes a transaction creating and filling the given account with the given data.
The account is required to be empty and will be owned by bpf_loader afterwards.
Source§fn deploy_program<P: AsRef<Path>>(&mut self, program_path: P) -> Pubkey
fn deploy_program<P: AsRef<Path>>(&mut self, program_path: P) -> Pubkey
Executes a transaction deploying a program from a file if it does not already exist.
The keypair is derived from the file contents.
Source§fn get_unpacked_account<T: Pack>(&self, pubkey: Pubkey) -> Option<T>
fn get_unpacked_account<T: Pack>(&self, pubkey: Pubkey) -> Option<T>
Gets and unpacks an account. None if the account does not exist.
Source§fn get_deserialized_account<T: BorshDeserialize>(
&self,
pubkey: Pubkey,
) -> Option<T>
fn get_deserialized_account<T: BorshDeserialize>( &self, pubkey: Pubkey, ) -> Option<T>
Gets and deserializes an account. None if the account does not exist.
Source§fn get_serde_deserialized_account<'a, T: DeserializeOwned>(
&self,
pubkey: Pubkey,
) -> Option<T>
fn get_serde_deserialized_account<'a, T: DeserializeOwned>( &self, pubkey: Pubkey, ) -> Option<T>
Gets and deserializes an account. None if the account does not exist.
Auto Trait Implementations§
impl !Freeze for LocalEnvironment
impl !RefUnwindSafe for LocalEnvironment
impl Send for LocalEnvironment
impl Sync for LocalEnvironment
impl Unpin for LocalEnvironment
impl !UnwindSafe for LocalEnvironment
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
Mutably borrows from an owned value. Read more
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>
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 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>
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