@@ -2,6 +2,7 @@ use bdk_chain::{spk_txout::SpkTxOutIndex, Indexer};
22use bitcoin:: {
33 absolute, transaction, Amount , OutPoint , ScriptBuf , SignedAmount , Transaction , TxIn , TxOut ,
44} ;
5+ use std:: ops:: Bound ;
56
67#[ test]
78fn spk_txout_sent_and_received ( ) {
@@ -212,11 +213,15 @@ fn outputs_in_range_excluded_bounds() {
212213 } ;
213214
214215 // Full range (unbounded)
215- let all_outputs: Vec < _ > = spk_index. outputs_in_range ( ..) . collect ( ) ;
216+ let all_outputs: Vec < _ > = spk_index
217+ . outputs_in_range ( ( Bound :: Unbounded :: < u32 > , Bound :: Unbounded :: < u32 > ) )
218+ . collect ( ) ;
216219 assert_eq ! ( all_outputs. len( ) , 5 ) ;
217220
218221 // Included start, included end
219- let outputs_one_to_four: Vec < _ > = spk_index. outputs_in_range ( 1 ..=4 ) . collect ( ) ;
222+ let outputs_one_to_four: Vec < _ > = spk_index
223+ . outputs_in_range ( ( Bound :: Included ( 1u32 ) , Bound :: Included ( 4u32 ) ) )
224+ . collect ( ) ;
220225 assert_eq ! ( outputs_one_to_four. len( ) , 4 ) ;
221226 assert ! ( outputs_one_to_four
222227 . iter( )
@@ -227,7 +232,9 @@ fn outputs_in_range_excluded_bounds() {
227232 assert ! ( !outputs_one_to_four. iter( ) . any( |( i, _) | * * i == 5 ) ) ;
228233
229234 // Included start, Excluded end
230- let outputs_one_to_four_excl: Vec < _ > = spk_index. outputs_in_range ( 1 ..4 ) . collect ( ) ;
235+ let outputs_one_to_four_excl: Vec < _ > = spk_index
236+ . outputs_in_range ( ( Bound :: Included ( 1u32 ) , Bound :: Excluded ( 4u32 ) ) )
237+ . collect ( ) ;
231238 assert_eq ! ( outputs_one_to_four_excl. len( ) , 3 ) ;
232239 assert ! ( outputs_one_to_four_excl. iter( ) . any( |( i, _) | * * i == 1 ) ) ;
233240 assert ! ( outputs_one_to_four_excl
@@ -236,7 +243,9 @@ fn outputs_in_range_excluded_bounds() {
236243 assert ! ( !outputs_one_to_four_excl. iter( ) . any( |( i, _) | * * i == 4 ) ) ;
237244
238245 // Excluded start, Included end
239- let outputs_one_excl_to_four: Vec < _ > = spk_index. outputs_in_range ( 2 ..=4 ) . collect ( ) ;
246+ let outputs_one_excl_to_four: Vec < _ > = spk_index
247+ . outputs_in_range ( ( Bound :: Excluded ( 1u32 ) , Bound :: Included ( 4u32 ) ) )
248+ . collect ( ) ;
240249 assert_eq ! ( outputs_one_excl_to_four. len( ) , 3 , ) ;
241250 assert ! ( !outputs_one_excl_to_four. iter( ) . any( |( i, _) | * * i == 1 ) ) ;
242251 assert ! ( outputs_one_excl_to_four
@@ -245,49 +254,63 @@ fn outputs_in_range_excluded_bounds() {
245254 assert ! ( outputs_one_excl_to_four. iter( ) . any( |( i, _) | * * i == 4 ) ) ;
246255
247256 // Excluded start, Excluded end
248- let outputs_one_excl_to_four_excl: Vec < _ > = spk_index. outputs_in_range ( 2 ..4 ) . collect ( ) ;
257+ let outputs_one_excl_to_four_excl: Vec < _ > = spk_index
258+ . outputs_in_range ( ( Bound :: Excluded ( 1u32 ) , Bound :: Excluded ( 4u32 ) ) )
259+ . collect ( ) ;
249260 assert_eq ! ( outputs_one_excl_to_four_excl. len( ) , 2 ) ;
250261 assert ! ( !outputs_one_excl_to_four_excl. iter( ) . any( |( i, _) | * * i == 1 ) ) ;
251262 assert ! ( outputs_one_excl_to_four_excl. iter( ) . any( |( i, _) | * * i == 2 ) ) ;
252263 assert ! ( outputs_one_excl_to_four_excl. iter( ) . any( |( i, _) | * * i == 3 ) ) ;
253264 assert ! ( !outputs_one_excl_to_four_excl. iter( ) . any( |( i, _) | * * i == 4 ) ) ;
254265
255266 // Unbounded start, Included end
256- let outputs_to_three: Vec < _ > = spk_index. outputs_in_range ( ..=3 ) . collect ( ) ;
267+ let outputs_to_three: Vec < _ > = spk_index
268+ . outputs_in_range ( ( Bound :: Unbounded :: < u32 > , Bound :: Included ( 3u32 ) ) )
269+ . collect ( ) ;
257270 assert_eq ! ( outputs_to_three. len( ) , 3 , ) ;
258271 assert ! ( outputs_to_three. iter( ) . any( |( i, _) | * * i == 1 ) ) ;
259272 assert ! ( outputs_to_three. iter( ) . any( |( i, _) | * * i == 3 ) ) ;
260273 assert ! ( !outputs_to_three. iter( ) . any( |( i, _) | * * i == 4 ) ) ;
261274
262275 // Unbounded start, excluded end
263- let outputs_to_three_excl: Vec < _ > = spk_index. outputs_in_range ( ..3 ) . collect ( ) ;
276+ let outputs_to_three_excl: Vec < _ > = spk_index
277+ . outputs_in_range ( ( Bound :: Unbounded :: < u32 > , Bound :: Excluded ( 3u32 ) ) )
278+ . collect ( ) ;
264279 assert_eq ! ( outputs_to_three_excl. len( ) , 2 , ) ;
265280 assert ! ( outputs_to_three_excl. iter( ) . any( |( i, _) | * * i == 1 ) ) ;
266281 assert ! ( outputs_to_three_excl. iter( ) . any( |( i, _) | * * i == 2 ) ) ;
267282 assert ! ( !outputs_to_three_excl. iter( ) . any( |( i, _) | * * i == 3 ) , ) ;
268283
269284 // Included start, Unbounded end
270- let outputs_to_three: Vec < _ > = spk_index. outputs_in_range ( 3 ..) . collect ( ) ;
285+ let outputs_to_three: Vec < _ > = spk_index
286+ . outputs_in_range ( ( Bound :: Included ( 3u32 ) , Bound :: Unbounded :: < u32 > ) )
287+ . collect ( ) ;
271288 assert_eq ! ( outputs_to_three. len( ) , 3 , ) ;
272289 assert ! ( outputs_to_three. iter( ) . any( |( i, _) | * * i == 3 ) ) ;
273290 assert ! ( outputs_to_three. iter( ) . any( |( i, _) | * * i == 5 ) , ) ;
274291 assert ! ( !outputs_to_three. iter( ) . any( |( i, _) | * * i == 2 ) , ) ;
275292
276293 // Excluded start, Unbounded end
277- let outputs_to_three_excl: Vec < _ > = spk_index. outputs_in_range ( 4 ..) . collect ( ) ;
294+ let outputs_to_three_excl: Vec < _ > = spk_index
295+ . outputs_in_range ( ( Bound :: Included ( 4u32 ) , Bound :: Unbounded :: < u32 > ) )
296+ . collect ( ) ;
278297 assert_eq ! ( outputs_to_three_excl. len( ) , 2 , ) ;
279298 assert ! ( !outputs_to_three_excl. iter( ) . any( |( i, _) | * * i == 3 ) ) ;
280299 assert ! ( outputs_to_three_excl. iter( ) . any( |( i, _) | * * i == 5 ) , ) ;
281300 assert ! ( outputs_to_three_excl. iter( ) . any( |( i, _) | * * i == 4 ) ) ;
282301
283302 // Single element range
284- let outputs_to_three: Vec < _ > = spk_index. outputs_in_range ( 3 ..=3 ) . collect ( ) ;
285- assert_eq ! ( outputs_to_three. len( ) , 1 , ) ;
286- assert ! ( outputs_to_three. iter( ) . any( |( i, _) | * * i == 3 ) ) ;
287- assert ! ( !outputs_to_three. iter( ) . any( |( i, _) | * * i == 4 ) ) ;
288- assert ! ( !outputs_to_three. iter( ) . any( |( i, _) | * * i == 2 ) ) ;
303+ let output_at_three: Vec < _ > = spk_index
304+ . outputs_in_range ( ( Bound :: Included ( 3u32 ) , Bound :: Included ( 3u32 ) ) )
305+ . collect ( ) ;
306+ assert_eq ! ( output_at_three. len( ) , 1 , ) ;
307+ assert ! ( output_at_three. iter( ) . any( |( i, _) | * * i == 3 ) ) ;
308+ assert ! ( !output_at_three. iter( ) . any( |( i, _) | * * i == 4 ) ) ;
309+ assert ! ( !output_at_three. iter( ) . any( |( i, _) | * * i == 2 ) ) ;
289310
290311 // Empty range with excluded bound
291- let outputs_empty: Vec < _ > = spk_index. outputs_in_range ( 3 ..3 ) . collect ( ) ;
312+ let outputs_empty: Vec < _ > = spk_index
313+ . outputs_in_range ( ( Bound :: Included ( 3u32 ) , Bound :: Excluded ( 3u32 ) ) )
314+ . collect ( ) ;
292315 assert_eq ! ( outputs_empty. len( ) , 0 ) ;
293316}
0 commit comments