Skip to content

Commit

Permalink
Write test cases for new send_to_address
Browse files Browse the repository at this point in the history
  • Loading branch information
luizParreira committed May 30, 2022
1 parent 11dc1f8 commit 0a0c11e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
4 changes: 2 additions & 2 deletions integration_test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ PID1=$!
sleep 3

BLOCKFILTERARG=""
if bitcoind -version | grep -q "v0\.\(19\|2\)"; then
if bitcoind -version | grep -q "v0.\\(19\|20\|21\)"; then
BLOCKFILTERARG="-blockfilterindex=1"
fi

FALLBACKFEEARG=""
if bitcoind -version | grep -q "v0\.2"; then
if bitcoind -version | grep -q "v0.\\(20\|21\\)"; then
FALLBACKFEEARG="-fallbackfee=0.00001000"
fi

Expand Down
39 changes: 21 additions & 18 deletions integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,17 +393,20 @@ fn test_set_label(cl: &Client) {
fn test_send_to_address(cl: &Client) {
let addr = cl.get_new_address(None, None).unwrap();
let est = json::EstimateMode::Conservative;
let _ = cl.send_to_address(&addr, btc(1), Some("cc"), None, None, None, None, None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, Some("tt"), None, None, None, None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, None, Some(true), None, None, None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, None, None, Some(true), None, None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, Some(3), None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, None, Some(est)).unwrap();
let _ = cl.send_to_address(&addr, btc(1), Some("cc"), None, None, None, None, None, None, None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, Some("tt"), None, None, None, None, None, None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, None, Some(true), None, None, None, None, None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, None, None, Some(true), None, None, None, None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, Some(3), None, None, None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, None, Some(est), None, None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None, Some(false), None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None, None, Some(5)).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None, None, None).unwrap();
}

fn test_get_received_by_address(cl: &Client) {
let addr = cl.get_new_address(None, None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None, None, None).unwrap();
assert_eq!(cl.get_received_by_address(&addr, Some(0)).unwrap(), btc(1));
assert_eq!(cl.get_received_by_address(&addr, Some(1)).unwrap(), btc(0));
let _ = cl.generate_to_address(7, &cl.get_new_address(None, None).unwrap()).unwrap();
Expand All @@ -413,13 +416,13 @@ fn test_get_received_by_address(cl: &Client) {

fn test_list_unspent(cl: &Client) {
let addr = cl.get_new_address(None, None).unwrap();
let txid = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None).unwrap();
let txid = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None, None, None).unwrap();
let unspent = cl.list_unspent(Some(0), None, Some(&[&addr]), None, None).unwrap();
assert_eq!(unspent[0].txid, txid);
assert_eq!(unspent[0].address.as_ref(), Some(&addr));
assert_eq!(unspent[0].amount, btc(1));

let txid = cl.send_to_address(&addr, btc(7), None, None, None, None, None, None).unwrap();
let txid = cl.send_to_address(&addr, btc(7), None, None, None, None, None, None, None, None).unwrap();
let options = json::ListUnspentQueryOptions {
minimum_amount: Some(btc(7)),
maximum_amount: Some(btc(7)),
Expand All @@ -442,7 +445,7 @@ fn test_get_connection_count(cl: &Client) {

fn test_get_raw_transaction(cl: &Client) {
let addr = cl.get_new_address(None, None).unwrap();
let txid = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None).unwrap();
let txid = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None, None, None).unwrap();
let tx = cl.get_raw_transaction(&txid, None).unwrap();
let hex = cl.get_raw_transaction_hex(&txid, None).unwrap();
assert_eq!(tx, deserialize(&Vec::<u8>::from_hex(&hex).unwrap()).unwrap());
Expand All @@ -461,7 +464,7 @@ fn test_get_raw_mempool(cl: &Client) {

fn test_get_transaction(cl: &Client) {
let txid =
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None).unwrap();
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None, None, None).unwrap();
let tx = cl.get_transaction(&txid, None).unwrap();
assert_eq!(tx.amount, sbtc(-1.0));
assert_eq!(tx.info.txid, txid);
Expand All @@ -486,7 +489,7 @@ fn test_list_since_block(cl: &Client) {

fn test_get_tx_out(cl: &Client) {
let txid =
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None).unwrap();
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None, None, None).unwrap();
let out = cl.get_tx_out(&txid, 0, Some(false)).unwrap();
assert!(out.is_none());
let out = cl.get_tx_out(&txid, 0, Some(true)).unwrap();
Expand All @@ -496,17 +499,17 @@ fn test_get_tx_out(cl: &Client) {

fn test_get_tx_out_proof(cl: &Client) {
let txid1 =
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None).unwrap();
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None, None, None).unwrap();
let txid2 =
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None).unwrap();
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None, None, None).unwrap();
let blocks = cl.generate_to_address(7, &cl.get_new_address(None, None).unwrap()).unwrap();
let proof = cl.get_tx_out_proof(&[txid1, txid2], Some(&blocks[0])).unwrap();
assert!(!proof.is_empty());
}

fn test_get_mempool_entry(cl: &Client) {
let txid =
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None).unwrap();
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None, None, None).unwrap();
let entry = cl.get_mempool_entry(&txid).unwrap();
assert!(entry.spent_by.is_empty());

Expand All @@ -516,7 +519,7 @@ fn test_get_mempool_entry(cl: &Client) {

fn test_lock_unspent_unlock_unspent(cl: &Client) {
let addr = cl.get_new_address(None, None).unwrap();
let txid = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None).unwrap();
let txid = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None, None, None).unwrap();

assert!(cl.lock_unspent(&[OutPoint::new(txid, 0)]).unwrap());
assert!(cl.unlock_unspent(&[OutPoint::new(txid, 0)]).unwrap());
Expand Down Expand Up @@ -832,7 +835,7 @@ fn test_finalize_psbt(cl: &Client) {

fn test_list_received_by_address(cl: &Client) {
let addr = cl.get_new_address(None, None).unwrap();
let txid = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None).unwrap();
let txid = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None, None, None).unwrap();

let _ = cl.list_received_by_address(Some(&addr), None, None, None).unwrap();
let _ = cl.list_received_by_address(Some(&addr), None, Some(true), None).unwrap();
Expand Down Expand Up @@ -1124,7 +1127,7 @@ fn test_getblocktemplate(cl: &Client) {
// contains an entry in the vector of GetBlockTemplateResultTransaction.
// Otherwise the GetBlockTemplateResultTransaction deserialization wouldn't
// be tested.
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None).unwrap();
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None, None, None).unwrap();

cl.get_block_template(GetBlockTemplateModes::Template, &[GetBlockTemplateRules::SegWit], &[])
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ impl<'a> serde::Serialize for ImportMultiRequestScriptPubkey<'a> {
#[derive(Serialize)]
struct Tmp<'a> {
pub address: &'a Address,
}
};
serde::Serialize::serialize(
&Tmp {
address: addr,
Expand Down

0 comments on commit 0a0c11e

Please sign in to comment.