Absorb vote utilities

But drop dependency on VotingKeypair. Only pass in VotingKeypair
in VotingKeypair tests or integration tests.
This commit is contained in:
Greg Fitzgerald 2019-02-20 09:43:30 -07:00
parent 88d6db8537
commit af1b8f8a26
3 changed files with 36 additions and 23 deletions

View File

@ -65,3 +65,37 @@ impl ActiveStakers {
LeaderSchedule::new(self.pubkeys())
}
}
pub mod tests {
use solana_runtime::bank::Bank;
use solana_sdk::hash::Hash;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::vote_transaction::VoteTransaction;
pub fn new_vote_account<T: KeypairUtil>(
from_keypair: &Keypair,
voting_keypair: &T,
bank: &Bank,
num_tokens: u64,
last_id: Hash,
) {
let tx = VoteTransaction::new_account(
from_keypair,
voting_keypair.pubkey(),
last_id,
num_tokens,
0,
);
bank.process_transaction(&tx).unwrap();
}
pub fn push_vote<T: KeypairUtil>(
voting_keypair: &T,
bank: &Bank,
tick_height: u64,
last_id: Hash,
) {
let new_vote_tx = VoteTransaction::new_vote(voting_keypair, tick_height, last_id, 0);
bank.process_transaction(&new_vote_tx).unwrap();
}
}

View File

@ -133,7 +133,7 @@ impl Service for LeaderConfirmationService {
#[cfg(test)]
pub mod tests {
use super::*;
use crate::leader_scheduler::tests::new_vote_account;
use crate::active_stakers::tests::new_vote_account;
use crate::voting_keypair::VotingKeypair;
use bincode::serialize;
use solana_sdk::genesis_block::GenesisBlock;

View File

@ -428,6 +428,7 @@ pub fn make_active_set_entries(
#[cfg(test)]
pub mod tests {
use super::*;
use crate::active_stakers::tests::{new_vote_account, push_vote};
use hashbrown::HashSet;
use solana_sdk::genesis_block::{GenesisBlock, BOOTSTRAP_LEADER_TOKENS};
use std::hash::Hash as StdHash;
@ -441,28 +442,6 @@ pub mod tests {
HashSet::from_iter(slice.iter().cloned())
}
pub fn new_vote_account(
from_keypair: &Keypair,
voting_keypair: &VotingKeypair,
bank: &Bank,
num_tokens: u64,
last_id: Hash,
) {
let tx = VoteTransaction::new_account(
from_keypair,
voting_keypair.pubkey(),
last_id,
num_tokens,
0,
);
bank.process_transaction(&tx).unwrap();
}
fn push_vote(voting_keypair: &VotingKeypair, bank: &Bank, tick_height: u64, last_id: Hash) {
let new_vote_tx = VoteTransaction::new_vote(voting_keypair, tick_height, last_id, 0);
bank.process_transaction(&new_vote_tx).unwrap();
}
fn run_scheduler_test(num_validators: usize, ticks_per_slot: u64, ticks_per_epoch: u64) {
info!(
"run_scheduler_test({}, {}, {})",