Skip to content

Commit 9cb95cd

Browse files
committed
refactor(validation): rename must_call_programs to require_one_of_programs
1 parent ad9cc32 commit 9cb95cd

6 files changed

Lines changed: 103 additions & 77 deletions

File tree

crates/lib/src/config.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ pub struct ValidationConfig {
137137
/// When >0, prices with a block_id older than `current_slot - max_price_staleness_slots` are rejected.
138138
#[serde(default)]
139139
pub max_price_staleness_slots: u64,
140-
/// Programs that must be called by the transaction (at least one must appear).
140+
/// Programs where at least one must be called by the transaction (OR semantics).
141141
/// Each required program must also be listed in `allowed_programs`.
142142
/// Default: empty (no restriction).
143-
#[serde(default)]
144-
pub must_call_programs: Vec<String>,
143+
#[serde(default, alias = "must_call_programs")]
144+
pub require_one_of_programs: Vec<String>,
145145
}
146146

147147
impl ValidationConfig {
@@ -891,6 +891,32 @@ rate_limit = 1
891891
);
892892
}
893893

894+
#[test]
895+
fn test_require_one_of_programs_parsing_alias_must_call_programs() {
896+
let legacy_key_alias_toml = r#"
897+
[validation]
898+
max_allowed_lamports = 1
899+
max_signatures = 1
900+
allowed_programs = ["11111111111111111111111111111111"]
901+
must_call_programs = ["11111111111111111111111111111111"]
902+
allowed_tokens = []
903+
allowed_spl_paid_tokens = []
904+
disallowed_accounts = []
905+
price_source = "Mock"
906+
907+
[kora]
908+
rate_limit = 1
909+
"#;
910+
911+
let config = crate::tests::toml_mock::create_invalid_config(legacy_key_alias_toml)
912+
.expect("Config with legacy must_call_programs key should parse");
913+
914+
assert_eq!(
915+
config.validation.require_one_of_programs,
916+
vec!["11111111111111111111111111111111".to_string()]
917+
);
918+
}
919+
894920
#[test]
895921
fn test_token2022_extension_blocking_check() {
896922
let config = ConfigBuilder::new()

crates/lib/src/tests/config_mock.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl ConfigMockBuilder {
9494
token_2022: Token2022Config::default(),
9595
allow_durable_transactions: false,
9696
max_price_staleness_slots: 0,
97-
must_call_programs: vec![],
97+
require_one_of_programs: vec![],
9898
},
9999
kora: KoraConfig {
100100
rate_limit: 100,
@@ -165,8 +165,8 @@ impl ConfigMockBuilder {
165165
self
166166
}
167167

168-
pub fn with_must_call_programs(mut self, programs: Vec<String>) -> Self {
169-
self.config.validation.must_call_programs = programs;
168+
pub fn with_require_one_of_programs(mut self, programs: Vec<String>) -> Self {
169+
self.config.validation.require_one_of_programs = programs;
170170
self
171171
}
172172

@@ -290,7 +290,7 @@ impl ValidationConfigBuilder {
290290
token_2022: Token2022Config::default(),
291291
allow_durable_transactions: false,
292292
max_price_staleness_slots: 0,
293-
must_call_programs: vec![],
293+
require_one_of_programs: vec![],
294294
},
295295
}
296296
}

crates/lib/src/tests/toml_mock.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct ValidationSection {
3131
max_allowed_lamports: u64,
3232
max_signatures: u64,
3333
allowed_programs: Vec<String>,
34-
must_call_programs: Vec<String>,
34+
require_one_of_programs: Vec<String>,
3535
allowed_tokens: Vec<String>,
3636
allowed_spl_paid_tokens: SplTokenConfig,
3737
disallowed_accounts: Vec<String>,
@@ -56,7 +56,7 @@ impl Default for ValidationSection {
5656
max_allowed_lamports: 1000000000,
5757
max_signatures: 10,
5858
allowed_programs: vec!["program1".to_string()],
59-
must_call_programs: vec![],
59+
require_one_of_programs: vec![],
6060
allowed_tokens: vec!["token1".to_string()],
6161
allowed_spl_paid_tokens: SplTokenConfig::Allowlist(vec!["token2".to_string()]),
6262
disallowed_accounts: vec![],
@@ -91,8 +91,8 @@ impl ConfigBuilder {
9191
self
9292
}
9393

94-
pub fn with_must_call_programs(mut self, programs: Vec<&str>) -> Self {
95-
self.validation.must_call_programs = programs.iter().map(|s| s.to_string()).collect();
94+
pub fn with_require_one_of_programs(mut self, programs: Vec<&str>) -> Self {
95+
self.validation.require_one_of_programs = programs.iter().map(|s| s.to_string()).collect();
9696
self
9797
}
9898

@@ -289,13 +289,13 @@ impl ConfigBuilder {
289289
)
290290
};
291291

292-
let must_call_list = if self.validation.must_call_programs.is_empty() {
292+
let require_one_of_list = if self.validation.require_one_of_programs.is_empty() {
293293
"[]".to_string()
294294
} else {
295295
format!(
296296
"[{}]",
297297
self.validation
298-
.must_call_programs
298+
.require_one_of_programs
299299
.iter()
300300
.map(|p| format!("\"{p}\""))
301301
.collect::<Vec<_>>()
@@ -308,15 +308,15 @@ impl ConfigBuilder {
308308
max_allowed_lamports = {}\n\
309309
max_signatures = {}\n\
310310
allowed_programs = [{}]\n\
311-
must_call_programs = {}\n\
311+
require_one_of_programs = {}\n\
312312
allowed_tokens = [{}]\n\
313313
allowed_spl_paid_tokens = {}\n\
314314
disallowed_accounts = {}\n\
315315
price_source = \"{}\"\n\n",
316316
self.validation.max_allowed_lamports,
317317
self.validation.max_signatures,
318318
programs_list,
319-
must_call_list,
319+
require_one_of_list,
320320
tokens_list,
321321
spl_tokens_config,
322322
disallowed_list,

0 commit comments

Comments
 (0)