Skip to content

Commit

Permalink
Initial solana-test-validator command-line program
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines authored and mergify[bot] committed Dec 11, 2020
1 parent 13db3ec commit 0a9ff1d
Show file tree
Hide file tree
Showing 25 changed files with 785 additions and 347 deletions.
5 changes: 4 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cli/tests/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ fn test_cli_deploy_program() {
pathbuf.push("noop");
pathbuf.set_extension("so");

let test_validator = TestValidator::with_no_fees();
let mint_keypair = Keypair::new();
let test_validator = TestValidator::with_no_fees(mint_keypair.pubkey());

let (sender, receiver) = channel();
run_local_faucet(test_validator.mint_keypair(), sender, None);
run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap();

let rpc_client = RpcClient::new(test_validator.rpc_url());
Expand Down
28 changes: 22 additions & 6 deletions cli/tests/nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,45 @@ use std::sync::mpsc::channel;

#[test]
fn test_nonce() {
full_battery_tests(TestValidator::with_no_fees(), None, false);
let mint_keypair = Keypair::new();
full_battery_tests(
TestValidator::with_no_fees(mint_keypair.pubkey()),
mint_keypair,
None,
false,
);
}

#[test]
fn test_nonce_with_seed() {
let mint_keypair = Keypair::new();
full_battery_tests(
TestValidator::with_no_fees(),
TestValidator::with_no_fees(mint_keypair.pubkey()),
mint_keypair,
Some(String::from("seed")),
false,
);
}

#[test]
fn test_nonce_with_authority() {
full_battery_tests(TestValidator::with_no_fees(), None, true);
let mint_keypair = Keypair::new();
full_battery_tests(
TestValidator::with_no_fees(mint_keypair.pubkey()),
mint_keypair,
None,
true,
);
}

fn full_battery_tests(
test_validator: TestValidator,
mint_keypair: Keypair,
seed: Option<String>,
use_nonce_authority: bool,
) {
let (sender, receiver) = channel();
run_local_faucet(test_validator.mint_keypair(), sender, None);
run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap();

let rpc_client = RpcClient::new(test_validator.rpc_url());
Expand Down Expand Up @@ -202,10 +217,11 @@ fn full_battery_tests(
#[test]
fn test_create_account_with_seed() {
solana_logger::setup();
let test_validator = TestValidator::with_custom_fees(1);
let mint_keypair = Keypair::new();
let test_validator = TestValidator::with_custom_fees(mint_keypair.pubkey(), 1);

let (sender, receiver) = channel();
run_local_faucet(test_validator.mint_keypair(), sender, None);
run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap();

let offline_nonce_authority_signer = keypair_from_seed(&[1u8; 32]).unwrap();
Expand Down
10 changes: 7 additions & 3 deletions cli/tests/request_airdrop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ use solana_cli::cli::{process_command, CliCommand, CliConfig};
use solana_client::rpc_client::RpcClient;
use solana_core::test_validator::TestValidator;
use solana_faucet::faucet::run_local_faucet;
use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair};
use solana_sdk::{
commitment_config::CommitmentConfig,
signature::{Keypair, Signer},
};
use std::sync::mpsc::channel;

#[test]
fn test_cli_request_airdrop() {
let test_validator = TestValidator::with_no_fees();
let mint_keypair = Keypair::new();
let test_validator = TestValidator::with_no_fees(mint_keypair.pubkey());

let (sender, receiver) = channel();
run_local_faucet(test_validator.mint_keypair(), sender, None);
run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap();

let mut bob_config = CliConfig::recent_for_tests();
Expand Down
50 changes: 30 additions & 20 deletions cli/tests/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ use std::sync::mpsc::channel;

#[test]
fn test_stake_delegation_force() {
let test_validator = TestValidator::with_no_fees();
let mint_keypair = Keypair::new();
let test_validator = TestValidator::with_no_fees(mint_keypair.pubkey());
let (sender, receiver) = channel();
run_local_faucet(test_validator.mint_keypair(), sender, None);
run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap();

let rpc_client = RpcClient::new(test_validator.rpc_url());
Expand Down Expand Up @@ -115,9 +116,10 @@ fn test_stake_delegation_force() {
fn test_seed_stake_delegation_and_deactivation() {
solana_logger::setup();

let test_validator = TestValidator::with_no_fees();
let mint_keypair = Keypair::new();
let test_validator = TestValidator::with_no_fees(mint_keypair.pubkey());
let (sender, receiver) = channel();
run_local_faucet(test_validator.mint_keypair(), sender, None);
run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap();

let rpc_client = RpcClient::new(test_validator.rpc_url());
Expand Down Expand Up @@ -195,9 +197,10 @@ fn test_seed_stake_delegation_and_deactivation() {
fn test_stake_delegation_and_deactivation() {
solana_logger::setup();

let test_validator = TestValidator::with_no_fees();
let mint_keypair = Keypair::new();
let test_validator = TestValidator::with_no_fees(mint_keypair.pubkey());
let (sender, receiver) = channel();
run_local_faucet(test_validator.mint_keypair(), sender, None);
run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap();

let rpc_client = RpcClient::new(test_validator.rpc_url());
Expand Down Expand Up @@ -271,9 +274,10 @@ fn test_stake_delegation_and_deactivation() {
fn test_offline_stake_delegation_and_deactivation() {
solana_logger::setup();

let test_validator = TestValidator::with_no_fees();
let mint_keypair = Keypair::new();
let test_validator = TestValidator::with_no_fees(mint_keypair.pubkey());
let (sender, receiver) = channel();
run_local_faucet(test_validator.mint_keypair(), sender, None);
run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap();

let rpc_client = RpcClient::new(test_validator.rpc_url());
Expand Down Expand Up @@ -404,9 +408,10 @@ fn test_offline_stake_delegation_and_deactivation() {
fn test_nonced_stake_delegation_and_deactivation() {
solana_logger::setup();

let test_validator = TestValidator::with_no_fees();
let mint_keypair = Keypair::new();
let test_validator = TestValidator::with_no_fees(mint_keypair.pubkey());
let (sender, receiver) = channel();
run_local_faucet(test_validator.mint_keypair(), sender, None);
run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap();

let rpc_client = RpcClient::new(test_validator.rpc_url());
Expand Down Expand Up @@ -519,9 +524,10 @@ fn test_nonced_stake_delegation_and_deactivation() {
fn test_stake_authorize() {
solana_logger::setup();

let test_validator = TestValidator::with_no_fees();
let mint_keypair = Keypair::new();
let test_validator = TestValidator::with_no_fees(mint_keypair.pubkey());
let (sender, receiver) = channel();
run_local_faucet(test_validator.mint_keypair(), sender, None);
run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap();

let rpc_client = RpcClient::new(test_validator.rpc_url());
Expand Down Expand Up @@ -792,9 +798,10 @@ fn test_stake_authorize_with_fee_payer() {
solana_logger::setup();
const SIG_FEE: u64 = 42;

let test_validator = TestValidator::with_custom_fees(SIG_FEE);
let mint_keypair = Keypair::new();
let test_validator = TestValidator::with_custom_fees(mint_keypair.pubkey(), SIG_FEE);
let (sender, receiver) = channel();
run_local_faucet(test_validator.mint_keypair(), sender, None);
run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap();

let rpc_client = RpcClient::new(test_validator.rpc_url());
Expand Down Expand Up @@ -917,9 +924,10 @@ fn test_stake_authorize_with_fee_payer() {
fn test_stake_split() {
solana_logger::setup();

let test_validator = TestValidator::with_custom_fees(1);
let mint_keypair = Keypair::new();
let test_validator = TestValidator::with_custom_fees(mint_keypair.pubkey(), 1);
let (sender, receiver) = channel();
run_local_faucet(test_validator.mint_keypair(), sender, None);
run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap();

let rpc_client = RpcClient::new(test_validator.rpc_url());
Expand Down Expand Up @@ -1061,9 +1069,10 @@ fn test_stake_split() {
fn test_stake_set_lockup() {
solana_logger::setup();

let test_validator = TestValidator::with_custom_fees(1);
let mint_keypair = Keypair::new();
let test_validator = TestValidator::with_custom_fees(mint_keypair.pubkey(), 1);
let (sender, receiver) = channel();
run_local_faucet(test_validator.mint_keypair(), sender, None);
run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap();

let rpc_client = RpcClient::new(test_validator.rpc_url());
Expand Down Expand Up @@ -1323,9 +1332,10 @@ fn test_stake_set_lockup() {
fn test_offline_nonced_create_stake_account_and_withdraw() {
solana_logger::setup();

let test_validator = TestValidator::with_no_fees();
let mint_keypair = Keypair::new();
let test_validator = TestValidator::with_no_fees(mint_keypair.pubkey());
let (sender, receiver) = channel();
run_local_faucet(test_validator.mint_keypair(), sender, None);
run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap();

let rpc_client = RpcClient::new(test_validator.rpc_url());
Expand Down
15 changes: 9 additions & 6 deletions cli/tests/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ use std::sync::mpsc::channel;
#[test]
fn test_transfer() {
solana_logger::setup();
let test_validator = TestValidator::with_custom_fees(1);
let mint_keypair = Keypair::new();
let test_validator = TestValidator::with_custom_fees(mint_keypair.pubkey(), 1);

let (sender, receiver) = channel();
run_local_faucet(test_validator.mint_keypair(), sender, None);
run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap();

let rpc_client = RpcClient::new(test_validator.rpc_url());
Expand Down Expand Up @@ -243,10 +244,11 @@ fn test_transfer() {
#[test]
fn test_transfer_multisession_signing() {
solana_logger::setup();
let test_validator = TestValidator::with_custom_fees(1);
let mint_keypair = Keypair::new();
let test_validator = TestValidator::with_custom_fees(mint_keypair.pubkey(), 1);

let (sender, receiver) = channel();
run_local_faucet(test_validator.mint_keypair(), sender, None);
run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap();

let to_pubkey = Pubkey::new(&[1u8; 32]);
Expand Down Expand Up @@ -363,10 +365,11 @@ fn test_transfer_multisession_signing() {
#[test]
fn test_transfer_all() {
solana_logger::setup();
let test_validator = TestValidator::with_custom_fees(1);
let mint_keypair = Keypair::new();
let test_validator = TestValidator::with_custom_fees(mint_keypair.pubkey(), 1);

let (sender, receiver) = channel();
run_local_faucet(test_validator.mint_keypair(), sender, None);
run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap();

let rpc_client = RpcClient::new(test_validator.rpc_url());
Expand Down
5 changes: 3 additions & 2 deletions cli/tests/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ use std::sync::mpsc::channel;

#[test]
fn test_vote_authorize_and_withdraw() {
let test_validator = TestValidator::with_no_fees();
let mint_keypair = Keypair::new();
let test_validator = TestValidator::with_no_fees(mint_keypair.pubkey());
let (sender, receiver) = channel();
run_local_faucet(test_validator.mint_keypair(), sender, None);
run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap();

let rpc_client = RpcClient::new(test_validator.rpc_url());
Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ solana-metrics = { path = "../metrics", version = "1.5.0" }
solana-measure = { path = "../measure", version = "1.5.0" }
solana-net-utils = { path = "../net-utils", version = "1.5.0" }
solana-perf = { path = "../perf", version = "1.5.0" }
solana-program-test = { path = "../program-test", version = "1.5.0" }
solana-runtime = { path = "../runtime", version = "1.5.0" }
solana-sdk = { path = "../sdk", version = "1.5.0" }
solana-frozen-abi = { path = "../frozen-abi", version = "1.5.0" }
Expand Down
Loading

0 comments on commit 0a9ff1d

Please sign in to comment.