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

Commit 5f490e5

Browse files
author
Joe C
authored
token 2022 test: refactor transfer hook test to use new offchain helper
Following up from the new helpers added in #6099 and #6100, there's a transfer hook test in `program-2022-test` that's using the now-deprecated helper to build a swap instruction for the test program. This PR replaces that bit of code to use the new helper from `spl_transfer_hook_interface`. Note: The test in question is designed to test Token2022's `invoke_transfer_checked(..)` on-chain helper, *not* the offchain helpers. So, it's appropriate to use the offchain helper directly from the interface crate for this step.
1 parent e13db27 commit 5f490e5

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ use {
2727
processor::Processor,
2828
},
2929
spl_token_client::token::{ExtensionInitializationParams, TokenError as TokenClientError},
30-
spl_transfer_hook_interface::get_extra_account_metas_address,
30+
spl_transfer_hook_interface::{
31+
get_extra_account_metas_address, offchain::add_extra_account_metas_for_execute,
32+
},
3133
std::{convert::TryInto, sync::Arc},
3234
};
3335

@@ -627,7 +629,6 @@ async fn success_downgrade_writable_and_signer_accounts() {
627629
.unwrap();
628630
}
629631

630-
#[allow(deprecated)]
631632
#[tokio::test]
632633
async fn success_transfers_using_onchain_helper() {
633634
let authority = Pubkey::new_unique();
@@ -704,8 +705,14 @@ async fn success_transfers_using_onchain_helper() {
704705

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

707-
offchain::resolve_extra_transfer_account_metas(
708+
add_extra_account_metas_for_execute(
708709
&mut instruction,
710+
&program_id,
711+
&source_a_account,
712+
&mint_a,
713+
&destination_a_account,
714+
&authority_a.pubkey(),
715+
amount,
709716
|address| {
710717
token_a.get_account(address).map_ok_or_else(
711718
|e| match e {
@@ -715,12 +722,17 @@ async fn success_transfers_using_onchain_helper() {
715722
|acc| Ok(Some(acc.data)),
716723
)
717724
},
718-
&mint_a,
719725
)
720726
.await
721727
.unwrap();
722-
offchain::resolve_extra_transfer_account_metas(
728+
add_extra_account_metas_for_execute(
723729
&mut instruction,
730+
&program_id,
731+
&source_b_account,
732+
&mint_b,
733+
&destination_b_account,
734+
&authority_b.pubkey(),
735+
amount,
724736
|address| {
725737
token_a.get_account(address).map_ok_or_else(
726738
|e| match e {
@@ -730,7 +742,6 @@ async fn success_transfers_using_onchain_helper() {
730742
|acc| Ok(Some(acc.data)),
731743
)
732744
},
733-
&mint_b,
734745
)
735746
.await
736747
.unwrap();

0 commit comments

Comments
 (0)