depolymerization

wire gateway for Bitcoin/Ethereum
Log | Files | Refs | Submodules | README | LICENSE

commit e5031ab9f90c5b7fea7c23f6ec55dbd80619bdf5
parent 14450d278ff85bde32f63ab43c48b8fa58def97d
Author: Antoine A <>
Date:   Tue, 23 Nov 2021 11:26:14 +0100

Pass refund test on testnet

Diffstat:
Msrc/bin/test.rs | 33++++++++++++++++++++++++---------
1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/src/bin/test.rs b/src/bin/test.rs @@ -80,6 +80,20 @@ pub fn main() { } }; + let wait_for_tx = |rpc: &Client, txs: &[Txid]| { + let mut count = 0; + while txs + .iter() + .any(|id| rpc.get_transaction(id, None).unwrap().info.confirmations <= 0) + { + next_block(); + if count > 3 { + panic!("Transaction no sended after 4 blocks"); + } + count += 1; + } + }; + // Balance check { // Transfer all wire money to client @@ -157,6 +171,7 @@ pub fn main() { } let mut runner = TestRunner::new(); + runner.test("OpReturn metadata", || { // Send metadata let msg = "J'aime le chocolat".as_bytes(); @@ -169,7 +184,7 @@ pub fn main() { "Not in mempool" ); // Check mined - next_block(); + wait_for_tx(&client_rpc, &[id]); assert!( tx_exist(&wire_rpc, &id, 1, Category::Receive).unwrap(), "Not mined" @@ -190,7 +205,7 @@ pub fn main() { "Not in mempool" ); // Check mined - next_block(); + wait_for_tx(&client_rpc, &[id]); assert!( tx_exist(&wire_rpc, &id, 1, Category::Receive).unwrap(), "Not mined" @@ -206,9 +221,9 @@ pub fn main() { let send_id = client_rpc .send_to_address(&wire_addr, test_amount, None, None, None, None, None, None) .unwrap(); - next_block(); + wait_for_tx(&client_rpc, &[send_id]); let refund_id = refund(&wire_rpc, &send_id, refund_fee).unwrap(); - next_block(); + wait_for_tx(&wire_rpc, &[refund_id]); let refund_tx_fee = wire_rpc.get_transaction(&refund_id, None).unwrap().details[0] .fee .unwrap() @@ -237,7 +252,7 @@ pub fn main() { None, ) .unwrap(); - next_block(); + wait_for_tx(&client_rpc, &[send_id]); assert!(refund(&wire_rpc, &send_id, refund_fee).is_err()); }); runner.test("Refund too small amount", || { @@ -253,7 +268,7 @@ pub fn main() { None, ) .unwrap(); - next_block(); + wait_for_tx(&client_rpc, &[send_id]); assert!(refund(&wire_rpc, &send_id, refund_fee).is_err()); }); runner.test("Refund complex", || { @@ -287,7 +302,7 @@ pub fn main() { client_rpc.send_raw_transaction(&signed.hex).unwrap() }) .collect(); - next_block(); + wait_for_tx(&client_rpc, txs.as_slice()); let before = client_rpc.get_balance(None, None).unwrap(); // Send a transaction with multiple input from multiple transaction of different outputs len let hex: String = client_rpc @@ -316,9 +331,9 @@ pub fn main() { .sign_raw_transaction_with_wallet(&funded.hex, None, None) .unwrap(); let send_id = client_rpc.send_raw_transaction(&signed.hex).unwrap(); - next_block(); + wait_for_tx(&client_rpc, &[send_id]); let refund_id = refund(&wire_rpc, &send_id, refund_fee).unwrap(); - next_block(); + wait_for_tx(&wire_rpc, &[refund_id]); let after = client_rpc.get_balance(None, None).unwrap(); let refund_tx_fee = wire_rpc.get_transaction(&refund_id, None).unwrap().details[0] .fee