depolymerization

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

commit 4afbaca386c7591ac4a9bb657ec375bf7cb153e6
parent 6efc2a939ab2b37f8e08678e168c9bf805afdeca
Author: Antoine A <>
Date:   Sat, 30 Jul 2022 17:47:53 +0200

Improve tests

Diffstat:
MCargo.lock | 96++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mbtc-wire/src/main.rs | 9+++------
Minstrumentation/src/btc.rs | 29++++++++++++-----------------
Minstrumentation/src/eth.rs | 4+++-
Minstrumentation/src/main.rs | 35+++++++++++++++++++++++++----------
Mscript/prepare.sh | 4++--
Mscript/tmp_db.sh | 0
Mwire-gateway/Cargo.toml | 2+-
8 files changed, 94 insertions(+), 85 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -159,7 +159,7 @@ dependencies = [ "base64", "bech32 0.9.0", "bitcoin", - "clap 3.2.13", + "clap 3.2.16", "common", "criterion", "hex", @@ -184,9 +184,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" [[package]] name = "cast" @@ -237,9 +237,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.13" +version = "3.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac2bd7a1eb07da9ac757c923f69373deb7bc2ba5efc951b873bcb5e693992dca" +checksum = "a3dbbb6653e7c55cc8595ad3e1f7be8f32aba4eb7ff7f0fd1163d4f3d137c0a9" dependencies = [ "atty", "bitflags", @@ -254,9 +254,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "3.2.7" +version = "3.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759bf187376e1afa7b85b959e6a664a3e7a95203415dba952ad19139e798f902" +checksum = "9ba52acd3b0a5c33aeada5cdaa3267cdc7c594a98731d4268cdc1532f4264cb4" dependencies = [ "heck", "proc-macro-error", @@ -280,7 +280,7 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "937efe4451c32be4ccb3e19549cbb1ea5cb85197f39b87a9662ca1d7b1765d1d" dependencies = [ - "clap 3.2.13", + "clap 3.2.16", "roff", ] @@ -371,9 +371,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.5" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c02a4d71819009c192cf4872265391563fd6a84c81ff2c0f2a7026ca4c1d85c" +checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" dependencies = [ "cfg-if", "crossbeam-utils", @@ -381,9 +381,9 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" +checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" dependencies = [ "cfg-if", "crossbeam-epoch", @@ -392,9 +392,9 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07db9d94cbd326813772c968ccd25999e5f8ae22f4f8d1b11effa37ef6ce281d" +checksum = "045ebe27666471bb549370b4b0b3e51b07f56325befa4284db65fc89c02511b1" dependencies = [ "autocfg", "cfg-if", @@ -406,9 +406,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.10" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d82ee10ce34d7bc12c2122495e7593a9c41347ecdd64185af4ecf72cb1a7f83" +checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" dependencies = [ "cfg-if", "once_cell", @@ -558,7 +558,7 @@ dependencies = [ name = "eth-wire" version = "0.1.0" dependencies = [ - "clap 3.2.13", + "clap 3.2.16", "common", "ethereum-types", "hex", @@ -601,9 +601,9 @@ checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" [[package]] name = "fastrand" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" +checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" dependencies = [ "instant", ] @@ -948,7 +948,7 @@ version = "0.1.0" dependencies = [ "bitcoin", "btc-wire", - "clap 3.2.13", + "clap 3.2.16", "clap_mangen", "color-backtrace", "common", @@ -985,9 +985,9 @@ checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" [[package]] name = "js-sys" -version = "0.3.58" +version = "0.3.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fac17f7123a73ca62df411b1bf727ccc805daa070338fda671c86dac1bdc27" +checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" dependencies = [ "wasm-bindgen", ] @@ -1377,9 +1377,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.40" +version = "1.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" +checksum = "c278e965f1d8cf32d6e0e96de3d3e79712178ae67986d9cf9151f51e95aac89b" dependencies = [ "unicode-ident", ] @@ -1471,9 +1471,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.13" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ "bitflags", ] @@ -1912,9 +1912,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.20.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57aec3cfa4c296db7255446efb4928a6be304b431a806216105542a67b6ca82e" +checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" dependencies = [ "autocfg", "bytes", @@ -1985,9 +1985,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.35" +version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" +checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" dependencies = [ "cfg-if", "pin-project-lite", @@ -1996,9 +1996,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.28" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7" +checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" dependencies = [ "once_cell", ] @@ -2147,9 +2147,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994" +checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -2157,13 +2157,13 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a" +checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" dependencies = [ "bumpalo", - "lazy_static", "log", + "once_cell", "proc-macro2", "quote", "syn", @@ -2172,9 +2172,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa" +checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2182,9 +2182,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" +checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" dependencies = [ "proc-macro2", "quote", @@ -2195,15 +2195,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" +checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" [[package]] name = "web-sys" -version = "0.3.58" +version = "0.3.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90" +checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" dependencies = [ "js-sys", "wasm-bindgen", @@ -2307,7 +2307,7 @@ name = "wire-gateway" version = "0.1.0" dependencies = [ "bitcoin", - "clap 3.2.13", + "clap 3.2.16", "common", "deadpool-postgres", "ethereum-types", @@ -2326,6 +2326,6 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.5.6" +version = "1.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20b578acffd8516a6c3f2a1bdefc1ec37e547bb4e0fb8b6b01a4cafc886b4442" +checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f" diff --git a/btc-wire/src/main.rs b/btc-wire/src/main.rs @@ -30,10 +30,7 @@ use common::{ use loops::LoopResult; use std::path::PathBuf; -use crate::{ - loops::{analysis::analysis, watcher::watcher, worker::worker}, - sql::sql_addr, -}; +use crate::loops::{analysis::analysis, watcher::watcher, worker::worker}; mod fail_point; mod loops; @@ -113,7 +110,7 @@ fn init(config: Option<PathBuf>, init: Init) -> LoopResult<()> { // TODO Use address label instead of the database ? let prev_addr = db.query_opt("SELECT value FROM state WHERE name = 'addr'", &[])?; let addr = if let Some(row) = prev_addr { - sql_addr(&row, 0) + String::from_utf8(row.get(0)).unwrap() } else { // Or generate a new one let new = Rpc::wallet(&btc_conf, WIRE_WALLET_NAME) @@ -123,7 +120,7 @@ fn init(config: Option<PathBuf>, init: Init) -> LoopResult<()> { "INSERT INTO state (name, value) VALUES ('addr', $1)", &[&new.to_string().as_bytes()], )?; - new + new.to_string() }; if created { diff --git a/instrumentation/src/btc.rs b/instrumentation/src/btc.rs @@ -26,7 +26,7 @@ use std::{ use bitcoin::{hashes::Hash, Address, Amount, BlockHash, Network, SignedAmount, Txid}; use btc_wire::{ btc_config::BitcoinConfig, - rpc::{self, Category, ErrorCode, Rpc, Transaction}, + rpc::{self, Category, ErrorCode, Rpc}, rpc_utils::{self, segwit_min_amount}, taler_utils::{btc_payto_url, btc_to_taler}, WireState, @@ -68,16 +68,14 @@ fn wait_for_pending(since: &mut BlockHash, client_rpc: &mut Rpc, wire_rpc: &mut println!(); } -pub fn btc_test(config: Option<&Path>, base_url: &str) { +pub fn online_test(config: Option<&Path>, base_url: &str) { let state = WireState::load_taler_config(config); if state.btc_config.network == Network::Bitcoin { panic!("You should never run this test on a real bitcoin network"); } + let mut rpc = Rpc::common(&state.btc_config).expect("Cannot connect to bitcoin node"); - let min_fund = Amount::from_sat(10_000); - - let mut rpc = Rpc::common(&state.btc_config).unwrap(); // Load client match rpc.load_wallet(CLIENT) { Ok(_) => {} @@ -95,6 +93,7 @@ pub fn btc_test(config: Option<&Path>, base_url: &str) { }; let mut client_rpc = Rpc::wallet(&state.btc_config, CLIENT).unwrap(); let client_addr = client_rpc.gen_addr().unwrap(); + let min_fund = Amount::from_sat(10_000); if client_rpc.get_balance().unwrap() < min_fund { println!( "Client need a minimum of {} BTC to run this test, send coins to this address: {}", @@ -152,18 +151,18 @@ pub fn btc_test(config: Option<&Path>, base_url: &str) { ); print_now("Wait for bounce:"); - let bounce: Transaction = 'l: loop { + 'l: loop { let sync = client_rpc.list_since_block(Some(&since), 1).unwrap(); for tx in sync.transactions { if tx.category == Category::Receive { - let (tx, metadata) = client_rpc.get_tx_op_return(&tx.txid).unwrap(); + let (_, metadata) = client_rpc.get_tx_op_return(&tx.txid).unwrap(); let metadata = OutMetadata::decode(&metadata).unwrap(); match metadata { OutMetadata::Debit { .. } => {} OutMetadata::Bounce { bounced } => { let bounced = Txid::from_inner(bounced); if bounced == bounce_id { - break 'l tx; + break 'l; } else if bounced == send_min_id { panic!("Bounced send min"); } else if bounced == bounce_min_id { @@ -176,20 +175,16 @@ pub fn btc_test(config: Option<&Path>, base_url: &str) { since = sync.lastblock; rpc.wait_for_new_block().unwrap(); print_now("."); - }; + } println!(); wait_for_pending(&mut since, &mut client_rpc, &mut wire_rpc); println!("Check balance"); - let new_client_balance = client_rpc.get_balance().unwrap(); let new_wire_balance = wire_rpc.get_balance().unwrap(); - assert_eq!( - client_balance - client_sent_amount_cost - client_sent_fees_cost + unsigned(bounce.amount), - new_client_balance - ); - assert_eq!( - wire_balance + test_amount + min_bounce_amount + min_send_amount + state.bounce_fee, - new_wire_balance + let new_client_balance = client_rpc.get_balance().unwrap(); + assert!(new_wire_balance > wire_balance + test_amount + min_bounce_amount + min_send_amount); + assert!( + new_wire_balance < wire_balance + test_amount * 2 + min_bounce_amount + min_send_amount ); println!("Check incoming history"); diff --git a/instrumentation/src/eth.rs b/instrumentation/src/eth.rs @@ -48,7 +48,7 @@ fn wait_for_pending(rpc: &mut Rpc) { println!(); } -pub fn eth_test(config: Option<&Path>, base_url: &str) { +pub fn online_test(config: Option<&Path>, base_url: &str) { let state = WireState::load_taler_config(config); // TODO eth network check let min_fund = U256::from(100_000 * TRUNC); @@ -438,6 +438,8 @@ impl EthCtx { &[ "--datadir", self.dirs.wire_dir2.to_str().unwrap(), + "--authrpc.port", + "8552", "--port", "30305", "--miner.gasprice", diff --git a/instrumentation/src/main.rs b/instrumentation/src/main.rs @@ -16,10 +16,8 @@ use std::{path::PathBuf, time::Instant}; -use btc::btc_test; use clap::StructOpt; use common::{config::TalerConfig, currency::Currency}; -use eth::eth_test; use owo_colors::OwoColorize; mod btc; @@ -43,9 +41,20 @@ enum Cmd { config: Option<PathBuf>, }, /// Perform offline tests on local private blockchain - Offline, + Offline { + /// With tests to run + #[clap( + global = true, + possible_values(TESTS_KIND), + case_insensitive = true, + default_value = "all" + )] + kind: String, + }, } +const TESTS_KIND: &[&str] = &["all", "gateway", "bitcoin", "btc", "ethereum", "eth"]; + pub fn main() { common::log::init(); color_backtrace::install(); @@ -54,19 +63,25 @@ pub fn main() { match args.cmd { Cmd::Online { config } => { let taler_config = TalerConfig::load(config.as_deref()); - let base_url = format!("http://localhost:{}", taler_config.port()); + let base_url = format!("http://localhost:{}/", taler_config.port()); match taler_config.currency { - Currency::BTC(_) => btc_test(config.as_deref(), &base_url), - Currency::ETH(_) => eth_test(config.as_deref(), &base_url), + Currency::BTC(_) => btc::online_test(config.as_deref(), &base_url), + Currency::ETH(_) => eth::online_test(config.as_deref(), &base_url), } println!("Instrumentation test successful"); } - Cmd::Offline => { + Cmd::Offline { kind } => { let mut tests = Vec::new(); - tests.extend_from_slice(gateway::TESTS); - tests.extend_from_slice(btc::TESTS); - tests.extend_from_slice(eth::TESTS); + if kind == "all" || kind == "gateway" { + tests.extend_from_slice(gateway::TESTS); + } + if kind == "all" || kind == "bitcoin" || kind == "btc" { + tests.extend_from_slice(btc::TESTS); + } + if kind == "all" || kind == "ethereum" || kind == "eth" { + tests.extend_from_slice(eth::TESTS); + } let start = Instant::now(); for (test, name) in &tests { let start = Instant::now(); diff --git a/script/prepare.sh b/script/prepare.sh @@ -30,11 +30,11 @@ mv -v bitcoin-23.0/* ~/bitcoin echo "Ⅲ - Install Go Ethereum (Geth) v1.10.20" cd $DIR -curl -L https://gethstore.blob.core.windows.net/builds/geth-alltools-linux-amd64-1.10.20-8f2416a8.tar.gz -o geth.tar.gz +curl -L https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.10.21-67109427.tar.gz -o geth.tar.gz rm -rfv ~/geth mkdir -pv ~/geth tar xvzf geth.tar.gz -mv -v geth-alltools-linux-amd64-1.10.20-8f2416a8/* ~/geth +mv -v geth-linux-amd64-1.10.21-67109427/* ~/geth echo "Ⅳ - PATH" diff --git a/script/tmp_db.sh b/script/tmp_db.sh diff --git a/wire-gateway/Cargo.toml b/wire-gateway/Cargo.toml @@ -33,7 +33,7 @@ listenfd = "1.0.0" common = { path = "../common" } # Bitcoin types bitcoin = { version = "0.28.1" } -# Euthereum types +# Ethereum types ethereum-types = { version = "0.13.1", default-features = false } # Cli args parser clap = { version = "3.2.13", features = ["derive"] }