Skip to content

Commit f68e806

Browse files
committed
Added proper functionality and tests for enable/disable cheatcode
1 parent d620266 commit f68e806

File tree

1 file changed

+45
-7
lines changed

1 file changed

+45
-7
lines changed

crates/types/src/types.rs

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,18 +1258,22 @@ impl RunbookExecutionStatusReport {
12581258
}
12591259
}
12601260

1261-
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
1261+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
12621262
#[serde(rename_all = "camelCase")]
12631263
pub struct CheatcodeConfig {
12641264
pub lockout: bool, // if true, allows disabling even the `surfnet_enableCheatcodes`/`surfnetdisableCheatcodes` methods
12651265
pub filter: CheatcodeFilter,
12661266
}
12671267

1268-
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
1268+
#[derive(Serialize, Deserialize, Default)]
1269+
pub struct CheatcodeControlConfig {
1270+
pub lockout: Option<bool>,
1271+
}
1272+
1273+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
12691274
#[serde(untagged)]
12701275
pub enum CheatcodeFilter {
1271-
#[default]
1272-
All,
1276+
All(String),
12731277
List(Vec<String>), // disables cheatcodes in a named list
12741278
}
12751279

@@ -1285,8 +1289,8 @@ impl CheatcodeConfig {
12851289
self.lockout = true;
12861290
}
12871291

1288-
pub fn disable_all(&mut self) {
1289-
self.filter = CheatcodeFilter::All;
1292+
pub fn disable_all(&mut self, lockout: bool) {
1293+
self.filter = Self::filter_all_list(lockout);
12901294
}
12911295

12921296
pub fn disable_cheatcode(&mut self, cheatcode: &String) -> Result<(), String> {
@@ -1324,7 +1328,41 @@ impl CheatcodeConfig {
13241328
pub fn is_cheatcode_disabled(&self, cheatcode: &String) -> bool {
13251329
match &self.filter {
13261330
CheatcodeFilter::List(list) => list.contains(cheatcode),
1327-
CheatcodeFilter::All => true,
1331+
CheatcodeFilter::All(_) => true,
1332+
}
1333+
}
1334+
1335+
pub fn filter_all_list(lockout: bool) -> CheatcodeFilter {
1336+
// when lockout == true, it's important to disable surfnet_disableCheatcode as well
1337+
// since calling surfnet_disableCheatcode with lockout == false will override the current config, which is a bug
1338+
if lockout {
1339+
CheatcodeFilter::All("all".to_string())
1340+
} else {
1341+
let filter = vec![
1342+
RpcCheatcodes::SetAccount.into(),
1343+
RpcCheatcodes::SetTokenAccount.into(),
1344+
RpcCheatcodes::CloneProgramAccount.into(),
1345+
RpcCheatcodes::ProfileTransaction.into(),
1346+
RpcCheatcodes::GetProfileResultsByTag.into(),
1347+
RpcCheatcodes::SetSupply.into(),
1348+
RpcCheatcodes::SetProgramAuthority.into(),
1349+
RpcCheatcodes::GetTransactionProfile.into(),
1350+
RpcCheatcodes::RegisterIdl.into(),
1351+
RpcCheatcodes::GetActiveIdl.into(),
1352+
RpcCheatcodes::GetLocalSignatures.into(),
1353+
RpcCheatcodes::TimeTravel.into(),
1354+
RpcCheatcodes::PauseClock.into(),
1355+
RpcCheatcodes::ResumeClock.into(),
1356+
RpcCheatcodes::ResetAccount.into(),
1357+
RpcCheatcodes::ResetNetwork.into(),
1358+
RpcCheatcodes::ExportSnapshot.into(),
1359+
RpcCheatcodes::StreamAccount.into(),
1360+
RpcCheatcodes::GetStreamedAccounts.into(),
1361+
RpcCheatcodes::GetSurfnetInfo.into(),
1362+
RpcCheatcodes::WriteProgram.into(),
1363+
RpcCheatcodes::RegisterScenario.into(),
1364+
];
1365+
CheatcodeFilter::List(filter)
13281366
}
13291367
}
13301368
}

0 commit comments

Comments
 (0)