From 1f613c0641d66a12558fc263b09ad4fd34ee9d58 Mon Sep 17 00:00:00 2001 From: yeastplume Date: Thu, 14 Feb 2019 13:40:29 +0000 Subject: [PATCH] move api into separate crate, integration tests working --- Cargo.lock | 36 ++++++++++++++ Cargo.toml | 3 +- apiwallet/Cargo.toml | 44 +++++++++++++++++ {libwallet => apiwallet}/src/api.rs | 20 ++++---- apiwallet/src/lib.rs | 37 +++++++++++++++ libwallet/Cargo.toml | 3 ++ libwallet/src/lib.rs | 1 - libwallet/tests/libwallet.rs | 23 +-------- refwallet/Cargo.toml | 1 + refwallet/src/controller.rs | 2 +- refwallet/src/lib.rs | 1 + refwallet/src/test_framework/mod.rs | 2 +- refwallet/tests/accounts.rs | 7 +-- refwallet/tests/check.rs | 7 +-- refwallet/tests/encryption.rs | 36 ++++++++++++++ refwallet/tests/file.rs | 6 ++- refwallet/tests/repost.rs | 5 +- refwallet/tests/restore.rs | 7 +-- refwallet/tests/self_send.rs | 4 +- refwallet/tests/transaction.rs | 7 +-- src/bin/cmd/wallet_tests.rs | 73 ++++++++++++----------------- src/bin/grin-wallet.rs | 1 + 22 files changed, 230 insertions(+), 96 deletions(-) create mode 100644 apiwallet/Cargo.toml rename {libwallet => apiwallet}/src/api.rs (98%) create mode 100644 apiwallet/src/lib.rs create mode 100644 refwallet/tests/encryption.rs diff --git a/Cargo.lock b/Cargo.lock index 0f150e96..7ebfb1c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -574,6 +574,39 @@ dependencies = [ "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "grin_apiwallet" +version = "1.1.0" +dependencies = [ + "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "grin_api 1.1.0", + "grin_chain 1.1.0", + "grin_core 1.1.0", + "grin_keychain 1.1.0", + "grin_libwallet 1.1.0", + "grin_store 1.1.0", + "grin_util 1.1.0", + "grin_wallet_config 1.1.0", + "hyper 0.12.19 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "prettytable-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)", + "term 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-retry 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "uuid 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "grin_chain" version = "1.1.0" @@ -653,6 +686,7 @@ dependencies = [ "grin_keychain 1.1.0", "grin_store 1.1.0", "grin_util 1.1.0", + "grin_wallet_config 1.1.0", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)", @@ -707,6 +741,7 @@ dependencies = [ "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "grin_api 1.1.0", + "grin_apiwallet 1.1.0", "grin_chain 1.1.0", "grin_core 1.1.0", "grin_keychain 1.1.0", @@ -797,6 +832,7 @@ dependencies = [ "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "grin_api 1.1.0", + "grin_apiwallet 1.1.0", "grin_chain 1.1.0", "grin_core 1.1.0", "grin_keychain 1.1.0", diff --git a/Cargo.toml b/Cargo.toml index 9147a93b..3ce63401 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ name = "grin-wallet" path = "src/bin/grin-wallet.rs" [workspace] -members = ["config", "libwallet", "refwallet"] +members = ["apiwallet", "config", "libwallet", "refwallet"] [dependencies] clap = { version = "2.31", features = ["yaml"] } @@ -44,6 +44,7 @@ uuid = { version = "0.6", features = ["serde", "v4"] } url = "1.7.0" chrono = { version = "0.4.4", features = ["serde"] } +grin_apiwallet = { path = "./apiwallet", version = "1.1.0" } grin_libwallet = { path = "./libwallet", version = "1.1.0" } grin_refwallet = { path = "./refwallet", version = "1.1.0" } grin_wallet_config = { path = "./config", version = "1.1.0" } diff --git a/apiwallet/Cargo.toml b/apiwallet/Cargo.toml new file mode 100644 index 00000000..86d21325 --- /dev/null +++ b/apiwallet/Cargo.toml @@ -0,0 +1,44 @@ +[package] +name = "grin_apiwallet" +version = "1.1.0" +authors = ["Grin Developers "] +description = "Simple, private and scalable cryptocurrency implementation based on the MimbleWimble chain format." +license = "Apache-2.0" +repository = "https://github.com/mimblewimble/grin" +keywords = [ "crypto", "grin", "mimblewimble" ] +readme = "README.md" +exclude = ["**/*.grin", "**/*.grin2"] +#build = "src/build/build.rs" +edition = "2018" + +[dependencies] +blake2-rfc = "0.2" +failure = "0.1" +failure_derive = "0.1" +futures = "0.1" +hyper = "0.12" +rand = "0.5" +serde = "1" +serde_derive = "1" +serde_json = "1" +log = "0.4" +prettytable-rs = "0.7" +ring = "0.13" +term = "0.5" +tokio = "= 0.1.11" +tokio-core = "0.1" +tokio-retry = "0.1" +uuid = { version = "0.6", features = ["serde", "v4"] } +url = "1.7.0" +chrono = { version = "0.4.4", features = ["serde"] } + +grin_libwallet = { path = "../libwallet", version = "1.1.0" } +grin_wallet_config = { path = "../config", version = "1.1.0" } +#grin_refwallet = { path = "../refwallet", version = "1.1.0" } + +grin_core = { path = "../../grin/core", version = "1.1.0" } +grin_keychain = { path = "../../grin/keychain", version = "1.1.0" } +grin_chain = { path = "../../grin/chain", version = "1.1.0" } +grin_util = { path = "../../grin/util", version = "1.1.0" } +grin_api = { path = "../../grin/api", version = "1.1.0" } +grin_store = { path = "../../grin/store", version = "1.1.0" } diff --git a/libwallet/src/api.rs b/apiwallet/src/api.rs similarity index 98% rename from libwallet/src/api.rs rename to apiwallet/src/api.rs index 4781988c..1130334f 100644 --- a/libwallet/src/api.rs +++ b/apiwallet/src/api.rs @@ -37,16 +37,16 @@ use uuid::Uuid; use crate::core::core::hash::Hashed; use crate::core::core::Transaction; use crate::core::ser; -use crate::internal::{keys, tx, updater}; +use crate::libwallet::internal::{keys, tx, updater}; use crate::keychain::{Identifier, Keychain}; -use crate::slate::Slate; -use crate::types::{ +use crate::libwallet::slate::Slate; +use crate::libwallet::types::{ AcctPathMapping, BlockFees, CbData, NodeClient, OutputData, OutputLockFn, TxLogEntry, TxLogEntryType, TxWrapper, WalletBackend, WalletInfo, }; use crate::util; use crate::util::secp::{pedersen, ContextFlag, Secp256k1}; -use crate::{Error, ErrorKind}; +use crate::libwallet::{Error, ErrorKind}; const USER_MESSAGE_MAX_LEN: usize = 256; @@ -87,7 +87,8 @@ where /// /// # Example /// ``` - /// # extern crate grin_wallet as wallet; + /// # extern crate grin_wallet_config as config; + /// # extern crate grin_refwallet as wallet; /// # extern crate grin_keychain as keychain; /// # extern crate grin_util as util; /// @@ -98,7 +99,8 @@ where /// use wallet::libwallet::api::APIOwner; /// /// // These contain sample implementations of each part needed for a wallet - /// use wallet::{LMDBBackend, HTTPNodeClient, WalletBackend, WalletConfig}; + /// use wallet::{LMDBBackend, HTTPNodeClient, WalletBackend}; + /// use config::WalletConfig; /// /// let mut wallet_config = WalletConfig::default(); /// # wallet_config.data_file_dir = "test_output/doc/wallet1".to_owned(); @@ -142,14 +144,16 @@ where /// # Example /// Set up as in [`new`](struct.APIOwner.html#method.new) method above. /// ``` - /// # extern crate grin_wallet as wallet; + /// # extern crate grin_wallet_config as config; + /// # extern crate grin_refwallet as wallet; /// # extern crate grin_keychain as keychain; /// # extern crate grin_util as util; /// # use std::sync::Arc; /// # use util::Mutex; /// # use keychain::ExtKeychain; /// # use wallet::libwallet::api::APIOwner; - /// # use wallet::{LMDBBackend, HTTPNodeClient, WalletBackend, WalletConfig}; + /// # use wallet::{LMDBBackend, HTTPNodeClient, WalletBackend}; + /// # use config::WalletConfig; /// # let mut wallet_config = WalletConfig::default(); /// # wallet_config.data_file_dir = "test_output/doc/wallet1".to_owned(); /// # let node_client = HTTPNodeClient::new(&wallet_config.check_node_api_http_addr, None); diff --git a/apiwallet/src/lib.rs b/apiwallet/src/lib.rs new file mode 100644 index 00000000..66e375b5 --- /dev/null +++ b/apiwallet/src/lib.rs @@ -0,0 +1,37 @@ +// Copyright 2019 The Grin Developers +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Higher level wallet functions which can be used by callers to operate +//! on the wallet, as well as helpers to invoke and instantiate wallets +//! and listeners + +#![deny(non_upper_case_globals)] +#![deny(non_camel_case_types)] +#![deny(non_snake_case)] +#![deny(unused_mut)] +#![warn(missing_docs)] + +extern crate grin_core as core; +extern crate grin_keychain as keychain; +extern crate grin_store as store; +extern crate grin_util as util; +extern crate grin_libwallet as libwallet; + +use failure; +extern crate failure_derive; + +#[macro_use] +extern crate log; + +pub mod api; diff --git a/libwallet/Cargo.toml b/libwallet/Cargo.toml index f2e22ec1..cf8b8e7a 100644 --- a/libwallet/Cargo.toml +++ b/libwallet/Cargo.toml @@ -27,3 +27,6 @@ grin_store = { path = "../../grin/store", version = "1.1.0" } grin_core = { path = "../../grin/core", version = "1.1.0" } grin_keychain = { path = "../../grin/keychain", version = "1.1.0" } grin_util = { path = "../../grin/util", version = "1.1.0" } + +[dev-dependencies] +grin_wallet_config = { path = "../config", version = "1.1.0" } diff --git a/libwallet/src/lib.rs b/libwallet/src/lib.rs index 5ef75a9f..28d33891 100644 --- a/libwallet/src/lib.rs +++ b/libwallet/src/lib.rs @@ -39,7 +39,6 @@ extern crate serde_derive; #[macro_use] extern crate log; -pub mod api; mod error; pub mod internal; pub mod slate; diff --git a/libwallet/tests/libwallet.rs b/libwallet/tests/libwallet.rs index 44447f50..1a1814b0 100644 --- a/libwallet/tests/libwallet.rs +++ b/libwallet/tests/libwallet.rs @@ -17,12 +17,10 @@ use self::core::libtx::{aggsig, proof}; use self::keychain::{BlindSum, BlindingFactor, ExtKeychain, Keychain}; use self::util::secp; use self::util::secp::key::{PublicKey, SecretKey}; -use self::wallet::libwallet::types::Context; -use self::wallet::{EncryptedWalletSeed, WalletSeed}; +use grin_libwallet::types::Context; use grin_core as core; use grin_keychain as keychain; use grin_util as util; -use grin_wallet as wallet; use rand::thread_rng; fn kernel_sig_msg() -> secp::Message { @@ -500,22 +498,3 @@ fn test_rewind_range_proof() { assert_eq!(proof_info.success, false); assert_eq!(proof_info.value, 0); } - -#[test] -fn wallet_seed_encrypt() { - let password = "passwoid"; - let wallet_seed = WalletSeed::init_new(32); - let mut enc_wallet_seed = EncryptedWalletSeed::from_seed(&wallet_seed, password).unwrap(); - println!("EWS: {:?}", enc_wallet_seed); - let decrypted_wallet_seed = enc_wallet_seed.decrypt(password).unwrap(); - assert_eq!(wallet_seed, decrypted_wallet_seed); - - // Wrong password - let decrypted_wallet_seed = enc_wallet_seed.decrypt(""); - assert!(decrypted_wallet_seed.is_err()); - - // Wrong nonce - enc_wallet_seed.nonce = "wrongnonce".to_owned(); - let decrypted_wallet_seed = enc_wallet_seed.decrypt(password); - assert!(decrypted_wallet_seed.is_err()); -} diff --git a/refwallet/Cargo.toml b/refwallet/Cargo.toml index 484ed6f4..bf56362d 100644 --- a/refwallet/Cargo.toml +++ b/refwallet/Cargo.toml @@ -32,6 +32,7 @@ uuid = { version = "0.6", features = ["serde", "v4"] } url = "1.7.0" chrono = { version = "0.4.4", features = ["serde"] } +grin_apiwallet = { path = "../apiwallet", version = "1.1.0" } grin_libwallet = { path = "../libwallet", version = "1.1.0" } grin_wallet_config = { path = "../config", version = "1.1.0" } diff --git a/refwallet/src/controller.rs b/refwallet/src/controller.rs index 18e64936..ca96498b 100644 --- a/refwallet/src/controller.rs +++ b/refwallet/src/controller.rs @@ -21,7 +21,7 @@ use crate::api::{ApiServer, BasicAuthMiddleware, Handler, ResponseFuture, Router use crate::core::core; use crate::core::core::Transaction; use crate::keychain::Keychain; -use crate::libwallet::api::{APIForeign, APIOwner}; +use crate::apiwallet::api::{APIForeign, APIOwner}; use crate::libwallet::slate::{Slate, VersionedSlate}; use crate::libwallet::types::{ CbData, NodeClient, OutputData, SendTXArgs, TxLogEntry, WalletBackend, WalletInfo, diff --git a/refwallet/src/lib.rs b/refwallet/src/lib.rs index 97258042..194e1a47 100644 --- a/refwallet/src/lib.rs +++ b/refwallet/src/lib.rs @@ -28,6 +28,7 @@ use grin_api as api; extern crate grin_core as core; use grin_keychain as keychain; use grin_libwallet as libwallet; +use grin_apiwallet as apiwallet; use grin_store as store; use grin_util as util; extern crate grin_wallet_config as config; diff --git a/refwallet/src/test_framework/mod.rs b/refwallet/src/test_framework/mod.rs index 029dff57..48f788ab 100644 --- a/refwallet/src/test_framework/mod.rs +++ b/refwallet/src/test_framework/mod.rs @@ -17,7 +17,7 @@ use self::core::core::{OutputFeatures, OutputIdentifier, Transaction}; use self::core::{consensus, global, pow, ser}; use self::util::secp::pedersen; use self::util::Mutex; -use crate::libwallet::api::APIOwner; +use crate::apiwallet::api::APIOwner; use crate::libwallet::types::{BlockFees, CbData, NodeClient, WalletInfo, WalletInst}; use crate::lmdb_wallet::LMDBBackend; use crate::{controller, libwallet, WalletSeed}; diff --git a/refwallet/tests/accounts.rs b/refwallet/tests/accounts.rs index 98340c0d..3798afa6 100644 --- a/refwallet/tests/accounts.rs +++ b/refwallet/tests/accounts.rs @@ -14,20 +14,21 @@ //! tests differing accounts in the same wallet #[macro_use] extern crate log; +extern crate grin_refwallet as wallet; use self::core::global; use self::core::global::ChainTypes; use self::keychain::{ExtKeychain, Keychain}; -use self::wallet::libwallet; -use self::wallet::test_framework::{self, LocalWalletClient, WalletProxy}; use grin_core as core; use grin_keychain as keychain; use grin_util as util; -use grin_wallet as wallet; +use grin_libwallet as libwallet; +use wallet::test_framework::{self, LocalWalletClient, WalletProxy}; use std::fs; use std::thread; use std::time::Duration; + fn clean_output_dir(test_dir: &str) { let _ = fs::remove_dir_all(test_dir); } diff --git a/refwallet/tests/check.rs b/refwallet/tests/check.rs index 8e46d70c..0726d880 100644 --- a/refwallet/tests/check.rs +++ b/refwallet/tests/check.rs @@ -14,17 +14,18 @@ //! tests differing accounts in the same wallet #[macro_use] extern crate log; +extern crate grin_refwallet as wallet; use self::core::consensus; use self::core::global; use self::core::global::ChainTypes; use self::keychain::ExtKeychain; -use self::wallet::test_framework::{self, LocalWalletClient, WalletProxy}; -use self::wallet::{libwallet, FileWalletCommAdapter}; +use wallet::FileWalletCommAdapter; use grin_core as core; use grin_keychain as keychain; use grin_util as util; -use grin_wallet as wallet; +use grin_libwallet as libwallet; +use wallet::test_framework::{self, LocalWalletClient, WalletProxy}; use std::fs; use std::thread; use std::time::Duration; diff --git a/refwallet/tests/encryption.rs b/refwallet/tests/encryption.rs new file mode 100644 index 00000000..5c052ab9 --- /dev/null +++ b/refwallet/tests/encryption.rs @@ -0,0 +1,36 @@ +// Copyright 2018 The Grin Developers +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! core::libtx specific tests +extern crate grin_refwallet as wallet; + +use self::wallet::{EncryptedWalletSeed, WalletSeed}; + +#[test] +fn wallet_seed_encrypt() { + let password = "passwoid"; + let wallet_seed = WalletSeed::init_new(32); + let mut enc_wallet_seed = EncryptedWalletSeed::from_seed(&wallet_seed, password).unwrap(); + println!("EWS: {:?}", enc_wallet_seed); + let decrypted_wallet_seed = enc_wallet_seed.decrypt(password).unwrap(); + assert_eq!(wallet_seed, decrypted_wallet_seed); + + // Wrong password + let decrypted_wallet_seed = enc_wallet_seed.decrypt(""); + assert!(decrypted_wallet_seed.is_err()); + + // Wrong nonce + enc_wallet_seed.nonce = "wrongnonce".to_owned(); + let decrypted_wallet_seed = enc_wallet_seed.decrypt(password); + assert!(decrypted_wallet_seed.is_err()); +} diff --git a/refwallet/tests/file.rs b/refwallet/tests/file.rs index 925f7cca..e90f8f41 100644 --- a/refwallet/tests/file.rs +++ b/refwallet/tests/file.rs @@ -14,15 +14,17 @@ //! Test a wallet file send/recieve #[macro_use] extern crate log; +extern crate grin_refwallet as wallet; + use self::core::global; use self::core::global::ChainTypes; use self::keychain::ExtKeychain; use self::wallet::test_framework::{self, LocalWalletClient, WalletProxy}; -use self::wallet::{libwallet, FileWalletCommAdapter}; +use self::wallet::FileWalletCommAdapter; use grin_core as core; use grin_keychain as keychain; use grin_util as util; -use grin_wallet as wallet; +use grin_libwallet as libwallet; use std::fs; use std::thread; use std::time::Duration; diff --git a/refwallet/tests/repost.rs b/refwallet/tests/repost.rs index e24cd6f6..b40bed48 100644 --- a/refwallet/tests/repost.rs +++ b/refwallet/tests/repost.rs @@ -14,17 +14,18 @@ //! Test a wallet repost command #[macro_use] extern crate log; +extern crate grin_refwallet as wallet; +extern crate grin_libwallet as libwallet; use self::core::global; use self::core::global::ChainTypes; use self::keychain::ExtKeychain; use self::libwallet::slate::Slate; use self::wallet::test_framework::{self, LocalWalletClient, WalletProxy}; -use self::wallet::{libwallet, FileWalletCommAdapter}; +use self::wallet::FileWalletCommAdapter; use grin_core as core; use grin_keychain as keychain; use grin_util as util; -use grin_wallet as wallet; use std::fs; use std::thread; use std::time::Duration; diff --git a/refwallet/tests/restore.rs b/refwallet/tests/restore.rs index 9f15a72b..63a60e37 100644 --- a/refwallet/tests/restore.rs +++ b/refwallet/tests/restore.rs @@ -14,17 +14,18 @@ //! tests for wallet restore #[macro_use] extern crate log; +extern crate grin_refwallet as wallet; +extern crate grin_libwallet as libwallet; + use self::core::global; use self::core::global::ChainTypes; use self::keychain::{ExtKeychain, Identifier, Keychain}; use self::libwallet::slate::Slate; -use self::wallet::libwallet; -use self::wallet::libwallet::types::AcctPathMapping; +use self::libwallet::types::AcctPathMapping; use self::wallet::test_framework::{self, LocalWalletClient, WalletProxy}; use grin_core as core; use grin_keychain as keychain; use grin_util as util; -use grin_wallet as wallet; use std::fs; use std::sync::atomic::Ordering; use std::thread; diff --git a/refwallet/tests/self_send.rs b/refwallet/tests/self_send.rs index 54cab307..0ab1b686 100644 --- a/refwallet/tests/self_send.rs +++ b/refwallet/tests/self_send.rs @@ -14,16 +14,16 @@ //! Test a wallet sending to self #[macro_use] extern crate log; +extern crate grin_refwallet as wallet; use self::core::global; use self::core::global::ChainTypes; use self::keychain::ExtKeychain; -use self::wallet::libwallet; use self::wallet::test_framework::{self, LocalWalletClient, WalletProxy}; use grin_core as core; use grin_keychain as keychain; use grin_util as util; -use grin_wallet as wallet; +use grin_libwallet as libwallet; use std::fs; use std::thread; use std::time::Duration; diff --git a/refwallet/tests/transaction.rs b/refwallet/tests/transaction.rs index ac22461f..159997ae 100644 --- a/refwallet/tests/transaction.rs +++ b/refwallet/tests/transaction.rs @@ -14,17 +14,18 @@ //! tests for transactions building within core::libtx #[macro_use] extern crate log; +extern crate grin_refwallet as wallet; +extern crate grin_libwallet as libwallet; + use self::core::global; use self::core::global::ChainTypes; use self::keychain::ExtKeychain; use self::libwallet::slate::Slate; -use self::wallet::libwallet; -use self::wallet::libwallet::types::OutputStatus; +use self::libwallet::types::OutputStatus; use self::wallet::test_framework::{self, LocalWalletClient, WalletProxy}; use grin_core as core; use grin_keychain as keychain; use grin_util as util; -use grin_wallet as wallet; use std::fs; use std::thread; use std::time::Duration; diff --git a/src/bin/cmd/wallet_tests.rs b/src/bin/cmd/wallet_tests.rs index a3407eb7..32814338 100644 --- a/src/bin/cmd/wallet_tests.rs +++ b/src/bin/cmd/wallet_tests.rs @@ -104,15 +104,13 @@ mod wallet_tests { args: ArgMatches<'a>, ) -> ArgMatches<'a> { match args.subcommand() { - ("wallet", Some(wallet_args)) => { + ("init", Some(init_args)) => { // wallet init command should spit out its config file then continue // (if desired) - if let ("init", Some(init_args)) = wallet_args.subcommand() { - if init_args.is_present("here") { - let _ = config_command_wallet(wallet_dir, wallet_name); - } + if init_args.is_present("here") { + let _ = config_command_wallet(wallet_dir, wallet_name); } - wallet_args.to_owned() + init_args.to_owned() } _ => ArgMatches::new(), } @@ -142,7 +140,7 @@ mod wallet_tests { arg_vec: Vec<&str>, ) -> Result { let args = app.clone().get_matches_from(arg_vec); - let args = get_wallet_subcommand(test_dir, wallet_name, args.clone()); + let _ = get_wallet_subcommand(test_dir, wallet_name, args.clone()); let mut config = initial_setup_wallet(test_dir, wallet_name); //unset chain type so it doesn't get reset config.chain_type = None; @@ -162,7 +160,7 @@ mod wallet_tests { let app = App::from_yaml(yml); // wallet init - let arg_vec = vec!["grin", "wallet", "-p", "password", "init", "-h"]; + let arg_vec = vec!["grin-wallet", "-p", "password", "init", "-h"]; // should create new wallet file let client1 = LocalWalletClient::new("wallet1", wallet_proxy.tx.clone()); execute_command(&app, test_dir, "wallet1", &client1, arg_vec.clone())?; @@ -194,13 +192,12 @@ mod wallet_tests { // Create some accounts in wallet 1 let arg_vec = vec![ - "grin", "wallet", "-p", "password", "account", "-c", "mining", + "grin-wallet", "-p", "password", "account", "-c", "mining", ]; execute_command(&app, test_dir, "wallet1", &client1, arg_vec)?; let arg_vec = vec![ - "grin", - "wallet", + "grin-wallet", "-p", "password", "account", @@ -211,8 +208,7 @@ mod wallet_tests { // Create some accounts in wallet 2 let arg_vec = vec![ - "grin", - "wallet", + "grin-wallet", "-p", "password", "account", @@ -224,8 +220,7 @@ mod wallet_tests { assert!(execute_command(&app, test_dir, "wallet2", &client2, arg_vec).is_err()); let arg_vec = vec![ - "grin", - "wallet", + "grin-wallet", "-p", "password", "account", @@ -235,11 +230,11 @@ mod wallet_tests { execute_command(&app, test_dir, "wallet2", &client2, arg_vec)?; // let's see those accounts - let arg_vec = vec!["grin", "wallet", "-p", "password", "account"]; + let arg_vec = vec!["grin-wallet", "-p", "password", "account"]; execute_command(&app, test_dir, "wallet2", &client2, arg_vec)?; // let's see those accounts - let arg_vec = vec!["grin", "wallet", "-p", "password", "account"]; + let arg_vec = vec!["grin-wallet", "-p", "password", "account"]; execute_command(&app, test_dir, "wallet2", &client2, arg_vec)?; // Mine a bit into wallet 1 so we have something to send @@ -264,15 +259,14 @@ mod wallet_tests { This part should all be truncated"; // Update info and check - let arg_vec = vec!["grin", "wallet", "-p", "password", "-a", "mining", "info"]; + let arg_vec = vec!["grin-wallet", "-p", "password", "-a", "mining", "info"]; execute_command(&app, test_dir, "wallet1", &client1, arg_vec)?; // try a file exchange let file_name = format!("{}/tx1.part_tx", test_dir); let response_file_name = format!("{}/tx1.part_tx.response", test_dir); let arg_vec = vec![ - "grin", - "wallet", + "grin-wallet", "-p", "password", "-a", @@ -289,8 +283,7 @@ mod wallet_tests { execute_command(&app, test_dir, "wallet1", &client1, arg_vec)?; let arg_vec = vec![ - "grin", - "wallet", + "grin-wallet", "-p", "password", "-a", @@ -307,8 +300,7 @@ mod wallet_tests { assert!(execute_command(&app, test_dir, "wallet2", &client2, arg_vec).is_err()); let arg_vec = vec![ - "grin", - "wallet", + "grin-wallet", "-p", "password", "finalize", @@ -333,12 +325,11 @@ mod wallet_tests { bh += 10; // update info for each - let arg_vec = vec!["grin", "wallet", "-p", "password", "-a", "mining", "info"]; + let arg_vec = vec!["grin-wallet", "-p", "password", "-a", "mining", "info"]; execute_command(&app, test_dir, "wallet1", &client1, arg_vec)?; let arg_vec = vec![ - "grin", - "wallet", + "grin-wallet", "-p", "password", "-a", @@ -359,8 +350,7 @@ mod wallet_tests { // Self-send to same account, using smallest strategy let arg_vec = vec![ - "grin", - "wallet", + "grin-wallet", "-p", "password", "-a", @@ -379,8 +369,7 @@ mod wallet_tests { execute_command(&app, test_dir, "wallet1", &client1, arg_vec)?; let arg_vec = vec![ - "grin", - "wallet", + "grin-wallet", "-p", "password", "-a", @@ -394,8 +383,7 @@ mod wallet_tests { execute_command(&app, test_dir, "wallet1", &client1, arg_vec.clone())?; let arg_vec = vec![ - "grin", - "wallet", + "grin-wallet", "-p", "password", "finalize", @@ -418,8 +406,7 @@ mod wallet_tests { // Try using the self-send method, splitting up outputs for the fun of it let arg_vec = vec![ - "grin", - "wallet", + "grin-wallet", "-p", "password", "-a", @@ -453,8 +440,7 @@ mod wallet_tests { // Another file exchange, don't send, but unlock with repair command let arg_vec = vec![ - "grin", - "wallet", + "grin-wallet", "-p", "password", "-a", @@ -470,13 +456,12 @@ mod wallet_tests { ]; execute_command(&app, test_dir, "wallet1", &client1, arg_vec)?; - let arg_vec = vec!["grin", "wallet", "-p", "password", "check"]; + let arg_vec = vec!["grin-wallet", "-p", "password", "check"]; execute_command(&app, test_dir, "wallet1", &client1, arg_vec)?; // Another file exchange, cancel this time let arg_vec = vec![ - "grin", - "wallet", + "grin-wallet", "-p", "password", "-a", @@ -493,23 +478,23 @@ mod wallet_tests { execute_command(&app, test_dir, "wallet1", &client1, arg_vec)?; let arg_vec = vec![ - "grin", "wallet", "-p", "password", "-a", "mining", "cancel", "-i", "26", + "grin-wallet", "-p", "password", "-a", "mining", "cancel", "-i", "26", ]; execute_command(&app, test_dir, "wallet1", &client1, arg_vec)?; // txs and outputs (mostly spit out for a visual in test logs) - let arg_vec = vec!["grin", "wallet", "-p", "password", "-a", "mining", "txs"]; + let arg_vec = vec!["grin-wallet", "-p", "password", "-a", "mining", "txs"]; execute_command(&app, test_dir, "wallet1", &client1, arg_vec)?; // message output (mostly spit out for a visual in test logs) let arg_vec = vec![ - "grin", "wallet", "-p", "password", "-a", "mining", "txs", "-i", "10", + "grin-wallet", "-p", "password", "-a", "mining", "txs", "-i", "10", ]; execute_command(&app, test_dir, "wallet1", &client1, arg_vec)?; // txs and outputs (mostly spit out for a visual in test logs) let arg_vec = vec![ - "grin", "wallet", "-p", "password", "-a", "mining", "outputs", + "grin-wallet", "-p", "password", "-a", "mining", "outputs", ]; execute_command(&app, test_dir, "wallet1", &client1, arg_vec)?; diff --git a/src/bin/grin-wallet.rs b/src/bin/grin-wallet.rs index a00caa4f..f7759e71 100644 --- a/src/bin/grin-wallet.rs +++ b/src/bin/grin-wallet.rs @@ -93,6 +93,7 @@ fn real_main() -> i32 { let mut w = config::initial_setup_wallet(&chain_type).unwrap_or_else(|e| { panic!("Error loading wallet configuration: {}", e); }); + if !cmd::seed_exists(w.members.as_ref().unwrap().wallet.clone()) { if "init" == args.subcommand().0 || "recover" == args.subcommand().0 { } else {