Wallet test framework (#2098)

* remove circular dependency

* rustfmt

* move wallet test framework
This commit is contained in:
Yeastplume 2018-12-07 17:18:33 +00:00 committed by GitHub
parent a6bb6344ac
commit 68896b2a76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 88 additions and 336 deletions

5
Cargo.lock generated
View file

@ -686,16 +686,19 @@ dependencies = [
"failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"flate2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"grin_api 0.4.2",
"grin_chain 0.4.2",
"grin_config 0.4.2",
"grin_core 0.4.2",
"grin_keychain 0.4.2",
"grin_p2p 0.4.2",
"grin_servers 0.4.2",
"grin_store 0.4.2",
"grin_util 0.4.2",
"grin_wallet 0.4.2",
"humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rpassword 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
"tar 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
@ -950,7 +953,6 @@ dependencies = [
"blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
@ -966,7 +968,6 @@ dependencies = [
"prettytable-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
"ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rpassword 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -21,6 +21,7 @@ path = "src/bin/grin.rs"
blake2-rfc = "0.2"
chrono = "0.4.4"
clap = { version = "2.31", features = ["yaml"] }
rpassword = "2.0.0"
ctrlc = { version = "3.1", features = ["termination"] }
cursive = "0.9.0"
humansize = "1.1.0"
@ -46,3 +47,7 @@ built = "0.3"
reqwest = "0.9"
flate2 = "1.0"
tar = "0.4"
[dev-dependencies]
grin_chain = { path = "./chain", version = "0.4.2" }
grin_store = { path = "./store", version = "0.4.2" }

View file

@ -16,6 +16,7 @@ mod client;
mod config;
mod server;
mod wallet;
pub mod wallet_args;
pub use self::client::client_command;
pub use self::config::{config_command_server, config_command_wallet};

View file

@ -14,9 +14,12 @@
use clap::ArgMatches;
use std::path::PathBuf;
use std::thread;
use std::time::Duration;
use super::wallet_args;
use config::GlobalWalletConfig;
use grin_wallet::{self, command_args, HTTPNodeClient, WalletConfig, WalletSeed};
use grin_wallet::{self, HTTPNodeClient, WalletConfig, WalletSeed};
use servers::start_webwallet_server;
pub fn _init_wallet_seed(wallet_config: WalletConfig, password: &str) {
@ -48,7 +51,7 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) -> i
};
let node_client = HTTPNodeClient::new(&wallet_config.check_node_api_http_addr, None);
let res = command_args::wallet_command(wallet_args, wallet_config, node_client);
let res = wallet_args::wallet_command(wallet_args, wallet_config, node_client);
// we need to give log output a chance to catch up before exiting
thread::sleep(Duration::from_millis(100));

View file

@ -15,19 +15,19 @@
/// Argument parsing and error handling for wallet commands
use clap::ArgMatches;
use std::sync::Arc;
use std::thread;
use std::time::Duration;
use util::Mutex;
use failure::Fail;
use rpassword;
use api::TLSConfig;
use core;
use grin_wallet::command;
use grin_wallet::{instantiate_wallet, NodeClient, WalletConfig, WalletInst, WalletSeed};
use grin_wallet::{Error, ErrorKind};
use keychain;
use std::path::Path;
use util::file::get_first_line;
use {command, instantiate_wallet, NodeClient, WalletConfig, WalletInst, WalletSeed};
use {Error, ErrorKind};
// define what to do on argument error
macro_rules! arg_parse {

View file

@ -21,6 +21,7 @@ extern crate clap;
extern crate ctrlc;
extern crate cursive;
extern crate daemonize;
extern crate rpassword;
extern crate serde;
extern crate serde_json;
#[macro_use]
@ -40,6 +41,8 @@ extern crate grin_wallet;
mod cmd;
pub mod tui;
pub use cmd::wallet_args;
use std::process::exit;
use clap::App;

View file

@ -10,8 +10,6 @@ workspace = '..'
[dependencies]
blake2-rfc = "0.2"
clap = { version = "2.31", features = ["yaml"] }
rpassword = "2.0.0"
byteorder = "1"
failure = "0.1"
failure_derive = "0.1"
@ -37,8 +35,8 @@ grin_core = { path = "../core", version = "0.4.2" }
grin_keychain = { path = "../keychain", version = "0.4.2" }
grin_store = { path = "../store", version = "0.4.2" }
grin_util = { path = "../util", version = "0.4.2" }
grin_chain = { path = "../chain", version = "0.4.2" }
[dev-dependencies]
grin_chain = { path = "../chain", version = "0.4.2" }
grin_store = { path = "../store", version = "0.4.2" }
grin_config = { path = "../config", version = "0.4.2" }

View file

@ -27,8 +27,6 @@ extern crate serde_json;
#[macro_use]
extern crate log;
extern crate chrono;
extern crate clap;
extern crate rpassword;
extern crate term;
extern crate url;
extern crate uuid;
@ -44,6 +42,7 @@ extern crate tokio_core;
extern crate tokio_retry;
extern crate grin_api as api;
extern crate grin_chain as chain;
extern crate grin_core as core;
extern crate grin_keychain as keychain;
extern crate grin_store as store;
@ -51,13 +50,13 @@ extern crate grin_util as util;
mod adapters;
pub mod command;
pub mod command_args;
pub mod controller;
pub mod display;
mod error;
pub mod libwallet;
pub mod lmdb_wallet;
mod node_clients;
pub mod test_framework;
mod types;
pub use adapters::{

View file

@ -12,31 +12,26 @@
// See the License for the specific language governing permissions and
// limitations under the License.
extern crate chrono;
extern crate failure;
extern crate grin_api as api;
extern crate grin_chain as chain;
extern crate grin_core as core;
extern crate grin_keychain as keychain;
extern crate grin_wallet as wallet;
extern crate serde_json;
use chrono::Duration;
use std::sync::Arc;
use util::Mutex;
use chain::Chain;
use api;
use chain::{self, Chain};
use keychain;
use core::core::{OutputFeatures, OutputIdentifier, Transaction};
use core::{consensus, global, pow, ser};
use wallet::libwallet::types::{BlockFees, CbData, NodeClient, WalletInst};
use wallet::lmdb_wallet::LMDBBackend;
use wallet::{controller, libwallet};
use wallet::{WalletBackend, WalletConfig};
use core::{self, consensus, global, pow, ser};
use libwallet::types::{BlockFees, CbData, NodeClient, WalletInst};
use lmdb_wallet::LMDBBackend;
use {controller, libwallet, WalletBackend, WalletConfig, WalletSeed};
use util;
use util::secp::pedersen;
pub mod testclient;
mod testclient;
pub use self::{testclient::LocalWalletClient, testclient::WalletProxy};
/// types of backends tests should iterate through
//#[derive(Clone)]
@ -163,7 +158,7 @@ where
{
let mut wallet_config = WalletConfig::default();
wallet_config.data_file_dir = String::from(dir);
let _ = wallet::WalletSeed::init_file(&wallet_config, 32, "");
let _ = WalletSeed::init_file(&wallet_config, 32, "");
let mut wallet = LMDBBackend::new(wallet_config.clone(), "", n_client)
.unwrap_or_else(|e| panic!("Error creating wallet: {:?} Config: {:?}", e, wallet_config));
wallet.open_with_credentials().unwrap_or_else(|e| {

View file

@ -25,13 +25,13 @@ use std::thread;
use std::time::Duration;
use util::{Mutex, RwLock};
use common::api;
use common::serde_json;
use api;
use serde_json;
use store;
use util;
use util::secp::pedersen::Commitment;
use common::failure::ResultExt;
use failure::ResultExt;
use chain::types::NoopAdapter;
use chain::Chain;
@ -42,11 +42,9 @@ use core::{pow, ser};
use keychain::Keychain;
use core::libtx::slate::Slate;
use libwallet::types::*;
use util::secp::pedersen;
use wallet::libwallet::types::*;
use wallet::{controller, libwallet, WalletCommAdapter, WalletConfig};
use common;
use {controller, libwallet, WalletCommAdapter, WalletConfig};
/// Messages to simulate wallet requests/responses
#[derive(Clone, Debug)]
@ -189,7 +187,7 @@ where
libwallet::ErrorKind::ClientCallback("Error parsing TxWrapper: tx"),
)?;
common::award_block_to_wallet(&self.chain, vec![&tx], dest_wallet)?;
super::award_block_to_wallet(&self.chain, vec![&tx], dest_wallet)?;
Ok(WalletProxyMessage {
sender_id: "node".to_owned(),
@ -250,7 +248,7 @@ where
}
let c = util::from_hex(o_str).unwrap();
let commit = Commitment::from_vec(c);
let out = common::get_output_local(&self.chain.clone(), &commit);
let out = super::get_output_local(&self.chain.clone(), &commit);
if let Some(o) = out {
outputs.push(o);
}
@ -271,7 +269,7 @@ where
let split = m.body.split(",").collect::<Vec<&str>>();
let start_index = split[0].parse::<u64>().unwrap();
let max = split[1].parse::<u64>().unwrap();
let ol = common::get_outputs_by_pmmr_index_local(self.chain.clone(), start_index, max);
let ol = super::get_outputs_by_pmmr_index_local(self.chain.clone(), start_index, max);
Ok(WalletProxyMessage {
sender_id: "node".to_owned(),
dest: m.sender_id,

View file

@ -25,8 +25,7 @@ extern crate chrono;
extern crate serde;
extern crate uuid;
mod common;
use common::testclient::{LocalWalletClient, WalletProxy};
use wallet::test_framework::{self, LocalWalletClient, WalletProxy};
use std::fs;
use std::thread;
@ -57,12 +56,12 @@ fn accounts_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
// Create a new wallet test client, and set its queues to communicate with the
// proxy
let client1 = LocalWalletClient::new("wallet1", wallet_proxy.tx.clone());
let wallet1 = common::create_wallet(&format!("{}/wallet1", test_dir), client1.clone());
let wallet1 = test_framework::create_wallet(&format!("{}/wallet1", test_dir), client1.clone());
wallet_proxy.add_wallet("wallet1", client1.get_send_instance(), wallet1.clone());
let client2 = LocalWalletClient::new("wallet2", wallet_proxy.tx.clone());
// define recipient wallet, add to proxy
let wallet2 = common::create_wallet(&format!("{}/wallet2", test_dir), client2.clone());
let wallet2 = test_framework::create_wallet(&format!("{}/wallet2", test_dir), client2.clone());
wallet_proxy.add_wallet("wallet2", client2.get_send_instance(), wallet2.clone());
// Set the wallet proxy listener running
@ -117,14 +116,14 @@ fn accounts_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
w.set_parent_key_id_by_name("account1")?;
assert_eq!(w.parent_key_id(), ExtKeychain::derive_key_id(2, 1, 0, 0, 0));
}
let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), 7);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 7);
{
let mut w = wallet1.lock();
w.set_parent_key_id_by_name("account2")?;
assert_eq!(w.parent_key_id(), ExtKeychain::derive_key_id(2, 2, 0, 0, 0));
}
let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), 5);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 5);
// Should have 5 in account1 (5 spendable), 5 in account (2 spendable)
wallet::controller::owner_single_use(wallet1.clone(), |api| {

View file

@ -1,245 +0,0 @@
// 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.
//! Test wallet command line works as expected
extern crate grin_chain as chain;
extern crate grin_config as config;
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_wallet as wallet;
extern crate rand;
#[macro_use]
extern crate log;
extern crate chrono;
extern crate serde;
extern crate uuid;
#[macro_use]
extern crate clap;
mod common;
use common::testclient::{LocalWalletClient, WalletProxy};
use clap::{App, ArgMatches};
use std::thread;
use std::time::Duration;
use std::{env, fs};
use config::GlobalWalletConfig;
use core::global;
use core::global::ChainTypes;
use keychain::ExtKeychain;
use wallet::{command_args, WalletConfig};
fn clean_output_dir(test_dir: &str) {
let _ = fs::remove_dir_all(test_dir);
}
fn setup(test_dir: &str) {
util::init_test_logger();
clean_output_dir(test_dir);
global::set_mining_mode(ChainTypes::AutomatedTesting);
}
/// Create a wallet config file in the given current directory
pub fn config_command_wallet(dir_name: &str, wallet_name: &str) -> Result<(), wallet::Error> {
let mut current_dir;
let mut default_config = GlobalWalletConfig::default();
current_dir = env::current_dir().unwrap_or_else(|e| {
panic!("Error creating config file: {}", e);
});
current_dir.push(dir_name);
current_dir.push(wallet_name);
let _ = fs::create_dir_all(current_dir.clone());
let mut config_file_name = current_dir.clone();
config_file_name.push("grin-wallet.toml");
if config_file_name.exists() {
return Err(wallet::ErrorKind::ArgumentError(
"grin-wallet.toml already exists in the target directory. Please remove it first"
.to_owned(),
))?;
}
default_config.update_paths(&current_dir);
default_config
.write_to_file(config_file_name.to_str().unwrap())
.unwrap_or_else(|e| {
panic!("Error creating config file: {}", e);
});
println!(
"File {} configured and created",
config_file_name.to_str().unwrap(),
);
Ok(())
}
/// Handles setup and detection of paths for wallet
pub fn initial_setup_wallet(dir_name: &str, wallet_name: &str) -> WalletConfig {
let mut current_dir;
current_dir = env::current_dir().unwrap_or_else(|e| {
panic!("Error creating config file: {}", e);
});
current_dir.push(dir_name);
current_dir.push(wallet_name);
let _ = fs::create_dir_all(current_dir.clone());
let mut config_file_name = current_dir.clone();
config_file_name.push("grin-wallet.toml");
GlobalWalletConfig::new(config_file_name.to_str().unwrap())
.unwrap()
.members
.unwrap()
.wallet
}
fn get_wallet_subcommand<'a>(
wallet_dir: &str,
wallet_name: &str,
args: ArgMatches<'a>,
) -> ArgMatches<'a> {
match args.subcommand() {
("wallet", Some(wallet_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);
}
}
wallet_args.to_owned()
}
_ => ArgMatches::new(),
}
}
fn execute_command(
app: &App,
test_dir: &str,
wallet_name: &str,
client: &LocalWalletClient,
arg_vec: Vec<&str>,
) -> Result<String, wallet::Error> {
let args = app.clone().get_matches_from(arg_vec);
let args = get_wallet_subcommand(test_dir, wallet_name, args.clone());
let config = initial_setup_wallet(test_dir, wallet_name);
command_args::wallet_command(&args, config.clone(), client.clone())
}
/// self send impl
fn command_line_test_impl(test_dir: &str) -> Result<(), wallet::Error> {
setup(test_dir);
// Create a new proxy to simulate server and wallet responses
let mut wallet_proxy: WalletProxy<LocalWalletClient, ExtKeychain> = WalletProxy::new(test_dir);
// load app yaml. If it don't exist, just say so and exit
let yml = load_yaml!("../../src/bin/grin.yml");
let app = App::from_yaml(yml);
// wallet init
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())?;
// trying to init twice - should fail
assert!(execute_command(&app, test_dir, "wallet1", &client1, arg_vec.clone()).is_err());
// add wallet to proxy
let wallet1 = common::create_wallet(&format!("{}/wallet1", test_dir), client1.clone());
wallet_proxy.add_wallet("wallet1", client1.get_send_instance(), wallet1.clone());
// Create wallet 2
let client2 = LocalWalletClient::new("wallet2", wallet_proxy.tx.clone());
execute_command(&app, test_dir, "wallet2", &client2, arg_vec.clone())?;
let wallet2 = common::create_wallet(&format!("{}/wallet2", test_dir), client2.clone());
wallet_proxy.add_wallet("wallet2", client2.get_send_instance(), wallet2.clone());
// Set the wallet proxy listener running
thread::spawn(move || {
if let Err(e) = wallet_proxy.run() {
error!("Wallet Proxy error: {}", e);
}
});
// Create some accounts in wallet 1
let arg_vec = vec![
"grin", "wallet", "-p", "password", "account", "-c", "mining",
];
execute_command(&app, test_dir, "wallet1", &client1, arg_vec)?;
let arg_vec = vec![
"grin",
"wallet",
"-p",
"password",
"account",
"-c",
"account_1",
];
execute_command(&app, test_dir, "wallet1", &client1, arg_vec)?;
// Create some accounts in wallet 2
let arg_vec = vec![
"grin",
"wallet",
"-p",
"password",
"account",
"-c",
"account_1",
];
execute_command(&app, test_dir, "wallet2", &client2, arg_vec.clone())?;
// already exists
assert!(execute_command(&app, test_dir, "wallet2", &client2, arg_vec).is_err());
let arg_vec = vec![
"grin",
"wallet",
"-p",
"password",
"account",
"-c",
"account_2",
];
execute_command(&app, test_dir, "wallet2", &client2, arg_vec)?;
// let's see those accounts
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
//let mut bh = 10u64;
//let chain = wallet_proxy.chain.clone();
//let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), bh as usize);
// let's see those accounts
let arg_vec = vec!["grin", "wallet", "-p", "password", "account"];
execute_command(&app, test_dir, "wallet2", &client2, arg_vec)?;
// Start wallet 1's listener, collect some coinbase outputs
let _arg_vec = vec!["grin", "wallet", "-p", "password", "-a", "mining", "listen"];
//execute_command(&app, test_dir, "wallet1", &client1, arg_vec)?;
// let logging finish
thread::sleep(Duration::from_millis(200));
Ok(())
}
#[test]
fn wallet_command_line() {
let test_dir = "test_output/command_line";
if let Err(e) = command_line_test_impl(test_dir) {
panic!("Libwallet Error: {} - {}", e, e.backtrace().unwrap());
}
}

