Browse Source

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

Kirill Fomichev 4 years ago
parent
commit
03042590a9
2 changed files with 10 additions and 2 deletions
  1. 1 0
      CHANGELOG.md
  2. 9 2
      cli/src/main.rs

+ 1 - 0
CHANGELOG.md

@@ -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

+ 9 - 2
cli/src/main.rs

@@ -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());