Skip to content

Commit 119a26e

Browse files
authored
fix: check_account_balance_is_rent_exempt return rent_exemption (#1715)
* fix: check_account_balance_is_rent_exempt return rent_exemption * test: test rollover fee is correct * Update program-tests/account-compression-test/tests/batched_merkle_tree_test.rs
1 parent e0cc087 commit 119a26e

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

program-libs/account-checks/src/checks.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,13 @@ pub fn check_account_balance_is_rent_exempt(
116116
if lamports < rent_exemption {
117117
return Err(AccountError::InvalidAccountBalance);
118118
}
119+
Ok(rent_exemption)
119120
}
120121
#[cfg(not(target_os = "solana"))]
121-
println!("Rent exemption check skipped since not target_os solana.");
122-
Ok(lamports)
122+
{
123+
println!("Rent exemption check skipped since not target_os solana.");
124+
Ok(lamports)
125+
}
123126
}
124127

125128
#[cfg(not(feature = "pinocchio"))]

program-tests/account-compression-test/tests/batched_merkle_tree_test.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ use solana_sdk::{
5656
instruction::Instruction,
5757
pubkey::Pubkey,
5858
signature::{Keypair, Signature, Signer},
59+
system_instruction,
5960
};
6061

6162
pub enum TestMode {
@@ -1234,7 +1235,7 @@ async fn test_rollover_batch_state_merkle_trees() {
12341235
airdrop_lamports(
12351236
&mut context,
12361237
&nullifier_queue_keypair.pubkey(),
1237-
100_000_000_000,
1238+
1000_000_000_000,
12381239
)
12391240
.await
12401241
.unwrap();
@@ -1249,7 +1250,7 @@ async fn test_rollover_batch_state_merkle_trees() {
12491250
&new_output_queue_keypair,
12501251
params.additional_bytes,
12511252
params.network_fee,
1252-
BatchStateMerkleTreeRollOverTestMode::Functional,
1253+
BatchStateMerkleTreeRollOverTestMode::FunctionalWithAdditionalLamports,
12531254
)
12541255
.await
12551256
.unwrap();
@@ -1274,6 +1275,7 @@ async fn test_rollover_batch_state_merkle_trees() {
12741275
#[derive(Debug, PartialEq)]
12751276
pub enum BatchStateMerkleTreeRollOverTestMode {
12761277
Functional,
1278+
FunctionalWithAdditionalLamports,
12771279
InvalidProgramOwnerMerkleTree,
12781280
InvalidProgramOwnerQueue,
12791281
InvalidDiscriminatorMerkleTree,
@@ -1375,9 +1377,21 @@ pub async fn perform_rollover_batch_state_merkle_tree<R: RpcConnection>(
13751377
accounts: accounts.to_account_metas(Some(true)),
13761378
data: instruction_data.data(),
13771379
};
1380+
let mut instructions = vec![create_mt_account_ix, create_queue_account_ix, instruction];
13781381

1382+
if test_mode == BatchStateMerkleTreeRollOverTestMode::FunctionalWithAdditionalLamports {
1383+
// Transfer 100 sol to new state merkle tree account to increase its balance.
1384+
// Assert that rollover fee is still correct.
1385+
let additional_lamports = 100_000_000_000;
1386+
let additional_lamports_instruction = system_instruction::transfer(
1387+
&payer_pubkey,
1388+
&new_state_merkle_tree_keypair.pubkey(),
1389+
additional_lamports,
1390+
);
1391+
instructions.insert(2, additional_lamports_instruction);
1392+
}
13791393
rpc.create_and_send_transaction(
1380-
&[create_mt_account_ix, create_queue_account_ix, instruction],
1394+
instructions.as_slice(),
13811395
&payer_pubkey,
13821396
&[
13831397
payer,

sdk-libs/program-test/src/test_batch_forester.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,19 +680,38 @@ pub async fn assert_perform_state_mt_roll_over<R: RpcConnection>(
680680
.unwrap()
681681
.data;
682682
let new_queue_account = rpc.get_account(new_queue_pubkey).await.unwrap().unwrap();
683-
683+
let old_queue_rent_exempt = rpc
684+
.get_minimum_balance_for_rent_exemption(old_queue_account_data.len())
685+
.await
686+
.unwrap();
687+
let old_tree_rent_exempt = rpc
688+
.get_minimum_balance_for_rent_exemption(old_state_merkle_tree.data.len())
689+
.await
690+
.unwrap();
691+
let queue_rent_exempt = rpc
692+
.get_minimum_balance_for_rent_exemption(new_queue_account.data.len())
693+
.await
694+
.unwrap();
695+
let tree_rent_exempt = rpc
696+
.get_minimum_balance_for_rent_exemption(new_state_merkle_tree.data.len())
697+
.await
698+
.unwrap();
699+
println!("queue rent exempt : {}", queue_rent_exempt);
700+
println!("tree rent exempt : {}", tree_rent_exempt);
701+
println!("old queue rent exempt : {}", old_queue_rent_exempt);
702+
println!("old tree rent exempt : {}", old_tree_rent_exempt);
684703
let queue_params = CreateOutputQueueParams::from(
685704
params,
686705
owner.into(),
687-
new_queue_account.lamports + new_state_merkle_tree.lamports + additional_bytes_rent,
706+
old_tree_rent_exempt + old_queue_rent_exempt + additional_bytes_rent,
688707
old_state_merkle_tree_pubkey.into(),
689708
old_queue_pubkey.into(),
690709
);
691710
let ref_queue_account = create_output_queue_account(queue_params);
692711
let queue_params = CreateOutputQueueParams::from(
693712
params,
694713
owner.into(),
695-
new_queue_account.lamports + new_state_merkle_tree.lamports + additional_bytes_rent,
714+
tree_rent_exempt + queue_rent_exempt + additional_bytes_rent,
696715
old_state_merkle_tree_pubkey.into(),
697716
new_queue_pubkey.into(),
698717
);

0 commit comments

Comments
 (0)