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

cli: Expose --account flag for solana-test-validator in Anchor.toml #1366

Merged
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ 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

* lang: Put `init_if_needed` behind a feature flag to decrease wrong usage ([#1258](https://github.com/project-serum/anchor/pull/1258)).
* 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<String, u8>` 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

Expand Down
15 changes: 14 additions & 1 deletion cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ fn deser_programs(
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Test {
pub genesis: Option<Vec<GenesisEntry>>,
pub clone: Option<Vec<CloneEntry>>,
pub validator: Option<Validator>,
pub startup_wait: Option<i32>,
}
Expand All @@ -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<Vec<AccountEntry>>,
// 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<Vec<CloneEntry>>,
// Range to use for dynamically assigned ports. [default: 1024-65535]
#[serde(skip_serializing_if = "Option::is_none")]
pub dynamic_port_range: Option<String>,
Expand Down
32 changes: 22 additions & 10 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1891,22 +1891,34 @@ fn validator_flags(cfg: &WithPath<Config>) -> Result<Vec<String>> {
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());
}
}
}
}
Expand Down