@@ -7,7 +7,7 @@ use common::setup::{TestData, OTHER_CHAIN};
77use example_native_token_transfers:: {
88 bitmap:: Bitmap ,
99 error:: NTTError ,
10- instructions:: TransferArgs ,
10+ instructions:: { SetOutboundLimitArgs , TransferArgs } ,
1111 queue:: outbox:: { OutboxItem , OutboxRateLimit } ,
1212 transceivers:: wormhole:: ReleaseOutboundArgs ,
1313 transfer:: Payload ,
@@ -28,7 +28,7 @@ use wormhole_anchor_sdk::wormhole::PostedVaa;
2828use crate :: {
2929 common:: {
3030 query:: GetAccountDataAnchor ,
31- setup:: { ANOTHER_CHAIN , OUTBOUND_LIMIT } ,
31+ setup:: { ANOTHER_CHAIN , OUTBOUND_LIMIT , UNREGISTERED_CHAIN } ,
3232 } ,
3333 sdk:: {
3434 accounts:: { good_ntt, NTTAccounts } ,
@@ -39,7 +39,7 @@ use crate::{
3939 common:: { setup:: OTHER_MANAGER , submit:: Submittable } ,
4040 sdk:: {
4141 instructions:: {
42- admin:: { set_paused, SetPaused } ,
42+ admin:: { set_outbound_limit , set_paused, SetOutboundLimit , SetPaused } ,
4343 transfer:: {
4444 approve_token_authority, approve_token_authority_with_token_program_id, transfer,
4545 transfer_with_token_program_id,
@@ -56,13 +56,6 @@ pub mod sdk;
5656
5757use crate :: common:: setup:: { setup, setup_with_transfer_fee} ;
5858
59- // TODO: some more tests
60- // - unregistered peer can't transfer
61- // - can't transfer to unregistered peer
62- // - can't transfer more than balance
63- // - wrong inbox accounts
64- // - paused contracts
65-
6659/// Helper function for setting up transfer accounts and args.
6760/// It sets the accounts up properly, so for negative testing we just modify the
6861/// result.
@@ -662,6 +655,64 @@ async fn test_transfer_wrong_mode() {
662655 ) ;
663656}
664657
658+ #[ tokio:: test]
659+ async fn test_cant_transfer_more_than_balance ( ) {
660+ let ( mut ctx, test_data) = setup ( Mode :: Locking ) . await ;
661+
662+ let outbox_item = Keypair :: new ( ) ;
663+
664+ let token_account: TokenAccount = ctx
665+ . get_account_data_anchor ( test_data. user_token_account )
666+ . await ;
667+ let more_than_balance = token_account. amount . checked_add ( 100 ) . unwrap ( ) ;
668+
669+ // extend outbound limit to avoid TransferExceedsRateLimit error
670+ set_outbound_limit (
671+ & good_ntt,
672+ SetOutboundLimit {
673+ owner : test_data. program_owner . pubkey ( ) ,
674+ } ,
675+ SetOutboundLimitArgs {
676+ limit : more_than_balance,
677+ } ,
678+ )
679+ . submit_with_signers ( & [ & test_data. program_owner ] , & mut ctx)
680+ . await
681+ . unwrap ( ) ;
682+
683+ // try to transfer more than balance
684+ let ( accs, args) = init_accs_args (
685+ & good_ntt,
686+ & mut ctx,
687+ & test_data,
688+ outbox_item. pubkey ( ) ,
689+ more_than_balance,
690+ false ,
691+ ) ;
692+
693+ approve_token_authority (
694+ & good_ntt,
695+ & test_data. user_token_account ,
696+ & test_data. user . pubkey ( ) ,
697+ & args,
698+ )
699+ . submit_with_signers ( & [ & test_data. user ] , & mut ctx)
700+ . await
701+ . unwrap ( ) ;
702+ let err = transfer ( & good_ntt, accs, args, Mode :: Locking )
703+ . submit_with_signers ( & [ & outbox_item] , & mut ctx)
704+ . await
705+ . unwrap_err ( ) ;
706+
707+ assert_eq ! (
708+ err. unwrap( ) ,
709+ TransactionError :: InstructionError (
710+ 0 ,
711+ InstructionError :: Custom ( spl_token:: error:: TokenError :: InsufficientFunds as u32 , )
712+ )
713+ ) ;
714+ }
715+
665716async fn assert_queued ( ctx : & mut ProgramTestContext , outbox_item : Pubkey ) {
666717 let outbox_item_account: OutboxItem = ctx. get_account_data_anchor ( outbox_item) . await ;
667718
0 commit comments