Skip to content

Commit

Permalink
Write failing test for keychain range querying
Browse files Browse the repository at this point in the history
  • Loading branch information
LLFourn authored and evanlinjin committed Jun 13, 2024
1 parent 3b040a7 commit 3b2ff0c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions crates/chain/tests/test_keychain_txout_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,3 +777,36 @@ fn test_only_highest_ord_keychain_is_returned() {
Some((TestKeychain::External, 1))
);
}

#[test]
fn when_querying_over_a_range_of_keychains_the_utxos_should_show_up() {
let mut indexer = KeychainTxOutIndex::<usize>::new(0);
let mut tx = common::new_tx(0);

for (i, descriptor) in DESCRIPTORS.iter().enumerate() {
let descriptor = parse_descriptor(descriptor);
let _ = indexer.insert_descriptor(i, descriptor.clone());
indexer.reveal_next_spk(&i);
tx.output.push(TxOut {
script_pubkey: descriptor.at_derivation_index(0).unwrap().script_pubkey(),
value: Amount::from_sat(10_000),
});
}

let _ = indexer.index_tx(&tx);
assert_eq!(indexer.outpoints().count(), DESCRIPTORS.len());

assert_eq!(
indexer.revealed_spks(0..DESCRIPTORS.len()).count(),
DESCRIPTORS.len()
);
assert_eq!(indexer.revealed_spks(1..4).count(), 4 - 1);
assert_eq!(
indexer.net_value(&tx, 0..DESCRIPTORS.len()).to_sat(),
(10_000 * DESCRIPTORS.len()) as i64
);
assert_eq!(
indexer.net_value(&tx, 3..5).to_sat(),
(10_000 * (5 - 3)) as i64
);
}

0 comments on commit 3b2ff0c

Please sign in to comment.