Add unit-test-friendly VoteSignerProxy constructor
This commit is contained in:
@@ -165,7 +165,6 @@ pub mod tests {
|
||||
use bincode::serialize;
|
||||
use solana_sdk::hash::hash;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_vote_signer::rpc::LocalVoteSigner;
|
||||
use std::sync::Arc;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
@@ -195,8 +194,7 @@ pub mod tests {
|
||||
// Create new validator to vote
|
||||
let validator_keypair = Arc::new(Keypair::new());
|
||||
let last_id = ids[i];
|
||||
let vote_signer =
|
||||
VoteSignerProxy::new(&validator_keypair, Box::new(LocalVoteSigner::default()));
|
||||
let vote_signer = VoteSignerProxy::new_local(&validator_keypair);
|
||||
|
||||
// Give the validator some tokens
|
||||
bank.transfer(2, &mint_keypair, validator_keypair.pubkey(), last_id)
|
||||
|
@@ -535,7 +535,6 @@ mod tests {
|
||||
use crate::tvu::TvuReturnType;
|
||||
use crate::vote_signer_proxy::VoteSignerProxy;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_vote_signer::rpc::LocalVoteSigner;
|
||||
use std::cmp;
|
||||
use std::fs::remove_dir_all;
|
||||
use std::net::UdpSocket;
|
||||
@@ -559,7 +558,7 @@ mod tests {
|
||||
|
||||
let last_id = bank.last_id();
|
||||
let keypair = Arc::new(keypair);
|
||||
let signer = VoteSignerProxy::new(&keypair, Box::new(LocalVoteSigner::default()));
|
||||
let signer = VoteSignerProxy::new_local(&keypair);
|
||||
let v = Fullnode::new_with_bank(
|
||||
keypair,
|
||||
Some(Arc::new(signer)),
|
||||
@@ -602,7 +601,7 @@ mod tests {
|
||||
let entry_height = 0;
|
||||
let last_id = bank.last_id();
|
||||
let keypair = Arc::new(keypair);
|
||||
let signer = VoteSignerProxy::new(&keypair, Box::new(LocalVoteSigner::default()));
|
||||
let signer = VoteSignerProxy::new_local(&keypair);
|
||||
Fullnode::new_with_bank(
|
||||
keypair,
|
||||
Some(Arc::new(signer)),
|
||||
@@ -675,10 +674,7 @@ mod tests {
|
||||
);
|
||||
|
||||
let bootstrap_leader_keypair = Arc::new(bootstrap_leader_keypair);
|
||||
let signer = VoteSignerProxy::new(
|
||||
&bootstrap_leader_keypair,
|
||||
Box::new(LocalVoteSigner::default()),
|
||||
);
|
||||
let signer = VoteSignerProxy::new_local(&bootstrap_leader_keypair);
|
||||
// Start up the leader
|
||||
let mut bootstrap_leader = Fullnode::new(
|
||||
bootstrap_leader_node,
|
||||
@@ -783,10 +779,7 @@ mod tests {
|
||||
|
||||
{
|
||||
// Test that a node knows to transition to a validator based on parsing the ledger
|
||||
let vote_signer = VoteSignerProxy::new(
|
||||
&bootstrap_leader_keypair,
|
||||
Box::new(LocalVoteSigner::default()),
|
||||
);
|
||||
let vote_signer = VoteSignerProxy::new_local(&bootstrap_leader_keypair);
|
||||
let bootstrap_leader = Fullnode::new(
|
||||
bootstrap_leader_node,
|
||||
&bootstrap_leader_ledger_path,
|
||||
@@ -895,8 +888,7 @@ mod tests {
|
||||
Some(bootstrap_height),
|
||||
);
|
||||
|
||||
let vote_signer =
|
||||
VoteSignerProxy::new(&validator_keypair, Box::new(LocalVoteSigner::default()));
|
||||
let vote_signer = VoteSignerProxy::new_local(&validator_keypair);
|
||||
// Start the validator
|
||||
let validator = Fullnode::new(
|
||||
validator_node,
|
||||
|
@@ -15,7 +15,6 @@ use solana_sdk::system_transaction::SystemTransaction;
|
||||
use solana_sdk::transaction::Transaction;
|
||||
use solana_sdk::vote_program::{self, Vote, VoteProgram};
|
||||
use solana_sdk::vote_transaction::VoteTransaction;
|
||||
use solana_vote_signer::rpc::LocalVoteSigner;
|
||||
use std::io::Cursor;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -495,7 +494,7 @@ pub fn make_active_set_entries(
|
||||
let mut last_entry_id = transfer_entry.id;
|
||||
|
||||
// 2) Create and register the vote account
|
||||
let vote_signer = VoteSignerProxy::new(active_keypair, Box::new(LocalVoteSigner::default()));
|
||||
let vote_signer = VoteSignerProxy::new_local(active_keypair);
|
||||
let vote_account_id: Pubkey = vote_signer.vote_account;
|
||||
|
||||
let new_vote_account_tx =
|
||||
@@ -539,7 +538,6 @@ mod tests {
|
||||
use solana_sdk::hash::Hash;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_vote_signer::rpc::LocalVoteSigner;
|
||||
use std::hash::Hash as StdHash;
|
||||
use std::iter::FromIterator;
|
||||
use std::sync::Arc;
|
||||
@@ -590,10 +588,7 @@ mod tests {
|
||||
for i in 0..num_validators {
|
||||
let new_validator = Keypair::new();
|
||||
let new_pubkey = new_validator.pubkey();
|
||||
let vote_signer = VoteSignerProxy::new(
|
||||
&Arc::new(new_validator),
|
||||
Box::new(LocalVoteSigner::default()),
|
||||
);
|
||||
let vote_signer = VoteSignerProxy::new_local(&Arc::new(new_validator));
|
||||
validators.push(new_pubkey);
|
||||
// Give the validator some tokens
|
||||
bank.transfer(
|
||||
@@ -720,8 +715,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
// Create a vote account
|
||||
let vote_signer =
|
||||
VoteSignerProxy::new(&Arc::new(new_keypair), Box::new(LocalVoteSigner::default()));
|
||||
let vote_signer = VoteSignerProxy::new_local(&Arc::new(new_keypair));
|
||||
vote_signer
|
||||
.new_vote_account(&bank, 1 as u64, genesis_block.last_id())
|
||||
.unwrap();
|
||||
@@ -742,8 +736,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
// Create a vote account
|
||||
let vote_signer =
|
||||
VoteSignerProxy::new(&Arc::new(new_keypair), Box::new(LocalVoteSigner::default()));
|
||||
let vote_signer = VoteSignerProxy::new_local(&Arc::new(new_keypair));
|
||||
vote_signer
|
||||
.new_vote_account(&bank, 1 as u64, genesis_block.last_id())
|
||||
.unwrap();
|
||||
@@ -1005,10 +998,7 @@ mod tests {
|
||||
for i in 0..num_validators {
|
||||
let new_validator = Keypair::new();
|
||||
let new_pubkey = new_validator.pubkey();
|
||||
let vote_signer = VoteSignerProxy::new(
|
||||
&Arc::new(new_validator),
|
||||
Box::new(LocalVoteSigner::default()),
|
||||
);
|
||||
let vote_signer = VoteSignerProxy::new_local(&Arc::new(new_validator));
|
||||
validators.push(new_pubkey);
|
||||
// Give the validator some tokens
|
||||
bank.transfer(
|
||||
@@ -1071,10 +1061,7 @@ mod tests {
|
||||
// window
|
||||
let initial_vote_height = 1;
|
||||
|
||||
let vote_signer = VoteSignerProxy::new(
|
||||
&Arc::new(leader_keypair),
|
||||
Box::new(LocalVoteSigner::default()),
|
||||
);
|
||||
let vote_signer = VoteSignerProxy::new_local(&Arc::new(leader_keypair));
|
||||
// Create a vote account
|
||||
vote_signer
|
||||
.new_vote_account(&bank, 1 as u64, genesis_block.last_id())
|
||||
@@ -1221,10 +1208,7 @@ mod tests {
|
||||
bank.transfer(5, &mint_keypair, validator_id, last_id)
|
||||
.unwrap();
|
||||
// Create a vote account
|
||||
let vote_signer = VoteSignerProxy::new(
|
||||
&Arc::new(validator_keypair),
|
||||
Box::new(LocalVoteSigner::default()),
|
||||
);
|
||||
let vote_signer = VoteSignerProxy::new_local(&Arc::new(validator_keypair));
|
||||
vote_signer
|
||||
.new_vote_account(&bank, 1 as u64, genesis_block.last_id())
|
||||
.unwrap();
|
||||
@@ -1261,10 +1245,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
// Create a vote account
|
||||
let vote_signer = VoteSignerProxy::new(
|
||||
&Arc::new(bootstrap_leader_keypair),
|
||||
Box::new(LocalVoteSigner::default()),
|
||||
);
|
||||
let vote_signer = VoteSignerProxy::new_local(&Arc::new(bootstrap_leader_keypair));
|
||||
vote_signer
|
||||
.new_vote_account(&bank, vote_account_tokens as u64, genesis_block.last_id())
|
||||
.unwrap();
|
||||
@@ -1387,10 +1368,7 @@ mod tests {
|
||||
// Create a vote account for the validator
|
||||
bank.transfer(5, &mint_keypair, validator_id, last_id)
|
||||
.unwrap();
|
||||
let vote_signer = VoteSignerProxy::new(
|
||||
&Arc::new(validator_keypair),
|
||||
Box::new(LocalVoteSigner::default()),
|
||||
);
|
||||
let vote_signer = VoteSignerProxy::new_local(&Arc::new(validator_keypair));
|
||||
vote_signer
|
||||
.new_vote_account(&bank, 1 as u64, genesis_block.last_id())
|
||||
.unwrap();
|
||||
@@ -1404,10 +1382,7 @@ mod tests {
|
||||
// Create a vote account for the leader
|
||||
bank.transfer(5, &mint_keypair, bootstrap_leader_id, last_id)
|
||||
.unwrap();
|
||||
let vote_signer = VoteSignerProxy::new(
|
||||
&Arc::new(bootstrap_leader_keypair),
|
||||
Box::new(LocalVoteSigner::default()),
|
||||
);
|
||||
let vote_signer = VoteSignerProxy::new_local(&Arc::new(bootstrap_leader_keypair));
|
||||
vote_signer
|
||||
.new_vote_account(&bank, 1 as u64, genesis_block.last_id())
|
||||
.unwrap();
|
||||
|
@@ -293,7 +293,6 @@ mod test {
|
||||
use crate::vote_signer_proxy::VoteSignerProxy;
|
||||
use solana_sdk::hash::Hash;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_vote_signer::rpc::LocalVoteSigner;
|
||||
use std::fs::remove_dir_all;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::mpsc::channel;
|
||||
@@ -474,10 +473,7 @@ mod test {
|
||||
let (entry_sender, entry_receiver) = channel();
|
||||
let exit = Arc::new(AtomicBool::new(false));
|
||||
let my_keypair = Arc::new(my_keypair);
|
||||
let vote_signer = Arc::new(VoteSignerProxy::new(
|
||||
&my_keypair,
|
||||
Box::new(LocalVoteSigner::default()),
|
||||
));
|
||||
let vote_signer = Arc::new(VoteSignerProxy::new_local(&my_keypair));
|
||||
let (to_leader_sender, _) = channel();
|
||||
let (replay_stage, ledger_writer_recv) = ReplayStage::new(
|
||||
my_keypair.clone(),
|
||||
@@ -692,10 +688,7 @@ mod test {
|
||||
.expect("Expected to err out");
|
||||
|
||||
let my_keypair = Arc::new(my_keypair);
|
||||
let vote_signer = Arc::new(VoteSignerProxy::new(
|
||||
&my_keypair,
|
||||
Box::new(LocalVoteSigner::default()),
|
||||
));
|
||||
let vote_signer = Arc::new(VoteSignerProxy::new_local(&my_keypair));
|
||||
let res = ReplayStage::process_entries(
|
||||
&Arc::new(Bank::default()),
|
||||
&cluster_info_me,
|
||||
|
@@ -452,7 +452,6 @@ mod tests {
|
||||
use solana_sdk::system_instruction::SystemInstruction;
|
||||
use solana_sdk::vote_program::VoteProgram;
|
||||
use solana_sdk::vote_transaction::VoteTransaction;
|
||||
use solana_vote_signer::rpc::LocalVoteSigner;
|
||||
use std::fs::remove_dir_all;
|
||||
|
||||
#[test]
|
||||
@@ -473,8 +472,7 @@ mod tests {
|
||||
)));
|
||||
bank.leader_scheduler = leader_scheduler;
|
||||
let vote_account_keypair = Arc::new(Keypair::new());
|
||||
let vote_signer =
|
||||
VoteSignerProxy::new(&vote_account_keypair, Box::new(LocalVoteSigner::default()));
|
||||
let vote_signer = VoteSignerProxy::new_local(&vote_account_keypair);
|
||||
let last_id = bank.last_id();
|
||||
let server = Fullnode::new_with_bank(
|
||||
leader_keypair,
|
||||
@@ -527,8 +525,7 @@ mod tests {
|
||||
)));
|
||||
bank.leader_scheduler = leader_scheduler;
|
||||
let vote_account_keypair = Arc::new(Keypair::new());
|
||||
let vote_signer =
|
||||
VoteSignerProxy::new(&vote_account_keypair, Box::new(LocalVoteSigner::default()));
|
||||
let vote_signer = VoteSignerProxy::new_local(&vote_account_keypair);
|
||||
let last_id = bank.last_id();
|
||||
let server = Fullnode::new_with_bank(
|
||||
leader_keypair,
|
||||
@@ -587,8 +584,7 @@ mod tests {
|
||||
)));
|
||||
bank.leader_scheduler = leader_scheduler;
|
||||
let vote_account_keypair = Arc::new(Keypair::new());
|
||||
let vote_signer =
|
||||
VoteSignerProxy::new(&vote_account_keypair, Box::new(LocalVoteSigner::default()));
|
||||
let vote_signer = VoteSignerProxy::new_local(&vote_account_keypair);
|
||||
let entry_height = 0;
|
||||
let last_id = bank.last_id();
|
||||
let server = Fullnode::new_with_bank(
|
||||
@@ -633,10 +629,7 @@ mod tests {
|
||||
)));
|
||||
bank.leader_scheduler = leader_scheduler;
|
||||
let leader_vote_account_keypair = Arc::new(Keypair::new());
|
||||
let vote_signer = VoteSignerProxy::new(
|
||||
&leader_vote_account_keypair,
|
||||
Box::new(LocalVoteSigner::default()),
|
||||
);
|
||||
let vote_signer = VoteSignerProxy::new_local(&leader_vote_account_keypair);
|
||||
let server = Fullnode::new_with_bank(
|
||||
leader_keypair,
|
||||
Some(Arc::new(vote_signer)),
|
||||
@@ -729,8 +722,7 @@ mod tests {
|
||||
)));
|
||||
bank.leader_scheduler = leader_scheduler;
|
||||
let vote_account_keypair = Arc::new(Keypair::new());
|
||||
let vote_signer =
|
||||
VoteSignerProxy::new(&vote_account_keypair, Box::new(LocalVoteSigner::default()));
|
||||
let vote_signer = VoteSignerProxy::new_local(&vote_account_keypair);
|
||||
let last_id = bank.last_id();
|
||||
let entry_height = 0;
|
||||
let server = Fullnode::new_with_bank(
|
||||
|
@@ -199,7 +199,6 @@ pub mod tests {
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::system_transaction::SystemTransaction;
|
||||
use solana_sdk::transaction::Transaction;
|
||||
use solana_vote_signer::rpc::LocalVoteSigner;
|
||||
use std::fs::remove_dir_all;
|
||||
use std::net::UdpSocket;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
@@ -280,8 +279,7 @@ pub mod tests {
|
||||
let db_ledger =
|
||||
DbLedger::open(&db_ledger_path).expect("Expected to successfully open ledger");
|
||||
let vote_account_keypair = Arc::new(Keypair::new());
|
||||
let vote_signer =
|
||||
VoteSignerProxy::new(&vote_account_keypair, Box::new(LocalVoteSigner::default()));
|
||||
let vote_signer = VoteSignerProxy::new_local(&vote_account_keypair);
|
||||
let (sender, _) = channel();
|
||||
let tvu = Tvu::new(
|
||||
Some(Arc::new(vote_signer)),
|
||||
|
@@ -16,6 +16,7 @@ use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
||||
use solana_sdk::transaction::Transaction;
|
||||
use solana_sdk::vote_program::Vote;
|
||||
use solana_sdk::vote_transaction::VoteTransaction;
|
||||
use solana_vote_signer::rpc::LocalVoteSigner;
|
||||
use solana_vote_signer::rpc::VoteSigner;
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
@@ -98,6 +99,10 @@ impl VoteSignerProxy {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_local(keypair: &Arc<Keypair>) -> Self {
|
||||
Self::new(keypair, Box::new(LocalVoteSigner::default()))
|
||||
}
|
||||
|
||||
pub fn new_vote_account(&self, bank: &Bank, num_tokens: u64, last_id: Hash) -> Result<()> {
|
||||
// Create and register the new vote account
|
||||
let tx =
|
||||
@@ -209,7 +214,6 @@ mod test {
|
||||
use crate::genesis_block::GenesisBlock;
|
||||
use crate::vote_signer_proxy::VoteSignerProxy;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_vote_signer::rpc::LocalVoteSigner;
|
||||
use std::sync::mpsc::channel;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::time::Duration;
|
||||
@@ -218,10 +222,7 @@ mod test {
|
||||
pub fn test_pending_votes() {
|
||||
solana_logger::setup();
|
||||
|
||||
let signer = VoteSignerProxy::new(
|
||||
&Arc::new(Keypair::new()),
|
||||
Box::new(LocalVoteSigner::default()),
|
||||
);
|
||||
let signer = VoteSignerProxy::new_local(&Arc::new(Keypair::new()));
|
||||
|
||||
// Set up dummy node to host a ReplayStage
|
||||
let my_keypair = Keypair::new();
|
||||
|
Reference in New Issue
Block a user