Trait poc_framework::Environment [−][src]
pub trait Environment {
Show 20 methods
fn payer(&self) -> Keypair;
fn execute_transaction(
&mut self,
txs: Transaction
) -> EncodedConfirmedTransaction;
fn get_recent_blockhash(&self) -> Hash;
fn get_rent_excemption(&self, data: usize) -> u64;
fn get_account(&self, pubkey: Pubkey) -> Option<Account>;
fn tx_with_instructions(
&self,
instructions: &[Instruction],
signers: &[&Keypair]
) -> Transaction { ... }
fn execute_as_transaction(
&mut self,
instructions: &[Instruction],
signers: &[&Keypair]
) -> EncodedConfirmedTransaction { ... }
fn execute_as_transaction_debug(
&mut self,
instructions: &[Instruction],
signers: &[&Keypair]
) -> EncodedConfirmedTransaction { ... }
fn create_account(
&mut self,
keypair: &Keypair,
lamports: u64,
space: usize,
owner: Pubkey
) { ... }
fn create_account_rent_excempt(
&mut self,
keypair: &Keypair,
space: usize,
owner: Pubkey
) { ... }
fn create_token_mint(
&mut self,
mint: &Keypair,
authority: Pubkey,
freeze_authority: Option<Pubkey>,
decimals: u8
) { ... }
fn mint_tokens(
&mut self,
mint: Pubkey,
authority: &Keypair,
account: Pubkey,
amount: u64
) { ... }
fn create_token_account(&mut self, account: &Keypair, mint: Pubkey) { ... }
fn 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 { ... }
fn create_account_with_data(&mut self, account: &Keypair, data: Vec<u8>) { ... }
fn deploy_program<P: AsRef<Path>>(&mut self, program_path: P) -> Pubkey { ... }
fn get_unpacked_account<T: Pack>(&self, pubkey: Pubkey) -> Option<T> { ... }
fn get_deserialized_account<T: BorshDeserialize>(
&self,
pubkey: Pubkey
) -> Option<T> { ... }
fn get_serde_deserialized_account<'a, T: DeserializeOwned>(
&self,
pubkey: Pubkey
) -> Option<T> { ... }
}
Expand description
A generic Environment trait. Provides the possibility of writing generic exploits that work both remote and local, for easy debugging.
Required methods
Returns the keypair used to pay for all transactions. All transaction fees and rent costs are payed for by this keypair.
fn execute_transaction(
&mut self,
txs: Transaction
) -> EncodedConfirmedTransaction
fn execute_transaction(
&mut self,
txs: Transaction
) -> EncodedConfirmedTransaction
Executes the batch of transactions in the right order and waits for them to be confirmed. The execution results are returned.
fn get_recent_blockhash(&self) -> Hash
fn get_recent_blockhash(&self) -> Hash
Fetch a recent blockhash, for construction of transactions.
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.
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.
Provided methods
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.
fn execute_as_transaction(
&mut self,
instructions: &[Instruction],
signers: &[&Keypair]
) -> EncodedConfirmedTransaction
fn execute_as_transaction(
&mut self,
instructions: &[Instruction],
signers: &[&Keypair]
) -> EncodedConfirmedTransaction
Assemble the given instructions into a transaction and sign it. All transactions executed by this method are signed and payed for by the payer.
fn execute_as_transaction_debug(
&mut self,
instructions: &[Instruction],
signers: &[&Keypair]
) -> EncodedConfirmedTransaction
fn execute_as_transaction_debug(
&mut self,
instructions: &[Instruction],
signers: &[&Keypair]
) -> EncodedConfirmedTransaction
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.
Executes a transaction constructing an empty account with the specified amount of space and lamports, owned by the provided program.
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.
Executes a transaction constructing a token mint. The account needs to be empty and belong to system for this to work.
Executes a transaction that mints tokens from a mint to an account belonging to that mint.
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.
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.
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.
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.
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.
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.
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.
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.