View file

@ -25,8 +25,7 @@ extern crate chrono;
extern crate serde;
extern crate uuid;
mod common;
use common::testclient::{LocalWalletClient, WalletProxy};
use wallet::test_framework::{self, LocalWalletClient, WalletProxy};
use std::fs;
use std::thread;
@ -55,11 +54,11 @@ fn file_exchange_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
let chain = wallet_proxy.chain.clone();
let client1 = LocalWalletClient::new("wallet1", wallet_proxy.tx.clone());
let wallet1 = common::create_wallet(&format!("{}/wallet1", test_dir), client1.clone());
let wallet1 = test_framework::create_wallet(&format!("{}/wallet1", test_dir), client1.clone());
wallet_proxy.add_wallet("wallet1", client1.get_send_instance(), wallet1.clone());
let client2 = LocalWalletClient::new("wallet2", wallet_proxy.tx.clone());
let wallet2 = common::create_wallet(&format!("{}/wallet2", test_dir), client2.clone());
let wallet2 = test_framework::create_wallet(&format!("{}/wallet2", test_dir), client2.clone());
wallet_proxy.add_wallet("wallet2", client2.get_send_instance(), wallet2.clone());
// Set the wallet proxy listener running
@ -92,7 +91,7 @@ fn file_exchange_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
w.set_parent_key_id_by_name("mining")?;
}
let mut bh = 10u64;
let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), bh as usize);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), bh as usize);
let send_file = format!("{}/part_tx_1.tx", test_dir);
let receive_file = format!("{}/part_tx_2.tx", test_dir);
@ -161,7 +160,7 @@ fn file_exchange_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
Ok(())
})?;
let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
bh += 3;
// Check total in mining account

