depolymerization

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

commit 638b7383208cb0b80f52b0d7f50b9a044a4939d4
parent e18367bae0a1cd3223896a6e55e7fac4b14f5266
Author: Antoine A <>
Date:   Wed, 23 Feb 2022 19:10:28 +0100

Better instrumentation test

Diffstat:
Mbtc-wire/src/rpc.rs | 8++++----
Minstrumentation/src/main.rs | 60+++++++++++++++++++++++++++++++++++++++++++-----------------
2 files changed, 47 insertions(+), 21 deletions(-)

diff --git a/btc-wire/src/rpc.rs b/btc-wire/src/rpc.rs @@ -31,7 +31,7 @@ use serde_json::{json, Value}; use std::{ fmt::Debug, io::{self, BufRead, BufReader, Write}, - net::{TcpStream, SocketAddr}, + net::{SocketAddr, TcpStream}, time::{Duration, Instant}, }; @@ -171,7 +171,7 @@ impl Rpc { let sock = TcpStream::connect_timeout(&self.addr, Duration::from_secs(5))?; self.conn = BufReader::new(sock); } - + let request = RpcRequest { method, id: self.id, @@ -301,7 +301,7 @@ impl Rpc { /// Get genesis block hash pub fn get_genesis(&mut self) -> Result<BlockHash> { self.call("getblockhash", &[0]) - } + } /* ----- Transactions ----- */ @@ -395,7 +395,7 @@ impl Rpc { hash: Option<&BlockHash>, confirmation: u16, ) -> Result<ListSinceBlock> { - self.call("listsinceblock", &(hash, confirmation, (), true)) + self.call("listsinceblock", &(hash, confirmation.max(1), (), true)) } } diff --git a/instrumentation/src/main.rs b/instrumentation/src/main.rs @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -use std::{fmt::Display, io::Write, path::PathBuf}; +use std::{fmt::Display, io::Write, path::PathBuf, time::Duration}; use bitcoin::{Amount, Network, SignedAmount}; use btc_wire::{ @@ -108,6 +108,27 @@ pub fn main() { // Load wire let mut wire_rpc = Rpc::wallet(&btc_config, WIRE).unwrap(); let wire_addr = wire_rpc.gen_addr().unwrap(); + + print_now("Wait for pending transactions mining:"); + 'l: loop { + let sync = client_rpc.list_since_block(Some(&since), 1).unwrap(); + let sync2 = wire_rpc.list_since_block(Some(&since), 1).unwrap(); + since = sync.lastblock; + for tx in sync + .transactions + .into_iter() + .chain(sync2.transactions.into_iter()) + { + if tx.confirmations == 0 { + rpc.wait_for_new_block().unwrap(); + print_now("."); + continue 'l; + } + } + break; + } + println!(""); + // Load balances let client_balance = client_rpc.get_balance().unwrap(); let wire_balance = wire_rpc.get_balance().unwrap(); @@ -116,7 +137,8 @@ pub fn main() { let min_send_amount = rpc_utils::segwit_min_amount(); // To small to send back let min_bounce_amount = rpc_utils::segwit_min_amount() + Amount::from_sat(999); // To small after bounce fee let taler_test_amount = btc_to_taler(&test_amount.to_signed().unwrap()); - // Send transaction + + println!("Send transaction"); let reserve_pub_key = rand_slice(); let deposit_id = client_rpc .send_segwit_key(&wire_addr, &test_amount, &reserve_pub_key) @@ -146,12 +168,12 @@ pub fn main() { new_balance ); - // Wait for mining and bounce - print_now("Wait for mining and bounce:"); + print_now("Wait for client mining and bounce:"); let mut pending = true; let mut bounced_id = None; while pending || bounced_id.is_none() { pending = false; + std::thread::sleep(Duration::from_secs(1)); rpc.wait_for_new_block().unwrap(); print_now("."); let sync = client_rpc.list_since_block(Some(&since), 1).unwrap(); @@ -178,7 +200,8 @@ pub fn main() { since = sync.lastblock; } println!(""); - // Check balances change + + println!("Check balance"); let new_client_balance = client_rpc.get_balance().unwrap(); let new_wire_balance = wire_rpc.get_balance().unwrap(); let bounced = client_rpc.get_tx(&bounced_id.unwrap()).unwrap(); @@ -191,7 +214,8 @@ pub fn main() { wire_balance + test_amount + min_bounce_amount + min_send_amount + bounce_fee, new_wire_balance ); - // Check history + + println!("Check history"); let history: IncomingHistory = ureq::get(&format!("{}/history/incoming", base_url)) .query("delta", "-5") .call() @@ -212,7 +236,8 @@ pub fn main() { ) }) .is_some()); - // Get back some money + + println!("Get back some money"); let url = Url::parse("ftp://example.com").unwrap(); let wtid = rand_slice(); ureq::post(&format!("{}/transfer", base_url)) @@ -225,26 +250,27 @@ pub fn main() { }) .unwrap(); - print_now("Wait for mining:"); - let mut pending = true; - while pending { - pending = false; - rpc.wait_for_new_block().unwrap(); - print_now("."); + print_now("Wait for wire mining:"); + std::thread::sleep(Duration::from_secs(1)); + 'l1: loop { let sync = wire_rpc.list_since_block(Some(&since), 1).unwrap(); + since = sync.lastblock; for tx in sync.transactions { if tx.confirmations == 0 { - pending = true; + rpc.wait_for_new_block().unwrap(); + print_now("."); + continue 'l1; } } - since = sync.lastblock; + break; } println!(""); - // Check balances change + println!("Check balances"); let last_client_balance = client_rpc.get_balance().unwrap(); assert_eq!(new_client_balance + test_amount, last_client_balance); - // Check history + + println!("Check history"); let history: OutgoingHistory = ureq::get(&format!("{}/history/outgoing", base_url)) .query("delta", "-5") .call()