Skip to content

Commit

Permalink
cli: Allow custom program addresses for test (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid authored Jul 28, 2021
1 parent a753eb0 commit 0304259
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 0304259

Please sign in to comment.