@@ -712,7 +712,7 @@ async fn fail_without_token_approval() {
712712}
713713
714714#[ tokio:: test]
715- async fn fail_with_low_delegation ( ) {
715+ async fn fail_with_not_enough_tokens ( ) {
716716 let (
717717 mut context,
718718 stake_pool_accounts,
@@ -723,20 +723,51 @@ async fn fail_with_low_delegation() {
723723 tokens_to_burn,
724724 ) = setup ( spl_token:: id ( ) ) . await ;
725725
726- // Delegate few tokens for burning
727- delegate_tokens (
726+ // Empty validator stake account
727+ let empty_stake_account = simple_add_validator_to_pool (
728+ & mut context. banks_client ,
729+ & context. payer ,
730+ & context. last_blockhash ,
731+ & stake_pool_accounts,
732+ None ,
733+ )
734+ . await ;
735+
736+ let new_authority = Pubkey :: new_unique ( ) ;
737+ let error = stake_pool_accounts
738+ . withdraw_stake (
739+ & mut context. banks_client ,
740+ & context. payer ,
741+ & context. last_blockhash ,
742+ & user_stake_recipient. pubkey ( ) ,
743+ & user_transfer_authority,
744+ & deposit_info. pool_account . pubkey ( ) ,
745+ & empty_stake_account. stake_account ,
746+ & new_authority,
747+ tokens_to_burn,
748+ )
749+ . await
750+ . unwrap ( )
751+ . unwrap ( ) ;
752+ assert_eq ! (
753+ error,
754+ TransactionError :: InstructionError (
755+ 0 ,
756+ InstructionError :: Custom ( StakePoolError :: StakeLamportsNotEqualToMinimum as u32 )
757+ ) ,
758+ ) ;
759+
760+ // revoked delegation
761+ revoke_tokens (
728762 & mut context. banks_client ,
729763 & context. payer ,
730764 & context. last_blockhash ,
731765 & stake_pool_accounts. token_program_id ,
732766 & deposit_info. pool_account . pubkey ( ) ,
733767 & deposit_info. authority ,
734- & user_transfer_authority. pubkey ( ) ,
735- 1 ,
736768 )
737769 . await ;
738770
739- let new_authority = Pubkey :: new_unique ( ) ;
740771 let transaction_error = stake_pool_accounts
741772 . withdraw_stake (
742773 & mut context. banks_client ,
@@ -750,45 +781,32 @@ async fn fail_with_low_delegation() {
750781 tokens_to_burn,
751782 )
752783 . await
784+ . unwrap ( )
753785 . unwrap ( ) ;
754786
755- match transaction_error {
756- TransportError :: TransactionError ( TransactionError :: InstructionError (
757- _,
758- InstructionError :: Custom ( error_index) ,
759- ) ) => {
760- let program_error = TokenError :: InsufficientFunds as u32 ;
761- assert_eq ! ( error_index, program_error) ;
762- }
763- _ => panic ! (
764- "Wrong error occurs while try to do withdraw with not enough delegated tokens to burn"
765- ) ,
766- }
767- }
768-
769- #[ tokio:: test]
770- async fn fail_overdraw_validator ( ) {
771- let (
772- mut context,
773- stake_pool_accounts,
774- _validator_stake_account,
775- deposit_info,
776- user_transfer_authority,
777- user_stake_recipient,
778- tokens_to_burn,
779- ) = setup ( spl_token:: id ( ) ) . await ;
787+ assert_eq ! (
788+ transaction_error,
789+ TransactionError :: InstructionError (
790+ 0 ,
791+ InstructionError :: Custom ( TokenError :: OwnerMismatch as u32 ) ,
792+ )
793+ ) ;
780794
781- let validator_stake_account = simple_add_validator_to_pool (
795+ // Delegate few tokens for burning
796+ delegate_tokens (
782797 & mut context. banks_client ,
783798 & context. payer ,
784799 & context. last_blockhash ,
785- & stake_pool_accounts,
786- None ,
800+ & stake_pool_accounts. token_program_id ,
801+ & deposit_info. pool_account . pubkey ( ) ,
802+ & deposit_info. authority ,
803+ & user_transfer_authority. pubkey ( ) ,
804+ 1 ,
787805 )
788806 . await ;
789807
790808 let new_authority = Pubkey :: new_unique ( ) ;
791- let error = stake_pool_accounts
809+ let transaction_error = stake_pool_accounts
792810 . withdraw_stake (
793811 & mut context. banks_client ,
794812 & context. payer ,
@@ -803,12 +821,13 @@ async fn fail_overdraw_validator() {
803821 . await
804822 . unwrap ( )
805823 . unwrap ( ) ;
824+
806825 assert_eq ! (
807- error ,
826+ transaction_error ,
808827 TransactionError :: InstructionError (
809828 0 ,
810- InstructionError :: Custom ( StakePoolError :: StakeLamportsNotEqualToMinimum as u32 )
811- ) ,
829+ InstructionError :: Custom ( TokenError :: InsufficientFunds as u32 ) ,
830+ )
812831 ) ;
813832}
814833
@@ -1180,46 +1199,7 @@ async fn success_with_reserve() {
11801199}
11811200
11821201#[ tokio:: test]
1183- async fn success_with_preferred_validator ( ) {
1184- let (
1185- mut context,
1186- stake_pool_accounts,
1187- validator_stake,
1188- deposit_info,
1189- user_transfer_authority,
1190- user_stake_recipient,
1191- tokens_to_burn,
1192- ) = setup ( spl_token:: id ( ) ) . await ;
1193-
1194- stake_pool_accounts
1195- . set_preferred_validator (
1196- & mut context. banks_client ,
1197- & context. payer ,
1198- & context. last_blockhash ,
1199- instruction:: PreferredValidatorType :: Withdraw ,
1200- Some ( validator_stake. vote . pubkey ( ) ) ,
1201- )
1202- . await ;
1203-
1204- let new_authority = Pubkey :: new_unique ( ) ;
1205- let error = stake_pool_accounts
1206- . withdraw_stake (
1207- & mut context. banks_client ,
1208- & context. payer ,
1209- & context. last_blockhash ,
1210- & user_stake_recipient. pubkey ( ) ,
1211- & user_transfer_authority,
1212- & deposit_info. pool_account . pubkey ( ) ,
1213- & validator_stake. stake_account ,
1214- & new_authority,
1215- tokens_to_burn,
1216- )
1217- . await ;
1218- assert ! ( error. is_none( ) ) ;
1219- }
1220-
1221- #[ tokio:: test]
1222- async fn fail_with_wrong_preferred_withdraw ( ) {
1202+ async fn success_and_fail_with_preferred_withdraw ( ) {
12231203 let (
12241204 mut context,
12251205 stake_pool_accounts,
@@ -1249,7 +1229,7 @@ async fn fail_with_wrong_preferred_withdraw() {
12491229 )
12501230 . await ;
12511231
1252- // preferred is empty, this works
1232+ // preferred is empty, withdrawing from non-preferred works
12531233 let new_authority = Pubkey :: new_unique ( ) ;
12541234 let error = stake_pool_accounts
12551235 . withdraw_stake (
@@ -1261,12 +1241,21 @@ async fn fail_with_wrong_preferred_withdraw() {
12611241 & deposit_info. pool_account . pubkey ( ) ,
12621242 & validator_stake. stake_account ,
12631243 & new_authority,
1264- tokens_to_burn,
1244+ tokens_to_burn / 2 ,
12651245 )
12661246 . await ;
12671247 assert ! ( error. is_none( ) ) ;
12681248
1269- // deposit into preferred, then fail
1249+ // Deposit into preferred, then fail
1250+ let user_stake_recipient = Keypair :: new ( ) ;
1251+ create_blank_stake_account (
1252+ & mut context. banks_client ,
1253+ & context. payer ,
1254+ & context. last_blockhash ,
1255+ & user_stake_recipient,
1256+ )
1257+ . await ;
1258+
12701259 let _preferred_deposit = simple_deposit_stake (
12711260 & mut context. banks_client ,
12721261 & context. payer ,
@@ -1278,16 +1267,6 @@ async fn fail_with_wrong_preferred_withdraw() {
12781267 . await
12791268 . unwrap ( ) ;
12801269
1281- // Create stake account to withdraw to
1282- let user_stake_recipient = Keypair :: new ( ) ;
1283- create_blank_stake_account (
1284- & mut context. banks_client ,
1285- & context. payer ,
1286- & context. last_blockhash ,
1287- & user_stake_recipient,
1288- )
1289- . await ;
1290-
12911270 let error = stake_pool_accounts
12921271 . withdraw_stake (
12931272 & mut context. banks_client ,
@@ -1298,20 +1277,34 @@ async fn fail_with_wrong_preferred_withdraw() {
12981277 & deposit_info. pool_account . pubkey ( ) ,
12991278 & validator_stake. stake_account ,
13001279 & new_authority,
1301- tokens_to_burn,
1280+ tokens_to_burn / 2 ,
13021281 )
13031282 . await
13041283 . unwrap ( )
13051284 . unwrap ( ) ;
1306- match error {
1307- TransactionError :: InstructionError ( _, InstructionError :: Custom ( error_index) ) => {
1308- assert_eq ! (
1309- error_index,
1310- StakePoolError :: IncorrectWithdrawVoteAddress as u32
1311- ) ;
1312- }
1313- _ => panic ! ( "Wrong error occurs while try to make a deposit with wrong stake program ID" ) ,
1314- }
1285+ assert_eq ! (
1286+ error,
1287+ TransactionError :: InstructionError (
1288+ 0 ,
1289+ InstructionError :: Custom ( StakePoolError :: IncorrectWithdrawVoteAddress as u32 )
1290+ )
1291+ ) ;
1292+
1293+ // success from preferred
1294+ let error = stake_pool_accounts
1295+ . withdraw_stake (
1296+ & mut context. banks_client ,
1297+ & context. payer ,
1298+ & context. last_blockhash ,
1299+ & user_stake_recipient. pubkey ( ) ,
1300+ & user_transfer_authority,
1301+ & deposit_info. pool_account . pubkey ( ) ,
1302+ & preferred_validator. stake_account ,
1303+ & new_authority,
1304+ tokens_to_burn / 2 ,
1305+ )
1306+ . await ;
1307+ assert ! ( error. is_none( ) ) ;
13151308}
13161309
13171310#[ tokio:: test]
0 commit comments