More TestValidator cleanup

This commit is contained in:
Michael Vines
2020-11-25 17:00:47 -08:00
committed by mergify[bot]
parent b5f7e39be8
commit 43b82b31e5
13 changed files with 345 additions and 552 deletions

View File

@ -940,67 +940,60 @@ pub fn test_process_distribute_stake_with_client(client: &RpcClient, sender_keyp
#[cfg(test)]
mod tests {
use super::*;
use solana_client::rpc_client::get_rpc_request_str;
use solana_core::test_validator::TestValidator;
use solana_sdk::{
clock::DEFAULT_MS_PER_SLOT,
signature::{read_keypair_file, write_keypair_file},
};
use solana_stake_program::stake_instruction::StakeInstruction;
use std::fs::remove_dir_all;
// This is a quick hack until TestValidator can be initialized with fees from block 0
fn test_validator_block_0_fee_workaround(client: &RpcClient) {
while client
.get_recent_blockhash()
.unwrap()
.1
.lamports_per_signature
== 0
{
sleep(Duration::from_millis(DEFAULT_MS_PER_SLOT));
}
}
#[test]
fn test_process_token_allocations() {
let TestValidator {
server,
leader_data,
alice,
ledger_path,
..
} = TestValidator::with_no_fee();
let url = get_rpc_request_str(leader_data.rpc, false);
let test_validator = TestValidator::with_no_fees();
let alice = test_validator.mint_keypair();
let url = test_validator.rpc_url();
let client = RpcClient::new_with_commitment(url, CommitmentConfig::recent());
test_process_distribute_tokens_with_client(&client, alice, None);
// Explicit cleanup, otherwise "pure virtual method called" crash in Docker
server.close().unwrap();
remove_dir_all(ledger_path).unwrap();
test_validator.close();
}
#[test]
fn test_process_transfer_amount_allocations() {
let TestValidator {
server,
leader_data,
alice,
ledger_path,
..
} = TestValidator::with_no_fee();
let url = get_rpc_request_str(leader_data.rpc, false);
let test_validator = TestValidator::with_no_fees();
let alice = test_validator.mint_keypair();
let url = test_validator.rpc_url();
let client = RpcClient::new_with_commitment(url, CommitmentConfig::recent());
test_process_distribute_tokens_with_client(&client, alice, Some(sol_to_lamports(1.5)));
// Explicit cleanup, otherwise "pure virtual method called" crash in Docker
server.close().unwrap();
remove_dir_all(ledger_path).unwrap();
test_validator.close();
}
#[test]
fn test_process_stake_allocations() {
let TestValidator {
server,
leader_data,
alice,
ledger_path,
..
} = TestValidator::with_no_fee();
let url = get_rpc_request_str(leader_data.rpc, false);
let test_validator = TestValidator::with_no_fees();
let alice = test_validator.mint_keypair();
let url = test_validator.rpc_url();
let client = RpcClient::new_with_commitment(url, CommitmentConfig::recent());
test_process_distribute_stake_with_client(&client, alice);
// Explicit cleanup, otherwise "pure virtual method called" crash in Docker
server.close().unwrap();
remove_dir_all(ledger_path).unwrap();
test_validator.close();
}
#[test]
@ -1309,28 +1302,16 @@ mod tests {
fn test_check_payer_balances_distribute_tokens_single_payer() {
let fees = 10_000;
let fees_in_sol = lamports_to_sol(fees);
let TestValidator {
server,
leader_data,
alice,
ledger_path,
..
} = TestValidator::with_custom_fee(fees);
let url = get_rpc_request_str(leader_data.rpc, false);
let test_validator = TestValidator::with_custom_fees(fees);
let alice = test_validator.mint_keypair();
let url = test_validator.rpc_url();
let client = RpcClient::new_with_commitment(url, CommitmentConfig::recent());
let sender_keypair_file = tmp_file_path("keypair_file", &alice.pubkey());
write_keypair_file(&alice, &sender_keypair_file).unwrap();
// This is a quick hack until TestValidator can be initialized with fees from block 0
while client
.get_recent_blockhash()
.unwrap()
.1
.lamports_per_signature
== 0
{
sleep(Duration::from_millis(DEFAULT_MS_PER_SLOT));
}
test_validator_block_0_fee_workaround(&client);
let allocation_amount = 1000.0;
@ -1402,39 +1383,23 @@ mod tests {
panic!("check_payer_balances should have errored");
}
// Explicit cleanup, otherwise "pure virtual method called" crash in Docker
server.close().unwrap();
remove_dir_all(ledger_path).unwrap();
test_validator.close();
}
#[test]
fn test_check_payer_balances_distribute_tokens_separate_payers() {
let fees = 10_000;
let fees_in_sol = lamports_to_sol(fees);
let TestValidator {
server,
leader_data,
alice,
ledger_path,
..
} = TestValidator::with_custom_fee(fees);
let url = get_rpc_request_str(leader_data.rpc, false);
let test_validator = TestValidator::with_custom_fees(fees);
let alice = test_validator.mint_keypair();
let url = test_validator.rpc_url();
let client = RpcClient::new_with_commitment(url, CommitmentConfig::recent());
test_validator_block_0_fee_workaround(&client);
let sender_keypair_file = tmp_file_path("keypair_file", &alice.pubkey());
write_keypair_file(&alice, &sender_keypair_file).unwrap();
// This is a quick hack until TestValidator can be initialized with fees from block 0
while client
.get_recent_blockhash()
.unwrap()
.1
.lamports_per_signature
== 0
{
sleep(Duration::from_millis(DEFAULT_MS_PER_SLOT));
}
let allocation_amount = 1000.0;
let funded_payer = Keypair::new();
@ -1491,9 +1456,7 @@ mod tests {
panic!("check_payer_balances should have errored");
}
// Explicit cleanup, otherwise "pure virtual method called" crash in Docker
server.close().unwrap();
remove_dir_all(ledger_path).unwrap();
test_validator.close();
}
fn initialize_stake_account(
@ -1540,30 +1503,15 @@ mod tests {
fn test_check_payer_balances_distribute_stakes_single_payer() {
let fees = 10_000;
let fees_in_sol = lamports_to_sol(fees);
let TestValidator {
server,
leader_data,
alice,
ledger_path,
..
} = TestValidator::with_custom_fee(fees);
let url = get_rpc_request_str(leader_data.rpc, false);
let test_validator = TestValidator::with_custom_fees(fees);
let alice = test_validator.mint_keypair();
let url = test_validator.rpc_url();
let client = RpcClient::new_with_commitment(url, CommitmentConfig::recent());
test_validator_block_0_fee_workaround(&client);
let sender_keypair_file = tmp_file_path("keypair_file", &alice.pubkey());
write_keypair_file(&alice, &sender_keypair_file).unwrap();
// This is a quick hack until TestValidator can be initialized with fees from block 0
while client
.get_recent_blockhash()
.unwrap()
.1
.lamports_per_signature
== 0
{
sleep(Duration::from_millis(DEFAULT_MS_PER_SLOT));
}
let allocation_amount = 1000.0;
let unlocked_sol = 1.0;
let stake_args = initialize_stake_account(
@ -1657,39 +1605,23 @@ mod tests {
panic!("check_payer_balances should have errored");
}
// Explicit cleanup, otherwise "pure virtual method called" crash in Docker
server.close().unwrap();
remove_dir_all(ledger_path).unwrap();
test_validator.close();
}
#[test]
fn test_check_payer_balances_distribute_stakes_separate_payers() {
let fees = 10_000;
let fees_in_sol = lamports_to_sol(fees);
let TestValidator {
server,
leader_data,
alice,
ledger_path,
..
} = TestValidator::with_custom_fee(fees);
let url = get_rpc_request_str(leader_data.rpc, false);
let test_validator = TestValidator::with_custom_fees(fees);
let alice = test_validator.mint_keypair();
let url = test_validator.rpc_url();
let client = RpcClient::new_with_commitment(url, CommitmentConfig::recent());
test_validator_block_0_fee_workaround(&client);
let sender_keypair_file = tmp_file_path("keypair_file", &alice.pubkey());
write_keypair_file(&alice, &sender_keypair_file).unwrap();
// This is a quick hack until TestValidator can be initialized with fees from block 0
while client
.get_recent_blockhash()
.unwrap()
.1
.lamports_per_signature
== 0
{
sleep(Duration::from_millis(DEFAULT_MS_PER_SLOT));
}
let allocation_amount = 1000.0;
let unlocked_sol = 1.0;
let stake_args = initialize_stake_account(
@ -1753,8 +1685,6 @@ mod tests {
panic!("check_payer_balances should have errored");
}
// Explicit cleanup, otherwise "pure virtual method called" crash in Docker
server.close().unwrap();
remove_dir_all(ledger_path).unwrap();
test_validator.close();
}
}