Skip to content

Commit 68f3044

Browse files
committed
crc: fix list_unspent maximum_count unlimited default, #6250
1 parent 932a98c commit 68f3044

File tree

2 files changed

+59
-8
lines changed

2 files changed

+59
-8
lines changed

stacks-node/src/burnchains/rpc/bitcoin_rpc_client/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ impl BitcoinRpcClient {
491491
/// * `addresses` - Optional list of addresses to filter UTXOs by (Default: no filtering).
492492
/// * `include_unsafe` - Whether to include UTXOs from unconfirmed unsafe transactions (Default: `true`).
493493
/// * `minimum_amount` - Minimum amount in satoshis (internally converted to BTC string to preserve full precision) a UTXO must have to be included (Default: 0).
494-
/// * `maximum_count` - Maximum number of UTXOs to return. Use `None` for effectively unlimited (Default: 9.999.999).
494+
/// * `maximum_count` - Maximum number of UTXOs to return. Use `None` for effectively 'unlimited' (Default: 0).
495495
///
496496
/// # Returns
497497
/// A Vec<[`ListUnspentResponse`]> containing the matching UTXOs.
@@ -513,7 +513,7 @@ impl BitcoinRpcClient {
513513
let addresses = addresses.unwrap_or(&[]);
514514
let include_unsafe = include_unsafe.unwrap_or(true);
515515
let minimum_amount = minimum_amount.unwrap_or(0);
516-
let maximum_count = maximum_count.unwrap_or(9_999_999);
516+
let maximum_count = maximum_count.unwrap_or(0);
517517

518518
let addr_as_strings: Vec<String> = addresses.iter().map(|addr| addr.to_string()).collect();
519519
let min_amount_btc_str = convert_sat_to_btc_string(minimum_amount);

stacks-node/src/tests/bitcoin_rpc_integrations.rs

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,31 @@ fn test_generate_to_address_ok() {
322322

323323
#[ignore]
324324
#[test]
325-
fn test_list_unspent_one_address_ok() {
325+
fn test_list_unspent_empty_with_empty_wallet() {
326+
if env::var("BITCOIND_TEST") != Ok("1".into()) {
327+
return;
328+
}
329+
330+
let mut config = utils::create_stx_config();
331+
config.burnchain.wallet_name = "my_wallet".to_string();
332+
333+
let mut btcd_controller = BitcoinCoreController::new(config.clone());
334+
btcd_controller
335+
.start_bitcoind()
336+
.expect("bitcoind should be started!");
337+
338+
let client = BitcoinRpcClient::from_stx_config(&config).expect("Client creation ok!");
339+
client.create_wallet("my_wallet", Some(false)).expect("OK");
340+
341+
let utxos = client
342+
.list_unspent(None, None, None, None, None, None)
343+
.expect("all list_unspent should be ok!");
344+
assert_eq!(0, utxos.len());
345+
}
346+
347+
#[ignore]
348+
#[test]
349+
fn test_list_unspent_with_defaults() {
326350
if env::var("BITCOIND_TEST") != Ok("1".into()) {
327351
return;
328352
}
@@ -337,14 +361,41 @@ fn test_list_unspent_one_address_ok() {
337361

338362
let client = BitcoinRpcClient::from_stx_config(&config).expect("Client creation ok!");
339363
client.create_wallet("my_wallet", Some(false)).expect("OK");
364+
340365
let address = client
341366
.get_new_address(None, Some(AddressType::Legacy))
342367
.expect("Should work!");
343368

344-
let no_utxos = client
345-
.list_unspent(None, None, None, Some(false), Some(1), Some(10))
346-
.expect("list_unspent empty should be ok!");
347-
assert_eq!(0, no_utxos.len());
369+
_ = client
370+
.generate_to_address(102, &address)
371+
.expect("generate to address ok!");
372+
373+
let utxos = client
374+
.list_unspent(None, None, None, None, None, None)
375+
.expect("all list_unspent should be ok!");
376+
assert_eq!(2, utxos.len());
377+
}
378+
379+
#[ignore]
380+
#[test]
381+
fn test_list_unspent_one_address_ok() {
382+
if env::var("BITCOIND_TEST") != Ok("1".into()) {
383+
return;
384+
}
385+
386+
let mut config = utils::create_stx_config();
387+
config.burnchain.wallet_name = "my_wallet".to_string();
388+
389+
let mut btcd_controller = BitcoinCoreController::new(config.clone());
390+
btcd_controller
391+
.start_bitcoind()
392+
.expect("bitcoind should be started!");
393+
394+
let client = BitcoinRpcClient::from_stx_config(&config).expect("Client creation ok!");
395+
client.create_wallet("my_wallet", Some(false)).expect("OK");
396+
let address = client
397+
.get_new_address(None, Some(AddressType::Legacy))
398+
.expect("Should work!");
348399

349400
_ = client
350401
.generate_to_address(102, &address)
@@ -395,10 +446,10 @@ fn test_list_unspent_two_addresses_ok() {
395446

396447
let client = BitcoinRpcClient::from_stx_config(&config).expect("Client creation ok!");
397448
client.create_wallet("my_wallet", Some(false)).expect("OK");
449+
398450
let address1 = client
399451
.get_new_address(None, Some(AddressType::Legacy))
400452
.expect("address 1 ok!");
401-
402453
let address2 = client
403454
.get_new_address(None, Some(AddressType::Legacy))
404455
.expect("address 2 ok!");

0 commit comments

Comments
 (0)