View file

@ -25,8 +25,7 @@ extern crate chrono;
extern crate serde;
extern crate uuid;
mod common;
use common::testclient::{LocalWalletClient, WalletProxy};
use wallet::test_framework::{self, LocalWalletClient, WalletProxy};
use std::fs;
use std::thread;
@ -56,11 +55,11 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
let chain = wallet_proxy.chain.clone();
let client1 = LocalWalletClient::new("wallet1", wallet_proxy.tx.clone());
let wallet1 = common::create_wallet(&format!("{}/wallet1", test_dir), client1.clone());
let wallet1 = test_framework::create_wallet(&format!("{}/wallet1", test_dir), client1.clone());
wallet_proxy.add_wallet("wallet1", client1.get_send_instance(), wallet1.clone());
let client2 = LocalWalletClient::new("wallet2", wallet_proxy.tx.clone());
let wallet2 = common::create_wallet(&format!("{}/wallet2", test_dir), client2.clone());
let wallet2 = test_framework::create_wallet(&format!("{}/wallet2", test_dir), client2.clone());
wallet_proxy.add_wallet("wallet2", client2.get_send_instance(), wallet2.clone());
// Set the wallet proxy listener running
@ -93,7 +92,7 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
w.set_parent_key_id_by_name("mining")?;
}
let mut bh = 10u64;
let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), bh as usize);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), bh as usize);
let send_file = format!("{}/part_tx_1.tx", test_dir);
let receive_file = format!("{}/part_tx_2.tx", test_dir);
@ -121,7 +120,7 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
Ok(())
})?;
let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
bh += 3;
// wallet 1 receives file to different account, completes
@ -161,7 +160,7 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
Ok(())
})?;
let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
bh += 3;
// update/test contents of both accounts
@ -216,7 +215,7 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
Ok(())
})?;
let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
bh += 3;
// Now repost from cached
@ -227,7 +226,7 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
Ok(())
})?;
let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
bh += 3;
//
// update/test contents of both accounts

