@@ -18,7 +18,10 @@ enum TestKeychain {
1818 Internal ,
1919}
2020
21- fn init_txout_index ( ) -> (
21+ fn init_txout_index (
22+ internal_lookahead : u32 ,
23+ external_lookahead : u32 ,
24+ ) -> (
2225 bdk_chain:: keychain:: KeychainTxOutIndex < TestKeychain > ,
2326 Descriptor < DescriptorPublicKey > ,
2427 Descriptor < DescriptorPublicKey > ,
@@ -29,8 +32,16 @@ fn init_txout_index() -> (
2932 let ( external_descriptor, _) = Descriptor :: < DescriptorPublicKey > :: parse_descriptor ( & secp, "tr([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/0/*)" ) . unwrap ( ) ;
3033 let ( internal_descriptor, _) = Descriptor :: < DescriptorPublicKey > :: parse_descriptor ( & secp, "tr([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/1/*)" ) . unwrap ( ) ;
3134
32- txout_index. add_keychain ( TestKeychain :: External , external_descriptor. clone ( ) ) ;
33- txout_index. add_keychain ( TestKeychain :: Internal , internal_descriptor. clone ( ) ) ;
35+ txout_index. add_keychain_with_lookahead (
36+ TestKeychain :: External ,
37+ external_descriptor. clone ( ) ,
38+ internal_lookahead,
39+ ) ;
40+ txout_index. add_keychain_with_lookahead (
41+ TestKeychain :: Internal ,
42+ internal_descriptor. clone ( ) ,
43+ external_lookahead,
44+ ) ;
3445
3546 ( txout_index, external_descriptor, internal_descriptor)
3647}
@@ -46,7 +57,7 @@ fn spk_at_index(descriptor: &Descriptor<DescriptorPublicKey>, index: u32) -> Scr
4657fn test_set_all_derivation_indices ( ) {
4758 use bdk_chain:: indexed_tx_graph:: Indexer ;
4859
49- let ( mut txout_index, _, _) = init_txout_index ( ) ;
60+ let ( mut txout_index, _, _) = init_txout_index ( 0 , 0 ) ;
5061 let derive_to: BTreeMap < _ , _ > =
5162 [ ( TestKeychain :: External , 12 ) , ( TestKeychain :: Internal , 24 ) ] . into ( ) ;
5263 assert_eq ! (
@@ -64,15 +75,7 @@ fn test_set_all_derivation_indices() {
6475
6576#[ test]
6677fn test_lookahead ( ) {
67- let ( mut txout_index, external_desc, internal_desc) = init_txout_index ( ) ;
68-
69- // ensure it does not break anything if lookahead is set multiple times
70- ( 0 ..=10 ) . for_each ( |lookahead| txout_index. set_lookahead ( & TestKeychain :: External , lookahead) ) ;
71- ( 0 ..=20 )
72- . filter ( |v| v % 2 == 0 )
73- . for_each ( |lookahead| txout_index. set_lookahead ( & TestKeychain :: Internal , lookahead) ) ;
74-
75- assert_eq ! ( txout_index. inner( ) . all_spks( ) . len( ) , 30 ) ;
78+ let ( mut txout_index, external_desc, internal_desc) = init_txout_index ( 10 , 20 ) ;
7679
7780 // given:
7881 // - external lookahead set to 10
@@ -226,8 +229,7 @@ fn test_lookahead() {
226229// - last used index should change as expected
227230#[ test]
228231fn test_scan_with_lookahead ( ) {
229- let ( mut txout_index, external_desc, _) = init_txout_index ( ) ;
230- txout_index. set_lookahead_for_all ( 10 ) ;
232+ let ( mut txout_index, external_desc, _) = init_txout_index ( 10 , 10 ) ;
231233
232234 let spks: BTreeMap < u32 , ScriptBuf > = [ 0 , 10 , 20 , 30 ]
233235 . into_iter ( )
@@ -281,7 +283,7 @@ fn test_scan_with_lookahead() {
281283#[ test]
282284#[ rustfmt:: skip]
283285fn test_wildcard_derivations ( ) {
284- let ( mut txout_index, external_desc, _) = init_txout_index ( ) ;
286+ let ( mut txout_index, external_desc, _) = init_txout_index ( 0 , 0 ) ;
285287 let external_spk_0 = external_desc. at_derivation_index ( 0 ) . unwrap ( ) . script_pubkey ( ) ;
286288 let external_spk_16 = external_desc. at_derivation_index ( 16 ) . unwrap ( ) . script_pubkey ( ) ;
287289 let external_spk_26 = external_desc. at_derivation_index ( 26 ) . unwrap ( ) . script_pubkey ( ) ;
@@ -348,7 +350,7 @@ fn test_non_wildcard_derivations() {
348350 . unwrap ( )
349351 . script_pubkey ( ) ;
350352
351- txout_index. add_keychain ( TestKeychain :: External , no_wildcard_descriptor) ;
353+ txout_index. add_keychain_with_lookahead ( TestKeychain :: External , no_wildcard_descriptor, 0 ) ;
352354
353355 // given:
354356 // - `txout_index` with no stored scripts
0 commit comments