Skip to content

Commit 42f2db1

Browse files
authored
Merge branch 'release/2.5.0.0.0' into fix/add-binaries-to-release-image
2 parents 29eb442 + 986a3d4 commit 42f2db1

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

testnet/stacks-node/src/config.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,32 @@ mod tests {
271271
// Should default add xenon affirmation overrides
272272
assert_eq!(config.burnchain.affirmation_overrides.len(), 5);
273273
}
274+
275+
#[test]
276+
fn should_override_xenon_default_affirmation_overrides() {
277+
let affirmation_string = "aaapnnnnnnnnnnnnnnnnnnnnnnnnnnnnppnnnnnnnnnnnnnnnnnnnnnnnnpppppnnnnnnnnnnnnnnnnnnnnnnnpppppppppppppppnnnnnnnnnnnnnnnnnnnnnnnppppppppppnnnnnnnnnnnnnnnnnnnppppnnnnnnnnnnnnnnnnnnnnnnnppppppppnnnnnnnnnnnnnnnnnnnnnnnppnppnnnnnnnnnnnnnnnnnnnnnnnppppnnnnnnnnnnnnnnnnnnnnnnnnnppppppnnnnnnnnnnnnnnnnnnnnnnnnnppnnnnnnnnnnnnnnnnnnnnnnnnnpppppppnnnnnnnnnnnnnnnnnnnnnnnnnnpnnnnnnnnnnnnnnnnnnnnnnnnnpppnppppppppppppppnnppppnpa";
278+
let affirmation =
279+
AffirmationMap::decode(affirmation_string).expect("Failed to decode affirmation map");
280+
281+
let config = Config::from_config_file(
282+
ConfigFile::from_str(&format!(
283+
r#"
284+
[burnchain]
285+
chain = "bitcoin"
286+
mode = "xenon"
287+
288+
[[burnchain.affirmation_overrides]]
289+
reward_cycle = 413
290+
affirmation = "{affirmation_string}"
291+
"#,
292+
))
293+
.expect("Expected to be able to parse config file from string"),
294+
)
295+
.expect("Expected to be able to parse affirmation map from file");
296+
// Should default add xenon affirmation overrides, but overwrite with the configured one above
297+
assert_eq!(config.burnchain.affirmation_overrides.len(), 5);
298+
assert_eq!(config.burnchain.affirmation_overrides[&413], affirmation);
299+
}
274300
}
275301

276302
impl ConfigFile {
@@ -1470,7 +1496,6 @@ impl BurnchainConfigFile {
14701496
BITCOIN_TESTNET_STACKS_25_BURN_HEIGHT,
14711497
)
14721498
.unwrap();
1473-
eprintln!("last_present_cycle = {last_present_cycle}");
14741499
assert_eq!(
14751500
u64::try_from(affirmations_pre_2_5.len()).unwrap(),
14761501
last_present_cycle - 1
@@ -1481,10 +1506,12 @@ impl BurnchainConfigFile {
14811506
BITCOIN_TESTNET_STACKS_25_REORGED_HEIGHT,
14821507
)
14831508
.unwrap();
1484-
eprintln!("last_present_cycle = {last_present_cycle}, last_override = {last_override}");
1509+
let override_values = ["a", "n"];
14851510

14861511
for (override_index, reward_cycle) in (last_present_cycle + 1..=last_override).enumerate() {
1487-
let affirmation = format!("{affirmations_pre_2_5}{}", "a".repeat(override_index + 1));
1512+
assert!(override_values.len() > override_index);
1513+
let overrides = override_values[..(override_index + 1)].join("");
1514+
let affirmation = format!("{affirmations_pre_2_5}{overrides}");
14881515
default_overrides.push(AffirmationOverride {
14891516
reward_cycle,
14901517
affirmation,
@@ -1493,7 +1520,10 @@ impl BurnchainConfigFile {
14931520

14941521
if let Some(affirmation_overrides) = self.affirmation_overrides.as_mut() {
14951522
for affirmation in default_overrides {
1496-
affirmation_overrides.push(affirmation);
1523+
// insert at front, so that the hashmap uses the configured overrides
1524+
// instead of the defaults (the configured overrides will write over the
1525+
// the defaults because they come later in the list).
1526+
affirmation_overrides.insert(0, affirmation);
14971527
}
14981528
} else {
14991529
self.affirmation_overrides = Some(default_overrides);

0 commit comments

Comments
 (0)