Add local cluster test for forwarding

This commit is contained in:
Carl 2019-03-09 16:25:38 -08:00 committed by Pankaj Garg
parent cd1a9faacd
commit ccd1173a83
2 changed files with 40 additions and 0 deletions

View File

@ -48,6 +48,27 @@ pub fn spend_and_verify_all_nodes(
}
}
pub fn send_many_transactions(node: &ContactInfo, funding_keypair: &Keypair, num_txs: u64) {
let mut client = mk_client(node);
for _ in 0..num_txs {
let random_keypair = Keypair::new();
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,
);
client
.retry_transfer(&funding_keypair, &mut transaction, 5)
.unwrap();
}
}
pub fn fullnode_exit(entry_point_info: &ContactInfo, nodes: usize) {
let cluster_nodes = discover(&entry_point_info.gossip, nodes).unwrap();
assert!(cluster_nodes.len() >= nodes);

View File

@ -2,6 +2,7 @@ extern crate solana;
use solana::cluster_tests;
use solana::fullnode::FullnodeConfig;
use solana::gossip_service::discover;
use solana::local_cluster::LocalCluster;
use solana::poh_service::PohServiceConfig;
use solana_sdk::timing::{DEFAULT_SLOTS_PER_EPOCH, DEFAULT_TICKS_PER_SLOT};
@ -109,3 +110,21 @@ fn test_two_unbalanced_stakes() {
drop(cluster);
}
#[test]
fn test_forwarding() {
// Set up a cluster where one node is never the leader, so all txs sent to this node
// will be have to be forwarded
let fullnode_config = FullnodeConfig::default();
let cluster = LocalCluster::new_with_config(&[999_990, 3], 2_000_000, &fullnode_config);
let cluster_nodes = discover(&cluster.entry_point_info.gossip, 2).unwrap();
assert!(cluster_nodes.len() >= 2);
let leader_id = cluster.entry_point_info.id;
let validator_info = cluster_nodes.iter().find(|c| c.id != leader_id).unwrap();
cluster_tests::send_many_transactions(&validator_info, &cluster.funding_keypair, 20);
drop(cluster);
}