diff --git a/Cargo.lock b/Cargo.lock index 61747d8a..68649f9c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -854,7 +854,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "grin_api" version = "4.0.0-alpha.1" -source = "git+https://github.com/mimblewimble/grin#5f5b1d2f135ab375d42c2efaf2477d8e180ae439" +source = "git+https://github.com/mimblewimble/grin#ee5fe1ac63c1b383350ded855db2f44c5ce0f555" dependencies = [ "bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "easy-jsonrpc-mw 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -887,7 +887,7 @@ dependencies = [ [[package]] name = "grin_chain" version = "4.0.0-alpha.1" -source = "git+https://github.com/mimblewimble/grin#5f5b1d2f135ab375d42c2efaf2477d8e180ae439" +source = "git+https://github.com/mimblewimble/grin#ee5fe1ac63c1b383350ded855db2f44c5ce0f555" dependencies = [ "bit-vec 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -910,7 +910,7 @@ dependencies = [ [[package]] name = "grin_core" version = "4.0.0-alpha.1" -source = "git+https://github.com/mimblewimble/grin#5f5b1d2f135ab375d42c2efaf2477d8e180ae439" +source = "git+https://github.com/mimblewimble/grin#ee5fe1ac63c1b383350ded855db2f44c5ce0f555" dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -936,7 +936,7 @@ dependencies = [ [[package]] name = "grin_keychain" version = "4.0.0-alpha.1" -source = "git+https://github.com/mimblewimble/grin#5f5b1d2f135ab375d42c2efaf2477d8e180ae439" +source = "git+https://github.com/mimblewimble/grin#ee5fe1ac63c1b383350ded855db2f44c5ce0f555" dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -958,7 +958,7 @@ dependencies = [ [[package]] name = "grin_p2p" version = "4.0.0-alpha.1" -source = "git+https://github.com/mimblewimble/grin#5f5b1d2f135ab375d42c2efaf2477d8e180ae439" +source = "git+https://github.com/mimblewimble/grin#ee5fe1ac63c1b383350ded855db2f44c5ce0f555" dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -979,7 +979,7 @@ dependencies = [ [[package]] name = "grin_pool" version = "4.0.0-alpha.1" -source = "git+https://github.com/mimblewimble/grin#5f5b1d2f135ab375d42c2efaf2477d8e180ae439" +source = "git+https://github.com/mimblewimble/grin#ee5fe1ac63c1b383350ded855db2f44c5ce0f555" dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1012,7 +1012,7 @@ dependencies = [ [[package]] name = "grin_store" version = "4.0.0-alpha.1" -source = "git+https://github.com/mimblewimble/grin#5f5b1d2f135ab375d42c2efaf2477d8e180ae439" +source = "git+https://github.com/mimblewimble/grin#ee5fe1ac63c1b383350ded855db2f44c5ce0f555" dependencies = [ "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "croaring 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1032,7 +1032,7 @@ dependencies = [ [[package]] name = "grin_util" version = "4.0.0-alpha.1" -source = "git+https://github.com/mimblewimble/grin#5f5b1d2f135ab375d42c2efaf2477d8e180ae439" +source = "git+https://github.com/mimblewimble/grin#ee5fe1ac63c1b383350ded855db2f44c5ce0f555" dependencies = [ "backtrace 0.3.44 (registry+https://github.com/rust-lang/crates.io-index)", "base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/controller/tests/accounts.rs b/controller/tests/accounts.rs index 799d1b35..b3eb2f2f 100644 --- a/controller/tests/accounts.rs +++ b/controller/tests/accounts.rs @@ -25,6 +25,7 @@ use self::keychain::{ExtKeychain, Keychain}; use grin_wallet_libwallet as libwallet; use impls::test_framework::{self, LocalWalletClient}; use libwallet::InitTxArgs; +use std::sync::atomic::Ordering; use std::thread; use std::time::Duration; @@ -37,6 +38,7 @@ fn accounts_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> { // Create a new proxy to simulate server and wallet responses let mut wallet_proxy = create_wallet_proxy(test_dir); let chain = wallet_proxy.chain.clone(); + let stopper = wallet_proxy.running.clone(); create_wallet_and_add!( client1, @@ -258,6 +260,7 @@ fn accounts_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> { })?; // let logging finish + stopper.store(false, Ordering::Relaxed); thread::sleep(Duration::from_millis(200)); Ok(()) } diff --git a/controller/tests/check.rs b/controller/tests/check.rs index e28c6257..e37f922a 100644 --- a/controller/tests/check.rs +++ b/controller/tests/check.rs @@ -26,6 +26,7 @@ use grin_wallet_libwallet as libwallet; use impls::test_framework::{self, LocalWalletClient}; use impls::{PathToSlate, SlatePutter as _}; use libwallet::{InitTxArgs, NodeClient}; +use std::sync::atomic::Ordering; use std::thread; use std::time::Duration; use util::ZeroingString; @@ -51,6 +52,7 @@ fn scan_impl(test_dir: &'static str) -> Result<(), libwallet::Error> { // Create a new proxy to simulate server and wallet responses let mut wallet_proxy = create_wallet_proxy(test_dir); let chain = wallet_proxy.chain.clone(); + let stopper = wallet_proxy.running.clone(); // Create a new wallet test client, and set its queues to communicate with the // proxy @@ -215,12 +217,12 @@ fn scan_impl(test_dir: &'static str) -> Result<(), libwallet::Error> { })?; // let logging finish + stopper.store(false, Ordering::Relaxed); thread::sleep(Duration::from_millis(200)); Ok(()) } fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Error> { - setup(test_dir); let seed_phrase = "affair pistol cancel crush garment candy ancient flag work \ market crush dry stand focus mutual weapon offer ceiling rival turn team spring \ where swift"; @@ -229,6 +231,7 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er // Create a new proxy to simulate server and wallet responses let mut wallet_proxy = create_wallet_proxy(test_dir); let chain = wallet_proxy.chain.clone(); + let stopper = wallet_proxy.running.clone(); // Create a new wallet test client, and set its queues to communicate with the // proxy @@ -752,6 +755,7 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er })?; // let logging finish + stopper.store(false, Ordering::Relaxed); thread::sleep(Duration::from_millis(200)); Ok(()) } @@ -761,6 +765,7 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er fn output_scanning_impl(test_dir: &'static str) -> Result<(), libwallet::Error> { let mut wallet_proxy = create_wallet_proxy(test_dir); let chain = wallet_proxy.chain.clone(); + let stopper = wallet_proxy.running.clone(); // Create a new wallet test client, and set its queues to communicate with the // proxy create_wallet_and_add!( @@ -836,6 +841,9 @@ fn output_scanning_impl(test_dir: &'static str) -> Result<(), libwallet::Error> assert_eq!(outputs.2.len(), 16); } + // let logging finish + stopper.store(false, Ordering::Relaxed); + thread::sleep(Duration::from_millis(200)); Ok(()) } diff --git a/controller/tests/common/mod.rs b/controller/tests/common/mod.rs index 84147faa..106daeeb 100644 --- a/controller/tests/common/mod.rs +++ b/controller/tests/common/mod.rs @@ -75,7 +75,10 @@ macro_rules! open_wallet_and_add { }; } pub fn clean_output_dir(test_dir: &str) { - let _ = fs::remove_dir_all(test_dir); + let path = std::path::Path::new(test_dir); + if path.is_dir() { + fs::remove_dir_all(test_dir).unwrap(); + } } pub fn setup(test_dir: &str) { diff --git a/controller/tests/file.rs b/controller/tests/file.rs index 88a35115..e7b2ed61 100644 --- a/controller/tests/file.rs +++ b/controller/tests/file.rs @@ -22,6 +22,7 @@ use grin_wallet_util::grin_core as core; use impls::test_framework::{self, LocalWalletClient}; use impls::{PathToSlate, SlateGetter as _, SlatePutter as _}; +use std::sync::atomic::Ordering; use std::thread; use std::time::Duration; @@ -38,6 +39,7 @@ fn file_exchange_test_impl(test_dir: &'static str) -> Result<(), libwallet::Erro // Create a new proxy to simulate server and wallet responses let mut wallet_proxy = create_wallet_proxy(test_dir); let chain = wallet_proxy.chain.clone(); + let stopper = wallet_proxy.running.clone(); // Create a new wallet test client, and set its queues to communicate with the // proxy @@ -215,6 +217,7 @@ fn file_exchange_test_impl(test_dir: &'static str) -> Result<(), libwallet::Erro })?; // let logging finish + stopper.store(false, Ordering::Relaxed); thread::sleep(Duration::from_millis(200)); Ok(()) } diff --git a/controller/tests/invoice.rs b/controller/tests/invoice.rs index d846e6df..215e69a9 100644 --- a/controller/tests/invoice.rs +++ b/controller/tests/invoice.rs @@ -22,6 +22,7 @@ use grin_wallet_util::grin_core as core; use impls::test_framework::{self, LocalWalletClient}; use libwallet::{InitTxArgs, IssueInvoiceTxArgs, Slate}; +use std::sync::atomic::Ordering; use std::thread; use std::time::Duration; @@ -34,6 +35,7 @@ fn invoice_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> { // Create a new proxy to simulate server and wallet responses let mut wallet_proxy = create_wallet_proxy(test_dir); let chain = wallet_proxy.chain.clone(); + let stopper = wallet_proxy.running.clone(); create_wallet_and_add!( client1, @@ -201,6 +203,7 @@ fn invoice_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> { //bh += 3; // let logging finish + stopper.store(false, Ordering::Relaxed); thread::sleep(Duration::from_millis(200)); Ok(()) diff --git a/controller/tests/no_change.rs b/controller/tests/no_change.rs index e5b35066..245f7d3f 100644 --- a/controller/tests/no_change.rs +++ b/controller/tests/no_change.rs @@ -22,6 +22,7 @@ use grin_wallet_util::grin_core as core; use grin_wallet_libwallet as libwallet; use impls::test_framework::{self, LocalWalletClient}; use libwallet::{InitTxArgs, IssueInvoiceTxArgs, Slate}; +use std::sync::atomic::Ordering; use std::thread; use std::time::Duration; @@ -32,6 +33,7 @@ use common::{clean_output_dir, create_wallet_proxy, setup}; fn no_change_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> { let mut wallet_proxy = create_wallet_proxy(test_dir); let chain = wallet_proxy.chain.clone(); + let stopper = wallet_proxy.running.clone(); create_wallet_and_add!( client1, @@ -153,6 +155,7 @@ fn no_change_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> { })?; // let logging finish + stopper.store(false, Ordering::Relaxed); thread::sleep(Duration::from_millis(200)); Ok(()) } diff --git a/controller/tests/payment_proofs.rs b/controller/tests/payment_proofs.rs index 3e76d916..66e13994 100644 --- a/controller/tests/payment_proofs.rs +++ b/controller/tests/payment_proofs.rs @@ -21,6 +21,7 @@ extern crate grin_wallet_util; use grin_wallet_libwallet as libwallet; use impls::test_framework::{self, LocalWalletClient}; use libwallet::{InitTxArgs, Slate}; +use std::sync::atomic::Ordering; use std::thread; use std::time::Duration; @@ -35,6 +36,7 @@ fn payment_proofs_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err // Create a new proxy to simulate server and wallet responses let mut wallet_proxy = create_wallet_proxy(test_dir); let chain = wallet_proxy.chain.clone(); + let stopper = wallet_proxy.running.clone(); create_wallet_and_add!( client1, @@ -157,6 +159,7 @@ fn payment_proofs_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err })?; // let logging finish + stopper.store(false, Ordering::Relaxed); thread::sleep(Duration::from_millis(200)); Ok(()) } diff --git a/controller/tests/repost.rs b/controller/tests/repost.rs index 3e1e3ccb..fca444d1 100644 --- a/controller/tests/repost.rs +++ b/controller/tests/repost.rs @@ -23,6 +23,7 @@ use grin_wallet_util::grin_core as core; use self::libwallet::{InitTxArgs, Slate}; use impls::test_framework::{self, LocalWalletClient}; use impls::{PathToSlate, SlateGetter as _, SlatePutter as _}; +use std::sync::atomic::Ordering; use std::thread; use std::time::Duration; @@ -35,6 +36,7 @@ fn file_repost_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> // Create a new proxy to simulate server and wallet responses let mut wallet_proxy = create_wallet_proxy(test_dir); let chain = wallet_proxy.chain.clone(); + let stopper = wallet_proxy.running.clone(); // Create a new wallet test client, and set its queues to communicate with the // proxy @@ -248,6 +250,7 @@ fn file_repost_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> })?; // let logging finish + stopper.store(false, Ordering::Relaxed); thread::sleep(Duration::from_millis(200)); Ok(()) } diff --git a/controller/tests/self_send.rs b/controller/tests/self_send.rs index d95e26bf..b878d01b 100644 --- a/controller/tests/self_send.rs +++ b/controller/tests/self_send.rs @@ -22,6 +22,7 @@ use grin_wallet_util::grin_core as core; use grin_wallet_libwallet as libwallet; use impls::test_framework::{self, LocalWalletClient}; use libwallet::InitTxArgs; +use std::sync::atomic::Ordering; use std::thread; use std::time::Duration; @@ -34,6 +35,7 @@ fn self_send_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> { // Create a new proxy to simulate server and wallet responses let mut wallet_proxy = create_wallet_proxy(test_dir); let chain = wallet_proxy.chain.clone(); + let stopper = wallet_proxy.running.clone(); // Create a new wallet test client, and set its queues to communicate with the // proxy @@ -130,6 +132,7 @@ fn self_send_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> { })?; // let logging finish + stopper.store(false, Ordering::Relaxed); thread::sleep(Duration::from_millis(200)); Ok(()) } diff --git a/controller/tests/transaction.rs b/controller/tests/transaction.rs index 64a2e324..86c77f67 100644 --- a/controller/tests/transaction.rs +++ b/controller/tests/transaction.rs @@ -24,6 +24,7 @@ use self::core::core::transaction; use self::core::global; use self::libwallet::{InitTxArgs, OutputStatus, Slate}; use impls::test_framework::{self, LocalWalletClient}; +use std::sync::atomic::Ordering; use std::thread; use std::time::Duration; @@ -37,6 +38,7 @@ fn basic_transaction_api(test_dir: &'static str) -> Result<(), libwallet::Error> // Create a new proxy to simulate server and wallet responses let mut wallet_proxy = create_wallet_proxy(test_dir); let chain = wallet_proxy.chain.clone(); + let stopper = wallet_proxy.running.clone(); create_wallet_and_add!( client1, @@ -338,6 +340,7 @@ fn basic_transaction_api(test_dir: &'static str) -> Result<(), libwallet::Error> })?; // let logging finish + stopper.store(false, Ordering::Relaxed); thread::sleep(Duration::from_millis(200)); Ok(()) } @@ -348,6 +351,7 @@ fn tx_rollback(test_dir: &'static str) -> Result<(), libwallet::Error> { // Create a new proxy to simulate server and wallet responses let mut wallet_proxy = create_wallet_proxy(test_dir); let chain = wallet_proxy.chain.clone(); + let stopper = wallet_proxy.running.clone(); create_wallet_and_add!( client1, @@ -515,6 +519,7 @@ fn tx_rollback(test_dir: &'static str) -> Result<(), libwallet::Error> { })?; // let logging finish + stopper.store(false, Ordering::Relaxed); thread::sleep(Duration::from_millis(200)); Ok(()) } diff --git a/controller/tests/ttl_cutoff.rs b/controller/tests/ttl_cutoff.rs index 33de904d..4ee1cd92 100644 --- a/controller/tests/ttl_cutoff.rs +++ b/controller/tests/ttl_cutoff.rs @@ -21,6 +21,7 @@ extern crate grin_wallet_util; use grin_wallet_libwallet as libwallet; use impls::test_framework::{self, LocalWalletClient}; use libwallet::{InitTxArgs, Slate, TxLogEntryType}; +use std::sync::atomic::Ordering; use std::thread; use std::time::Duration; @@ -33,6 +34,7 @@ fn ttl_cutoff_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> // Create a new proxy to simulate server and wallet responses let mut wallet_proxy = create_wallet_proxy(test_dir); let chain = wallet_proxy.chain.clone(); + let stopper = wallet_proxy.running.clone(); create_wallet_and_add!( client1, @@ -167,6 +169,7 @@ fn ttl_cutoff_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> })?; // let logging finish + stopper.store(false, Ordering::Relaxed); thread::sleep(Duration::from_millis(200)); Ok(()) } diff --git a/controller/tests/updater_thread.rs b/controller/tests/updater_thread.rs index f9564f09..0e8f5094 100644 --- a/controller/tests/updater_thread.rs +++ b/controller/tests/updater_thread.rs @@ -23,6 +23,7 @@ extern crate grin_wallet_libwallet as libwallet; // use grin_wallet_util::grin_core as core; use impls::test_framework::{self, LocalWalletClient}; +use std::sync::atomic::Ordering; use std::thread; use std::time::Duration; @@ -35,6 +36,7 @@ fn updater_thread_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err // Create a new proxy to simulate server and wallet responses let mut wallet_proxy = create_wallet_proxy(test_dir); let chain = wallet_proxy.chain.clone(); + let stopper = wallet_proxy.running.clone(); // Create a new wallet test client, and set its queues to communicate with the // proxy @@ -101,6 +103,7 @@ fn updater_thread_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err assert_eq!(messages.len(), 32); owner_api.stop_updater()?; + stopper.store(false, Ordering::Relaxed); thread::sleep(Duration::from_secs(2)); Ok(()) } diff --git a/impls/src/test_framework/mod.rs b/impls/src/test_framework/mod.rs index 73e290df..cfd4df02 100644 --- a/impls/src/test_framework/mod.rs +++ b/impls/src/test_framework/mod.rs @@ -43,7 +43,7 @@ fn get_output_local(chain: &chain::Chain, commit: &pedersen::Commitment) -> Opti ]; for x in outputs.iter() { - if chain.is_unspent(&x).is_ok() { + if chain.get_unspent(&x).unwrap().is_some() { let block_height = chain.get_header_for_output(&x).unwrap().height; let output_pos = chain.get_output_pos(&x.commit).unwrap_or(0); return Some(api::Output::new(&commit, block_height, output_pos)); diff --git a/impls/src/test_framework/testclient.rs b/impls/src/test_framework/testclient.rs index 8b6ddf11..3245fc34 100644 --- a/impls/src/test_framework/testclient.rs +++ b/impls/src/test_framework/testclient.rs @@ -139,8 +139,16 @@ where self.running.store(true, Ordering::Relaxed); loop { thread::sleep(Duration::from_millis(10)); + if !self.running.load(Ordering::Relaxed) { + info!("Proxy stopped"); + return Ok(()); + } + // read queue - let m = self.rx.recv().unwrap(); + let m = match self.rx.recv_timeout(Duration::from_millis(10)) { + Ok(m) => m, + Err(_) => continue, + }; trace!("Wallet Client Proxy Received: {:?}", m); let resp = match m.method.as_ref() { "get_chain_tip" => self.get_chain_tip(m)?, @@ -154,9 +162,6 @@ where }; self.respond(resp); - if !self.running.load(Ordering::Relaxed) { - return Ok(()); - } } }