Skip to content

Commit

Permalink
Fixup tests to use rent-exempt accounts (#2717)
Browse files Browse the repository at this point in the history
  • Loading branch information
CriesofCarrots authored Jan 10, 2022
1 parent f4e0cae commit 7fd1b6b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async fn test_associated_token_address() {
}

#[tokio::test]
async fn test_create_with_a_lamport() {
async fn test_create_with_fewer_lamports() {
let wallet_address = Pubkey::new_unique();
let token_mint_address = Pubkey::new_unique();
let associated_token_address =
Expand All @@ -78,12 +78,13 @@ async fn test_create_with_a_lamport() {
let rent = banks_client.get_rent().await.unwrap();
let expected_token_account_balance = rent.minimum_balance(spl_token::state::Account::LEN);

// Transfer 1 lamport into `associated_token_address` before creating it
// Transfer lamports into `associated_token_address` before creating it - enough to be
// rent-exempt for 0 data, but not for an initialized token account
let mut transaction = Transaction::new_with_payer(
&[system_instruction::transfer(
&payer.pubkey(),
&associated_token_address,
1,
rent.minimum_balance(0),
)],
Some(&payer.pubkey()),
);
Expand All @@ -95,7 +96,7 @@ async fn test_create_with_a_lamport() {
.get_balance(associated_token_address)
.await
.unwrap(),
1
rent.minimum_balance(0)
);

// Check that the program adds the extra lamports
Expand Down
10 changes: 6 additions & 4 deletions name-service/program/tests/functional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ async fn test_name_service() {
None,
);

let space = 1_000usize;
let rent = ctx.banks_client.get_rent().await.unwrap();
let create_name_instruction = create(
program_id,
NameRegistryInstruction::Create {
hashed_name: hashed_root_name,
lamports: 1_000_000,
space: 1_000,
lamports: rent.minimum_balance(space + NameRecordHeader::LEN),
space: space as u32,
},
root_name_account_key,
ctx.payer.pubkey(),
Expand Down Expand Up @@ -91,8 +93,8 @@ async fn test_name_service() {
program_id,
NameRegistryInstruction::Create {
hashed_name,
lamports: 1_000_000,
space: 1_000,
lamports: rent.minimum_balance(space + NameRecordHeader::LEN),
space: space as u32,
},
name_account_key,
ctx.payer.pubkey(),
Expand Down

0 comments on commit 7fd1b6b

Please sign in to comment.