View file

@ -25,8 +25,7 @@ extern crate chrono;
extern crate serde;
extern crate uuid;
mod common;
use common::testclient::{LocalWalletClient, WalletProxy};
use wallet::test_framework::{self, LocalWalletClient, WalletProxy};
use std::fs;
use std::thread;
@ -59,7 +58,7 @@ fn restore_wallet(base_dir: &str, wallet_dir: &str) -> Result<(), libwallet::Err
let mut wallet_proxy: WalletProxy<LocalWalletClient, ExtKeychain> = WalletProxy::new(base_dir);
let client = LocalWalletClient::new(wallet_dir, wallet_proxy.tx.clone());
let wallet = common::create_wallet(&dest_dir, client.clone());
let wallet = test_framework::create_wallet(&dest_dir, client.clone());
wallet_proxy.add_wallet(wallet_dir, client.get_send_instance(), wallet.clone());
@ -92,7 +91,7 @@ fn compare_wallet_restore(
let mut wallet_proxy: WalletProxy<LocalWalletClient, ExtKeychain> = WalletProxy::new(base_dir);
let client = LocalWalletClient::new(wallet_dir, wallet_proxy.tx.clone());
let wallet_source = common::create_wallet(&source_dir, client.clone());
let wallet_source = test_framework::create_wallet(&source_dir, client.clone());
wallet_proxy.add_wallet(
&wallet_dir,
client.get_send_instance(),
@ -100,7 +99,7 @@ fn compare_wallet_restore(
);
let client = LocalWalletClient::new(&restore_name, wallet_proxy.tx.clone());
let wallet_dest = common::create_wallet(&dest_dir, client.clone());
let wallet_dest = test_framework::create_wallet(&dest_dir, client.clone());
wallet_proxy.add_wallet(
&restore_name,
client.get_send_instance(),
@ -188,12 +187,12 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
// Create a new wallet test client, and set its queues to communicate with the
// proxy
let client1 = LocalWalletClient::new("wallet1", wallet_proxy.tx.clone());
let wallet1 = common::create_wallet(&format!("{}/wallet1", test_dir), client1.clone());
let wallet1 = test_framework::create_wallet(&format!("{}/wallet1", test_dir), client1.clone());
wallet_proxy.add_wallet("wallet1", client1.get_send_instance(), wallet1.clone());
// define recipient wallet, add to proxy
let client2 = LocalWalletClient::new("wallet2", wallet_proxy.tx.clone());
let wallet2 = common::create_wallet(&format!("{}/wallet2", test_dir), client2.clone());
let wallet2 = test_framework::create_wallet(&format!("{}/wallet2", test_dir), client2.clone());
wallet_proxy.add_wallet("wallet2", client2.get_send_instance(), wallet2.clone());
// wallet 2 will use another account
@ -211,7 +210,7 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
// Another wallet
let client3 = LocalWalletClient::new("wallet3", wallet_proxy.tx.clone());
let wallet3 = common::create_wallet(&format!("{}/wallet3", test_dir), client3.clone());
let wallet3 = test_framework::create_wallet(&format!("{}/wallet3", test_dir), client3.clone());
wallet_proxy.add_wallet("wallet3", client3.get_send_instance(), wallet3.clone());
// Set the wallet proxy listener running
@ -222,7 +221,7 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
});
// mine a few blocks
let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), 10);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 10);
// assert wallet contents
// and a single use api for a send command
@ -246,7 +245,7 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
})?;
// mine a few more blocks
let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
// Send some to wallet 3
wallet::controller::owner_single_use(wallet1.clone(), |sender_api| {
@ -268,7 +267,7 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
})?;
// mine a few more blocks
let _ = common::award_blocks_to_wallet(&chain, wallet3.clone(), 10);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet3.clone(), 10);
// Wallet3 to wallet 2
wallet::controller::owner_single_use(wallet3.clone(), |sender_api| {
@ -296,7 +295,7 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
}
// mine a few more blocks
let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), 2);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 2);
// Wallet3 to wallet 2 again (to another account)
wallet::controller::owner_single_use(wallet3.clone(), |sender_api| {
@ -318,7 +317,7 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
})?;
// mine a few more blocks
let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), 5);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 5);
// update everyone
wallet::controller::owner_single_use(wallet1.clone(), |api| {

View file

@ -25,8 +25,7 @@ extern crate chrono;
extern crate serde;
extern crate uuid;
mod common;
use common::testclient::{LocalWalletClient, WalletProxy};
use wallet::test_framework::{self, LocalWalletClient, WalletProxy};
use std::fs;
use std::thread;
@ -57,7 +56,7 @@ fn self_send_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
// Create a new wallet test client, and set its queues to communicate with the
// proxy
let client1 = LocalWalletClient::new("wallet1", wallet_proxy.tx.clone());
let wallet1 = common::create_wallet(&format!("{}/wallet1", test_dir), client1.clone());
let wallet1 = test_framework::create_wallet(&format!("{}/wallet1", test_dir), client1.clone());
wallet_proxy.add_wallet("wallet1", client1.get_send_instance(), wallet1.clone());
// Set the wallet proxy listener running
@ -83,7 +82,7 @@ fn self_send_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
w.set_parent_key_id_by_name("mining")?;
}
let mut bh = 10u64;
let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), bh as usize);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), bh as usize);
// Should have 5 in account1 (5 spendable), 5 in account (2 spendable)
wallet::controller::owner_single_use(wallet1.clone(), |api| {
@ -113,7 +112,7 @@ fn self_send_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
Ok(())
})?;
let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
bh += 3;
// Check total in mining account

