wallet.sync(&blockchain, SyncOptions::default()).unwrap();
assert!(wallet.database().deref().get_sync_time().unwrap().is_some(), "sync_time hasn't been updated");
- assert_eq!(wallet.get_balance().unwrap(), 50_000, "incorrect balance");
+ assert_eq!(wallet.get_balance().unwrap().untrusted_pending, 50_000, "incorrect balance");
assert_eq!(wallet.list_unspent().unwrap()[0].keychain, KeychainKind::External, "incorrect keychain kind");
let list_tx_item = &wallet.list_transactions(false).unwrap()[0];
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 100_000, "incorrect balance");
+ assert_eq!(wallet.get_balance().unwrap().untrusted_pending, 100_000, "incorrect balance");
assert_eq!(wallet.list_transactions(false).unwrap().len(), 2, "incorrect number of txs");
}
let (wallet, blockchain, descriptors, mut test_client) = init_single_sig();
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 0);
+ assert_eq!(wallet.get_balance().unwrap().get_total(), 0);
test_client.receive(testutils! {
@tx ( (@external descriptors, 0) => 50_000 )
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000, "incorrect balance");
- assert_eq!(wallet.list_transactions(false).unwrap().len(), 1, "incorrect number of txs");
+ assert_eq!(wallet.get_balance().unwrap().untrusted_pending, 50_000, "incorrect balance");
+
+ test_client.receive(testutils! {
+ @tx ( (@external descriptors, 0) => 50_000 ) (@confirmations 1)
+ });
+
+ wallet.sync(&blockchain, SyncOptions::default()).unwrap();
+
+ assert_eq!(wallet.get_balance().unwrap().confirmed, 100_000, "incorrect balance");
+ assert_eq!(wallet.list_transactions(false).unwrap().len(), 2, "incorrect number of txs");
}
#[test]
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 105_000, "incorrect balance");
+ assert_eq!(wallet.get_balance().unwrap().untrusted_pending, 105_000, "incorrect balance");
assert_eq!(wallet.list_transactions(false).unwrap().len(), 1, "incorrect number of txs");
assert_eq!(wallet.list_unspent().unwrap().len(), 3, "incorrect number of unspents");
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 75_000, "incorrect balance");
+ assert_eq!(wallet.get_balance().unwrap().untrusted_pending, 75_000, "incorrect balance");
assert_eq!(wallet.list_transactions(false).unwrap().len(), 2, "incorrect number of txs");
assert_eq!(wallet.list_unspent().unwrap().len(), 2, "incorrect number of unspent");
}
});
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000);
+ assert_eq!(wallet.get_balance().unwrap().untrusted_pending, 50_000);
test_client.receive(testutils! {
@tx ( (@external descriptors, 0) => 25_000 )
});
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 75_000, "incorrect balance");
+ assert_eq!(wallet.get_balance().unwrap().untrusted_pending, 75_000, "incorrect balance");
}
#[test]
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000, "incorrect balance");
+ assert_eq!(wallet.get_balance().unwrap().untrusted_pending, 50_000, "incorrect balance");
assert_eq!(wallet.list_transactions(false).unwrap().len(), 1, "incorrect number of txs");
assert_eq!(wallet.list_unspent().unwrap().len(), 1, "incorrect unspent");
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000, "incorrect balance after bump");
+ assert_eq!(wallet.get_balance().unwrap().untrusted_pending, 50_000, "incorrect balance after bump");
assert_eq!(wallet.list_transactions(false).unwrap().len(), 1, "incorrect number of txs after bump");
assert_eq!(wallet.list_unspent().unwrap().len(), 1, "incorrect unspent after bump");
});
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
-
- assert_eq!(wallet.get_balance().unwrap(), 50_000, "incorrect balance");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), 50_000, "incorrect balance");
assert_eq!(wallet.list_transactions(false).unwrap().len(), 1, "incorrect number of txs");
assert_eq!(wallet.list_unspent().unwrap().len(), 1, "incorrect number of unspents");
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000, "incorrect balance after invalidate");
+ assert_eq!(wallet.get_balance().unwrap().untrusted_pending, 50_000, "incorrect balance after invalidate");
let list_tx_item = &wallet.list_transactions(false).unwrap()[0];
assert_eq!(list_tx_item.txid, txid, "incorrect txid after invalidate");
});
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000, "incorrect balance");
+ assert_eq!(wallet.get_balance().unwrap().untrusted_pending, 50_000, "incorrect balance");
let mut builder = wallet.build_tx();
builder.add_recipient(node_addr.script_pubkey(), 25_000);
println!("{}", bitcoin::consensus::encode::serialize_hex(&tx));
blockchain.broadcast(&tx).unwrap();
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), details.received, "incorrect balance after send");
+ assert_eq!(wallet.get_balance().unwrap().trusted_pending, details.received, "incorrect balance after send");
+
+ test_client.generate(1, Some(node_addr));
+ wallet.sync(&blockchain, SyncOptions::default()).unwrap();
+
+ assert_eq!(wallet.get_balance().unwrap().confirmed, details.received, "incorrect balance after send");
assert_eq!(wallet.list_transactions(false).unwrap().len(), 2, "incorrect number of txs");
assert_eq!(wallet.list_unspent().unwrap().len(), 1, "incorrect number of unspents");
});
wallet.sync(&blockchain, SyncOptions::default()).expect("sync");
- assert_eq!(wallet.get_balance().unwrap(), 75_000, "incorrect balance");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), 75_000, "incorrect balance");
let target_addr = receiver_wallet.get_address($crate::wallet::AddressIndex::New).unwrap().address;
let tx1 = {
blockchain.broadcast(&tx1).expect("broadcasting first");
blockchain.broadcast(&tx2).expect("broadcasting replacement");
receiver_wallet.sync(&blockchain, SyncOptions::default()).expect("syncing receiver");
- assert_eq!(receiver_wallet.get_balance().expect("balance"), 49_000, "should have received coins once and only once");
+ assert_eq!(receiver_wallet.get_balance().expect("balance").untrusted_pending, 49_000, "should have received coins once and only once");
}
#[test]
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 100_000);
+ let balance = wallet.get_balance().unwrap();
+ assert_eq!(balance.untrusted_pending + balance.get_spendable(), 100_000);
}
#[test]
});
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000, "incorrect balance");
+ assert_eq!(wallet.get_balance().unwrap().untrusted_pending, 50_000, "incorrect balance");
let tx_map = wallet.list_transactions(false).unwrap().into_iter().map(|tx| (tx.txid, tx)).collect::<std::collections::HashMap<_, _>>();
let details = tx_map.get(&received_txid).unwrap();
});
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000, "incorrect balance");
+ assert_eq!(wallet.get_balance().unwrap().untrusted_pending, 50_000, "incorrect balance");
let mut builder = wallet.build_tx();
builder.add_recipient(node_addr.script_pubkey(), 25_000);
blockchain.broadcast(&sent_tx).unwrap();
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), details.received, "incorrect balance after receive");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), details.received, "incorrect balance after receive");
// empty wallet
let wallet = get_wallet_from_descriptors(&descriptors);
});
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000, "incorrect balance");
+ assert_eq!(wallet.get_balance().unwrap().untrusted_pending, 50_000, "incorrect balance");
let mut total_sent = 0;
for _ in 0..5 {
}
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000 - total_sent, "incorrect balance after chain");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), 50_000 - total_sent, "incorrect balance after chain");
// empty wallet
test_client.generate(1, Some(node_addr));
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000 - total_sent, "incorrect balance empty wallet");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), 50_000 - total_sent, "incorrect balance empty wallet");
}
});
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000, "incorrect balance");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), 50_000, "incorrect balance");
let mut builder = wallet.build_tx();
builder.add_recipient(node_addr.script_pubkey().clone(), 5_000).enable_rbf();
assert!(finalized, "Cannot finalize transaction");
blockchain.broadcast(&psbt.extract_tx()).unwrap();
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000 - details.fee.unwrap_or(0) - 5_000, "incorrect balance from fees");
- assert_eq!(wallet.get_balance().unwrap(), details.received, "incorrect balance from received");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), 50_000 - details.fee.unwrap_or(0) - 5_000, "incorrect balance from fees");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), details.received, "incorrect balance from received");
let mut builder = wallet.build_fee_bump(details.txid).unwrap();
builder.fee_rate(FeeRate::from_sat_per_vb(2.1));
assert!(finalized, "Cannot finalize transaction");
blockchain.broadcast(&new_psbt.extract_tx()).unwrap();
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000 - new_details.fee.unwrap_or(0) - 5_000, "incorrect balance from fees after bump");
- assert_eq!(wallet.get_balance().unwrap(), new_details.received, "incorrect balance from received after bump");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), 50_000 - new_details.fee.unwrap_or(0) - 5_000, "incorrect balance from fees after bump");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), new_details.received, "incorrect balance from received after bump");
assert!(new_details.fee.unwrap_or(0) > details.fee.unwrap_or(0), "incorrect fees");
}
});
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000, "incorrect balance");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), 50_000, "incorrect balance");
let mut builder = wallet.build_tx();
builder.add_recipient(node_addr.script_pubkey().clone(), 49_000).enable_rbf();
assert!(finalized, "Cannot finalize transaction");
blockchain.broadcast(&psbt.extract_tx()).unwrap();
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 1_000 - details.fee.unwrap_or(0), "incorrect balance after send");
- assert_eq!(wallet.get_balance().unwrap(), details.received, "incorrect received after send");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), 1_000 - details.fee.unwrap_or(0), "incorrect balance after send");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), details.received, "incorrect received after send");
let mut builder = wallet.build_fee_bump(details.txid).unwrap();
builder.fee_rate(FeeRate::from_sat_per_vb(5.1));
assert!(finalized, "Cannot finalize transaction");
blockchain.broadcast(&new_psbt.extract_tx()).unwrap();
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 0, "incorrect balance after change removal");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), 0, "incorrect balance after change removal");
assert_eq!(new_details.received, 0, "incorrect received after change removal");
assert!(new_details.fee.unwrap_or(0) > details.fee.unwrap_or(0), "incorrect fees");
});
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 75_000, "incorrect balance");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), 75_000, "incorrect balance");
let mut builder = wallet.build_tx();
builder.add_recipient(node_addr.script_pubkey().clone(), 49_000).enable_rbf();
assert!(finalized, "Cannot finalize transaction");
blockchain.broadcast(&psbt.extract_tx()).unwrap();
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 26_000 - details.fee.unwrap_or(0), "incorrect balance after send");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), 26_000 - details.fee.unwrap_or(0), "incorrect balance after send");
assert_eq!(details.received, 1_000 - details.fee.unwrap_or(0), "incorrect received after send");
let mut builder = wallet.build_fee_bump(details.txid).unwrap();
blockchain.broadcast(&new_psbt.extract_tx()).unwrap();
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
assert_eq!(new_details.sent, 75_000, "incorrect sent");
- assert_eq!(wallet.get_balance().unwrap(), new_details.received, "incorrect balance after add input");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), new_details.received, "incorrect balance after add input");
}
#[test]
});
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 75_000, "incorrect balance");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), 75_000, "incorrect balance");
let mut builder = wallet.build_tx();
builder.add_recipient(node_addr.script_pubkey().clone(), 49_000).enable_rbf();
assert!(finalized, "Cannot finalize transaction");
blockchain.broadcast(&psbt.extract_tx()).unwrap();
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 26_000 - details.fee.unwrap_or(0), "incorrect balance after send");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), 26_000 - details.fee.unwrap_or(0), "incorrect balance after send");
assert_eq!(details.received, 1_000 - details.fee.unwrap_or(0), "incorrect received after send");
let mut builder = wallet.build_fee_bump(details.txid).unwrap();
blockchain.broadcast(&new_psbt.extract_tx()).unwrap();
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
assert_eq!(new_details.sent, 75_000, "incorrect sent");
- assert_eq!(wallet.get_balance().unwrap(), 0, "incorrect balance after add input");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), 0, "incorrect balance after add input");
assert_eq!(new_details.received, 0, "incorrect received after add input");
}
});
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000, "incorrect balance");
+ assert_eq!(wallet.get_balance().unwrap().untrusted_pending, 50_000, "incorrect balance");
let mut builder = wallet.build_tx();
let data = [42u8;80];
blockchain.broadcast(&tx).unwrap();
test_client.generate(1, Some(node_addr));
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000 - details.fee.unwrap_or(0), "incorrect balance after send");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), 50_000 - details.fee.unwrap_or(0), "incorrect balance after send");
let tx_map = wallet.list_transactions(false).unwrap().into_iter().map(|tx| (tx.txid, tx)).collect::<std::collections::HashMap<_, _>>();
let _ = tx_map.get(&tx.txid()).unwrap();
println!("wallet addr: {}", wallet_addr);
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 0, "incorrect balance");
+ assert_eq!(wallet.get_balance().unwrap().immature, 0, "incorrect balance");
test_client.generate(1, Some(wallet_addr));
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert!(wallet.get_balance().unwrap() > 0, "incorrect balance after receiving coinbase");
+
+ assert!(wallet.get_balance().unwrap().immature > 0, "incorrect balance after receiving coinbase");
+
+ // make coinbase mature (100 blocks)
+ let node_addr = test_client.get_node_address(None);
+ test_client.generate(100, Some(node_addr));
+ wallet.sync(&blockchain, SyncOptions::default()).unwrap();
+
+ assert!(wallet.get_balance().unwrap().confirmed > 0, "incorrect balance after maturing coinbase");
+
}
#[test]
});
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000, "wallet has incorrect balance");
+ assert_eq!(wallet.get_balance().unwrap().untrusted_pending, 50_000, "wallet has incorrect balance");
// 4. Send 25_000 sats from test BDK wallet to test bitcoind node taproot wallet
let tx = psbt.extract_tx();
blockchain.broadcast(&tx).unwrap();
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), details.received, "wallet has incorrect balance after send");
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), details.received, "wallet has incorrect balance after send");
assert_eq!(wallet.list_transactions(false).unwrap().len(), 2, "wallet has incorrect number of txs");
assert_eq!(wallet.list_unspent().unwrap().len(), 1, "wallet has incorrect number of unspents");
test_client.generate(1, None);
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000);
+ assert_eq!(wallet.get_balance().unwrap().untrusted_pending, 50_000);
let tx = {
let mut builder = wallet.build_tx();
@tx ( (@external descriptors, 0) => 50_000 )
});
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000);
+ assert_eq!(wallet.get_balance().unwrap().untrusted_pending, 50_000);
let tx = {
let mut builder = wallet.build_tx();
@tx ( (@external descriptors, 0) => 50_000 ) ( @confirmations 6 )
});
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
- assert_eq!(wallet.get_balance().unwrap(), 50_000);
+ assert_eq!(wallet.get_balance().unwrap().get_spendable(), 50_000);
let ext_policy = wallet.policies(KeychainKind::External).unwrap().unwrap();
let int_policy = wallet.policies(KeychainKind::Internal).unwrap().unwrap();