cli: Allow custom program addresses for test (#554)

This commit is contained in:
Kirill Fomichev 2021-07-29 00:04:14 +03:00 committed by GitHub
parent a753eb0f0b
commit 03042590a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -14,6 +14,7 @@ incremented for features.
### Features
* cli: Add keys `members` / `exclude` in config `programs` section ([#546](https://github.com/project-serum/anchor/pull/546)).
* cli: Allow program address configuration for test command through `clusters.localnet` ([#554](https://github.com/project-serum/anchor/pull/554)).
* lang: IDLs are now parsed from the entire crate ([#517](https://github.com/project-serum/anchor/pull/517)).
### Breaking Changes

View File

@ -1063,12 +1063,19 @@ fn test(
// Returns the solana-test-validator flags to embed the workspace programs
// in the genesis block. This allows us to run tests without every deploying.
fn genesis_flags(cfg: &Config) -> Result<Vec<String>> {
let clusters = cfg.clusters.get(&Cluster::Localnet);
let mut flags = Vec::new();
for mut program in cfg.read_all_programs()? {
let binary_path = program.binary_path().display().to_string();
let kp = Keypair::generate(&mut OsRng);
let address = kp.pubkey().to_string();
let address = clusters
.and_then(|m| m.get(&program.idl.name))
.map(|deployment| deployment.address.to_string())
.unwrap_or_else(|| {
let kp = Keypair::generate(&mut OsRng);
kp.pubkey().to_string()
});
flags.push("--bpf-program".to_string());
flags.push(address.clone());