Skip to content

Commit de53d72

Browse files
test: Only the highest ord keychain is returned
1 parent 9d8023b commit de53d72

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

crates/chain/tests/test_keychain_txout_index.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,3 +742,38 @@ 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
758+
.reveal_next_spk(&TestKeychain::External)
759+
.unwrap()
760+
.0
761+
.1
762+
.into();
763+
let spk1: ScriptBuf = indexer
764+
.reveal_next_spk(&TestKeychain::Internal)
765+
.unwrap()
766+
.0
767+
.1
768+
.into();
769+
770+
// index_of_spk will always return External
771+
assert_eq!(
772+
indexer.index_of_spk(&spk0),
773+
Some((TestKeychain::External, 0))
774+
);
775+
assert_eq!(
776+
indexer.index_of_spk(&spk1),
777+
Some((TestKeychain::External, 1))
778+
);
779+
}

0 commit comments

Comments
 (0)