pub trait ProgramTestExtension {
// Required methods
fn generate_accounts(&mut self, number_of_accounts: u8) -> Vec<Keypair>;
fn add_account_with_data(
&mut self,
pubkey: Pubkey,
owner: Pubkey,
data: &[u8],
executable: bool,
);
fn add_account_with_lamports(
&mut self,
pubkey: Pubkey,
owner: Pubkey,
lamports: u64,
);
fn add_account_with_packable<P: Pack>(
&mut self,
pubkey: Pubkey,
owner: Pubkey,
data: P,
);
fn add_account_with_borsh<B: BorshSerialize>(
&mut self,
pubkey: Pubkey,
owner: Pubkey,
data: B,
);
fn add_token_mint(
&mut self,
pubkey: Pubkey,
mint_authority: Option<Pubkey>,
supply: u64,
decimals: u8,
freeze_authority: Option<Pubkey>,
);
fn add_token_account(
&mut self,
pubkey: Pubkey,
mint: Pubkey,
owner: Pubkey,
amount: u64,
delegate: Option<Pubkey>,
is_native: Option<u64>,
delegated_amount: u64,
close_authority: Option<Pubkey>,
);
fn add_associated_token_account(
&mut self,
mint: Pubkey,
owner: Pubkey,
amount: u64,
delegate: Option<Pubkey>,
is_native: Option<u64>,
delegated_amount: u64,
close_authority: Option<Pubkey>,
) -> Pubkey;
fn add_bpf_program(
&mut self,
program_name: &'static str,
program_id: Pubkey,
program_authority: Option<Pubkey>,
process_instruction: Option<BuiltinFunctionWithContext>,
);
fn add_bpf_program_with_program_data(
&mut self,
program_name: &'static str,
program_id: Pubkey,
program_authority: Option<Pubkey>,
program_data: Pubkey,
process_instruction: Option<BuiltinFunctionWithContext>,
);
}
Required Methods§
Sourcefn generate_accounts(&mut self, number_of_accounts: u8) -> Vec<Keypair>
fn generate_accounts(&mut self, number_of_accounts: u8) -> Vec<Keypair>
Adds a requested number of account with initial balance of 1_000
SOL
to the test environment
Sourcefn add_account_with_data(
&mut self,
pubkey: Pubkey,
owner: Pubkey,
data: &[u8],
executable: bool,
)
fn add_account_with_data( &mut self, pubkey: Pubkey, owner: Pubkey, data: &[u8], executable: bool, )
Add a rent-exempt account with some data to the test environment.
Sourcefn add_account_with_lamports(
&mut self,
pubkey: Pubkey,
owner: Pubkey,
lamports: u64,
)
fn add_account_with_lamports( &mut self, pubkey: Pubkey, owner: Pubkey, lamports: u64, )
Adds an account with the given balance to the test environment.
Sourcefn add_account_with_packable<P: Pack>(
&mut self,
pubkey: Pubkey,
owner: Pubkey,
data: P,
)
fn add_account_with_packable<P: Pack>( &mut self, pubkey: Pubkey, owner: Pubkey, data: P, )
Adds a rent-exempt account with some Packable data to the test environment.
Sourcefn add_account_with_borsh<B: BorshSerialize>(
&mut self,
pubkey: Pubkey,
owner: Pubkey,
data: B,
)
fn add_account_with_borsh<B: BorshSerialize>( &mut self, pubkey: Pubkey, owner: Pubkey, data: B, )
Adds a rent-exempt account with some Borsh-serializable to the test environment
Sourcefn add_token_mint(
&mut self,
pubkey: Pubkey,
mint_authority: Option<Pubkey>,
supply: u64,
decimals: u8,
freeze_authority: Option<Pubkey>,
)
fn add_token_mint( &mut self, pubkey: Pubkey, mint_authority: Option<Pubkey>, supply: u64, decimals: u8, freeze_authority: Option<Pubkey>, )
Adds an SPL Token Mint account to the test environment.
Sourcefn add_token_account(
&mut self,
pubkey: Pubkey,
mint: Pubkey,
owner: Pubkey,
amount: u64,
delegate: Option<Pubkey>,
is_native: Option<u64>,
delegated_amount: u64,
close_authority: Option<Pubkey>,
)
fn add_token_account( &mut self, pubkey: Pubkey, mint: Pubkey, owner: Pubkey, amount: u64, delegate: Option<Pubkey>, is_native: Option<u64>, delegated_amount: u64, close_authority: Option<Pubkey>, )
Adds an SPL Token account to the test environment.
Sourcefn add_associated_token_account(
&mut self,
mint: Pubkey,
owner: Pubkey,
amount: u64,
delegate: Option<Pubkey>,
is_native: Option<u64>,
delegated_amount: u64,
close_authority: Option<Pubkey>,
) -> Pubkey
fn add_associated_token_account( &mut self, mint: Pubkey, owner: Pubkey, amount: u64, delegate: Option<Pubkey>, is_native: Option<u64>, delegated_amount: u64, close_authority: Option<Pubkey>, ) -> Pubkey
Adds an associated token account to the test environment. Returns the address of the created account.
Sourcefn add_bpf_program(
&mut self,
program_name: &'static str,
program_id: Pubkey,
program_authority: Option<Pubkey>,
process_instruction: Option<BuiltinFunctionWithContext>,
)
fn add_bpf_program( &mut self, program_name: &'static str, program_id: Pubkey, program_authority: Option<Pubkey>, process_instruction: Option<BuiltinFunctionWithContext>, )
Adds a BPF program to the test environment.
The program is upgradeable if Some
program_authority
is provided.
Sourcefn add_bpf_program_with_program_data(
&mut self,
program_name: &'static str,
program_id: Pubkey,
program_authority: Option<Pubkey>,
program_data: Pubkey,
process_instruction: Option<BuiltinFunctionWithContext>,
)
fn add_bpf_program_with_program_data( &mut self, program_name: &'static str, program_id: Pubkey, program_authority: Option<Pubkey>, program_data: Pubkey, process_instruction: Option<BuiltinFunctionWithContext>, )
Adds a BPF program to the test environment.
The program is upgradeable if Some
program_authority
and then
providing the program data account This is useful for those programs
which the program data has to be a spefic one, if not, use
ProgramTestExtension::add_bpf_program
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.