5
5
instruction:: { AccountMeta , Instruction , InstructionError } ,
6
6
pubkey:: Pubkey ,
7
7
rent:: Rent ,
8
- system_instruction, system_program ,
8
+ system_instruction,
9
9
} ,
10
10
solana_program_test:: * ,
11
11
solana_sdk:: {
@@ -533,13 +533,19 @@ async fn reallocate_success() {
533
533
. checked_add ( new_data_length as usize )
534
534
. unwrap ( ) ;
535
535
536
+ let delta_account_data_length = new_data_length. saturating_sub ( data. len ( ) as u64 ) ;
537
+ let additional_lamports_needed =
538
+ Rent :: default ( ) . minimum_balance ( delta_account_data_length as usize ) ;
539
+
536
540
let transaction = Transaction :: new_signed_with_payer (
537
- & [ instruction:: reallocate (
538
- & account. pubkey ( ) ,
539
- & context. payer . pubkey ( ) ,
540
- & authority. pubkey ( ) ,
541
- new_data_length,
542
- ) ] ,
541
+ & [
542
+ instruction:: reallocate ( & account. pubkey ( ) , & authority. pubkey ( ) , new_data_length) ,
543
+ system_instruction:: transfer (
544
+ & context. payer . pubkey ( ) ,
545
+ & account. pubkey ( ) ,
546
+ additional_lamports_needed,
547
+ ) ,
548
+ ] ,
543
549
Some ( & context. payer . pubkey ( ) ) ,
544
550
& [ & context. payer , & authority] ,
545
551
context. last_blockhash ,
@@ -564,7 +570,6 @@ async fn reallocate_success() {
564
570
let transaction = Transaction :: new_signed_with_payer (
565
571
& [ instruction:: reallocate (
566
572
& account. pubkey ( ) ,
567
- & context. payer . pubkey ( ) ,
568
573
& authority. pubkey ( ) ,
569
574
old_data_length,
570
575
) ] ,
@@ -598,22 +603,30 @@ async fn reallocate_fail_wrong_authority() {
598
603
initialize_storage_account ( & mut context, & authority, & account, data) . await ;
599
604
600
605
let new_data_length = 16u64 ;
606
+ let delta_account_data_length = new_data_length. saturating_sub ( data. len ( ) as u64 ) ;
607
+ let additional_lamports_needed =
608
+ Rent :: default ( ) . minimum_balance ( delta_account_data_length as usize ) ;
601
609
602
610
let wrong_authority = Keypair :: new ( ) ;
603
611
let transaction = Transaction :: new_signed_with_payer (
604
- & [ Instruction {
605
- program_id : id ( ) ,
606
- accounts : vec ! [
607
- AccountMeta :: new( account. pubkey( ) , false ) ,
608
- AccountMeta :: new( context. payer. pubkey( ) , true ) ,
609
- AccountMeta :: new_readonly( system_program:: id( ) , false ) ,
610
- AccountMeta :: new( wrong_authority. pubkey( ) , true ) ,
611
- ] ,
612
- data : instruction:: RecordInstruction :: Reallocate {
613
- data_length : new_data_length,
614
- }
615
- . pack ( ) ,
616
- } ] ,
612
+ & [
613
+ Instruction {
614
+ program_id : id ( ) ,
615
+ accounts : vec ! [
616
+ AccountMeta :: new( account. pubkey( ) , false ) ,
617
+ AccountMeta :: new( wrong_authority. pubkey( ) , true ) ,
618
+ ] ,
619
+ data : instruction:: RecordInstruction :: Reallocate {
620
+ data_length : new_data_length,
621
+ }
622
+ . pack ( ) ,
623
+ } ,
624
+ system_instruction:: transfer (
625
+ & context. payer . pubkey ( ) ,
626
+ & account. pubkey ( ) ,
627
+ additional_lamports_needed,
628
+ ) ,
629
+ ] ,
617
630
Some ( & context. payer . pubkey ( ) ) ,
618
631
& [ & context. payer , & wrong_authority] ,
619
632
context. last_blockhash ,
@@ -643,21 +656,29 @@ async fn reallocate_fail_unsigned() {
643
656
initialize_storage_account ( & mut context, & authority, & account, data) . await ;
644
657
645
658
let new_data_length = 16u64 ;
659
+ let delta_account_data_length = new_data_length. saturating_sub ( data. len ( ) as u64 ) ;
660
+ let additional_lamports_needed =
661
+ Rent :: default ( ) . minimum_balance ( delta_account_data_length as usize ) ;
646
662
647
663
let transaction = Transaction :: new_signed_with_payer (
648
- & [ Instruction {
649
- program_id : id ( ) ,
650
- accounts : vec ! [
651
- AccountMeta :: new( account. pubkey( ) , false ) ,
652
- AccountMeta :: new( context. payer. pubkey( ) , true ) ,
653
- AccountMeta :: new_readonly( system_program:: id( ) , false ) ,
654
- AccountMeta :: new( authority. pubkey( ) , false ) ,
655
- ] ,
656
- data : instruction:: RecordInstruction :: Reallocate {
657
- data_length : new_data_length,
658
- }
659
- . pack ( ) ,
660
- } ] ,
664
+ & [
665
+ Instruction {
666
+ program_id : id ( ) ,
667
+ accounts : vec ! [
668
+ AccountMeta :: new( account. pubkey( ) , false ) ,
669
+ AccountMeta :: new( authority. pubkey( ) , false ) ,
670
+ ] ,
671
+ data : instruction:: RecordInstruction :: Reallocate {
672
+ data_length : new_data_length,
673
+ }
674
+ . pack ( ) ,
675
+ } ,
676
+ system_instruction:: transfer (
677
+ & context. payer . pubkey ( ) ,
678
+ & account. pubkey ( ) ,
679
+ additional_lamports_needed,
680
+ ) ,
681
+ ] ,
661
682
Some ( & context. payer . pubkey ( ) ) ,
662
683
& [ & context. payer ] ,
663
684
context. last_blockhash ,
0 commit comments