Add a constructor to generate random pubkeys

This commit is contained in:
Greg Fitzgerald
2019-03-30 21:37:33 -06:00
parent 32683cac7c
commit fcef54d062
51 changed files with 263 additions and 298 deletions

View File

@ -600,16 +600,16 @@ mod tests {
bank.process_transaction(&fund_tx).unwrap();
// good tx
let to = Keypair::new().pubkey();
let to = Pubkey::new_rand();
let tx = SystemTransaction::new_account(&mint_keypair, &to, 1, start_hash, 0);
// good tx, but no verify
let to2 = Keypair::new().pubkey();
let to2 = Pubkey::new_rand();
let tx_no_ver = SystemTransaction::new_account(&keypair, &to2, 2, start_hash, 0);
// bad tx, AccountNotFound
let keypair = Keypair::new();
let to3 = Keypair::new().pubkey();
let to3 = Pubkey::new_rand();
let tx_anf = SystemTransaction::new_account(&keypair, &to3, 1, start_hash, 0);
// send 'em over
@ -777,7 +777,7 @@ mod tests {
let poh_recorder = Arc::new(Mutex::new(poh_recorder));
poh_recorder.lock().unwrap().set_working_bank(working_bank);
let pubkey = Keypair::new().pubkey();
let pubkey = Pubkey::new_rand();
let transactions = vec![
SystemTransaction::new_move(&mint_keypair, &pubkey, 1, genesis_block.hash(), 0),
@ -815,7 +815,7 @@ mod tests {
solana_logger::setup();
let (genesis_block, mint_keypair) = GenesisBlock::new(10_000);
let bank = Arc::new(Bank::new(&genesis_block));
let pubkey = Keypair::new().pubkey();
let pubkey = Pubkey::new_rand();
let transactions = vec![SystemTransaction::new_move(
&mint_keypair,

View File

@ -206,7 +206,7 @@ mod test {
let tick_height_initial = 0;
let tick_height_final = tick_height_initial + ticks_per_slot + 2;
let mut curr_slot = 0;
let leader_id = Keypair::new().pubkey();
let leader_id = Pubkey::new_rand();
for tick_height in tick_height_initial..=tick_height_final {
if tick_height == 5 {

View File

@ -121,7 +121,7 @@ mod test {
#[test]
fn test_blockstream_service_process_entries() {
let ticks_per_slot = 5;
let leader_id = Keypair::new().pubkey();
let leader_id = Pubkey::new_rand();
// Set up genesis block and blocktree
let (mut genesis_block, _mint_keypair) = GenesisBlock::new(1000);

View File

@ -1085,6 +1085,7 @@ pub mod tests {
use rand::seq::SliceRandom;
use rand::thread_rng;
use solana_sdk::hash::Hash;
use solana_sdk::pubkey::Pubkey;
use std::cmp::min;
use std::collections::HashSet;
use std::iter::once;
@ -1255,7 +1256,7 @@ pub mod tests {
fn test_read_blobs_bytes() {
let shared_blobs = make_tiny_test_entries(10).to_single_entry_shared_blobs();
let slot = 0;
packet::index_blobs(&shared_blobs, &Keypair::new().pubkey(), 0, slot, 0);
packet::index_blobs(&shared_blobs, &Pubkey::new_rand(), 0, slot, 0);
let blob_locks: Vec<_> = shared_blobs.iter().map(|b| b.read().unwrap()).collect();
let blobs: Vec<&Blob> = blob_locks.iter().map(|b| &**b).collect();
@ -2379,7 +2380,7 @@ pub mod tests {
let num_entries = 10;
let shared_blobs = make_tiny_test_entries(num_entries).to_single_entry_shared_blobs();
crate::packet::index_blobs(&shared_blobs, &Keypair::new().pubkey(), 0, slot, 0);
crate::packet::index_blobs(&shared_blobs, &Pubkey::new_rand(), 0, slot, 0);
let blob_locks: Vec<_> = shared_blobs.iter().map(|b| b.read().unwrap()).collect();
let blobs: Vec<&Blob> = blob_locks.iter().map(|b| &**b).collect();

View File

@ -230,6 +230,7 @@ mod tests {
use crate::entry::{create_ticks, next_entry, Entry};
use solana_sdk::genesis_block::GenesisBlock;
use solana_sdk::hash::Hash;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::system_transaction::SystemTransaction;
use solana_sdk::transaction::TransactionError;
@ -441,7 +442,7 @@ mod tests {
#[test]
fn test_process_ledger_simple() {
solana_logger::setup();
let leader_pubkey = Keypair::new().pubkey();
let leader_pubkey = Pubkey::new_rand();
let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(100, &leader_pubkey, 50);
let (ledger_path, mut last_entry_hash) = create_new_tmp_ledger!(&genesis_block);
debug!("ledger_path: {:?}", ledger_path);

View File

@ -1358,7 +1358,7 @@ pub struct Node {
impl Node {
pub fn new_localhost() -> Self {
let pubkey = Keypair::new().pubkey();
let pubkey = Pubkey::new_rand();
Self::new_localhost_with_pubkey(&pubkey)
}
pub fn new_localhost_replicator(pubkey: &Pubkey) -> Self {
@ -1536,7 +1536,7 @@ mod tests {
fn test_cluster_spy_gossip() {
//check that gossip doesn't try to push to invalid addresses
let node = Node::new_localhost();
let (spy, _) = ClusterInfo::spy_node(&Keypair::new().pubkey());
let (spy, _) = ClusterInfo::spy_node(&Pubkey::new_rand());
let cluster_info = Arc::new(RwLock::new(ClusterInfo::new_with_invalid_keypair(
node.info,
)));
@ -1560,43 +1560,43 @@ mod tests {
#[test]
fn test_cluster_info_new() {
let d = ContactInfo::new_localhost(&Keypair::new().pubkey(), timestamp());
let d = ContactInfo::new_localhost(&Pubkey::new_rand(), timestamp());
let cluster_info = ClusterInfo::new_with_invalid_keypair(d.clone());
assert_eq!(d.id, cluster_info.my_data().id);
}
#[test]
fn insert_info_test() {
let d = ContactInfo::new_localhost(&Keypair::new().pubkey(), timestamp());
let d = ContactInfo::new_localhost(&Pubkey::new_rand(), timestamp());
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(d);
let d = ContactInfo::new_localhost(&Keypair::new().pubkey(), timestamp());
let d = ContactInfo::new_localhost(&Pubkey::new_rand(), timestamp());
let label = CrdsValueLabel::ContactInfo(d.id);
cluster_info.insert_info(d);
assert!(cluster_info.gossip.crds.lookup(&label).is_some());
}
#[test]
fn test_insert_self() {
let d = ContactInfo::new_localhost(&Keypair::new().pubkey(), timestamp());
let d = ContactInfo::new_localhost(&Pubkey::new_rand(), timestamp());
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(d.clone());
let entry_label = CrdsValueLabel::ContactInfo(cluster_info.id());
assert!(cluster_info.gossip.crds.lookup(&entry_label).is_some());
// inserting something else shouldn't work
let d = ContactInfo::new_localhost(&Keypair::new().pubkey(), timestamp());
let d = ContactInfo::new_localhost(&Pubkey::new_rand(), timestamp());
cluster_info.insert_self(d.clone());
let label = CrdsValueLabel::ContactInfo(d.id);
assert!(cluster_info.gossip.crds.lookup(&label).is_none());
}
#[test]
fn window_index_request() {
let me = ContactInfo::new_localhost(&Keypair::new().pubkey(), timestamp());
let me = ContactInfo::new_localhost(&Pubkey::new_rand(), timestamp());
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(me);
let rv = cluster_info.window_index_request(0, 0, false);
assert_matches!(rv, Err(Error::ClusterInfoError(ClusterInfoError::NoPeers)));
let gossip_addr = socketaddr!([127, 0, 0, 1], 1234);
let nxt = ContactInfo::new(
&Keypair::new().pubkey(),
&Pubkey::new_rand(),
gossip_addr,
socketaddr!([127, 0, 0, 1], 1235),
socketaddr!([127, 0, 0, 1], 1236),
@ -1613,7 +1613,7 @@ mod tests {
let gossip_addr2 = socketaddr!([127, 0, 0, 2], 1234);
let nxt = ContactInfo::new(
&Keypair::new().pubkey(),
&Pubkey::new_rand(),
gossip_addr2,
socketaddr!([127, 0, 0, 1], 1235),
socketaddr!([127, 0, 0, 1], 1236),
@ -1647,7 +1647,7 @@ mod tests {
{
let blocktree = Arc::new(Blocktree::open(&ledger_path).unwrap());
let me = ContactInfo::new(
&Keypair::new().pubkey(),
&Pubkey::new_rand(),
socketaddr!("127.0.0.1:1234"),
socketaddr!("127.0.0.1:1235"),
socketaddr!("127.0.0.1:1236"),
@ -1749,7 +1749,7 @@ mod tests {
#[test]
fn test_default_leader() {
solana_logger::setup();
let contact_info = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0);
let contact_info = ContactInfo::new_localhost(&Pubkey::new_rand(), 0);
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(contact_info);
let network_entry_point =
ContactInfo::new_gossip_entry_point(&socketaddr!("127.0.0.1:1239"));
@ -1788,7 +1788,7 @@ mod tests {
#[test]
fn new_with_external_ip_test_random() {
let ip = Ipv4Addr::from(0);
let node = Node::new_with_external_ip(&Keypair::new().pubkey(), &socketaddr!(ip, 0));
let node = Node::new_with_external_ip(&Pubkey::new_rand(), &socketaddr!(ip, 0));
check_node_sockets(&node, IpAddr::V4(ip), FULLNODE_PORT_RANGE);
}
@ -1801,7 +1801,7 @@ mod tests {
.expect("Failed to bind")
.0
};
let node = Node::new_with_external_ip(&Keypair::new().pubkey(), &socketaddr!(0, port));
let node = Node::new_with_external_ip(&Pubkey::new_rand(), &socketaddr!(0, port));
check_node_sockets(&node, ip, FULLNODE_PORT_RANGE);
@ -1811,8 +1811,7 @@ mod tests {
#[test]
fn new_replicator_external_ip_test() {
let ip = Ipv4Addr::from(0);
let node =
Node::new_replicator_with_external_ip(&Keypair::new().pubkey(), &socketaddr!(ip, 0));
let node = Node::new_replicator_with_external_ip(&Pubkey::new_rand(), &socketaddr!(ip, 0));
let ip = IpAddr::V4(ip);
check_socket(&node.sockets.storage.unwrap(), ip, FULLNODE_PORT_RANGE);
@ -2034,7 +2033,7 @@ fn test_add_entrypoint() {
ContactInfo::new_localhost(&node_keypair.pubkey(), timestamp()),
node_keypair,
);
let entrypoint_id = Keypair::new().pubkey();
let entrypoint_id = Pubkey::new_rand();
let entrypoint = ContactInfo::new_localhost(&entrypoint_id, timestamp());
cluster_info.set_entrypoint(entrypoint.clone());
let pulls = cluster_info.new_pull_requests(&HashMap::new());

View File

@ -130,7 +130,7 @@ impl ContactInfo {
let addr = socketaddr!("224.0.1.255:1000");
assert!(addr.ip().is_multicast());
Self::new(
&Keypair::new().pubkey(),
&Pubkey::new_rand(),
addr,
addr,
addr,

View File

@ -165,7 +165,6 @@ impl Crds {
mod test {
use super::*;
use crate::contact_info::ContactInfo;
use solana_sdk::signature::{Keypair, KeypairUtil};
#[test]
fn test_insert() {
@ -302,11 +301,11 @@ mod test {
fn test_label_order() {
let v1 = VersionedCrdsValue::new(
1,
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)),
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0)),
);
let v2 = VersionedCrdsValue::new(
1,
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)),
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0)),
);
assert_ne!(v1, v2);
assert!(!(v1 == v2));

View File

@ -209,18 +209,16 @@ impl CrdsGossipPull {
mod test {
use super::*;
use crate::contact_info::ContactInfo;
use solana_sdk::signature::{Keypair, KeypairUtil};
#[test]
fn test_new_pull_with_stakes() {
let mut crds = Crds::default();
let mut stakes = HashMap::new();
let node = CrdsGossipPull::default();
let me = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let me = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
crds.insert(me.clone(), 0).unwrap();
for i in 1..=30 {
let entry =
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
let id = entry.label().pubkey();
crds.insert(entry.clone(), 0).unwrap();
stakes.insert(id, i * 100);
@ -239,7 +237,7 @@ mod test {
#[test]
fn test_new_pull_request() {
let mut crds = Crds::default();
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
let id = entry.label().pubkey();
let node = CrdsGossipPull::default();
assert_eq!(
@ -253,7 +251,7 @@ mod test {
Err(CrdsGossipError::NoPeers)
);
let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
crds.insert(new.clone(), 0).unwrap();
let req = node.new_pull_request(&crds, &id, 0, &HashMap::new());
let (to, _, self_info) = req.unwrap();
@ -264,13 +262,13 @@ mod test {
#[test]
fn test_new_mark_creation_time() {
let mut crds = Crds::default();
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
let node_id = entry.label().pubkey();
let mut node = CrdsGossipPull::default();
crds.insert(entry.clone(), 0).unwrap();
let old = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let old = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
crds.insert(old.clone(), 0).unwrap();
let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
crds.insert(new.clone(), 0).unwrap();
// set request creation time to max_value
@ -288,11 +286,11 @@ mod test {
#[test]
fn test_process_pull_request() {
let mut node_crds = Crds::default();
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
let node_id = entry.label().pubkey();
let node = CrdsGossipPull::default();
node_crds.insert(entry.clone(), 0).unwrap();
let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
node_crds.insert(new.clone(), 0).unwrap();
let req = node.new_pull_request(&node_crds, &node_id, 0, &HashMap::new());
@ -320,17 +318,17 @@ mod test {
#[test]
fn test_process_pull_request_response() {
let mut node_crds = Crds::default();
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
let node_id = entry.label().pubkey();
let mut node = CrdsGossipPull::default();
node_crds.insert(entry.clone(), 0).unwrap();
let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
node_crds.insert(new.clone(), 0).unwrap();
let mut dest = CrdsGossipPull::default();
let mut dest_crds = Crds::default();
let new_id = Keypair::new().pubkey();
let new_id = Pubkey::new_rand();
let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(&new_id, 1));
dest_crds.insert(new.clone(), 0).unwrap();
@ -384,12 +382,12 @@ mod test {
#[test]
fn test_gossip_purge() {
let mut node_crds = Crds::default();
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
let node_label = entry.label();
let node_id = node_label.pubkey();
let mut node = CrdsGossipPull::default();
node_crds.insert(entry.clone(), 0).unwrap();
let old = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let old = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
node_crds.insert(old.clone(), 0).unwrap();
let value_hash = node_crds.lookup_versioned(&old.label()).unwrap().value_hash;

View File

@ -266,13 +266,12 @@ impl CrdsGossipPush {
mod test {
use super::*;
use crate::contact_info::ContactInfo;
use solana_sdk::signature::{Keypair, KeypairUtil};
#[test]
fn test_process_push() {
let mut crds = Crds::default();
let mut push = CrdsGossipPush::default();
let value = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let value = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
let label = value.label();
// push a new message
assert_eq!(
@ -291,7 +290,7 @@ mod test {
fn test_process_push_old_version() {
let mut crds = Crds::default();
let mut push = CrdsGossipPush::default();
let mut ci = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0);
let mut ci = ContactInfo::new_localhost(&Pubkey::new_rand(), 0);
ci.wallclock = 1;
let value = CrdsValue::ContactInfo(ci.clone());
@ -311,7 +310,7 @@ mod test {
let mut crds = Crds::default();
let mut push = CrdsGossipPush::default();
let timeout = push.msg_timeout;
let mut ci = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0);
let mut ci = ContactInfo::new_localhost(&Pubkey::new_rand(), 0);
// push a version to far in the future
ci.wallclock = timeout + 1;
@ -333,7 +332,7 @@ mod test {
fn test_process_push_update() {
let mut crds = Crds::default();
let mut push = CrdsGossipPush::default();
let mut ci = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0);
let mut ci = ContactInfo::new_localhost(&Pubkey::new_rand(), 0);
ci.wallclock = 0;
let value_old = CrdsValue::ContactInfo(ci.clone());
@ -366,15 +365,13 @@ mod test {
solana_logger::setup();
let mut crds = Crds::default();
let mut push = CrdsGossipPush::default();
let value1 =
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let value1 = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
assert_eq!(crds.insert(value1.clone(), 0), Ok(None));
push.refresh_push_active_set(&crds, &HashMap::new(), &Pubkey::default(), 1, 1);
assert!(push.active_set.get(&value1.label().pubkey()).is_some());
let value2 =
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let value2 = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
assert!(push.active_set.get(&value2.label().pubkey()).is_none());
assert_eq!(crds.insert(value2.clone(), 0), Ok(None));
for _ in 0..30 {
@ -386,8 +383,7 @@ mod test {
assert!(push.active_set.get(&value2.label().pubkey()).is_some());
for _ in 0..push.num_active {
let value2 =
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let value2 = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
assert_eq!(crds.insert(value2.clone(), 0), Ok(None));
}
push.refresh_push_active_set(&crds, &HashMap::new(), &Pubkey::default(), 1, 1);
@ -401,7 +397,7 @@ mod test {
let mut stakes = HashMap::new();
for i in 1..=100 {
let peer =
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), time));
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), time));
let id = peer.label().pubkey();
crds.insert(peer.clone(), time).unwrap();
stakes.insert(id, i * 100);
@ -419,12 +415,11 @@ mod test {
fn test_new_push_messages() {
let mut crds = Crds::default();
let mut push = CrdsGossipPush::default();
let peer = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let peer = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
assert_eq!(crds.insert(peer.clone(), 0), Ok(None));
push.refresh_push_active_set(&crds, &HashMap::new(), &Pubkey::default(), 1, 1);
let new_msg =
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let new_msg = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
assert_eq!(
push.process_push_message(&mut crds, new_msg.clone(), 0),
Ok(None)
@ -439,12 +434,11 @@ mod test {
fn test_process_prune() {
let mut crds = Crds::default();
let mut push = CrdsGossipPush::default();
let peer = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let peer = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
assert_eq!(crds.insert(peer.clone(), 0), Ok(None));
push.refresh_push_active_set(&crds, &HashMap::new(), &Pubkey::default(), 1, 1);
let new_msg =
CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let new_msg = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
assert_eq!(
push.process_push_message(&mut crds, new_msg.clone(), 0),
Ok(None)
@ -459,11 +453,11 @@ mod test {
fn test_purge_old_pending_push_messages() {
let mut crds = Crds::default();
let mut push = CrdsGossipPush::default();
let peer = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0));
let peer = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::new_rand(), 0));
assert_eq!(crds.insert(peer.clone(), 0), Ok(None));
push.refresh_push_active_set(&crds, &HashMap::new(), &Pubkey::default(), 1, 1);
let mut ci = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0);
let mut ci = ContactInfo::new_localhost(&Pubkey::new_rand(), 0);
ci.wallclock = 1;
let new_msg = CrdsValue::ContactInfo(ci.clone());
assert_eq!(
@ -481,7 +475,7 @@ mod test {
fn test_purge_old_pushed_once_messages() {
let mut crds = Crds::default();
let mut push = CrdsGossipPush::default();
let mut ci = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0);
let mut ci = ContactInfo::new_localhost(&Pubkey::new_rand(), 0);
ci.wallclock = 0;
let value = CrdsValue::ContactInfo(ci.clone());
let label = value.label();

View File

@ -56,7 +56,6 @@ mod test {
use crate::blocktree::get_tmp_ledger_path;
use crate::entry::{make_tiny_test_entries, EntrySlice};
use crate::packet::index_blobs;
use solana_sdk::signature::{Keypair, KeypairUtil};
use std::sync::Arc;
#[test]
@ -67,7 +66,7 @@ mod test {
let original_entries = make_tiny_test_entries(num_entries);
let shared_blobs = original_entries.clone().to_shared_blobs();
index_blobs(&shared_blobs, &Keypair::new().pubkey(), 0, 0, 0);
index_blobs(&shared_blobs, &Pubkey::new_rand(), 0, 0, 0);
for blob in shared_blobs.iter().rev() {
process_blob(&blocktree, blob).expect("Expect successful processing of blob");

View File

@ -502,9 +502,8 @@ pub mod test {
use crate::blocktree::get_tmp_ledger_path;
use crate::blocktree::Blocktree;
use crate::entry::{make_tiny_test_entries, EntrySlice};
use crate::packet::{index_blobs, SharedBlob};
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::pubkey::Pubkey;
/// Specifies the contents of a 16-data-blob and 4-coding-blob erasure set
/// Exists to be passed to `generate_blocktree_with_coding`
@ -793,13 +792,7 @@ pub mod test {
let start_index = set_index * NUM_DATA;
let mut blobs = make_tiny_test_entries(NUM_DATA).to_single_entry_shared_blobs();
index_blobs(
&blobs,
&Keypair::new().pubkey(),
start_index as u64,
slot,
0,
);
index_blobs(&blobs, &Pubkey::new_rand(), start_index as u64, slot, 0);
let mut coding_generator = CodingGenerator::new();
let mut coding_blobs = coding_generator.next(&blobs).unwrap();
@ -831,7 +824,7 @@ pub mod test {
fn generate_test_blobs(offset: usize, num_blobs: usize) -> Vec<SharedBlob> {
let blobs = make_tiny_test_entries(num_blobs).to_single_entry_shared_blobs();
index_blobs(&blobs, &Keypair::new().pubkey(), offset as u64, 0, 0);
index_blobs(&blobs, &Pubkey::new_rand(), offset as u64, 0, 0);
blobs
}

View File

@ -42,12 +42,11 @@ impl Index<u64> for LeaderSchedule {
#[cfg(test)]
mod tests {
use super::*;
use solana_sdk::signature::{Keypair, KeypairUtil};
#[test]
fn test_leader_schedule_index() {
let pubkey0 = Keypair::new().pubkey();
let pubkey1 = Keypair::new().pubkey();
let pubkey0 = Pubkey::new_rand();
let pubkey1 = Pubkey::new_rand();
let leader_schedule = LeaderSchedule {
slot_leaders: vec![pubkey0, pubkey1],
};
@ -59,11 +58,9 @@ mod tests {
#[test]
fn test_leader_schedule_basic() {
let num_keys = 10;
let stakes: Vec<_> = (0..num_keys)
.map(|i| (Keypair::new().pubkey(), i))
.collect();
let stakes: Vec<_> = (0..num_keys).map(|i| (Pubkey::new_rand(), i)).collect();
let seed = Keypair::new().pubkey();
let seed = Pubkey::new_rand();
let mut seed_bytes = [0u8; 32];
seed_bytes.copy_from_slice(seed.as_ref());
let len = num_keys * 10;
@ -77,11 +74,9 @@ mod tests {
#[test]
fn test_repeated_leader_schedule() {
let num_keys = 10;
let stakes: Vec<_> = (0..num_keys)
.map(|i| (Keypair::new().pubkey(), i))
.collect();
let stakes: Vec<_> = (0..num_keys).map(|i| (Pubkey::new_rand(), i)).collect();
let seed = Keypair::new().pubkey();
let seed = Pubkey::new_rand();
let mut seed_bytes = [0u8; 32];
seed_bytes.copy_from_slice(seed.as_ref());
let len = num_keys * 10;
@ -100,8 +95,8 @@ mod tests {
#[test]
fn test_repeated_leader_schedule_specific() {
let alice_pubkey = Keypair::new().pubkey();
let bob_pubkey = Keypair::new().pubkey();
let alice_pubkey = Pubkey::new_rand();
let bob_pubkey = Pubkey::new_rand();
let stakes = vec![(alice_pubkey, 2), (bob_pubkey, 1)];
let seed = Pubkey::default();

View File

@ -107,7 +107,7 @@ mod tests {
#[test]
fn test_next_leader_slot() {
let pubkey = Keypair::new().pubkey();
let pubkey = Pubkey::new_rand();
let mut genesis_block = GenesisBlock::new_with_leader(
BOOTSTRAP_LEADER_LAMPORTS,
&pubkey,
@ -132,7 +132,7 @@ mod tests {
assert_eq!(
next_leader_slot(
&Keypair::new().pubkey(), // not in leader_schedule
&Pubkey::new_rand(), // not in leader_schedule
0,
&bank,
None
@ -143,7 +143,7 @@ mod tests {
#[test]
fn test_next_leader_slot_blocktree() {
let pubkey = Keypair::new().pubkey();
let pubkey = Pubkey::new_rand();
let mut genesis_block = GenesisBlock::new_with_leader(
BOOTSTRAP_LEADER_LAMPORTS,
&pubkey,
@ -198,7 +198,7 @@ mod tests {
assert_eq!(
next_leader_slot(
&Keypair::new().pubkey(), // not in leader_schedule
&Pubkey::new_rand(), // not in leader_schedule
0,
&bank,
Some(&blocktree)
@ -211,7 +211,7 @@ mod tests {
#[test]
fn test_next_leader_slot_next_epoch() {
let pubkey = Keypair::new().pubkey();
let pubkey = Pubkey::new_rand();
let (mut genesis_block, mint_keypair) = GenesisBlock::new_with_leader(
2 * BOOTSTRAP_LEADER_LAMPORTS,
&pubkey,
@ -220,7 +220,7 @@ mod tests {
genesis_block.epoch_warmup = false;
let bank = Bank::new(&genesis_block);
let delegate_id = Keypair::new().pubkey();
let delegate_id = Pubkey::new_rand();
// Create new vote account
let new_voting_keypair = Keypair::new();
@ -263,7 +263,7 @@ mod tests {
#[test]
fn test_leader_schedule_via_bank() {
let pubkey = Keypair::new().pubkey();
let pubkey = Pubkey::new_rand();
let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(
BOOTSTRAP_LEADER_LAMPORTS,
&pubkey,
@ -287,7 +287,7 @@ mod tests {
#[test]
fn test_leader_scheduler1_basic() {
let pubkey = Keypair::new().pubkey();
let pubkey = Pubkey::new_rand();
let genesis_block = GenesisBlock::new_with_leader(
BOOTSTRAP_LEADER_LAMPORTS,
&pubkey,
@ -300,8 +300,8 @@ mod tests {
#[test]
fn test_sort_stakes_basic() {
let pubkey0 = Keypair::new().pubkey();
let pubkey1 = Keypair::new().pubkey();
let pubkey0 = Pubkey::new_rand();
let pubkey1 = Pubkey::new_rand();
let mut stakes = vec![(pubkey0, 1), (pubkey1, 2)];
sort_stakes(&mut stakes);
assert_eq!(stakes, vec![(pubkey1, 2), (pubkey0, 1)]);
@ -309,8 +309,8 @@ mod tests {
#[test]
fn test_sort_stakes_with_dup() {
let pubkey0 = Keypair::new().pubkey();
let pubkey1 = Keypair::new().pubkey();
let pubkey0 = Pubkey::new_rand();
let pubkey1 = Pubkey::new_rand();
let mut stakes = vec![(pubkey0, 1), (pubkey1, 2), (pubkey0, 1)];
sort_stakes(&mut stakes);
assert_eq!(stakes, vec![(pubkey1, 2), (pubkey0, 1)]);
@ -319,7 +319,7 @@ mod tests {
#[test]
fn test_sort_stakes_with_equal_stakes() {
let pubkey0 = Pubkey::default();
let pubkey1 = Keypair::new().pubkey();
let pubkey1 = Pubkey::new_rand();
let mut stakes = vec![(pubkey0, 1), (pubkey1, 1)];
sort_stakes(&mut stakes);
assert_eq!(stakes, vec![(pubkey1, 1), (pubkey0, 1)]);

View File

@ -369,7 +369,6 @@ impl Locktower {
#[cfg(test)]
mod test {
use super::*;
use solana_sdk::signature::{Keypair, KeypairUtil};
fn gen_accounts(stake_votes: &[(u64, &[u64])]) -> Vec<(Pubkey, Account)> {
let mut accounts = vec![];
@ -384,7 +383,7 @@ mod test {
vote_state
.serialize(&mut account.data)
.expect("serialize state");
accounts.push((Keypair::new().pubkey(), account));
accounts.push((Pubkey::new_rand(), account));
}
accounts
}

View File

@ -599,7 +599,7 @@ mod test {
let my_node = Node::new_localhost_with_pubkey(&my_id);
// Create keypair for the leader
let leader_id = Keypair::new().pubkey();
let leader_id = Pubkey::new_rand();
let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(10_000, &leader_id, 500);

View File

@ -491,7 +491,7 @@ mod tests {
#[test]
fn test_rpc_request_processor_new() {
let bob_pubkey = Keypair::new().pubkey();
let bob_pubkey = Pubkey::new_rand();
let exit = Arc::new(AtomicBool::new(false));
let (bank_forks, alice) = new_bank_forks();
let bank = bank_forks.read().unwrap().working_bank();
@ -513,7 +513,7 @@ mod tests {
#[test]
fn test_rpc_get_balance() {
let bob_pubkey = Keypair::new().pubkey();
let bob_pubkey = Pubkey::new_rand();
let (io, meta, _blockhash, _alice) = start_rpc_handler_with_tx(&bob_pubkey);
let req = format!(
@ -531,7 +531,7 @@ mod tests {
#[test]
fn test_rpc_get_tx_count() {
let bob_pubkey = Keypair::new().pubkey();
let bob_pubkey = Pubkey::new_rand();
let (io, meta, _blockhash, _alice) = start_rpc_handler_with_tx(&bob_pubkey);
let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getTransactionCount"}}"#);
@ -546,7 +546,7 @@ mod tests {
#[test]
fn test_rpc_get_account_info() {
let bob_pubkey = Keypair::new().pubkey();
let bob_pubkey = Pubkey::new_rand();
let (io, meta, _blockhash, _alice) = start_rpc_handler_with_tx(&bob_pubkey);
let req = format!(
@ -573,7 +573,7 @@ mod tests {
#[test]
fn test_rpc_confirm_tx() {
let bob_pubkey = Keypair::new().pubkey();
let bob_pubkey = Pubkey::new_rand();
let (io, meta, blockhash, alice) = start_rpc_handler_with_tx(&bob_pubkey);
let tx = SystemTransaction::new_move(&alice, &bob_pubkey, 20, blockhash, 0);
@ -592,7 +592,7 @@ mod tests {
#[test]
fn test_rpc_get_signature_status() {
let bob_pubkey = Keypair::new().pubkey();
let bob_pubkey = Pubkey::new_rand();
let (io, meta, blockhash, alice) = start_rpc_handler_with_tx(&bob_pubkey);
let tx = SystemTransaction::new_move(&alice, &bob_pubkey, 20, blockhash, 0);
@ -625,7 +625,7 @@ mod tests {
#[test]
fn test_rpc_get_recent_blockhash() {
let bob_pubkey = Keypair::new().pubkey();
let bob_pubkey = Pubkey::new_rand();
let (io, meta, blockhash, _alice) = start_rpc_handler_with_tx(&bob_pubkey);
let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getRecentBlockhash"}}"#);
@ -640,7 +640,7 @@ mod tests {
#[test]
fn test_rpc_fail_request_airdrop() {
let bob_pubkey = Keypair::new().pubkey();
let bob_pubkey = Pubkey::new_rand();
let (io, meta, _blockhash, _alice) = start_rpc_handler_with_tx(&bob_pubkey);
// Expect internal error because no drone is available
@ -705,7 +705,7 @@ mod tests {
#[test]
fn test_rpc_verify_pubkey() {
let pubkey = Keypair::new().pubkey();
let pubkey = Pubkey::new_rand();
assert_eq!(verify_pubkey(pubkey.to_string()).unwrap(), pubkey);
let bad_pubkey = "a1b2c3d4";
assert_eq!(
@ -716,13 +716,8 @@ mod tests {
#[test]
fn test_rpc_verify_signature() {
let tx = SystemTransaction::new_move(
&Keypair::new(),
&Keypair::new().pubkey(),
20,
hash(&[0]),
0,
);
let tx =
SystemTransaction::new_move(&Keypair::new(), &Pubkey::new_rand(), 20, hash(&[0]), 0);
assert_eq!(
verify_signature(&tx.signatures[0].to_string()).unwrap(),
tx.signatures[0]

View File

@ -291,7 +291,7 @@ mod tests {
#[test]
fn test_signature_unsubscribe() {
let (genesis_block, alice) = GenesisBlock::new(10_000);
let bob_pubkey = Keypair::new().pubkey();
let bob_pubkey = Pubkey::new_rand();
let bank = Bank::new(&genesis_block);
let arc_bank = Arc::new(bank);
let blockhash = arc_bank.last_blockhash();
@ -339,7 +339,7 @@ mod tests {
.native_programs
.push(("solana_budget_program".to_string(), solana_budget_api::id()));
let bob_pubkey = Keypair::new().pubkey();
let bob_pubkey = Pubkey::new_rand();
let witness = Keypair::new();
let contract_funds = Keypair::new();
let contract_state = Keypair::new();
@ -407,7 +407,7 @@ mod tests {
#[test]
fn test_account_unsubscribe() {
let bob_pubkey = Keypair::new().pubkey();
let bob_pubkey = Pubkey::new_rand();
let session = create_session();
let mut io = PubSubHandler::default();

View File

@ -160,7 +160,7 @@ mod tests {
#[test]
fn test_bank_staked_nodes_at_epoch() {
let pubkey = Keypair::new().pubkey();
let pubkey = Pubkey::new_rand();
let bootstrap_lamports = 2;
let (genesis_block, _) =
GenesisBlock::new_with_leader(bootstrap_lamports, &pubkey, bootstrap_lamports);
@ -276,8 +276,8 @@ mod tests {
#[test]
fn test_to_delegated_stakes() {
let mut stakes = Vec::new();
let delegate1 = Keypair::new().pubkey();
let delegate2 = Keypair::new().pubkey();
let delegate1 = Pubkey::new_rand();
let delegate2 = Pubkey::new_rand();
// Delegate 1 has stake of 3
for i in 0..3 {