Explorar el Código

cli: Add `deactivate_feature` flag to `solana-test-validator` config in Anchor.toml (#2872)

amilz hace 1 año
padre
commit
45c84c524f
Se han modificado 3 ficheros con 29 adiciones y 0 borrados
  1. 1 0
      CHANGELOG.md
  2. 10 0
      cli/src/config.rs
  3. 18 0
      cli/src/lib.rs

+ 1 - 0
CHANGELOG.md

@@ -39,6 +39,7 @@ The minor version will be incremented upon a breaking change and the patch versi
 - cli: Add priority fees to idl commands ([#2845](https://github.com/coral-xyz/anchor/pull/2845)).
 - ts: Add `prepend` option to MethodBuilder `preInstructions` method ([#2863](https://github.com/coral-xyz/anchor/pull/2863)).
 - lang: Add `declare_program!` macro ([#2857](https://github.com/coral-xyz/anchor/pull/2857)).
+- cli: Add `deactivate_feature` flag to `solana-test-validator` config in Anchor.toml ([#2872](https://github.com/coral-xyz/anchor/pull/2872)).
 
 ### Fixes
 

+ 10 - 0
cli/src/config.rs

@@ -1059,6 +1059,9 @@ pub struct _Validator {
     // Warp the ledger to WARP_SLOT after starting the validator.
     #[serde(skip_serializing_if = "Option::is_none")]
     pub warp_slot: Option<String>,
+    // Deactivate one or more features.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub deactivate_feature: Option<Vec<String>>,
 }
 
 #[derive(Debug, Default, Clone, Serialize, Deserialize)]
@@ -1094,6 +1097,8 @@ pub struct Validator {
     pub ticks_per_slot: Option<u16>,
     #[serde(skip_serializing_if = "Option::is_none")]
     pub warp_slot: Option<String>,
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub deactivate_feature: Option<Vec<String>>,
 }
 
 impl From<_Validator> for Validator {
@@ -1122,6 +1127,7 @@ impl From<_Validator> for Validator {
             slots_per_epoch: _validator.slots_per_epoch,
             ticks_per_slot: _validator.ticks_per_slot,
             warp_slot: _validator.warp_slot,
+            deactivate_feature: _validator.deactivate_feature,
         }
     }
 }
@@ -1146,6 +1152,7 @@ impl From<Validator> for _Validator {
             slots_per_epoch: validator.slots_per_epoch,
             ticks_per_slot: validator.ticks_per_slot,
             warp_slot: validator.warp_slot,
+            deactivate_feature: validator.deactivate_feature,
         }
     }
 }
@@ -1235,6 +1242,9 @@ impl Merge for _Validator {
                 .or_else(|| self.slots_per_epoch.take()),
             ticks_per_slot: other.ticks_per_slot.or_else(|| self.ticks_per_slot.take()),
             warp_slot: other.warp_slot.or_else(|| self.warp_slot.take()),
+            deactivate_feature: other
+                .deactivate_feature
+                .or_else(|| self.deactivate_feature.take()),
         };
     }
 }

+ 18 - 0
cli/src/lib.rs

@@ -3338,6 +3338,24 @@ fn validator_flags(
                         flags.push("--clone".to_string());
                         flags.push(pubkey.to_string());
                     }
+                } else if key == "deactivate_feature" {
+                    // Verify that the feature flags are valid pubkeys
+                    let pubkeys_result: Result<Vec<Pubkey>, _> = value
+                        .as_array()
+                        .unwrap()
+                        .iter()
+                        .map(|entry| {
+                            let feature_flag = entry.as_str().unwrap();
+                            Pubkey::from_str(feature_flag).map_err(|_| {
+                                anyhow!("Invalid pubkey (feature flag) {}", feature_flag)
+                            })
+                        })
+                        .collect();
+                    let features = pubkeys_result?;
+                    for feature in features {
+                        flags.push("--deactivate-feature".to_string());
+                        flags.push(feature.to_string());
+                    }
                 } else {
                     // Remaining validator flags are non-array types
                     flags.push(format!("--{}", key.replace('_', "-")));