@@ -322,7 +322,7 @@ fn test_generate_to_address_ok() {
322
322
323
323
#[ ignore]
324
324
#[ test]
325
- fn test_list_unspent_ok ( ) {
325
+ fn test_list_unspent_one_address_ok ( ) {
326
326
if env:: var ( "BITCOIND_TEST" ) != Ok ( "1" . into ( ) ) {
327
327
return ;
328
328
}
@@ -341,24 +341,104 @@ fn test_list_unspent_ok() {
341
341
. get_new_address ( None , Some ( AddressType :: Legacy ) )
342
342
. expect ( "Should work!" ) ;
343
343
344
- let utxos = client
344
+ let no_utxos = client
345
345
. list_unspent ( None , None , None , Some ( false ) , Some ( 1 ) , Some ( 10 ) )
346
- . expect ( "list_unspent should be ok!" ) ;
347
- assert_eq ! ( 0 , utxos . len( ) ) ;
346
+ . expect ( "list_unspent empty should be ok!" ) ;
347
+ assert_eq ! ( 0 , no_utxos . len( ) ) ;
348
348
349
349
_ = client
350
350
. generate_to_address ( 102 , & address)
351
351
. expect ( "generate to address ok!" ) ;
352
352
353
- let utxos = client
353
+ let all_utxos = client
354
354
. list_unspent ( None , None , None , Some ( false ) , Some ( 1 ) , Some ( 10 ) )
355
- . expect ( "list_unspent should be ok!" ) ;
356
- assert_eq ! ( 2 , utxos. len( ) ) ;
355
+ . expect ( "all list_unspent should be ok!" ) ;
356
+ assert_eq ! ( 2 , all_utxos. len( ) ) ;
357
+ assert_eq ! ( address, all_utxos[ 0 ] . address) ;
358
+ assert_eq ! ( address, all_utxos[ 1 ] . address) ;
359
+
360
+ let addr_utxos = client
361
+ . list_unspent (
362
+ None ,
363
+ None ,
364
+ Some ( & [ & address] ) ,
365
+ Some ( false ) ,
366
+ Some ( 1 ) ,
367
+ Some ( 10 ) ,
368
+ )
369
+ . expect ( "list_unspent per address should be ok!" ) ;
370
+ assert_eq ! ( 2 , addr_utxos. len( ) ) ;
371
+ assert_eq ! ( address, addr_utxos[ 0 ] . address) ;
372
+ assert_eq ! ( address, addr_utxos[ 1 ] . address) ;
357
373
358
- let utxos = client
374
+ let max1_utxos = client
359
375
. list_unspent ( None , None , None , Some ( false ) , Some ( 1 ) , Some ( 1 ) )
360
- . expect ( "list_unspent should be ok!" ) ;
361
- assert_eq ! ( 1 , utxos. len( ) ) ;
376
+ . expect ( "list_unspent per address and max count should be ok!" ) ;
377
+ assert_eq ! ( 1 , max1_utxos. len( ) ) ;
378
+ assert_eq ! ( address, max1_utxos[ 0 ] . address) ;
379
+ }
380
+
381
+ #[ ignore]
382
+ #[ test]
383
+ fn test_list_unspent_two_addresses_ok ( ) {
384
+ if env:: var ( "BITCOIND_TEST" ) != Ok ( "1" . into ( ) ) {
385
+ return ;
386
+ }
387
+
388
+ let mut config = utils:: create_stx_config ( ) ;
389
+ config. burnchain . wallet_name = "my_wallet" . to_string ( ) ;
390
+
391
+ let mut btcd_controller = BitcoinCoreController :: new ( config. clone ( ) ) ;
392
+ btcd_controller
393
+ . start_bitcoind ( )
394
+ . expect ( "bitcoind should be started!" ) ;
395
+
396
+ let client = BitcoinRpcClient :: from_stx_config ( & config) . expect ( "Client creation ok!" ) ;
397
+ client. create_wallet ( "my_wallet" , Some ( false ) ) . expect ( "OK" ) ;
398
+ let address1 = client
399
+ . get_new_address ( None , Some ( AddressType :: Legacy ) )
400
+ . expect ( "address 1 ok!" ) ;
401
+
402
+ let address2 = client
403
+ . get_new_address ( None , Some ( AddressType :: Legacy ) )
404
+ . expect ( "address 2 ok!" ) ;
405
+
406
+ _ = client
407
+ . generate_to_address ( 2 , & address1)
408
+ . expect ( "generate to address 1 ok!" ) ;
409
+ _ = client
410
+ . generate_to_address ( 101 , & address2)
411
+ . expect ( "generate to address 2 ok!" ) ;
412
+
413
+ let all_utxos = client
414
+ . list_unspent ( None , None , None , Some ( false ) , None , None )
415
+ . expect ( "all list_unspent should be ok!" ) ;
416
+ assert_eq ! ( 3 , all_utxos. len( ) ) ;
417
+
418
+ let addr1_utxos = client
419
+ . list_unspent ( None , None , Some ( & [ & address1] ) , Some ( false ) , None , None )
420
+ . expect ( "list_unspent per address1 should be ok!" ) ;
421
+ assert_eq ! ( 2 , addr1_utxos. len( ) ) ;
422
+ assert_eq ! ( address1, addr1_utxos[ 0 ] . address) ;
423
+ assert_eq ! ( address1, addr1_utxos[ 1 ] . address) ;
424
+
425
+ let addr2_utxos = client
426
+ . list_unspent ( None , None , Some ( & [ & address2] ) , Some ( false ) , None , None )
427
+ . expect ( "list_unspent per address2 should be ok!" ) ;
428
+ assert_eq ! ( 1 , addr2_utxos. len( ) ) ;
429
+ assert_eq ! ( address2, addr2_utxos[ 0 ] . address) ;
430
+
431
+ let all2_utxos = client
432
+ . list_unspent (
433
+ None ,
434
+ None ,
435
+ Some ( & [ & address1, & address2] ) ,
436
+ Some ( false ) ,
437
+ None ,
438
+ None ,
439
+ )
440
+ . expect ( "all list_unspent for both addresses should be ok!" ) ;
441
+ assert_eq ! ( 3 , all2_utxos. len( ) ) ;
362
442
}
363
443
364
444
#[ ignore]
0 commit comments