Skip to content

Commit

Permalink
token 2022 test: refactor transfer hook test to use new offchain helper
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Jan 10, 2024
1 parent 8bda3ed commit 7de4df7
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions token/program-2022-test/tests/transfer_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use {
processor::Processor,
},
spl_token_client::token::{ExtensionInitializationParams, TokenError as TokenClientError},
spl_transfer_hook_interface::get_extra_account_metas_address,
spl_transfer_hook_interface::{get_extra_account_metas_address, offchain::add_extra_account_metas_for_execute},
std::{convert::TryInto, sync::Arc},
};

Expand Down Expand Up @@ -627,7 +627,6 @@ async fn success_downgrade_writable_and_signer_accounts() {
.unwrap();
}

#[allow(deprecated)]
#[tokio::test]
async fn success_transfers_using_onchain_helper() {
let authority = Pubkey::new_unique();
Expand Down Expand Up @@ -704,8 +703,14 @@ async fn success_transfers_using_onchain_helper() {

let mut instruction = Instruction::new_with_bytes(swap_program_id, &[], account_metas);

offchain::resolve_extra_transfer_account_metas(
add_extra_account_metas_for_execute(
&mut instruction,
&program_id,
&source_a_account,
&mint_a,
&destination_a_account,
&authority_a.pubkey(),
amount,
|address| {
token_a.get_account(address).map_ok_or_else(
|e| match e {
Expand All @@ -715,12 +720,17 @@ async fn success_transfers_using_onchain_helper() {
|acc| Ok(Some(acc.data)),
)
},
&mint_a,
)
.await
.unwrap();
offchain::resolve_extra_transfer_account_metas(
add_extra_account_metas_for_execute(
&mut instruction,
&program_id,
&source_b_account,
&mint_b,
&destination_b_account,
&authority_b.pubkey(),
amount,
|address| {
token_a.get_account(address).map_ok_or_else(
|e| match e {
Expand All @@ -730,7 +740,6 @@ async fn success_transfers_using_onchain_helper() {
|acc| Ok(Some(acc.data)),
)
},
&mint_b,
)
.await
.unwrap();
Expand Down

0 comments on commit 7de4df7

Please sign in to comment.