Crates.io | spl-transfer-hook-example |
lib.rs | spl-transfer-hook-example |
version | 0.6.1 |
source | src |
created_at | 2023-05-18 12:23:03.614528 |
updated_at | 2024-07-11 01:37:19.13113 |
description | Solana Program Library Transfer Hook Example Program |
homepage | |
repository | https://github.com/solana-labs/solana-program-library |
max_upload_size | |
id | 867831 |
size | 61,477 |
Full example program and tests implementing the spl-transfer-hook-interface
,
to be used for testing a program that calls into the spl-transfer-hook-interface
.
See the SPL Transfer Hook Interface code for more information.
When testing your program that uses spl-transfer-hook-interface
, you can also
import this crate, and then use it with solana-program-test
, ie:
use {
solana_program_test::{processor, ProgramTest},
solana_sdk::{account::Account, instruction::AccountMeta},
spl_transfer_hook_example::state::example_data,
spl_transfer_hook_interface::get_extra_account_metas_address,
};
#[test]
fn my_program_test() {
let mut program_test = ProgramTest::new(
"my_program",
my_program_id,
processor!(my_program_processor),
);
let transfer_hook_program_id = Pubkey::new_unique();
program_test.prefer_bpf(false); // BPF won't work, unless you've built this from scratch!
program_test.add_program(
"spl_transfer_hook_example",
transfer_hook_program_id,
processor!(spl_transfer_hook_example::processor::process),
);
let mint = Pubkey::new_unique();
let extra_accounts_address = get_extra_account_metas_address(&mint, &transfer_hook_program_id);
let account_metas = vec![
AccountMeta {
pubkey: Pubkey::new_unique(),
is_signer: false,
is_writable: false,
},
AccountMeta {
pubkey: Pubkey::new_unique(),
is_signer: false,
is_writable: false,
},
];
let data = example_data(&account_metas);
program_test.add_account(
extra_accounts_address,
Account {
lamports: 1_000_000_000, // a lot, just to be safe
data,
owner: transfer_hook_program_id,
..Account::default()
},
);
// run your test logic!
}