From 7fd1b6b75facecf6642813de9d4f82ea210d9c17 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Mon, 10 Jan 2022 09:49:32 -0700 Subject: [PATCH] Fixup tests to use rent-exempt accounts (#2717) --- .../tests/process_create_associated_token_account.rs | 9 +++++---- name-service/program/tests/functional.rs | 10 ++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/associated-token-account/program/tests/process_create_associated_token_account.rs b/associated-token-account/program/tests/process_create_associated_token_account.rs index 64163c17e4b..16adff41f9c 100644 --- a/associated-token-account/program/tests/process_create_associated_token_account.rs +++ b/associated-token-account/program/tests/process_create_associated_token_account.rs @@ -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 = @@ -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()), ); @@ -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 diff --git a/name-service/program/tests/functional.rs b/name-service/program/tests/functional.rs index 312ff5f3b87..1373cf4bb98 100644 --- a/name-service/program/tests/functional.rs +++ b/name-service/program/tests/functional.rs @@ -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(), @@ -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(),