@@ -454,10 +454,107 @@ async fn fail_with_wrong_token_program_id() {
454
454
. await
455
455
. unwrap ( ) ;
456
456
457
+ create_token_account (
458
+ & mut banks_client,
459
+ & payer,
460
+ & recent_blockhash,
461
+ & stake_pool_accounts. pool_fee_account ,
462
+ & stake_pool_accounts. pool_mint . pubkey ( ) ,
463
+ & stake_pool_accounts. manager . pubkey ( ) ,
464
+ )
465
+ . await
466
+ . unwrap ( ) ;
467
+
457
468
let rent = banks_client. get_rent ( ) . await . unwrap ( ) ;
469
+ let rent_stake_pool = rent. minimum_balance ( get_packed_len :: < state:: StakePool > ( ) ) ;
470
+ let validator_list_size = get_instance_packed_len ( & state:: ValidatorList :: new (
471
+ stake_pool_accounts. max_validators ,
472
+ ) )
473
+ . unwrap ( ) ;
474
+ let rent_validator_list = rent. minimum_balance ( validator_list_size) ;
458
475
459
- let account_rent = rent. minimum_balance ( spl_token:: state:: Account :: LEN ) ;
460
476
let mut transaction = Transaction :: new_with_payer (
477
+ & [
478
+ system_instruction:: create_account (
479
+ & payer. pubkey ( ) ,
480
+ & stake_pool_accounts. stake_pool . pubkey ( ) ,
481
+ rent_stake_pool,
482
+ get_packed_len :: < state:: StakePool > ( ) as u64 ,
483
+ & id ( ) ,
484
+ ) ,
485
+ system_instruction:: create_account (
486
+ & payer. pubkey ( ) ,
487
+ & stake_pool_accounts. validator_list . pubkey ( ) ,
488
+ rent_validator_list,
489
+ validator_list_size as u64 ,
490
+ & id ( ) ,
491
+ ) ,
492
+ instruction:: initialize (
493
+ & id ( ) ,
494
+ & stake_pool_accounts. stake_pool . pubkey ( ) ,
495
+ & stake_pool_accounts. manager . pubkey ( ) ,
496
+ & stake_pool_accounts. staker . pubkey ( ) ,
497
+ & stake_pool_accounts. validator_list . pubkey ( ) ,
498
+ & stake_pool_accounts. reserve_stake . pubkey ( ) ,
499
+ & stake_pool_accounts. pool_mint . pubkey ( ) ,
500
+ & stake_pool_accounts. pool_fee_account . pubkey ( ) ,
501
+ & wrong_token_program. pubkey ( ) ,
502
+ None ,
503
+ stake_pool_accounts. epoch_fee ,
504
+ stake_pool_accounts. withdrawal_fee ,
505
+ stake_pool_accounts. deposit_fee ,
506
+ stake_pool_accounts. referral_fee ,
507
+ stake_pool_accounts. max_validators ,
508
+ ) ,
509
+ ] ,
510
+ Some ( & payer. pubkey ( ) ) ,
511
+ ) ;
512
+ transaction. sign (
513
+ & [
514
+ & payer,
515
+ & stake_pool_accounts. stake_pool ,
516
+ & stake_pool_accounts. validator_list ,
517
+ & stake_pool_accounts. manager ,
518
+ ] ,
519
+ recent_blockhash,
520
+ ) ;
521
+ let transaction_error = banks_client
522
+ . process_transaction ( transaction)
523
+ . await
524
+ . err ( )
525
+ . unwrap ( ) ;
526
+
527
+ match transaction_error {
528
+ TransportError :: TransactionError ( TransactionError :: InstructionError ( _, error) ) => {
529
+ assert_eq ! ( error, InstructionError :: IncorrectProgramId ) ;
530
+ }
531
+ _ => panic ! (
532
+ "Wrong error occurs while try to initialize stake pool with wrong token program ID"
533
+ ) ,
534
+ }
535
+ }
536
+
537
+ #[ tokio:: test]
538
+ async fn fail_with_fee_owned_by_wrong_token_program_id ( ) {
539
+ let ( mut banks_client, payer, recent_blockhash) = program_test ( ) . start ( ) . await ;
540
+ let stake_pool_accounts = StakePoolAccounts :: new ( ) ;
541
+
542
+ let wrong_token_program = Keypair :: new ( ) ;
543
+
544
+ create_mint (
545
+ & mut banks_client,
546
+ & payer,
547
+ & recent_blockhash,
548
+ & stake_pool_accounts. pool_mint ,
549
+ & stake_pool_accounts. withdraw_authority ,
550
+ )
551
+ . await
552
+ . unwrap ( ) ;
553
+
554
+ let rent = banks_client. get_rent ( ) . await . unwrap ( ) ;
555
+
556
+ let account_rent = rent. minimum_balance ( spl_token:: state:: Account :: LEN ) ;
557
+ let transaction = Transaction :: new_signed_with_payer (
461
558
& [ system_instruction:: create_account (
462
559
& payer. pubkey ( ) ,
463
560
& stake_pool_accounts. pool_fee_account . pubkey ( ) ,
@@ -466,8 +563,6 @@ async fn fail_with_wrong_token_program_id() {
466
563
& wrong_token_program. pubkey ( ) ,
467
564
) ] ,
468
565
Some ( & payer. pubkey ( ) ) ,
469
- ) ;
470
- transaction. sign (
471
566
& [ & payer, & stake_pool_accounts. pool_fee_account ] ,
472
567
recent_blockhash,
473
568
) ;
0 commit comments