View file

@ -25,8 +25,7 @@ extern crate chrono;
extern crate serde;
extern crate uuid;
mod common;
use common::testclient::{LocalWalletClient, WalletProxy};
use wallet::test_framework::{self, LocalWalletClient, WalletProxy};
use std::fs;
use std::thread;
@ -61,12 +60,12 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
// Create a new wallet test client, and set its queues to communicate with the
// proxy
let client1 = LocalWalletClient::new("wallet1", wallet_proxy.tx.clone());
let wallet1 = common::create_wallet(&format!("{}/wallet1", test_dir), client1.clone());
let wallet1 = test_framework::create_wallet(&format!("{}/wallet1", test_dir), client1.clone());
wallet_proxy.add_wallet("wallet1", client1.get_send_instance(), wallet1.clone());
let client2 = LocalWalletClient::new("wallet2", wallet_proxy.tx.clone());
// define recipient wallet, add to proxy
let wallet2 = common::create_wallet(&format!("{}/wallet2", test_dir), client2.clone());
let wallet2 = test_framework::create_wallet(&format!("{}/wallet2", test_dir), client2.clone());
wallet_proxy.add_wallet("wallet2", client2.get_send_instance(), wallet2.clone());
// Set the wallet proxy listener running
@ -80,7 +79,7 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
let reward = core::consensus::REWARD;
let cm = global::coinbase_maturity(); // assume all testing precedes soft fork height
// mine a few blocks
let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), 10);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 10);
// Check wallet 1 contents are as expected
wallet::controller::owner_single_use(wallet1.clone(), |api| {
@ -200,7 +199,7 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
})?;
// mine a few more blocks
let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
// refresh wallets and retrieve info/tests for each wallet after maturity
wallet::controller::owner_single_use(wallet1.clone(), |api| {
@ -273,7 +272,7 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
})?;
// mine a few more blocks
let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
// check wallet2 has stored transaction
wallet::controller::owner_single_use(wallet2.clone(), |api| {
@ -308,12 +307,12 @@ fn tx_rollback(test_dir: &str) -> Result<(), libwallet::Error> {
// Create a new wallet test client, and set its queues to communicate with the
// proxy
let client1 = LocalWalletClient::new("wallet1", wallet_proxy.tx.clone());
let wallet1 = common::create_wallet(&format!("{}/wallet1", test_dir), client1.clone());
let wallet1 = test_framework::create_wallet(&format!("{}/wallet1", test_dir), client1.clone());
wallet_proxy.add_wallet("wallet1", client1.get_send_instance(), wallet1.clone());
// define recipient wallet, add to proxy
let client2 = LocalWalletClient::new("wallet2", wallet_proxy.tx.clone());
let wallet2 = common::create_wallet(&format!("{}/wallet2", test_dir), client2.clone());
let wallet2 = test_framework::create_wallet(&format!("{}/wallet2", test_dir), client2.clone());
wallet_proxy.add_wallet("wallet2", client2.get_send_instance(), wallet2.clone());
// Set the wallet proxy listener running
@ -327,7 +326,7 @@ fn tx_rollback(test_dir: &str) -> Result<(), libwallet::Error> {
let reward = core::consensus::REWARD;
let cm = global::coinbase_maturity(); // assume all testing precedes soft fork height
// mine a few blocks
let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), 5);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 5);
let amount = 30_000_000_000;
let mut slate = Slate::blank(1);
@ -402,7 +401,7 @@ fn tx_rollback(test_dir: &str) -> Result<(), libwallet::Error> {
})?;
// wallet 1 is bold and doesn't ever post the transaction mine a few more blocks
let _ = common::award_blocks_to_wallet(&chain, wallet1.clone(), 5);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 5);
// Wallet 1 decides to roll back instead
wallet::controller::owner_single_use(wallet1.clone(), |api| {