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 Sep 29, 2021
1 parent c00ee91 commit f0ae3d5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 26 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 "v\\(19\|20\|21\|22\)"; then
BLOCKFILTERARG="-blockfilterindex=1"
fi

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

Expand Down
78 changes: 55 additions & 23 deletions integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,17 +362,38 @@ 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 @@ -382,13 +403,15 @@ 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 @@ -411,7 +434,8 @@ 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 @@ -429,8 +453,9 @@ 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();
let txid = 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 @@ -454,8 +479,9 @@ 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();
let txid = 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 @@ -464,18 +490,21 @@ 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();
let txid2 =
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None).unwrap();
let txid1 = 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, 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();
let txid = 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 @@ -485,7 +514,8 @@ 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 @@ -801,7 +831,8 @@ 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 @@ -1038,7 +1069,8 @@ 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 @@ -835,7 +835,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 f0ae3d5

Please sign in to comment.