Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 8f0d965

Browse files
committed
fix: correctly use the new onchain helper in test
1 parent ebc47d2 commit 8f0d965

File tree

1 file changed

+55
-3
lines changed

1 file changed

+55
-3
lines changed

token/program-2022-test/tests/transfer_hook.rs

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use {
3939
};
4040

4141
const TEST_MAXIMUM_FEE: u64 = 10_000_000;
42-
const TEST_FEE_BASIS_POINTS: u16 = 250;
42+
const TEST_FEE_BASIS_POINTS: u16 = 100;
4343

4444
/// Test program to fail transfer hook, conforms to transfer-hook-interface
4545
pub fn process_instruction_fail(
@@ -144,6 +144,58 @@ pub fn process_instruction_swap(
144144
Ok(())
145145
}
146146

147+
// Test program to transfer two types of tokens with transfer hooks at once with
148+
// fees
149+
pub fn process_instruction_swap_with_fee(
150+
_program_id: &Pubkey,
151+
accounts: &[AccountInfo],
152+
_input: &[u8],
153+
) -> ProgramResult {
154+
let account_info_iter = &mut accounts.iter();
155+
156+
let source_a_account_info = next_account_info(account_info_iter)?;
157+
let mint_a_info = next_account_info(account_info_iter)?;
158+
let destination_a_account_info = next_account_info(account_info_iter)?;
159+
let authority_a_info = next_account_info(account_info_iter)?;
160+
let token_program_a_info = next_account_info(account_info_iter)?;
161+
162+
let source_b_account_info = next_account_info(account_info_iter)?;
163+
let mint_b_info = next_account_info(account_info_iter)?;
164+
let destination_b_account_info = next_account_info(account_info_iter)?;
165+
let authority_b_info = next_account_info(account_info_iter)?;
166+
let token_program_b_info = next_account_info(account_info_iter)?;
167+
168+
let remaining_accounts = account_info_iter.as_slice();
169+
170+
onchain::invoke_transfer_checked_with_fee(
171+
token_program_a_info.key,
172+
source_a_account_info.clone(),
173+
mint_a_info.clone(),
174+
destination_a_account_info.clone(),
175+
authority_a_info.clone(),
176+
remaining_accounts,
177+
1_000_000_000,
178+
9,
179+
10_000_000,
180+
&[],
181+
)?;
182+
183+
onchain::invoke_transfer_checked_with_fee(
184+
token_program_b_info.key,
185+
source_b_account_info.clone(),
186+
mint_b_info.clone(),
187+
destination_b_account_info.clone(),
188+
authority_b_info.clone(),
189+
remaining_accounts,
190+
1_000_000_000,
191+
9,
192+
10_000_000,
193+
&[],
194+
)?;
195+
196+
Ok(())
197+
}
198+
147199
async fn setup_accounts(
148200
token_context: &TokenContext,
149201
alice_account: Keypair,
@@ -973,7 +1025,7 @@ async fn success_transfers_with_fee_using_onchain_helper() {
9731025
let mint_a = mint_a_keypair.pubkey();
9741026
let mint_b_keypair = Keypair::new();
9751027
let mint_b = mint_b_keypair.pubkey();
976-
let amount = 10;
1028+
let amount = 10_000_000_000;
9771029

9781030
let transfer_fee_config_authority = Keypair::new();
9791031
let withdraw_withheld_authority = Keypair::new();
@@ -985,7 +1037,7 @@ async fn success_transfers_with_fee_using_onchain_helper() {
9851037
program_test.add_program(
9861038
"my_swap",
9871039
swap_program_id,
988-
processor!(process_instruction_swap),
1040+
processor!(process_instruction_swap_with_fee),
9891041
);
9901042
add_validation_account(&mut program_test, &mint_a, &program_id);
9911043
add_validation_account(&mut program_test, &mint_b, &program_id);

0 commit comments

Comments
 (0)