Skip to content

Commit 33fe84f

Browse files
test: Only the highest ord keychain is returned
1 parent 746ae75 commit 33fe84f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

crates/chain/tests/test_keychain_txout_index.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,3 +742,22 @@ fn applying_changesets_one_by_one_vs_aggregate_must_have_same_result() {
742742
indexer_b.last_revealed_indices()
743743
);
744744
}
745+
746+
// When the same descriptor is associated with various keychains,
747+
// index methods only return the highest keychain by Ord
748+
#[test]
749+
fn test_only_highest_ord_keychain_is_returned() {
750+
let desc = parse_descriptor(DESCRIPTORS[0]);
751+
752+
let mut indexer = KeychainTxOutIndex::<TestKeychain>::new(0);
753+
let _ = indexer.insert_descriptor(TestKeychain::Internal, desc.clone());
754+
let _ = indexer.insert_descriptor(TestKeychain::External, desc);
755+
756+
// reveal_next_spk will work with either keychain
757+
let spk0: ScriptBuf = indexer.reveal_next_spk(&TestKeychain::External).unwrap().0.1.into();
758+
let spk1: ScriptBuf = indexer.reveal_next_spk(&TestKeychain::Internal).unwrap().0.1.into();
759+
760+
// index_of_spk will always return External
761+
assert_eq!(indexer.index_of_spk(&spk0), Some((TestKeychain::External, 0)));
762+
assert_eq!(indexer.index_of_spk(&spk1), Some((TestKeychain::External, 1)));
763+
}

0 commit comments

Comments
 (0)