From 3ade00ea697e7e617d1aeb884593ee9e0325845d Mon Sep 17 00:00:00 2001 From: Tom Linton Date: Tue, 1 Feb 2022 13:52:08 +1300 Subject: [PATCH] cli: Expose --account flag for solana-test-validator in Anchor.toml (#1366) --- CHANGELOG.md | 3 +++ cli/src/config.rs | 15 ++++++++++++++- cli/src/lib.rs | 32 ++++++++++++++++++++++---------- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 778d68002c..620e36885b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ incremented for features. * ts: Remove error logging in the event parser when log websocket encounters a program error ([#1313](https://github.com/project-serum/anchor/pull/1313)). * ts: Add new `methods` namespace to the program client, introducing a more ergonomic builder API ([#1324](https://github.com/project-serum/anchor/pull/1324)). * ts: Add registry utility for fetching the latest verified build ([#1371](https://github.com/project-serum/anchor/pull/1371)). +* cli: Expose the solana-test-validator --account flag in Anchor.toml via [[test.validator.account]] ([#1366](https://github.com/project-serum/anchor/pull/1366)). ### Breaking @@ -29,6 +30,8 @@ incremented for features. * lang: rename `loader_account` module to `account_loader` module ([#1279](https://github.com/project-serum/anchor/pull/1279)) * lang: The `Accounts` trait's `try_accounts` method now has an additional `bumps: &mut BTreeMap` argument, which accumulates bump seeds ([#1367](https://github.com/project-serum/anchor/pull/1367)). * ts: `Coder` is now an interface and the existing class has been renamed to `BorshCoder`. This change allows the generation of Anchor clients for non anchor programs ([#1259](https://github.com/project-serum/anchor/pull/1259/files)). +* cli: [[test.clone]] key in Anchor.toml is renamed to [[test.validator.clone]] ([#1366](https://github.com/project-serum/anchor/pull/1366)). + ## [0.20.1] - 2022-01-09 diff --git a/cli/src/config.rs b/cli/src/config.rs index c88b2e9f52..828e21d3f8 100644 --- a/cli/src/config.rs +++ b/cli/src/config.rs @@ -506,7 +506,6 @@ fn deser_programs( #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Test { pub genesis: Option>, - pub clone: Option>, pub validator: Option, pub startup_wait: Option, } @@ -525,11 +524,25 @@ pub struct CloneEntry { pub address: String, } +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct AccountEntry { + // Base58 pubkey string. + pub address: String, + // Name of JSON file containing the account data. + pub filename: String, +} + #[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct Validator { + // Load an account from the provided JSON file + #[serde(skip_serializing_if = "Option::is_none")] + pub account: Option>, // IP address to bind the validator ports. [default: 0.0.0.0] #[serde(default = "default_bind_address")] pub bind_address: String, + // Copy an account from the cluster referenced by the url argument. + #[serde(skip_serializing_if = "Option::is_none")] + pub clone: Option>, // Range to use for dynamically assigned ports. [default: 1024-65535] #[serde(skip_serializing_if = "Option::is_none")] pub dynamic_port_range: Option, diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 57624e84c7..041f77c7ee 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -1891,22 +1891,34 @@ fn validator_flags(cfg: &WithPath) -> Result> { flags.push(entry.program.clone()); } } - if let Some(clone) = &test.clone { - for entry in clone { - flags.push("--clone".to_string()); - flags.push(entry.address.clone()); - } - } if let Some(validator) = &test.validator { for (key, value) in serde_json::to_value(validator)?.as_object().unwrap() { if key == "ledger" { + // Ledger flag is a special case as it is passed separately to the rest of + // these validator flags. continue; }; - flags.push(format!("--{}", key.replace('_', "-"))); - if let serde_json::Value::String(v) = value { - flags.push(v.to_string()); + if key == "account" { + for entry in value.as_array().unwrap() { + // Push the account flag for each array entry + flags.push("--account".to_string()); + flags.push(entry["address"].as_str().unwrap().to_string()); + flags.push(entry["filename"].as_str().unwrap().to_string()); + } + } else if key == "clone" { + for entry in value.as_array().unwrap() { + // Push the clone flag for each array entry + flags.push("--clone".to_string()); + flags.push(entry["address"].as_str().unwrap().to_string()); + } } else { - flags.push(value.to_string()); + // Remaining validator flags are non-array types + flags.push(format!("--{}", key.replace('_', "-"))); + if let serde_json::Value::String(v) = value { + flags.push(v.to_string()); + } else { + flags.push(value.to_string()); + } } } }