summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine A <>2021-11-23 11:26:14 +0100
committerAntoine A <>2021-11-23 11:26:14 +0100
commite5031ab9f90c5b7fea7c23f6ec55dbd80619bdf5 (patch)
tree49ec01a7ae6fe0425b379134d19a6eaaa9e60d28
parent14450d278ff85bde32f63ab43c48b8fa58def97d (diff)
downloaddepolymerization-e5031ab9f90c5b7fea7c23f6ec55dbd80619bdf5.tar.gz
depolymerization-e5031ab9f90c5b7fea7c23f6ec55dbd80619bdf5.tar.bz2
depolymerization-e5031ab9f90c5b7fea7c23f6ec55dbd80619bdf5.zip
Pass refund test on testnet
-rw-r--r--src/bin/test.rs33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/bin/test.rs b/src/bin/test.rs
index 98555e5..2c29f51 100644
--- 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