Skip to content

Commit 4a66bc5

Browse files
fix(rpc-integration-test): handle insufficient funds in sign+send test
Attempt funding with 3/1/0.5 DASH before mining and selecting the UTXO, so the test does not fail on temporary low balance; adjusts minimum_amount to match the funded output and filters by address for deterministic selection.
1 parent 21becec commit 4a66bc5

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

rpc-integration-test/src/main.rs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -785,15 +785,44 @@ fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) {
785785
..Default::default()
786786
};
787787
// Ensure we have a confirmed, sufficiently large UTXO owned by this wallet.
788-
// 1) Create a fresh funding output of 3 DASH to a new wallet address.
788+
// 1) Create a fresh funding output to a new wallet address, with fallbacks if balance is tight.
789789
let fund_addr = cl.get_new_address(None).unwrap().require_network(*NET).unwrap();
790-
let _ = cl
791-
.send_to_address(&fund_addr, btc(3), None, None, None, None, None, None, None, None)
792-
.unwrap();
790+
let mut funded_amount_btc: Option<f64> = None;
791+
for amt in [3.0_f64, 1.0_f64, 0.5_f64] {
792+
match cl.send_to_address(
793+
&fund_addr,
794+
btc(amt),
795+
None,
796+
None,
797+
None,
798+
None,
799+
None,
800+
None,
801+
None,
802+
None,
803+
) {
804+
Ok(_) => {
805+
funded_amount_btc = Some(amt);
806+
break;
807+
}
808+
Err(dashcore_rpc::Error::JsonRpc(dashcore_rpc::jsonrpc::error::Error::Rpc(e)))
809+
if e.code == -6 && e.message.contains("Insufficient funds") =>
810+
{
811+
continue;
812+
}
813+
Err(e) => panic!("Unexpected error funding test UTXO: {:?}", e),
814+
}
815+
}
816+
let funded_amount_btc =
817+
funded_amount_btc.expect("wallet has insufficient balance even for 0.5 DASH");
793818
// 2) Mine 6 blocks to confirm all pending transactions (not coinbases).
794819
let mine_addr = cl.get_new_address(None).unwrap().require_network(*NET).unwrap();
795820
let _ = cl.generate_to_address(6, &mine_addr).unwrap();
796-
// 3) Select a confirmed UTXO >= 2 DASH, preferably the one we just created.
821+
// 3) Select a confirmed UTXO with at least the funded amount (the vout to fund_addr equals the send amount).
822+
let options = json::ListUnspentQueryOptions {
823+
minimum_amount: Some(btc(funded_amount_btc)),
824+
..Default::default()
825+
};
797826
let unspent = cl.list_unspent(Some(6), None, Some(&[&fund_addr]), None, Some(options)).unwrap();
798827
let unspent = unspent.into_iter().next().unwrap();
799828

0 commit comments

Comments
 (0)