2019-03-01 10:36:52 -08:00
|
|
|
/// Cluster independant integration tests
|
|
|
|
///
|
|
|
|
/// All tests must start from an entry point and a funding keypair and
|
|
|
|
/// discover the rest of the network.
|
|
|
|
use crate::client::mk_client;
|
|
|
|
use crate::contact_info::ContactInfo;
|
|
|
|
use crate::gossip_service::discover;
|
|
|
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
|
|
|
use solana_sdk::system_transaction::SystemTransaction;
|
2019-03-05 17:56:51 -08:00
|
|
|
use solana_sdk::timing::{DEFAULT_SLOTS_PER_EPOCH, DEFAULT_TICKS_PER_SLOT, NUM_TICKS_PER_SECOND};
|
2019-03-03 22:01:09 -08:00
|
|
|
use std::thread::sleep;
|
|
|
|
use std::time::Duration;
|
2019-03-01 10:36:52 -08:00
|
|
|
|
2019-03-05 17:56:51 -08:00
|
|
|
const SLOT_MILLIS: u64 = (DEFAULT_TICKS_PER_SLOT * 1000) / NUM_TICKS_PER_SECOND;
|
|
|
|
|
2019-03-01 10:36:52 -08:00
|
|
|
/// Spend and verify from every node in the network
|
|
|
|
pub fn spend_and_verify_all_nodes(
|
|
|
|
entry_point_info: &ContactInfo,
|
|
|
|
funding_keypair: &Keypair,
|
|
|
|
nodes: usize,
|
|
|
|
) {
|
2019-03-07 10:13:54 -08:00
|
|
|
let (_leader_id, cluster_nodes) = discover(&entry_point_info, nodes).unwrap();
|
2019-03-01 10:36:52 -08:00
|
|
|
assert!(cluster_nodes.len() >= nodes);
|
|
|
|
for ingress_node in &cluster_nodes {
|
|
|
|
let random_keypair = Keypair::new();
|
|
|
|
let mut client = mk_client(&ingress_node);
|
|
|
|
let bal = client
|
|
|
|
.poll_get_balance(&funding_keypair.pubkey())
|
|
|
|
.expect("balance in source");
|
|
|
|
assert!(bal > 0);
|
|
|
|
let mut transaction = SystemTransaction::new_move(
|
|
|
|
&funding_keypair,
|
|
|
|
random_keypair.pubkey(),
|
|
|
|
1,
|
2019-03-02 10:25:16 -08:00
|
|
|
client.get_recent_blockhash(),
|
2019-03-01 10:36:52 -08:00
|
|
|
0,
|
|
|
|
);
|
|
|
|
let sig = client
|
|
|
|
.retry_transfer(&funding_keypair, &mut transaction, 5)
|
|
|
|
.unwrap();
|
|
|
|
for validator in &cluster_nodes {
|
|
|
|
let mut client = mk_client(&validator);
|
|
|
|
client.poll_for_signature(&sig).unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-03 22:01:09 -08:00
|
|
|
|
|
|
|
pub fn fullnode_exit(entry_point_info: &ContactInfo, nodes: usize) {
|
2019-03-07 10:13:54 -08:00
|
|
|
let (_leader_id, cluster_nodes) = discover(&entry_point_info, nodes).unwrap();
|
2019-03-03 22:01:09 -08:00
|
|
|
assert!(cluster_nodes.len() >= nodes);
|
|
|
|
for node in &cluster_nodes {
|
|
|
|
let mut client = mk_client(&node);
|
|
|
|
assert!(client.fullnode_exit().unwrap());
|
|
|
|
}
|
2019-03-05 17:56:51 -08:00
|
|
|
sleep(Duration::from_millis(SLOT_MILLIS));
|
2019-03-03 22:01:09 -08:00
|
|
|
for node in &cluster_nodes {
|
|
|
|
let mut client = mk_client(&node);
|
|
|
|
assert!(client.fullnode_exit().is_err());
|
|
|
|
}
|
|
|
|
}
|
2019-03-05 17:56:51 -08:00
|
|
|
|
|
|
|
pub fn kill_entry_and_spend_and_verify_rest(
|
|
|
|
entry_point_info: &ContactInfo,
|
|
|
|
funding_keypair: &Keypair,
|
|
|
|
nodes: usize,
|
|
|
|
) {
|
|
|
|
solana_logger::setup();
|
2019-03-07 10:13:54 -08:00
|
|
|
let (_leader_id, cluster_nodes) = discover(&entry_point_info, nodes).unwrap();
|
2019-03-05 17:56:51 -08:00
|
|
|
assert!(cluster_nodes.len() >= nodes);
|
|
|
|
let mut client = mk_client(&entry_point_info);
|
|
|
|
info!("sleeping for an epoch");
|
|
|
|
sleep(Duration::from_millis(SLOT_MILLIS * DEFAULT_SLOTS_PER_EPOCH));
|
|
|
|
info!("done sleeping for an epoch");
|
|
|
|
info!("killing entry point");
|
|
|
|
assert!(client.fullnode_exit().unwrap());
|
|
|
|
info!("sleeping for a slot");
|
|
|
|
sleep(Duration::from_millis(SLOT_MILLIS));
|
|
|
|
info!("done sleeping for a slot");
|
|
|
|
for ingress_node in &cluster_nodes {
|
|
|
|
if ingress_node.id == entry_point_info.id {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let random_keypair = Keypair::new();
|
|
|
|
let mut client = mk_client(&ingress_node);
|
|
|
|
let bal = client
|
|
|
|
.poll_get_balance(&funding_keypair.pubkey())
|
|
|
|
.expect("balance in source");
|
|
|
|
assert!(bal > 0);
|
|
|
|
let mut transaction = SystemTransaction::new_move(
|
|
|
|
&funding_keypair,
|
|
|
|
random_keypair.pubkey(),
|
|
|
|
1,
|
|
|
|
client.get_recent_blockhash(),
|
|
|
|
0,
|
|
|
|
);
|
|
|
|
let sig = client
|
|
|
|
.retry_transfer(&funding_keypair, &mut transaction, 5)
|
|
|
|
.unwrap();
|
|
|
|
for validator in &cluster_nodes {
|
|
|
|
if validator.id == entry_point_info.id {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let mut client = mk_client(&validator);
|
|
|
|
client.poll_for_signature(&sig).unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|