Skip to content

Commit bc5931c

Browse files
Allow selecting channel_keys_id in tests
Add `override_next_keys_id` to `TestKeysInterface`, enabling predictable `generate_channel_keys_id` output when se
1 parent ebdbee0 commit bc5931c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lightning/src/util/test_utils.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,7 @@ pub struct TestKeysInterface {
14961496
expectations: Mutex<Option<VecDeque<OnGetShutdownScriptpubkey>>>,
14971497
pub unavailable_signers_ops: Mutex<HashMap<[u8; 32], HashSet<SignerOp>>>,
14981498
pub next_signer_disabled_ops: Mutex<HashSet<SignerOp>>,
1499+
pub override_next_keys_id: Mutex<Option<[u8; 32]>>,
14991500
}
15001501

15011502
impl EntropySource for TestKeysInterface {
@@ -1546,6 +1547,13 @@ impl SignerProvider for TestKeysInterface {
15461547
type TaprootSigner = TestChannelSigner;
15471548

15481549
fn generate_channel_keys_id(&self, inbound: bool, user_channel_id: u128) -> [u8; 32] {
1550+
let mut override_keys = self.override_next_keys_id.lock().unwrap();
1551+
1552+
if let Some(keys_id) = *override_keys {
1553+
// Reset after use
1554+
*override_keys = None;
1555+
return keys_id;
1556+
}
15491557
self.backing.generate_channel_keys_id(inbound, user_channel_id)
15501558
}
15511559

@@ -1625,6 +1633,7 @@ impl TestKeysInterface {
16251633
expectations: Mutex::new(None),
16261634
unavailable_signers_ops: Mutex::new(new_hash_map()),
16271635
next_signer_disabled_ops: Mutex::new(new_hash_set()),
1636+
override_next_keys_id: Mutex::new(None),
16281637
}
16291638
}
16301639

@@ -1652,6 +1661,11 @@ impl TestKeysInterface {
16521661
let cell = states.get(&keys_id).unwrap();
16531662
Arc::clone(cell)
16541663
}
1664+
1665+
pub fn set_next_keys_id(&self, keys_id: [u8; 32]) -> &Self {
1666+
*self.override_next_keys_id.lock().unwrap() = Some(keys_id);
1667+
self
1668+
}
16551669
}
16561670

16571671
impl Drop for TestKeysInterface {

0 commit comments

Comments
 (0)