From 4fba7e68657e1add00b9f23cd67a180b54ea63c7 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Thu, 10 Dec 2020 17:40:13 -0800 Subject: [PATCH] Move validator_block_0_fee_workaround into TestValidator --- core/src/test_validator.rs | 23 +++++++++++++++++++++++ tokens/src/commands.rs | 23 +---------------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/core/src/test_validator.rs b/core/src/test_validator.rs index 25032b3249..1d3eb23671 100644 --- a/core/src/test_validator.rs +++ b/core/src/test_validator.rs @@ -244,6 +244,29 @@ impl TestValidator { // test validators concurrently... discover_cluster(&gossip, 1).expect("TestValidator startup failed"); + // This is a hack to delay until the single gossip commitment fees are non-zero for test + // consistency + // (fees from genesis are zero until the first block with a transaction in it is completed) + { + let rpc_client = + RpcClient::new_with_commitment(rpc_url.clone(), CommitmentConfig::single_gossip()); + let fee_rate_governor = rpc_client + .get_fee_rate_governor() + .expect("get_fee_rate_governor") + .value; + if fee_rate_governor.target_lamports_per_signature > 0 { + while rpc_client + .get_recent_blockhash() + .expect("get_recent_blockhash") + .1 + .lamports_per_signature + == 0 + { + sleep(Duration::from_millis(DEFAULT_MS_PER_SLOT)); + } + } + } + Ok(TestValidator { ledger_path: ledger_path.to_path_buf(), preserve_ledger: false, diff --git a/tokens/src/commands.rs b/tokens/src/commands.rs index 67108a21e5..45b170c75d 100644 --- a/tokens/src/commands.rs +++ b/tokens/src/commands.rs @@ -1036,25 +1036,9 @@ pub fn test_process_distribute_stake_with_client(client: &RpcClient, sender_keyp mod tests { use super::*; use solana_core::test_validator::TestValidator; - use solana_sdk::{ - clock::DEFAULT_MS_PER_SLOT, - signature::{read_keypair_file, write_keypair_file, Signer}, - }; + use solana_sdk::signature::{read_keypair_file, write_keypair_file, Signer}; use solana_stake_program::stake_instruction::StakeInstruction; - // 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 alice = Keypair::new(); @@ -1400,8 +1384,6 @@ mod tests { let sender_keypair_file = tmp_file_path("keypair_file", &alice.pubkey()); write_keypair_file(&alice, &sender_keypair_file).unwrap(); - test_validator_block_0_fee_workaround(&client); - let allocation_amount = 1000.0; // Fully funded payer @@ -1482,7 +1464,6 @@ mod tests { 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(); @@ -1592,7 +1573,6 @@ mod tests { let test_validator = TestValidator::with_custom_fees(alice.pubkey(), fees); 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(); @@ -1700,7 +1680,6 @@ mod tests { 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();