diff --git a/core/src/test_validator.rs b/core/src/test_validator.rs index a241735ff2..a2fa2beea8 100644 --- a/core/src/test_validator.rs +++ b/core/src/test_validator.rs @@ -27,7 +27,7 @@ use { collections::HashMap, fs::remove_dir_all, net::{IpAddr, Ipv4Addr, SocketAddr}, - path::PathBuf, + path::{Path, PathBuf}, sync::{Arc, RwLock}, thread::sleep, time::Duration, @@ -62,6 +62,11 @@ impl TestValidatorGenesis { self } + /// Check if a given TestValidator ledger has already been initialized + pub fn ledger_exists(ledger_path: &Path) -> bool { + ledger_path.join("vote-account-keypair.json").exists() + } + pub fn fee_rate_governor(&mut self, fee_rate_governor: FeeRateGovernor) -> &mut Self { self.fee_rate_governor = fee_rate_governor; self @@ -313,7 +318,7 @@ impl TestValidator { let ledger_path = match &config.ledger_path { None => create_new_tmp_ledger!(&genesis_config).0, Some(ledger_path) => { - if ledger_path.join("validator-keypair.json").exists() { + if TestValidatorGenesis::ledger_exists(ledger_path) { return Ok(ledger_path.to_path_buf()); } @@ -338,6 +343,10 @@ impl TestValidator { &validator_identity, ledger_path.join("validator-keypair.json").to_str().unwrap(), )?; + + // `ledger_exists` should fail until the vote account keypair is written + assert!(!TestValidatorGenesis::ledger_exists(&ledger_path)); + write_keypair_file( &validator_vote_account, ledger_path diff --git a/validator/src/bin/solana-test-validator.rs b/validator/src/bin/solana-test-validator.rs index 72c8e5cf42..74aa299c2f 100644 --- a/validator/src/bin/solana-test-validator.rs +++ b/validator/src/bin/solana-test-validator.rs @@ -354,6 +354,18 @@ fn main() { }); } + if TestValidatorGenesis::ledger_exists(&ledger_path) { + for (name, long) in &[ + ("bpf_program", "--bpf-program"), + ("clone_account", "--clone"), + ("mint_address", "--mint"), + ] { + if matches.is_present(name) { + println!("{} argument ignored, ledger already exists", long); + } + } + } + let mut genesis = TestValidatorGenesis::default(); admin_rpc_service::run(