depolymerization

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

commit 8880a7d5254601bff6ff52aee96a174bb503759d
parent e778b159b7ce20becc5ff60dbe4186b113efaf82
Author: Antoine A <>
Date:   Wed,  2 Mar 2022 18:51:41 +0100

Repair test

Diffstat:
Meth-wire/src/bin/eth-wire-utils.rs | 52++++++++++++++++++++++++++++++++++++++++++++++++++--
Meth-wire/src/rpc.rs | 9+++++++--
Mtest/btc/conflict.sh | 2+-
Mtest/common.sh | 14++------------
Mtest/eth/reorg.sh | 1+
5 files changed, 61 insertions(+), 17 deletions(-)

diff --git a/eth-wire/src/bin/eth-wire-utils.rs b/eth-wire/src/bin/eth-wire-utils.rs @@ -15,7 +15,9 @@ */ use std::{ path::{Path, PathBuf}, + process::exit, str::FromStr, + time::{Duration, Instant}, }; use clap::StructOpt; @@ -29,7 +31,7 @@ use common::{ }; use eth_wire::{ rpc::{hex::Hex, Rpc, TransactionRequest}, - taler_util::taler_to_eth, + taler_util::{taler_to_eth, TRUNC}, SyncState, }; use ethereum_types::{H160, U256}; @@ -81,6 +83,13 @@ enum Cmd { /// account address addr: String, }, + // Check client and wire balance + CheckBalance { + client_addr: String, + client: u64, + wire_addr: String, + wire: u64, + }, /// Add a peer Connect { /// peer datadir @@ -188,7 +197,32 @@ fn main() { Cmd::Balance { addr } => { let addr = H160::from_str(&addr).unwrap(); let balance = rpc.get_balance(&addr).unwrap(); - println!("{}", (balance / 10_000_000_000u64).as_u64()); + println!("{}", (balance / TRUNC).as_u64()); + } + Cmd::CheckBalance { + client_addr, + client, + wire_addr, + wire, + } => { + let start = Instant::now(); + let client_addr = H160::from_str(&client_addr).unwrap(); + let wire_addr = H160::from_str(&wire_addr).unwrap(); + loop { + let client_balance = (rpc.get_balance(&client_addr).unwrap() / TRUNC).as_u64(); + let wire_balance = (rpc.get_balance(&wire_addr).unwrap() / TRUNC).as_u64(); + if client_balance == client && wire_balance == wire { + break; + } else if start.elapsed() > Duration::from_secs(60) { + println!( + "Expected {} {} got {} {}", + client, wire, client_balance, wire_balance + ); + exit(1); + } else { + std::thread::sleep(Duration::from_secs(1)) + } + } } Cmd::Connect { datadir } => { let mut peer = Rpc::new(datadir.join("geth.ipc")).unwrap(); @@ -196,6 +230,13 @@ fn main() { // Replace ip with localhost because it is broken enode.set_host(Some("127.0.0.1")).unwrap(); assert!(rpc.add_peer(&enode).unwrap()); + let start = Instant::now(); + while rpc.count_peer().unwrap() == 0 { + if start.elapsed() > Duration::from_secs(60) { + panic!("Connect timeout"); + } + std::thread::sleep(Duration::from_secs(1)) + } } Cmd::Disconnect { datadir } => { let mut peer = Rpc::new(datadir.join("geth.ipc")).unwrap(); @@ -203,6 +244,13 @@ fn main() { // Replace ip with localhost because it is broken enode.set_host(Some("127.0.0.1")).unwrap(); assert!(rpc.remove_peer(&enode).unwrap()); + let start = Instant::now(); + while rpc.count_peer().unwrap() != 0 { + if start.elapsed() > Duration::from_secs(60) { + panic!("Disconnect timeout"); + } + std::thread::sleep(Duration::from_secs(1)) + } } Cmd::Abandon { from } => { let from = H160::from_str(&from).unwrap(); diff --git a/eth-wire/src/rpc.rs b/eth-wire/src/rpc.rs @@ -268,7 +268,7 @@ impl Rpc { } } - pub fn subscribe_new_head(&mut self) -> Result<RpcStream<BlockHead>> { + pub fn subscribe_new_head(&mut self) -> Result<RpcStream<Nothing>> { let mut rpc = Self::new(&self.path)?; let id: String = rpc.call("eth_subscribe", &["newHeads"])?; Ok(RpcStream::new(rpc, id)) @@ -299,6 +299,11 @@ impl Rpc { pub fn remove_peer(&mut self, url: &Url) -> Result<bool> { self.call("admin_removePeer", &[url]) } + + pub fn count_peer(&mut self) -> Result<usize> { + let peers: Vec<Nothing> = self.call("admin_peers", &EMPTY)?; + Ok(peers.len()) + } } pub struct RpcStream<T: Debug + DeserializeOwned> { @@ -353,7 +358,7 @@ pub struct Block { } #[derive(Debug, serde::Deserialize)] -pub struct BlockHead {} +pub struct Nothing {} /// Description of a Transaction, pending or in the chain. #[derive(Debug, Clone, serde::Deserialize)] diff --git a/test/btc/conflict.sh b/test/btc/conflict.sh @@ -48,7 +48,7 @@ taler-exchange-wire-gateway-client \ -b $BANK_ENDPOINT \ -C payto://bitcoin/$CLIENT \ -a BTC:0.005 > /dev/null -sleep 1 +sleep 5 restart_btc mine_btc check_balance 9.96299209 0.03698010 diff --git a/test/common.sh b/test/common.sh @@ -293,10 +293,9 @@ function eth_deco() { # Create a fork on the second node and reconnect the two node function eth_fork() { - sleep 5 # Sync before fork + sleep 2 # Sync before fork $WIRE_UTILS2 mine $RESERVE ${1:-} $WIRE_UTILS connect $WIRE_DIR2 - sleep 20 # Can take soooooo long for nodes to sync } # Restart an initialized geth dev node @@ -316,16 +315,7 @@ function restart_eth() { # Check client and wire balance function check_balance_eth() { - local CLIENT_BALANCE=`$WIRE_UTILS balance $CLIENT` - local WIRE_BALANCE=`$WIRE_UTILS balance $WIRE` - local CLIENT="${1:-*}" - if [ "$1" == "*" ]; then - local CLIENT="$CLIENT_BALANCE" - fi - if [ "$CLIENT_BALANCE" != "$CLIENT" ] || [ "$WIRE_BALANCE" != "${2:-$WIRE_BALANCE}" ]; then - echo "expected: client $CLIENT wire ${2:-$WIRE_BALANCE} got: client $CLIENT_BALANCE wire $WIRE_BALANCE" - exit 1 - fi + $WIRE_UTILS check-balance $CLIENT $1 $WIRE $2 } diff --git a/test/eth/reorg.sh b/test/eth/reorg.sh @@ -93,6 +93,7 @@ echo -n "Perform fork and check eth-wire hard error:" gateway_up eth_fork 10 check_balance_eth 999851500 148500 +sleep 5 # Wait for reconnect gateway_down echo " OK"