From: busayo-OD Date: Sun, 18 Oct 2026 08:05:56 +0000 (+0100) Subject: test(chain): reuse indexer helper in apply_changeset clamp test X-Git-Url: http://internal-gitweb-vhost/-script/src/consensus/encode/scripts/-script-interface/FromScriptException.UnrecognizedScript.html?a=commitdiff_plain;h=b7931c88fe70a1a4633873b5cf6fab805ff4a62a;p=bdk test(chain): reuse indexer helper in apply_changeset clamp test Reuse `indexer_with_last_revealed_at` to simplify the test setup for `apply_changeset_clamps_out_of_range_index_and_derives_correct_spk`. Move the helper above its first use. --- diff --git a/crates/chain/src/indexer/keychain_txout.rs b/crates/chain/src/indexer/keychain_txout.rs index 25e36dbf..4717cffd 100644 --- a/crates/chain/src/indexer/keychain_txout.rs +++ b/crates/chain/src/indexer/keychain_txout.rs @@ -1227,8 +1227,8 @@ mod test { assert!(index.spk_cache.is_empty()); } - #[test] - fn apply_changeset_clamps_out_of_range_index_and_derives_correct_spk() { + /// Build an index with `last_revealed` (and the matching spk) at `last_revealed_index`. + fn indexer_with_last_revealed_at(last_revealed_index: u32) -> KeychainTxOutIndex { let s = DESCRIPTORS[0]; let desc = Descriptor::parse_descriptor(&Secp256k1::new(), s) .unwrap() @@ -1236,14 +1236,22 @@ mod test { let mut index = KeychainTxOutIndex::new(0, false); let did = desc.descriptor_id(); let _ = index.insert_descriptor(0i32, desc.clone()); - let seed_index = BIP32_MAX_INDEX - 1; + let spk = desc - .at_derivation_index(seed_index) + .at_derivation_index(last_revealed_index) .unwrap() .script_pubkey(); - index.inner.insert_spk((0i32, seed_index), spk); + index.inner.insert_spk((0i32, last_revealed_index), spk); + index.last_revealed.insert(did, last_revealed_index); + index + } + + #[test] + fn apply_changeset_clamps_out_of_range_index_and_derives_correct_spk() { + let mut index = indexer_with_last_revealed_at(BIP32_MAX_INDEX - 1); + let desc = index.get_descriptor(0i32).unwrap().clone(); let changeset = ChangeSet { - last_revealed: [(did, BIP32_MAX_INDEX + 1)].into(), + last_revealed: [(desc.descriptor_id(), BIP32_MAX_INDEX + 1)].into(), ..Default::default() }; index.apply_changeset(changeset); @@ -1258,25 +1266,6 @@ mod test { ); } - /// Build an index with `last_revealed` (and the matching spk) at `last_revealed_index`. - fn indexer_with_last_revealed_at(last_revealed_index: u32) -> KeychainTxOutIndex { - let s = DESCRIPTORS[0]; - let desc = Descriptor::parse_descriptor(&Secp256k1::new(), s) - .unwrap() - .0; - let mut index = KeychainTxOutIndex::new(0, false); - let did = desc.descriptor_id(); - let _ = index.insert_descriptor(0i32, desc.clone()); - - let spk = desc - .at_derivation_index(last_revealed_index) - .unwrap() - .script_pubkey(); - index.inner.insert_spk((0i32, last_revealed_index), spk); - index.last_revealed.insert(did, last_revealed_index); - index - } - #[test] fn reveal_next_spk_and_next_unused_spk_return_last_script_when_saturated() { let mut index = indexer_with_last_revealed_at(BIP32_MAX_INDEX);