Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Test Validator Account Cloning #833

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,17 +459,36 @@ fn deser_programs(

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Test {
pub genesis: Vec<GenesisEntry>,
pub genesis: GenesisState,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GenesisEntry {
pub struct GenesisState {
// Programs to embed into genesis
pub programs: Vec<GenesisProgram>,
// Accounts to embed into genesis
pub accounts: Option<Vec<GenesisAccount>>,
// Network url to clone genesis accounts from
pub url: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GenesisProgram {
// Base58 pubkey string.
pub address: String,
// Filepath to the compiled program to embed into the genesis.
pub program: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GenesisAccount {
// Base58 pubkey string of the mainnet account to clone
// embedding into gensis
pub address: String,
// Name of the account, used only for documentation
pub name: String,
}

#[derive(Debug, Clone)]
pub struct Program {
pub lib_name: String,
Expand Down
12 changes: 10 additions & 2 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1531,11 +1531,19 @@ fn genesis_flags(cfg: &WithPath<Config>) -> Result<Vec<String>> {
}
}
if let Some(test) = cfg.test.as_ref() {
for entry in &test.genesis {
for entry in &test.genesis.programs {
flags.push("--bpf-program".to_string());
flags.push(entry.address.clone());
flags.push(entry.program.clone());
}
if test.genesis.accounts.is_some() && test.genesis.url.is_some() {
flags.push("--url".to_string());
flags.push(test.genesis.url.clone().unwrap());
for entry in &test.genesis.clone().accounts.unwrap() {
flags.push("--clone".to_string());
flags.push(entry.address.clone());
}
}
}
Ok(flags)
}
Expand Down Expand Up @@ -1572,7 +1580,7 @@ fn stream_logs(config: &WithPath<Config>) -> Result<Vec<std::process::Child>> {
handles.push(child);
}
if let Some(test) = config.test.as_ref() {
for entry in &test.genesis {
for entry in &test.genesis.programs {
let log_file = File::create(format!("{}/{}.log", program_logs_dir, entry.address))?;
let stdio = std::process::Stdio::from(log_file);
let child = std::process::Command::new("solana")
Expand Down