From 8abb41f545fbb2a104ad5e1c8d87bfad87dc4452 Mon Sep 17 00:00:00 2001 From: Csongor Kiss Date: Wed, 28 Feb 2024 01:45:01 -0500 Subject: [PATCH] solana: add some more receive tests --- .../tests/cancel_flow.rs | 152 ++------ .../tests/common/mod.rs | 1 + .../tests/common/setup.rs | 10 +- .../tests/common/utils.rs | 73 ++++ .../tests/governance.rs | 1 - .../tests/receive.rs | 369 ++++++++++++++++++ .../tests/sdk/instructions/mod.rs | 1 + .../tests/sdk/instructions/release_inbound.rs | 40 ++ .../tests/transfer.rs | 20 +- 9 files changed, 542 insertions(+), 125 deletions(-) create mode 100644 solana/programs/example-native-token-transfers/tests/common/utils.rs create mode 100644 solana/programs/example-native-token-transfers/tests/receive.rs create mode 100644 solana/programs/example-native-token-transfers/tests/sdk/instructions/release_inbound.rs diff --git a/solana/programs/example-native-token-transfers/tests/cancel_flow.rs b/solana/programs/example-native-token-transfers/tests/cancel_flow.rs index da3c7b773..5116b2d3d 100644 --- a/solana/programs/example-native-token-transfers/tests/cancel_flow.rs +++ b/solana/programs/example-native-token-transfers/tests/cancel_flow.rs @@ -2,41 +2,40 @@ #![feature(type_changing_struct_update)] use anchor_lang::prelude::*; -use common::setup::{TestData, OTHER_CHAIN, OTHER_MANAGER, OTHER_TRANSCEIVER, THIS_CHAIN}; +use common::setup::{TestData, OTHER_CHAIN}; use example_native_token_transfers::{ - error::NTTError, instructions::{RedeemArgs, TransferArgs}, queue::{inbox::InboxRateLimit, outbox::OutboxRateLimit}, }; use ntt_messages::{ chain_id::ChainId, mode::Mode, ntt::NativeTokenTransfer, ntt_manager::NttManagerMessage, - transceiver::TransceiverMessage, transceivers::wormhole::WormholeTransceiver, - trimmed_amount::TrimmedAmount, }; use sdk::{ accounts::{good_ntt, NTTAccounts}, transceivers::wormhole::instructions::receive_message::ReceiveMessage, }; -use solana_program::instruction::InstructionError; use solana_program_test::*; -use solana_sdk::{signature::Keypair, signer::Signer, transaction::TransactionError}; -use wormhole_sdk::{Address, Vaa}; +use solana_sdk::{signature::Keypair, signer::Signer}; +use wormhole_sdk::Address; use crate::{ - common::submit::Submittable, - sdk::instructions::transfer::{approve_token_authority, transfer}, -}; -use crate::{ - common::{query::GetAccountDataAnchor, setup::setup}, + common::{ + query::GetAccountDataAnchor, + setup::{setup, OTHER_TRANSCEIVER}, + utils::make_transfer_message, + }, sdk::{ instructions::{ - post_vaa::post_vaa, redeem::{redeem, Redeem}, transfer::Transfer, }, transceivers::wormhole::instructions::receive_message::receive_message, }, }; +use crate::{ + common::{submit::Submittable, utils::post_vaa_helper}, + sdk::instructions::transfer::{approve_token_authority, transfer}, +}; pub mod common; pub mod sdk; @@ -99,58 +98,6 @@ fn init_receive_message_accs( } } -async fn post_transfer_vaa( - ctx: &mut ProgramTestContext, - id: [u8; 32], - amount: u64, - // TODO: this is used for a negative testing of the recipient ntt_manager - // address. this should not be done in the cancel flow tests, but instead a - // dedicated receive transfer test suite - recipient_ntt_manager: Option<&Pubkey>, - recipient: &Keypair, -) -> (Pubkey, NttManagerMessage) { - let ntt_manager_message = NttManagerMessage { - id, - sender: [4u8; 32], - payload: NativeTokenTransfer { - amount: TrimmedAmount { - amount, - decimals: 9, - }, - source_token: [3u8; 32], - to_chain: ChainId { id: THIS_CHAIN }, - to: recipient.pubkey().to_bytes(), - }, - }; - - let transceiver_message: TransceiverMessage = - TransceiverMessage::new( - OTHER_MANAGER, - recipient_ntt_manager - .map(|k| k.to_bytes()) - .unwrap_or_else(|| good_ntt.program().to_bytes()), - ntt_manager_message.clone(), - vec![], - ); - - let vaa = Vaa { - version: 1, - guardian_set_index: 0, - signatures: vec![], - timestamp: 123232, - nonce: 0, - emitter_chain: OTHER_CHAIN.into(), - emitter_address: Address(OTHER_TRANSCEIVER), - sequence: 0, - consistency_level: 0, - payload: transceiver_message, - }; - - let posted_vaa = post_vaa(&good_ntt.wormhole(), ctx, vaa).await; - - (posted_vaa, ntt_manager_message) -} - async fn outbound_capacity(ctx: &mut ProgramTestContext) -> u64 { let clock: Clock = ctx.banks_client.get_sysvar().await.unwrap(); let rate_limit: OutboxRateLimit = ctx @@ -174,8 +121,24 @@ async fn test_cancel() { let recipient = Keypair::new(); let (mut ctx, test_data) = setup(Mode::Locking).await; - let (vaa0, msg0) = post_transfer_vaa(&mut ctx, [0u8; 32], 1000, None, &recipient).await; - let (vaa1, msg1) = post_transfer_vaa(&mut ctx, [1u8; 32], 2000, None, &recipient).await; + let msg0 = make_transfer_message(&good_ntt, [0u8; 32], 1000, &recipient.pubkey()); + let msg1 = make_transfer_message(&good_ntt, [1u8; 32], 2000, &recipient.pubkey()); + let vaa0 = post_vaa_helper( + &good_ntt, + OTHER_CHAIN.into(), + Address(OTHER_TRANSCEIVER), + msg0.clone(), + &mut ctx, + ) + .await; + let vaa1 = post_vaa_helper( + &good_ntt, + OTHER_CHAIN.into(), + Address(OTHER_TRANSCEIVER), + msg1.clone(), + &mut ctx, + ) + .await; let inbound_limit_before = inbound_capacity(&mut ctx).await; let outbound_limit_before = outbound_capacity(&mut ctx).await; @@ -190,7 +153,12 @@ async fn test_cancel() { redeem( &good_ntt, - init_redeem_accs(&mut ctx, &test_data, OTHER_CHAIN, msg0), + init_redeem_accs( + &mut ctx, + &test_data, + OTHER_CHAIN, + msg0.ntt_manager_payload.clone(), + ), RedeemArgs {}, ) .submit(&mut ctx) @@ -241,7 +209,12 @@ async fn test_cancel() { redeem( &good_ntt, - init_redeem_accs(&mut ctx, &test_data, OTHER_CHAIN, msg1), + init_redeem_accs( + &mut ctx, + &test_data, + OTHER_CHAIN, + msg1.ntt_manager_payload.clone(), + ), RedeemArgs {}, ) .submit(&mut ctx) @@ -258,44 +231,3 @@ async fn test_cancel() { inbound_capacity(&mut ctx).await ); } - -// TODO: this should not live in this file, move to a dedicated receive test suite -#[tokio::test] -async fn test_wrong_recipient_ntt_manager() { - let recipient = Keypair::new(); - let (mut ctx, test_data) = setup(Mode::Locking).await; - - let (vaa0, msg0) = post_transfer_vaa( - &mut ctx, - [0u8; 32], - 1000, - Some(&Pubkey::default()), - &recipient, - ) - .await; - - receive_message( - &good_ntt, - init_receive_message_accs(&mut ctx, vaa0, OTHER_CHAIN, [0u8; 32]), - ) - .submit(&mut ctx) - .await - .unwrap(); - - let err = redeem( - &good_ntt, - init_redeem_accs(&mut ctx, &test_data, OTHER_CHAIN, msg0), - RedeemArgs {}, - ) - .submit(&mut ctx) - .await - .unwrap_err(); - - assert_eq!( - err.unwrap(), - TransactionError::InstructionError( - 0, - InstructionError::Custom(NTTError::InvalidRecipientNttManager.into()) - ) - ); -} diff --git a/solana/programs/example-native-token-transfers/tests/common/mod.rs b/solana/programs/example-native-token-transfers/tests/common/mod.rs index 5c1f8f0ca..ecf9020a8 100644 --- a/solana/programs/example-native-token-transfers/tests/common/mod.rs +++ b/solana/programs/example-native-token-transfers/tests/common/mod.rs @@ -3,3 +3,4 @@ pub mod account_json_utils; pub mod query; pub mod setup; pub mod submit; +pub mod utils; diff --git a/solana/programs/example-native-token-transfers/tests/common/setup.rs b/solana/programs/example-native-token-transfers/tests/common/setup.rs index 73b0883c0..fa09a8f6b 100644 --- a/solana/programs/example-native-token-transfers/tests/common/setup.rs +++ b/solana/programs/example-native-token-transfers/tests/common/setup.rs @@ -215,7 +215,7 @@ pub async fn setup_ntt(ctx: &mut ProgramTestContext, test_data: &TestData, mode: .unwrap(); set_peer( - &GoodNTT {}, + &good_ntt, SetPeer { payer: ctx.payer.pubkey(), owner: test_data.program_owner.pubkey(), @@ -268,8 +268,11 @@ pub async fn setup_accounts(ctx: &mut ProgramTestContext, program_owner: Keypair .await .unwrap(); - let bad_user_token_account = - get_associated_token_address_with_program_id(&user.pubkey(), &bad_mint.pubkey(), &Token::id()); + let bad_user_token_account = get_associated_token_address_with_program_id( + &user.pubkey(), + &bad_mint.pubkey(), + &Token::id(), + ); spl_associated_token_account::instruction::create_associated_token_account( &payer, @@ -281,7 +284,6 @@ pub async fn setup_accounts(ctx: &mut ProgramTestContext, program_owner: Keypair .await .unwrap(); - spl_token::instruction::mint_to( &Token::id(), &mint.pubkey(), diff --git a/solana/programs/example-native-token-transfers/tests/common/utils.rs b/solana/programs/example-native-token-transfers/tests/common/utils.rs new file mode 100644 index 000000000..4d044f715 --- /dev/null +++ b/solana/programs/example-native-token-transfers/tests/common/utils.rs @@ -0,0 +1,73 @@ +use std::sync::atomic::AtomicU64; + +use anchor_lang::AnchorSerialize; +use ntt_messages::{ + chain_id::ChainId, ntt::NativeTokenTransfer, ntt_manager::NttManagerMessage, + transceiver::TransceiverMessage, transceivers::wormhole::WormholeTransceiver, + trimmed_amount::TrimmedAmount, +}; +use solana_program::pubkey::Pubkey; +use solana_program_test::ProgramTestContext; +use wormhole_sdk::{Address, Chain, Vaa}; + +use crate::sdk::accounts::NTT; + +use super::setup::{OTHER_MANAGER, THIS_CHAIN}; +use crate::sdk::instructions::post_vaa::post_vaa; + +pub fn make_transfer_message( + ntt: &NTT, + id: [u8; 32], + amount: u64, + recipient: &Pubkey, +) -> TransceiverMessage { + let ntt_manager_message = NttManagerMessage { + id, + sender: [4u8; 32], + payload: NativeTokenTransfer { + amount: TrimmedAmount { + amount, + decimals: 9, + }, + source_token: [3u8; 32], + to_chain: ChainId { id: THIS_CHAIN }, + to: recipient.to_bytes(), + }, + }; + + TransceiverMessage::new( + OTHER_MANAGER, + ntt.program().to_bytes(), + ntt_manager_message.clone(), + vec![], + ) +} + +pub async fn post_vaa_helper( + ntt: &NTT, + emitter_chain: Chain, + emitter_address: Address, + msg: A, + ctx: &mut ProgramTestContext, +) -> Pubkey { + static I: AtomicU64 = AtomicU64::new(0); + + let sequence = I.fetch_add(1, std::sync::atomic::Ordering::Acquire); + + let vaa = Vaa { + version: 1, + guardian_set_index: 0, + signatures: vec![], + timestamp: 123232, + nonce: 0, + emitter_chain, + emitter_address, + sequence, + consistency_level: 0, + payload: msg, + }; + + let posted_vaa = post_vaa(&ntt.wormhole(), ctx, vaa).await; + + posted_vaa +} diff --git a/solana/programs/example-native-token-transfers/tests/governance.rs b/solana/programs/example-native-token-transfers/tests/governance.rs index d86a79f82..6ce44d482 100644 --- a/solana/programs/example-native-token-transfers/tests/governance.rs +++ b/solana/programs/example-native-token-transfers/tests/governance.rs @@ -122,7 +122,6 @@ async fn transfer_ownership_to_gov_program( (vaa, inner_ix) } - #[tokio::test] async fn test_governance() { let (mut ctx, test_data) = setup(Mode::Locking).await; diff --git a/solana/programs/example-native-token-transfers/tests/receive.rs b/solana/programs/example-native-token-transfers/tests/receive.rs new file mode 100644 index 000000000..51eb2afbb --- /dev/null +++ b/solana/programs/example-native-token-transfers/tests/receive.rs @@ -0,0 +1,369 @@ +#![cfg(feature = "test-sbf")] +#![feature(type_changing_struct_update)] + +use anchor_lang::prelude::*; +use anchor_spl::token::{Token, TokenAccount}; +use common::{ + setup::{TestData, OTHER_CHAIN}, + utils::make_transfer_message, +}; +use example_native_token_transfers::{ + error::NTTError, + instructions::{RedeemArgs, ReleaseInboundArgs}, +}; +use ntt_messages::{mode::Mode, ntt::NativeTokenTransfer, ntt_manager::NttManagerMessage}; +use sdk::{ + accounts::NTTAccounts, transceivers::wormhole::instructions::receive_message::ReceiveMessage, +}; +use solana_program::instruction::InstructionError; +use solana_program_test::*; +use solana_sdk::{signature::Keypair, signer::Signer, transaction::TransactionError}; +use spl_associated_token_account::get_associated_token_address_with_program_id; +use wormhole_sdk::Address; + +use crate::{ + common::{ + query::GetAccountDataAnchor, + setup::{setup, OTHER_TRANSCEIVER}, + }, + sdk::{ + accounts::good_ntt, + instructions::redeem::{redeem, Redeem}, + transceivers::wormhole::instructions::receive_message::receive_message, + }, +}; +use crate::{ + common::{submit::Submittable, utils::post_vaa_helper}, + sdk::instructions::release_inbound::{release_inbound_unlock, ReleaseInbound}, +}; + +pub mod common; +pub mod sdk; + +fn init_redeem_accs( + ctx: &mut ProgramTestContext, + test_data: &TestData, + chain_id: u16, + ntt_manager_message: NttManagerMessage, +) -> Redeem { + Redeem { + payer: ctx.payer.pubkey(), + peer: good_ntt.peer(chain_id), + transceiver: good_ntt.program(), + transceiver_message: good_ntt.transceiver_message(chain_id, ntt_manager_message.id), + inbox_item: good_ntt.inbox_item(chain_id, ntt_manager_message), + inbox_rate_limit: good_ntt.inbox_rate_limit(chain_id), + mint: test_data.mint, + } +} + +fn init_receive_message_accs( + ctx: &mut ProgramTestContext, + vaa: Pubkey, + chain_id: u16, + id: [u8; 32], +) -> ReceiveMessage { + ReceiveMessage { + payer: ctx.payer.pubkey(), + peer: good_ntt.transceiver_peer(chain_id), + vaa, + chain_id, + id, + } +} + +#[tokio::test] +async fn test_receive() { + let recipient = Keypair::new(); + let (mut ctx, test_data) = setup(Mode::Locking).await; + + // transfer tokens to custody account + spl_token::instruction::transfer_checked( + &Token::id(), + &test_data.user_token_account, + &test_data.mint, + &good_ntt.custody(&test_data.mint), + &test_data.user.pubkey(), + &[], + 1000, + 9, + ) + .unwrap() + .submit_with_signers(&[&test_data.user], &mut ctx) + .await + .unwrap(); + + spl_associated_token_account::instruction::create_associated_token_account( + &ctx.payer.pubkey(), + &recipient.pubkey(), + &test_data.mint, + &Token::id(), + ) + .submit(&mut ctx) + .await + .unwrap(); + + let recipient_token_account = get_associated_token_address_with_program_id( + &recipient.pubkey(), + &test_data.mint, + &Token::id(), + ); + + let msg = make_transfer_message(&good_ntt, [0u8; 32], 1000, &recipient.pubkey()); + + let vaa0 = post_vaa_helper( + &good_ntt, + OTHER_CHAIN.into(), + Address(OTHER_TRANSCEIVER), + msg.clone(), + &mut ctx, + ) + .await; + + receive_message( + &good_ntt, + init_receive_message_accs(&mut ctx, vaa0, OTHER_CHAIN, [0u8; 32]), + ) + .submit(&mut ctx) + .await + .unwrap(); + + redeem( + &good_ntt, + init_redeem_accs( + &mut ctx, + &test_data, + OTHER_CHAIN, + msg.ntt_manager_payload.clone(), + ), + RedeemArgs {}, + ) + .submit(&mut ctx) + .await + .unwrap(); + + let token_account: TokenAccount = ctx.get_account_data_anchor(recipient_token_account).await; + + assert_eq!(token_account.amount, 0); + + release_inbound_unlock( + &good_ntt, + ReleaseInbound { + payer: ctx.payer.pubkey(), + inbox_item: good_ntt.inbox_item(OTHER_CHAIN, msg.ntt_manager_payload.clone()), + mint: test_data.mint, + recipient: recipient_token_account, + }, + ReleaseInboundArgs { + revert_on_delay: false, + }, + ) + .submit(&mut ctx) + .await + .unwrap(); + + let token_account: TokenAccount = ctx.get_account_data_anchor(recipient_token_account).await; + assert_eq!(token_account.amount, 1000); + + // let's make sure we can't redeem again. + let err = release_inbound_unlock( + &good_ntt, + ReleaseInbound { + payer: ctx.payer.pubkey(), + inbox_item: good_ntt.inbox_item(OTHER_CHAIN, msg.ntt_manager_payload.clone()), + mint: test_data.mint, + recipient: recipient_token_account, + }, + ReleaseInboundArgs { + revert_on_delay: false, + }, + ) + .submit(&mut ctx) + .await + .unwrap_err(); + + assert_eq!( + err.unwrap(), + TransactionError::InstructionError( + 0, + InstructionError::Custom(NTTError::TransferAlreadyRedeemed.into()) + ) + ); +} + +#[tokio::test] +async fn test_double_receive() { + let recipient = Keypair::new(); + let (mut ctx, _test_data) = setup(Mode::Locking).await; + + let msg = make_transfer_message(&good_ntt, [0u8; 32], 1000, &recipient.pubkey()); + + let vaa0 = post_vaa_helper( + &good_ntt, + OTHER_CHAIN.into(), + Address(OTHER_TRANSCEIVER), + msg.clone(), + &mut ctx, + ) + .await; + let vaa1 = post_vaa_helper( + &good_ntt, + OTHER_CHAIN.into(), + Address(OTHER_TRANSCEIVER), + msg, + &mut ctx, + ) + .await; + + receive_message( + &good_ntt, + init_receive_message_accs(&mut ctx, vaa0, OTHER_CHAIN, [0u8; 32]), + ) + .submit(&mut ctx) + .await + .unwrap(); + + let err = receive_message( + &good_ntt, + init_receive_message_accs(&mut ctx, vaa1, OTHER_CHAIN, [0u8; 32]), + ) + .submit(&mut ctx) + .await + .unwrap_err(); + + assert_eq!( + err.unwrap(), + TransactionError::InstructionError(0, InstructionError::Custom(0)) + ); +} + +#[tokio::test] +async fn test_wrong_recipient_ntt_manager() { + let recipient = Keypair::new(); + let (mut ctx, test_data) = setup(Mode::Locking).await; + + let mut msg = make_transfer_message(&good_ntt, [0u8; 32], 1000, &recipient.pubkey()); + + msg.recipient_ntt_manager = Pubkey::new_unique().to_bytes(); + + let vaa0 = post_vaa_helper( + &good_ntt, + OTHER_CHAIN.into(), + Address(OTHER_TRANSCEIVER), + msg.clone(), + &mut ctx, + ) + .await; + + receive_message( + &good_ntt, + init_receive_message_accs(&mut ctx, vaa0, OTHER_CHAIN, [0u8; 32]), + ) + .submit(&mut ctx) + .await + .unwrap(); + + let err = redeem( + &good_ntt, + init_redeem_accs( + &mut ctx, + &test_data, + OTHER_CHAIN, + msg.ntt_manager_payload.clone(), + ), + RedeemArgs {}, + ) + .submit(&mut ctx) + .await + .unwrap_err(); + + assert_eq!( + err.unwrap(), + TransactionError::InstructionError( + 0, + InstructionError::Custom(NTTError::InvalidRecipientNttManager.into()) + ) + ); +} + +#[tokio::test] +async fn test_wrong_transceiver_peer() { + let recipient = Keypair::new(); + let (mut ctx, _test_data) = setup(Mode::Locking).await; + + let msg = make_transfer_message(&good_ntt, [0u8; 32], 1000, &recipient.pubkey()); + + let vaa0 = post_vaa_helper( + &good_ntt, + OTHER_CHAIN.into(), + Address(Pubkey::new_unique().to_bytes()), // not the expected transceiver + msg.clone(), + &mut ctx, + ) + .await; + + let err = receive_message( + &good_ntt, + init_receive_message_accs(&mut ctx, vaa0, OTHER_CHAIN, [0u8; 32]), + ) + .submit(&mut ctx) + .await + .unwrap_err(); + + assert_eq!( + err.unwrap(), + TransactionError::InstructionError( + 0, + InstructionError::Custom(NTTError::InvalidTransceiverPeer.into()) + ) + ); +} + +#[tokio::test] +async fn test_wrong_manager_peer() { + let recipient = Keypair::new(); + let (mut ctx, test_data) = setup(Mode::Locking).await; + + let mut msg = make_transfer_message(&good_ntt, [0u8; 32], 1000, &recipient.pubkey()); + + msg.source_ntt_manager = Pubkey::new_unique().to_bytes(); // not the expected source manager + + let vaa0 = post_vaa_helper( + &good_ntt, + OTHER_CHAIN.into(), + Address(OTHER_TRANSCEIVER), + msg.clone(), + &mut ctx, + ) + .await; + + receive_message( + &good_ntt, + init_receive_message_accs(&mut ctx, vaa0, OTHER_CHAIN, [0u8; 32]), + ) + .submit(&mut ctx) + .await + .unwrap(); + + let err = redeem( + &good_ntt, + init_redeem_accs( + &mut ctx, + &test_data, + OTHER_CHAIN, + msg.ntt_manager_payload.clone(), + ), + RedeemArgs {}, + ) + .submit(&mut ctx) + .await + .unwrap_err(); + + assert_eq!( + err.unwrap(), + TransactionError::InstructionError( + 0, + InstructionError::Custom(NTTError::InvalidNttManagerPeer.into()) + ) + ); +} diff --git a/solana/programs/example-native-token-transfers/tests/sdk/instructions/mod.rs b/solana/programs/example-native-token-transfers/tests/sdk/instructions/mod.rs index b97075c76..dc9fbe6bd 100644 --- a/solana/programs/example-native-token-transfers/tests/sdk/instructions/mod.rs +++ b/solana/programs/example-native-token-transfers/tests/sdk/instructions/mod.rs @@ -2,4 +2,5 @@ pub mod admin; pub mod initialize; pub mod post_vaa; pub mod redeem; +pub mod release_inbound; pub mod transfer; diff --git a/solana/programs/example-native-token-transfers/tests/sdk/instructions/release_inbound.rs b/solana/programs/example-native-token-transfers/tests/sdk/instructions/release_inbound.rs new file mode 100644 index 000000000..68c792316 --- /dev/null +++ b/solana/programs/example-native-token-transfers/tests/sdk/instructions/release_inbound.rs @@ -0,0 +1,40 @@ +use anchor_lang::{prelude::*, InstructionData}; +use anchor_spl::token::Token; +use example_native_token_transfers::{accounts::NotPausedConfig, instructions::ReleaseInboundArgs}; +use solana_sdk::instruction::Instruction; + +use crate::sdk::accounts::NTT; + +pub struct ReleaseInbound { + pub payer: Pubkey, + pub inbox_item: Pubkey, + pub mint: Pubkey, + pub recipient: Pubkey, +} + +pub fn release_inbound_unlock( + ntt: &NTT, + release_inbound: ReleaseInbound, + args: ReleaseInboundArgs, +) -> Instruction { + let data = example_native_token_transfers::instruction::ReleaseInboundUnlock { args }; + let accounts = example_native_token_transfers::accounts::ReleaseInboundUnlock { + common: example_native_token_transfers::accounts::ReleaseInbound { + payer: release_inbound.payer, + config: NotPausedConfig { + config: ntt.config(), + }, + inbox_item: release_inbound.inbox_item, + recipient: release_inbound.recipient, + token_authority: ntt.token_authority(), + mint: release_inbound.mint, + token_program: Token::id(), + }, + custody: ntt.custody(&release_inbound.mint), + }; + Instruction { + program_id: example_native_token_transfers::ID, + accounts: accounts.to_account_metas(None), + data: data.data(), + } +} diff --git a/solana/programs/example-native-token-transfers/tests/transfer.rs b/solana/programs/example-native-token-transfers/tests/transfer.rs index 874b8fb96..e932cadc5 100644 --- a/solana/programs/example-native-token-transfers/tests/transfer.rs +++ b/solana/programs/example-native-token-transfers/tests/transfer.rs @@ -1,4 +1,4 @@ -// #![cfg(feature = "test-sbf")] +#![cfg(feature = "test-sbf")] #![feature(type_changing_struct_update)] use anchor_lang::prelude::{Clock, ErrorCode, Pubkey}; @@ -326,7 +326,7 @@ async fn test_bad_mint() { let outbox_item = Keypair::new(); let (mut accs, args) = init_accs_args( - &GoodNTT {}, + &good_ntt, &mut ctx, &test_data, outbox_item.pubkey(), @@ -338,17 +338,17 @@ async fn test_bad_mint() { accs.mint = test_data.bad_mint; approve_token_authority( - &GoodNTT {}, + &good_ntt, &test_data.bad_user_token_account, &test_data.user.pubkey(), - args.amount, + &args, ) .submit_with_signers(&[&test_data.user], &mut ctx) .await .unwrap(); - let err = transfer(&GoodNTT {}, accs, args, Mode::Locking) - .submit_with_signers(&[&test_data.user, &outbox_item], &mut ctx) + let err = transfer(&good_ntt, accs, args, Mode::Locking) + .submit_with_signers(&[&outbox_item], &mut ctx) .await .unwrap_err(); @@ -370,7 +370,7 @@ async fn test_invalid_peer() { impl NTTAccounts for BadNTT { fn peer(&self, _chain_id: u16) -> Pubkey { // return 'ANOTHER_CHAIN' peer account - GoodNTT {}.peer(ANOTHER_CHAIN) + good_ntt.peer(ANOTHER_CHAIN) } } @@ -388,17 +388,17 @@ async fn test_invalid_peer() { ); approve_token_authority( - &GoodNTT {}, + &good_ntt, &test_data.bad_user_token_account, &test_data.user.pubkey(), - args.amount, + &args, ) .submit_with_signers(&[&test_data.user], &mut ctx) .await .unwrap(); let err = transfer(&BadNTT {}, accs, args, Mode::Locking) - .submit_with_signers(&[&test_data.user, &outbox_item], &mut ctx) + .submit_with_signers(&[&outbox_item], &mut ctx) .await .unwrap_err();