2019-11-12 19:30:35 -08:00
|
|
|
use log::*;
|
2019-09-18 13:10:50 -07:00
|
|
|
use solana_bench_exchange::bench::{airdrop_lamports, do_bench_exchange, Config};
|
|
|
|
use solana_core::gossip_service::{discover_cluster, get_multi_client};
|
|
|
|
use solana_core::validator::ValidatorConfig;
|
2019-11-20 16:32:19 -08:00
|
|
|
use solana_exchange_program::exchange_processor::process_instruction;
|
|
|
|
use solana_exchange_program::id;
|
2019-11-12 19:30:35 -08:00
|
|
|
use solana_exchange_program::solana_exchange_program;
|
2019-12-16 13:05:17 -08:00
|
|
|
use solana_faucet::faucet::run_local_faucet;
|
2019-11-12 19:30:35 -08:00
|
|
|
use solana_local_cluster::local_cluster::{ClusterConfig, LocalCluster};
|
2019-09-18 13:10:50 -07:00
|
|
|
use solana_runtime::bank::Bank;
|
|
|
|
use solana_runtime::bank_client::BankClient;
|
2019-11-08 20:56:57 -08:00
|
|
|
use solana_sdk::genesis_config::create_genesis_config;
|
2020-02-20 13:28:55 -08:00
|
|
|
use solana_sdk::signature::{Keypair, Signer};
|
2019-09-18 13:10:50 -07:00
|
|
|
use std::process::exit;
|
|
|
|
use std::sync::mpsc::channel;
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
#[test]
|
2020-02-06 10:44:17 -08:00
|
|
|
#[ignore]
|
2019-09-18 13:10:50 -07:00
|
|
|
fn test_exchange_local_cluster() {
|
|
|
|
solana_logger::setup();
|
|
|
|
|
|
|
|
const NUM_NODES: usize = 1;
|
|
|
|
|
|
|
|
let mut config = Config::default();
|
|
|
|
config.identity = Keypair::new();
|
|
|
|
config.duration = Duration::from_secs(1);
|
|
|
|
config.fund_amount = 100_000;
|
|
|
|
config.threads = 1;
|
|
|
|
config.transfer_delay = 20; // 15
|
|
|
|
config.batch_size = 100; // 1000;
|
|
|
|
config.chunk_size = 10; // 200;
|
|
|
|
config.account_groups = 1; // 10;
|
|
|
|
let Config {
|
|
|
|
fund_amount,
|
|
|
|
batch_size,
|
|
|
|
account_groups,
|
|
|
|
..
|
|
|
|
} = config;
|
|
|
|
let accounts_in_groups = batch_size * account_groups;
|
|
|
|
|
|
|
|
let cluster = LocalCluster::new(&ClusterConfig {
|
|
|
|
node_stakes: vec![100_000; NUM_NODES],
|
|
|
|
cluster_lamports: 100_000_000_000_000,
|
|
|
|
validator_configs: vec![ValidatorConfig::default(); NUM_NODES],
|
|
|
|
native_instruction_processors: [solana_exchange_program!()].to_vec(),
|
|
|
|
..ClusterConfig::default()
|
|
|
|
});
|
|
|
|
|
2019-12-16 13:05:17 -08:00
|
|
|
let faucet_keypair = Keypair::new();
|
2019-09-18 13:10:50 -07:00
|
|
|
cluster.transfer(
|
|
|
|
&cluster.funding_keypair,
|
2019-12-16 13:05:17 -08:00
|
|
|
&faucet_keypair.pubkey(),
|
2019-09-18 13:10:50 -07:00
|
|
|
2_000_000_000_000,
|
|
|
|
);
|
|
|
|
|
|
|
|
let (addr_sender, addr_receiver) = channel();
|
2019-12-16 13:05:17 -08:00
|
|
|
run_local_faucet(faucet_keypair, addr_sender, Some(1_000_000_000_000));
|
|
|
|
let faucet_addr = addr_receiver.recv_timeout(Duration::from_secs(2)).unwrap();
|
2019-09-18 13:10:50 -07:00
|
|
|
|
|
|
|
info!("Connecting to the cluster");
|
2020-05-14 18:22:47 -07:00
|
|
|
let nodes =
|
2019-09-18 13:10:50 -07:00
|
|
|
discover_cluster(&cluster.entry_point_info.gossip, NUM_NODES).unwrap_or_else(|err| {
|
|
|
|
error!("Failed to discover {} nodes: {:?}", NUM_NODES, err);
|
|
|
|
exit(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
let (client, num_clients) = get_multi_client(&nodes);
|
|
|
|
|
|
|
|
info!("clients: {}", num_clients);
|
|
|
|
assert!(num_clients >= NUM_NODES);
|
|
|
|
|
|
|
|
const NUM_SIGNERS: u64 = 2;
|
|
|
|
airdrop_lamports(
|
|
|
|
&client,
|
2019-12-16 13:05:17 -08:00
|
|
|
&faucet_addr,
|
2019-09-18 13:10:50 -07:00
|
|
|
&config.identity,
|
|
|
|
fund_amount * (accounts_in_groups + 1) as u64 * NUM_SIGNERS,
|
|
|
|
);
|
|
|
|
|
|
|
|
do_bench_exchange(vec![client], config);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_exchange_bank_client() {
|
|
|
|
solana_logger::setup();
|
2019-11-08 20:56:57 -08:00
|
|
|
let (genesis_config, identity) = create_genesis_config(100_000_000_000_000);
|
|
|
|
let mut bank = Bank::new(&genesis_config);
|
2020-05-19 19:45:30 -07:00
|
|
|
bank.add_builtin_program("exchange_program", id(), process_instruction);
|
2019-09-18 13:10:50 -07:00
|
|
|
let clients = vec![BankClient::new(bank)];
|
|
|
|
|
|
|
|
let mut config = Config::default();
|
|
|
|
config.identity = identity;
|
|
|
|
config.duration = Duration::from_secs(1);
|
|
|
|
config.fund_amount = 100_000;
|
|
|
|
config.threads = 1;
|
|
|
|
config.transfer_delay = 20; // 0;
|
|
|
|
config.batch_size = 100; // 1500;
|
|
|
|
config.chunk_size = 10; // 1500;
|
|
|
|
config.account_groups = 1; // 50;
|
|
|
|
|
|
|
|
do_bench_exchange(clients, config);
|
|
|
|
}
|