mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-11-11 02:03:53 +01:00
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release * Merge master into milestone/2.1.0 (#182) * Derive --version output dynamically from cargo package version (#174) * add --txid to the `wallet txs` command (#176) * add --txid to the `wallet txs` command * add test for `wallet txs` command with `--txid` parameter * Refactor - Split WalletCommAdapter into multiple traits (#180) * Derive --version output dynamically from cargo package version (#174) * add server auth argument to http client * Revert "add server auth argument to http client" This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee. * modify WalletCommAdapter, moving dest argument into fields on implementors, visiting havok on automated tests, at least one of which is now out of date and failing * Split WalletCommAdapter into four traits, one for each of its intended behaviors. * Remove two vestigals 1. args, a stringly typed argument to put_tx 2. NullAdapter, which is no longer used * Remove unused "params" argument from listen method. * Re-add previously existing TODO comment * Fix non-test build * completely Fix non-test build * Full Lifecycle API Support (#184) * refactoring wallet lib traits * rustfmt * rustfmt * add new files * explicit lifetime specifiers on all wallet traits * rustfmt * modify apis to use new walletinst * rustfmt * converting controller crate * rustfmt * controller crate compiling * rustfmt * compilation * rustfmt * Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl * rustfmt * full compilation, changing recovery + init to new model * rustfmt * wallet initialisation working, init command output and flow identical to v2.0.0 wallet * rustfmt * fix listener and owner api startup * rustfmt * rustfmt * move encryption test * rustfmt * fix api doctests * rustfmt * fix for most tests in controller crate * rustfmt * fix for check tests in controller crate * fix main wallet tests * rustfmt * add explicit functions to handle mnemonic recovery, fix CLI recovery workflow * rustfmt * update keybase adapter to use new wallet format * rustfmt * test fix * remove debug output
This commit is contained in:
@@ -19,47 +19,43 @@ extern crate grin_wallet_impls as impls;
|
||||
|
||||
use grin_wallet_util::grin_core as core;
|
||||
use grin_wallet_util::grin_keychain as keychain;
|
||||
use grin_wallet_util::grin_util as util;
|
||||
|
||||
use self::core::global;
|
||||
use self::core::global::ChainTypes;
|
||||
use self::keychain::{ExtKeychain, Keychain};
|
||||
use grin_wallet_libwallet as libwallet;
|
||||
use impls::test_framework::{self, LocalWalletClient, WalletProxy};
|
||||
use impls::test_framework::{self, LocalWalletClient};
|
||||
use libwallet::InitTxArgs;
|
||||
use std::fs;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
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);
|
||||
}
|
||||
#[macro_use]
|
||||
mod common;
|
||||
use common::{create_wallet_proxy, setup};
|
||||
|
||||
/// Various tests on accounts within the same wallet
|
||||
fn accounts_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
fn accounts_test_impl(test_dir: &'static str) -> Result<(), libwallet::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);
|
||||
let mut wallet_proxy = create_wallet_proxy(test_dir);
|
||||
let chain = wallet_proxy.chain.clone();
|
||||
|
||||
// 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 =
|
||||
test_framework::create_wallet(&format!("{}/wallet1", test_dir), client1.clone(), None);
|
||||
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 =
|
||||
test_framework::create_wallet(&format!("{}/wallet2", test_dir), client2.clone(), None);
|
||||
wallet_proxy.add_wallet("wallet2", client2.get_send_instance(), wallet2.clone());
|
||||
create_wallet_and_add!(
|
||||
client1,
|
||||
wallet1,
|
||||
test_dir,
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
test_dir,
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -103,20 +99,20 @@ fn accounts_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
|
||||
// Default wallet 2 to listen on that account
|
||||
{
|
||||
let mut w = wallet2.lock();
|
||||
wallet_inst!(wallet2, w);
|
||||
w.set_parent_key_id_by_name("listener_account")?;
|
||||
}
|
||||
|
||||
// Mine into two different accounts in the same wallet
|
||||
{
|
||||
let mut w = wallet1.lock();
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account1")?;
|
||||
assert_eq!(w.parent_key_id(), ExtKeychain::derive_key_id(2, 1, 0, 0, 0));
|
||||
}
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 7, false);
|
||||
|
||||
{
|
||||
let mut w = wallet1.lock();
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account2")?;
|
||||
assert_eq!(w.parent_key_id(), ExtKeychain::derive_key_id(2, 2, 0, 0, 0));
|
||||
}
|
||||
@@ -136,7 +132,9 @@ fn accounts_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
})?;
|
||||
// now check second account
|
||||
{
|
||||
let mut w = wallet1.lock();
|
||||
let mut w_lock = wallet1.lock();
|
||||
let lc = w_lock.lc_provider()?;
|
||||
let w = lc.wallet_inst()?;
|
||||
w.set_parent_key_id_by_name("account1")?;
|
||||
}
|
||||
wallet::controller::owner_single_use(wallet1.clone(), |api| {
|
||||
@@ -156,7 +154,7 @@ fn accounts_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
|
||||
// should be nothing in default account
|
||||
{
|
||||
let mut w = wallet1.lock();
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("default")?;
|
||||
}
|
||||
wallet::controller::owner_single_use(wallet1.clone(), |api| {
|
||||
@@ -175,7 +173,7 @@ fn accounts_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
|
||||
// Send a tx to another wallet
|
||||
{
|
||||
let mut w = wallet1.lock();
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account1")?;
|
||||
}
|
||||
|
||||
@@ -208,7 +206,7 @@ fn accounts_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
|
||||
// other account should be untouched
|
||||
{
|
||||
let mut w = wallet1.lock();
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account2")?;
|
||||
}
|
||||
wallet::controller::owner_single_use(wallet1.clone(), |api| {
|
||||
@@ -233,7 +231,7 @@ fn accounts_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
})?;
|
||||
// Default account on wallet 2 should be untouched
|
||||
{
|
||||
let mut w = wallet2.lock();
|
||||
wallet_inst!(wallet2, w);
|
||||
w.set_parent_key_id_by_name("default")?;
|
||||
}
|
||||
wallet::controller::owner_single_use(wallet2.clone(), |api| {
|
||||
|
||||
+106
-119
@@ -18,70 +18,60 @@ extern crate grin_wallet_controller as wallet;
|
||||
extern crate grin_wallet_impls as impls;
|
||||
|
||||
use grin_wallet_util::grin_core as core;
|
||||
use grin_wallet_util::grin_keychain as keychain;
|
||||
use grin_wallet_util::grin_util as util;
|
||||
|
||||
use self::core::consensus;
|
||||
use self::core::global;
|
||||
use self::core::global::ChainTypes;
|
||||
use self::keychain::ExtKeychain;
|
||||
use grin_wallet_libwallet as libwallet;
|
||||
use impls::test_framework::{self, LocalWalletClient, WalletProxy};
|
||||
use impls::FileWalletCommAdapter;
|
||||
use libwallet::{InitTxArgs, WalletInst};
|
||||
use std::fs;
|
||||
use impls::test_framework::{self, LocalWalletClient};
|
||||
use impls::{PathToSlate, SlatePutter as _};
|
||||
use libwallet::InitTxArgs;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use util::ZeroingString;
|
||||
|
||||
#[macro_use]
|
||||
mod common;
|
||||
use common::{create_wallet_proxy, setup};
|
||||
|
||||
macro_rules! send_to_dest {
|
||||
($a:expr, $b:expr, $c:expr, $d:expr) => {
|
||||
test_framework::send_to_dest::<
|
||||
WalletInst<LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
ExtKeychain,
|
||||
>($a, $b, $c, $d, false)
|
||||
test_framework::send_to_dest($a, $b, $c, $d, false)
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! wallet_info {
|
||||
($a:expr) => {
|
||||
test_framework::wallet_info::<
|
||||
WalletInst<LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
ExtKeychain,
|
||||
>($a)
|
||||
test_framework::wallet_info($a)
|
||||
};
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/// Various tests on checking functionality
|
||||
fn check_repair_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
fn check_repair_impl(test_dir: &'static str) -> Result<(), libwallet::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);
|
||||
let mut wallet_proxy = create_wallet_proxy(test_dir);
|
||||
let chain = wallet_proxy.chain.clone();
|
||||
|
||||
// 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 =
|
||||
test_framework::create_wallet(&format!("{}/wallet1", test_dir), client1.clone(), None);
|
||||
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 =
|
||||
test_framework::create_wallet(&format!("{}/wallet2", test_dir), client2.clone(), None);
|
||||
wallet_proxy.add_wallet("wallet2", client2.get_send_instance(), wallet2.clone());
|
||||
create_wallet_and_add!(
|
||||
client1,
|
||||
wallet1,
|
||||
test_dir,
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
test_dir,
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -138,8 +128,7 @@ fn check_repair_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
let w1_outputs: Vec<libwallet::OutputData> =
|
||||
w1_outputs_commits.into_iter().map(|m| m.output).collect();
|
||||
{
|
||||
let mut w = wallet1.lock();
|
||||
w.open_with_credentials()?;
|
||||
wallet_inst!(wallet1, w);
|
||||
{
|
||||
let mut batch = w.batch()?;
|
||||
batch.delete(&w1_outputs[4].key_id, &None)?;
|
||||
@@ -149,7 +138,6 @@ fn check_repair_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
batch.save(accidental_spent)?;
|
||||
batch.commit()?;
|
||||
}
|
||||
w.close()?;
|
||||
}
|
||||
|
||||
// check we have a problem now
|
||||
@@ -187,11 +175,10 @@ fn check_repair_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
let mut slate = api.init_send_tx(args)?;
|
||||
let slate = api.init_send_tx(args)?;
|
||||
// output tx file
|
||||
let file_adapter = FileWalletCommAdapter::new();
|
||||
let send_file = format!("{}/part_tx_1.tx", test_dir);
|
||||
file_adapter.send_tx_async(&send_file, &mut slate)?;
|
||||
PathToSlate(send_file.into()).put_tx(&slate)?;
|
||||
api.tx_lock_outputs(&slate, 0)?;
|
||||
Ok(())
|
||||
})?;
|
||||
@@ -221,107 +208,107 @@ fn check_repair_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn two_wallets_one_seed_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
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";
|
||||
let seed_phrase = Some(ZeroingString::from(seed_phrase));
|
||||
|
||||
// Create a new proxy to simulate server and wallet responses
|
||||
let mut wallet_proxy: WalletProxy<LocalWalletClient, ExtKeychain> = WalletProxy::new(test_dir);
|
||||
let mut wallet_proxy = create_wallet_proxy(test_dir);
|
||||
let chain = wallet_proxy.chain.clone();
|
||||
|
||||
// Create a new wallet test client, and set its queues to communicate with the
|
||||
// proxy
|
||||
let m_client = LocalWalletClient::new("miner", wallet_proxy.tx.clone());
|
||||
let miner =
|
||||
test_framework::create_wallet(&format!("{}/miner", test_dir), m_client.clone(), None);
|
||||
wallet_proxy.add_wallet("miner", m_client.get_send_instance(), miner.clone());
|
||||
create_wallet_and_add!(m_client, miner, test_dir, "miner", None, &mut wallet_proxy);
|
||||
|
||||
// non-mining recipient wallets
|
||||
let client1 = LocalWalletClient::new("wallet1", wallet_proxy.tx.clone());
|
||||
let wallet1 = test_framework::create_wallet(
|
||||
&format!("{}/wallet1", test_dir),
|
||||
client1.clone(),
|
||||
Some(seed_phrase),
|
||||
create_wallet_and_add!(
|
||||
client1,
|
||||
wallet1,
|
||||
test_dir,
|
||||
"wallet1",
|
||||
seed_phrase,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
wallet_proxy.add_wallet("wallet1", client1.get_send_instance(), wallet1.clone());
|
||||
|
||||
let client2 = LocalWalletClient::new("wallet2", wallet_proxy.tx.clone());
|
||||
let wallet2 = test_framework::create_wallet(
|
||||
&format!("{}/wallet2", test_dir),
|
||||
client2.clone(),
|
||||
Some(seed_phrase),
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
test_dir,
|
||||
"wallet2",
|
||||
seed_phrase,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
wallet_proxy.add_wallet("wallet2", client2.get_send_instance(), wallet2.clone());
|
||||
|
||||
// we'll restore into here
|
||||
let client3 = LocalWalletClient::new("wallet3", wallet_proxy.tx.clone());
|
||||
let wallet3 = test_framework::create_wallet(
|
||||
&format!("{}/wallet3", test_dir),
|
||||
client3.clone(),
|
||||
Some(seed_phrase),
|
||||
create_wallet_and_add!(
|
||||
client3,
|
||||
wallet3,
|
||||
test_dir,
|
||||
"wallet3",
|
||||
seed_phrase,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
wallet_proxy.add_wallet("wallet3", client3.get_send_instance(), wallet3.clone());
|
||||
|
||||
// also restore into here
|
||||
let client4 = LocalWalletClient::new("wallet4", wallet_proxy.tx.clone());
|
||||
let wallet4 = test_framework::create_wallet(
|
||||
&format!("{}/wallet4", test_dir),
|
||||
client4.clone(),
|
||||
Some(seed_phrase),
|
||||
create_wallet_and_add!(
|
||||
client4,
|
||||
wallet4,
|
||||
test_dir,
|
||||
"wallet4",
|
||||
seed_phrase,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
wallet_proxy.add_wallet("wallet4", client4.get_send_instance(), wallet4.clone());
|
||||
|
||||
// Simulate a recover from seed without restore into here
|
||||
let client5 = LocalWalletClient::new("wallet5", wallet_proxy.tx.clone());
|
||||
let wallet5 = test_framework::create_wallet(
|
||||
&format!("{}/wallet5", test_dir),
|
||||
client5.clone(),
|
||||
Some(seed_phrase),
|
||||
create_wallet_and_add!(
|
||||
client5,
|
||||
wallet5,
|
||||
test_dir,
|
||||
"wallet5",
|
||||
seed_phrase,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
wallet_proxy.add_wallet("wallet5", client5.get_send_instance(), wallet5.clone());
|
||||
|
||||
//simulate a recover from seed without restore into here
|
||||
let client6 = LocalWalletClient::new("wallet6", wallet_proxy.tx.clone());
|
||||
let wallet6 = test_framework::create_wallet(
|
||||
&format!("{}/wallet6", test_dir),
|
||||
client6.clone(),
|
||||
Some(seed_phrase),
|
||||
create_wallet_and_add!(
|
||||
client6,
|
||||
wallet6,
|
||||
test_dir,
|
||||
"wallet6",
|
||||
seed_phrase,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
wallet_proxy.add_wallet("wallet6", client6.get_send_instance(), wallet6.clone());
|
||||
|
||||
let client7 = LocalWalletClient::new("wallet7", wallet_proxy.tx.clone());
|
||||
let wallet7 = test_framework::create_wallet(
|
||||
&format!("{}/wallet7", test_dir),
|
||||
client7.clone(),
|
||||
Some(seed_phrase),
|
||||
create_wallet_and_add!(
|
||||
client7,
|
||||
wallet7,
|
||||
test_dir,
|
||||
"wallet7",
|
||||
seed_phrase,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
wallet_proxy.add_wallet("wallet7", client7.get_send_instance(), wallet7.clone());
|
||||
|
||||
let client8 = LocalWalletClient::new("wallet8", wallet_proxy.tx.clone());
|
||||
let wallet8 = test_framework::create_wallet(
|
||||
&format!("{}/wallet8", test_dir),
|
||||
client8.clone(),
|
||||
Some(seed_phrase),
|
||||
create_wallet_and_add!(
|
||||
client8,
|
||||
wallet8,
|
||||
test_dir,
|
||||
"wallet8",
|
||||
seed_phrase,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
wallet_proxy.add_wallet("wallet8", client8.get_send_instance(), wallet8.clone());
|
||||
|
||||
let client9 = LocalWalletClient::new("wallet9", wallet_proxy.tx.clone());
|
||||
let wallet9 = test_framework::create_wallet(
|
||||
&format!("{}/wallet9", test_dir),
|
||||
client9.clone(),
|
||||
Some(seed_phrase),
|
||||
create_wallet_and_add!(
|
||||
client9,
|
||||
wallet9,
|
||||
test_dir,
|
||||
"wallet9",
|
||||
seed_phrase,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
wallet_proxy.add_wallet("wallet9", client9.get_send_instance(), wallet9.clone());
|
||||
|
||||
let client10 = LocalWalletClient::new("wallet10", wallet_proxy.tx.clone());
|
||||
let wallet10 = test_framework::create_wallet(
|
||||
&format!("{}/wallet10", test_dir),
|
||||
client10.clone(),
|
||||
Some(seed_phrase),
|
||||
create_wallet_and_add!(
|
||||
client10,
|
||||
wallet10,
|
||||
test_dir,
|
||||
"wallet10",
|
||||
seed_phrase,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
wallet_proxy.add_wallet("wallet10", client10.get_send_instance(), wallet10.clone());
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
// 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.
|
||||
|
||||
//! common functions for tests (instantiating wallet and proxy, mostly)
|
||||
extern crate grin_wallet_controller as wallet;
|
||||
extern crate grin_wallet_impls as impls;
|
||||
extern crate grin_wallet_libwallet as libwallet;
|
||||
|
||||
use grin_wallet_util::grin_core as core;
|
||||
use grin_wallet_util::grin_keychain as keychain;
|
||||
use grin_wallet_util::grin_util as util;
|
||||
|
||||
use self::core::global;
|
||||
use self::core::global::ChainTypes;
|
||||
use self::keychain::ExtKeychain;
|
||||
use self::libwallet::WalletInst;
|
||||
use impls::test_framework::{LocalWalletClient, WalletProxy};
|
||||
use impls::{DefaultLCProvider, DefaultWalletImpl};
|
||||
use std::fs;
|
||||
use std::sync::Arc;
|
||||
use util::{Mutex, ZeroingString};
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! wallet_inst {
|
||||
($wallet:ident, $w: ident) => {
|
||||
let mut w_lock = $wallet.lock();
|
||||
let lc = w_lock.lc_provider()?;
|
||||
let $w = lc.wallet_inst()?;
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! create_wallet_and_add {
|
||||
($client:ident, $wallet: ident, $test_dir: expr, $name: expr, $seed_phrase: expr, $proxy: expr) => {
|
||||
let $client = LocalWalletClient::new($name, $proxy.tx.clone());
|
||||
let $wallet =
|
||||
common::create_local_wallet($test_dir, $name, $seed_phrase.clone(), $client.clone());
|
||||
$proxy.add_wallet($name, $client.get_send_instance(), $wallet.clone());
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! open_wallet_and_add {
|
||||
($client:ident, $wallet: ident, $test_dir: expr, $name: expr, $proxy: expr) => {
|
||||
let $client = LocalWalletClient::new($name, $proxy.tx.clone());
|
||||
let $wallet = common::open_local_wallet($test_dir, $name, $client.clone());
|
||||
$proxy.add_wallet($name, $client.get_send_instance(), $wallet.clone());
|
||||
};
|
||||
}
|
||||
pub fn clean_output_dir(test_dir: &str) {
|
||||
let _ = fs::remove_dir_all(test_dir);
|
||||
}
|
||||
|
||||
pub fn setup(test_dir: &str) {
|
||||
util::init_test_logger();
|
||||
clean_output_dir(test_dir);
|
||||
global::set_mining_mode(ChainTypes::AutomatedTesting);
|
||||
}
|
||||
|
||||
pub fn create_wallet_proxy(
|
||||
test_dir: &str,
|
||||
) -> WalletProxy<DefaultLCProvider<LocalWalletClient, ExtKeychain>, LocalWalletClient, ExtKeychain>
|
||||
{
|
||||
WalletProxy::new(test_dir)
|
||||
}
|
||||
|
||||
pub fn create_local_wallet(
|
||||
test_dir: &str,
|
||||
name: &str,
|
||||
mnemonic: Option<ZeroingString>,
|
||||
client: LocalWalletClient,
|
||||
) -> Arc<
|
||||
Mutex<
|
||||
Box<
|
||||
WalletInst<
|
||||
'static,
|
||||
DefaultLCProvider<'static, LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
ExtKeychain,
|
||||
>,
|
||||
>,
|
||||
>,
|
||||
> {
|
||||
let mut wallet = Box::new(DefaultWalletImpl::<LocalWalletClient>::new(client).unwrap())
|
||||
as Box<
|
||||
WalletInst<
|
||||
DefaultLCProvider<'static, LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
ExtKeychain,
|
||||
>,
|
||||
>;
|
||||
let lc = wallet.lc_provider().unwrap();
|
||||
lc.set_wallet_directory(&format!("{}/{}", test_dir, name));
|
||||
lc.create_wallet(None, mnemonic, 32, ZeroingString::from(""))
|
||||
.unwrap();
|
||||
lc.open_wallet(None, ZeroingString::from("")).unwrap();
|
||||
Arc::new(Mutex::new(wallet))
|
||||
}
|
||||
|
||||
pub fn open_local_wallet(
|
||||
test_dir: &str,
|
||||
name: &str,
|
||||
client: LocalWalletClient,
|
||||
) -> Arc<
|
||||
Mutex<
|
||||
Box<
|
||||
WalletInst<
|
||||
'static,
|
||||
DefaultLCProvider<'static, LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
ExtKeychain,
|
||||
>,
|
||||
>,
|
||||
>,
|
||||
> {
|
||||
let mut wallet = Box::new(DefaultWalletImpl::<LocalWalletClient>::new(client).unwrap())
|
||||
as Box<
|
||||
WalletInst<
|
||||
DefaultLCProvider<'static, LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
ExtKeychain,
|
||||
>,
|
||||
>;
|
||||
let lc = wallet.lc_provider().unwrap();
|
||||
lc.set_wallet_directory(&format!("{}/{}", test_dir, name));
|
||||
lc.open_wallet(None, ZeroingString::from("")).unwrap();
|
||||
Arc::new(Mutex::new(wallet))
|
||||
}
|
||||
+34
-39
@@ -17,17 +17,11 @@ extern crate log;
|
||||
extern crate grin_wallet_controller as wallet;
|
||||
extern crate grin_wallet_impls as impls;
|
||||
|
||||
use grin_wallet_util::grin_core as core;
|
||||
use grin_wallet_util::grin_keychain as keychain;
|
||||
use grin_wallet_util::grin_util as util;
|
||||
|
||||
use self::core::global;
|
||||
use self::core::global::ChainTypes;
|
||||
use self::keychain::ExtKeychain;
|
||||
use grin_wallet_libwallet as libwallet;
|
||||
use impls::test_framework::{self, LocalWalletClient, WalletProxy};
|
||||
use impls::FileWalletCommAdapter;
|
||||
use std::fs;
|
||||
use grin_wallet_util::grin_core as core;
|
||||
|
||||
use impls::test_framework::{self, LocalWalletClient};
|
||||
use impls::{PathToSlate, SlateGetter as _, SlatePutter as _};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -35,32 +29,36 @@ use grin_wallet_libwallet::InitTxArgs;
|
||||
|
||||
use serde_json;
|
||||
|
||||
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);
|
||||
}
|
||||
#[macro_use]
|
||||
mod common;
|
||||
use common::{create_wallet_proxy, setup};
|
||||
|
||||
/// self send impl
|
||||
fn file_exchange_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
fn file_exchange_test_impl(test_dir: &'static str) -> Result<(), libwallet::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);
|
||||
let mut wallet_proxy = create_wallet_proxy(test_dir);
|
||||
let chain = wallet_proxy.chain.clone();
|
||||
|
||||
let client1 = LocalWalletClient::new("wallet1", wallet_proxy.tx.clone());
|
||||
let wallet1 =
|
||||
test_framework::create_wallet(&format!("{}/wallet1", test_dir), client1.clone(), None);
|
||||
wallet_proxy.add_wallet("wallet1", client1.get_send_instance(), wallet1.clone());
|
||||
|
||||
let client2 = LocalWalletClient::new("wallet2", wallet_proxy.tx.clone());
|
||||
let wallet2 =
|
||||
test_framework::create_wallet(&format!("{}/wallet2", test_dir), client2.clone(), None);
|
||||
wallet_proxy.add_wallet("wallet2", client2.get_send_instance(), wallet2.clone());
|
||||
// Create a new wallet test client, and set its queues to communicate with the
|
||||
// proxy
|
||||
create_wallet_and_add!(
|
||||
client1,
|
||||
wallet1,
|
||||
test_dir,
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
test_dir,
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -88,7 +86,7 @@ fn file_exchange_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
|
||||
// Get some mining done
|
||||
{
|
||||
let mut w = wallet1.lock();
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("mining")?;
|
||||
}
|
||||
let mut bh = 10u64;
|
||||
@@ -119,20 +117,18 @@ fn file_exchange_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
};
|
||||
let mut slate = api.init_send_tx(args)?;
|
||||
// output tx file
|
||||
let file_adapter = FileWalletCommAdapter::new();
|
||||
file_adapter.send_tx_async(&send_file, &mut slate)?;
|
||||
PathToSlate((&send_file).into()).put_tx(&mut slate)?;
|
||||
api.tx_lock_outputs(&slate, 0)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// Get some mining done
|
||||
{
|
||||
let mut w = wallet2.lock();
|
||||
wallet_inst!(wallet2, w);
|
||||
w.set_parent_key_id_by_name("account1")?;
|
||||
}
|
||||
|
||||
let adapter = FileWalletCommAdapter::new();
|
||||
let mut slate = adapter.receive_tx_async(&send_file)?;
|
||||
let mut slate = PathToSlate((&send_file).into()).get_tx()?;
|
||||
let mut naughty_slate = slate.clone();
|
||||
naughty_slate.participant_data[0].message = Some("I changed the message".to_owned());
|
||||
|
||||
@@ -148,14 +144,13 @@ fn file_exchange_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
// wallet 2 receives file, completes, sends file back
|
||||
wallet::controller::foreign_single_use(wallet2.clone(), |api| {
|
||||
slate = api.receive_tx(&slate, None, Some(sender2_message.clone()))?;
|
||||
adapter.send_tx_async(&receive_file, &mut slate)?;
|
||||
PathToSlate((&receive_file).into()).put_tx(&slate)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// wallet 1 finalises and posts
|
||||
wallet::controller::owner_single_use(wallet1.clone(), |api| {
|
||||
let adapter = FileWalletCommAdapter::new();
|
||||
let mut slate = adapter.receive_tx_async(&receive_file)?;
|
||||
let mut slate = PathToSlate(receive_file.into()).get_tx()?;
|
||||
api.verify_slate_messages(&slate)?;
|
||||
slate = api.finalize_tx(&slate)?;
|
||||
api.post_tx(&slate.tx, false)?;
|
||||
|
||||
+27
-38
@@ -17,54 +17,43 @@ extern crate log;
|
||||
extern crate grin_wallet_controller as wallet;
|
||||
extern crate grin_wallet_impls as impls;
|
||||
|
||||
use grin_wallet_util::grin_core as core;
|
||||
use grin_wallet_util::grin_keychain as keychain;
|
||||
use grin_wallet_util::grin_util as util;
|
||||
|
||||
use self::core::global;
|
||||
use self::core::global::ChainTypes;
|
||||
use self::keychain::ExtKeychain;
|
||||
use grin_wallet_libwallet as libwallet;
|
||||
use impls::test_framework::{self, LocalWalletClient, WalletProxy};
|
||||
use grin_wallet_util::grin_core as core;
|
||||
|
||||
use impls::test_framework::{self, LocalWalletClient};
|
||||
use libwallet::{InitTxArgs, IssueInvoiceTxArgs, Slate};
|
||||
use std::fs;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
fn teardown(test_dir: &str) {
|
||||
clean_output_dir(test_dir);
|
||||
}
|
||||
#[macro_use]
|
||||
mod common;
|
||||
use common::{clean_output_dir, create_wallet_proxy, setup};
|
||||
|
||||
/// self send impl
|
||||
fn invoice_tx_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
fn invoice_tx_impl(test_dir: &'static str) -> Result<(), libwallet::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);
|
||||
let mut wallet_proxy = create_wallet_proxy(test_dir);
|
||||
let chain = wallet_proxy.chain.clone();
|
||||
|
||||
// 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 =
|
||||
test_framework::create_wallet(&format!("{}/wallet1", test_dir), client1.clone(), None);
|
||||
wallet_proxy.add_wallet("wallet1", client1.get_send_instance(), wallet1.clone());
|
||||
|
||||
// wallet 2, will be recipient
|
||||
let client2 = LocalWalletClient::new("wallet2", wallet_proxy.tx.clone());
|
||||
let wallet2 =
|
||||
test_framework::create_wallet(&format!("{}/wallet2", test_dir), client2.clone(), None);
|
||||
wallet_proxy.add_wallet("wallet2", client2.get_send_instance(), wallet2.clone());
|
||||
create_wallet_and_add!(
|
||||
client1,
|
||||
wallet1,
|
||||
test_dir,
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
test_dir,
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -85,7 +74,7 @@ fn invoice_tx_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
|
||||
// Get some mining done
|
||||
{
|
||||
let mut w = wallet1.lock();
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("mining")?;
|
||||
}
|
||||
let mut bh = 10u64;
|
||||
@@ -211,7 +200,7 @@ fn invoice_tx_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
}
|
||||
|
||||
teardown(test_dir);
|
||||
clean_output_dir(test_dir);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
+37
-43
@@ -19,45 +19,43 @@ extern crate grin_wallet_impls as impls;
|
||||
extern crate grin_wallet_libwallet as libwallet;
|
||||
|
||||
use grin_wallet_util::grin_core as core;
|
||||
use grin_wallet_util::grin_keychain as keychain;
|
||||
use grin_wallet_util::grin_util as util;
|
||||
|
||||
use self::core::global;
|
||||
use self::core::global::ChainTypes;
|
||||
use self::keychain::ExtKeychain;
|
||||
use self::libwallet::{InitTxArgs, Slate};
|
||||
use impls::test_framework::{self, LocalWalletClient, WalletProxy};
|
||||
use impls::FileWalletCommAdapter;
|
||||
use std::fs;
|
||||
use impls::test_framework::{self, LocalWalletClient};
|
||||
use impls::{PathToSlate, SlateGetter as _, SlatePutter as _};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
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);
|
||||
}
|
||||
#[macro_use]
|
||||
mod common;
|
||||
use common::{create_wallet_proxy, setup};
|
||||
|
||||
/// self send impl
|
||||
fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
fn file_repost_test_impl(test_dir: &'static str) -> Result<(), libwallet::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);
|
||||
let mut wallet_proxy = create_wallet_proxy(test_dir);
|
||||
let chain = wallet_proxy.chain.clone();
|
||||
|
||||
let client1 = LocalWalletClient::new("wallet1", wallet_proxy.tx.clone());
|
||||
let wallet1 =
|
||||
test_framework::create_wallet(&format!("{}/wallet1", test_dir), client1.clone(), None);
|
||||
wallet_proxy.add_wallet("wallet1", client1.get_send_instance(), wallet1.clone());
|
||||
|
||||
let client2 = LocalWalletClient::new("wallet2", wallet_proxy.tx.clone());
|
||||
let wallet2 =
|
||||
test_framework::create_wallet(&format!("{}/wallet2", test_dir), client2.clone(), None);
|
||||
wallet_proxy.add_wallet("wallet2", client2.get_send_instance(), wallet2.clone());
|
||||
// Create a new wallet test client, and set its queues to communicate with the
|
||||
// proxy
|
||||
create_wallet_and_add!(
|
||||
client1,
|
||||
wallet1,
|
||||
test_dir,
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
test_dir,
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -85,7 +83,7 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
|
||||
// Get some mining done
|
||||
{
|
||||
let mut w = wallet1.lock();
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("mining")?;
|
||||
}
|
||||
let mut bh = 10u64;
|
||||
@@ -112,10 +110,8 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
let mut slate = api.init_send_tx(args)?;
|
||||
// output tx file
|
||||
let file_adapter = FileWalletCommAdapter::new();
|
||||
file_adapter.send_tx_async(&send_file, &mut slate)?;
|
||||
let slate = api.init_send_tx(args)?;
|
||||
PathToSlate((&send_file).into()).put_tx(&slate)?;
|
||||
api.tx_lock_outputs(&slate, 0)?;
|
||||
Ok(())
|
||||
})?;
|
||||
@@ -125,28 +121,26 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
|
||||
// wallet 1 receives file to different account, completes
|
||||
{
|
||||
let mut w = wallet1.lock();
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("listener")?;
|
||||
}
|
||||
|
||||
wallet::controller::foreign_single_use(wallet1.clone(), |api| {
|
||||
let adapter = FileWalletCommAdapter::new();
|
||||
slate = adapter.receive_tx_async(&send_file)?;
|
||||
slate = PathToSlate((&send_file).into()).get_tx()?;
|
||||
slate = api.receive_tx(&slate, None, None)?;
|
||||
adapter.send_tx_async(&receive_file, &mut slate)?;
|
||||
PathToSlate((&receive_file).into()).put_tx(&slate)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// wallet 1 receives file to different account, completes
|
||||
{
|
||||
let mut w = wallet1.lock();
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("mining")?;
|
||||
}
|
||||
|
||||
// wallet 1 finalize
|
||||
wallet::controller::owner_single_use(wallet1.clone(), |api| {
|
||||
let adapter = FileWalletCommAdapter::new();
|
||||
slate = adapter.receive_tx_async(&receive_file)?;
|
||||
slate = PathToSlate((&receive_file).into()).get_tx()?;
|
||||
slate = api.finalize_tx(&slate)?;
|
||||
Ok(())
|
||||
})?;
|
||||
@@ -173,7 +167,7 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
})?;
|
||||
|
||||
{
|
||||
let mut w = wallet1.lock();
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("listener")?;
|
||||
}
|
||||
|
||||
@@ -187,11 +181,11 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
|
||||
// as above, but syncronously
|
||||
{
|
||||
let mut w = wallet1.lock();
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("mining")?;
|
||||
}
|
||||
{
|
||||
let mut w = wallet2.lock();
|
||||
wallet_inst!(wallet2, w);
|
||||
w.set_parent_key_id_by_name("account1")?;
|
||||
}
|
||||
|
||||
|
||||
+74
-62
@@ -18,44 +18,51 @@ extern crate grin_wallet_controller as wallet;
|
||||
extern crate grin_wallet_impls as impls;
|
||||
extern crate grin_wallet_libwallet as libwallet;
|
||||
|
||||
use grin_wallet_util::grin_core as core;
|
||||
use grin_wallet_util::grin_keychain as keychain;
|
||||
use grin_wallet_util::grin_util as util;
|
||||
|
||||
use self::core::global;
|
||||
use self::core::global::ChainTypes;
|
||||
use self::keychain::{ExtKeychain, Identifier, Keychain};
|
||||
use self::libwallet::{AcctPathMapping, InitTxArgs, Slate};
|
||||
use impls::test_framework::{self, LocalWalletClient, WalletProxy};
|
||||
use impls::test_framework::{self, LocalWalletClient};
|
||||
use std::fs;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
fn clean_output_dir(test_dir: &str) {
|
||||
let _ = fs::remove_dir_all(test_dir);
|
||||
}
|
||||
#[macro_use]
|
||||
mod common;
|
||||
use common::{create_wallet_proxy, setup};
|
||||
|
||||
fn setup(test_dir: &str) {
|
||||
util::init_test_logger();
|
||||
clean_output_dir(test_dir);
|
||||
global::set_mining_mode(ChainTypes::AutomatedTesting);
|
||||
}
|
||||
fn restore_wallet(base_dir: &'static str, wallet_dir: &str) -> Result<(), libwallet::Error> {
|
||||
let source_seed = format!("{}/{}/wallet_data/wallet.seed", base_dir, wallet_dir);
|
||||
let dest_wallet_name = format!("{}_restore", wallet_dir);
|
||||
let dest_dir = format!("{}/{}/wallet_data", base_dir, dest_wallet_name);
|
||||
|
||||
let mut wallet_proxy = create_wallet_proxy(base_dir);
|
||||
create_wallet_and_add!(
|
||||
client,
|
||||
wallet,
|
||||
base_dir,
|
||||
&dest_wallet_name,
|
||||
None,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
// close created wallet
|
||||
let mut w_lock = wallet.lock();
|
||||
let lc = w_lock.lc_provider()?;
|
||||
lc.close_wallet(None)?;
|
||||
|
||||
fn restore_wallet(base_dir: &str, wallet_dir: &str) -> Result<(), libwallet::Error> {
|
||||
let source_seed = format!("{}/{}/wallet.seed", base_dir, wallet_dir);
|
||||
let dest_dir = format!("{}/{}_restore", base_dir, wallet_dir);
|
||||
fs::create_dir_all(dest_dir.clone())?;
|
||||
let dest_seed = format!("{}/wallet.seed", dest_dir);
|
||||
println!("Source: {}, Dest: {}", source_seed, dest_seed);
|
||||
fs::copy(source_seed, dest_seed)?;
|
||||
|
||||
let mut wallet_proxy: WalletProxy<LocalWalletClient, ExtKeychain> = WalletProxy::new(base_dir);
|
||||
let client = LocalWalletClient::new(wallet_dir, wallet_proxy.tx.clone());
|
||||
|
||||
let wallet = test_framework::create_wallet(&dest_dir, client.clone(), None);
|
||||
|
||||
wallet_proxy.add_wallet(wallet_dir, client.get_send_instance(), wallet.clone());
|
||||
// reopen with new seed
|
||||
open_wallet_and_add!(
|
||||
client,
|
||||
wallet,
|
||||
&base_dir,
|
||||
&dest_wallet_name,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
let wp_running = wallet_proxy.running.clone();
|
||||
@@ -79,39 +86,35 @@ fn restore_wallet(base_dir: &str, wallet_dir: &str) -> Result<(), libwallet::Err
|
||||
}
|
||||
|
||||
fn compare_wallet_restore(
|
||||
base_dir: &str,
|
||||
base_dir: &'static str,
|
||||
wallet_dir: &str,
|
||||
account_path: &Identifier,
|
||||
) -> Result<(), libwallet::Error> {
|
||||
let restore_name = format!("{}_restore", wallet_dir);
|
||||
let source_dir = format!("{}/{}", base_dir, wallet_dir);
|
||||
let dest_dir = format!("{}/{}", base_dir, restore_name);
|
||||
let mut wallet_proxy = create_wallet_proxy(base_dir);
|
||||
|
||||
let mut wallet_proxy: WalletProxy<LocalWalletClient, ExtKeychain> = WalletProxy::new(base_dir);
|
||||
|
||||
let client = LocalWalletClient::new(wallet_dir, wallet_proxy.tx.clone());
|
||||
let wallet_source = test_framework::create_wallet(&source_dir, client.clone(), None);
|
||||
wallet_proxy.add_wallet(
|
||||
open_wallet_and_add!(
|
||||
client,
|
||||
wallet_source,
|
||||
&base_dir,
|
||||
&wallet_dir,
|
||||
client.get_send_instance(),
|
||||
wallet_source.clone(),
|
||||
&mut wallet_proxy
|
||||
);
|
||||
|
||||
let client = LocalWalletClient::new(&restore_name, wallet_proxy.tx.clone());
|
||||
let wallet_dest = test_framework::create_wallet(&dest_dir, client.clone(), None);
|
||||
wallet_proxy.add_wallet(
|
||||
open_wallet_and_add!(
|
||||
client,
|
||||
wallet_dest,
|
||||
&base_dir,
|
||||
&restore_name,
|
||||
client.get_send_instance(),
|
||||
wallet_dest.clone(),
|
||||
&mut wallet_proxy
|
||||
);
|
||||
|
||||
{
|
||||
let mut w = wallet_source.lock();
|
||||
wallet_inst!(wallet_source, w);
|
||||
w.set_parent_key_id(account_path.clone());
|
||||
}
|
||||
|
||||
{
|
||||
let mut w = wallet_dest.lock();
|
||||
wallet_inst!(wallet_dest, w);
|
||||
w.set_parent_key_id(account_path.clone());
|
||||
}
|
||||
|
||||
@@ -181,24 +184,29 @@ fn compare_wallet_restore(
|
||||
|
||||
/// Build up 2 wallets, perform a few transactions on them
|
||||
/// Then attempt to restore them in separate directories and check contents are the same
|
||||
fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
fn setup_restore(test_dir: &'static str) -> Result<(), libwallet::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);
|
||||
let mut wallet_proxy = create_wallet_proxy(test_dir);
|
||||
let chain = wallet_proxy.chain.clone();
|
||||
|
||||
// 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 =
|
||||
test_framework::create_wallet(&format!("{}/wallet1", test_dir), client1.clone(), None);
|
||||
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 =
|
||||
test_framework::create_wallet(&format!("{}/wallet2", test_dir), client2.clone(), None);
|
||||
wallet_proxy.add_wallet("wallet2", client2.get_send_instance(), wallet2.clone());
|
||||
create_wallet_and_add!(
|
||||
client1,
|
||||
wallet1,
|
||||
test_dir,
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
test_dir,
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
|
||||
// wallet 2 will use another account
|
||||
wallet::controller::owner_single_use(wallet2.clone(), |api| {
|
||||
@@ -209,15 +217,19 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
|
||||
// Default wallet 2 to listen on that account
|
||||
{
|
||||
let mut w = wallet2.lock();
|
||||
wallet_inst!(wallet2, w);
|
||||
w.set_parent_key_id_by_name("account1")?;
|
||||
}
|
||||
|
||||
// Another wallet
|
||||
let client3 = LocalWalletClient::new("wallet3", wallet_proxy.tx.clone());
|
||||
let wallet3 =
|
||||
test_framework::create_wallet(&format!("{}/wallet3", test_dir), client3.clone(), None);
|
||||
wallet_proxy.add_wallet("wallet3", client3.get_send_instance(), wallet3.clone());
|
||||
create_wallet_and_add!(
|
||||
client3,
|
||||
wallet3,
|
||||
test_dir,
|
||||
"wallet3",
|
||||
None,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
let wp_running = wallet_proxy.running.clone();
|
||||
@@ -301,7 +313,7 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
|
||||
// Another listener account on wallet 2
|
||||
{
|
||||
let mut w = wallet2.lock();
|
||||
wallet_inst!(wallet2, w);
|
||||
w.set_parent_key_id_by_name("account2")?;
|
||||
}
|
||||
|
||||
@@ -350,7 +362,7 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn perform_restore(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
fn perform_restore(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
restore_wallet(test_dir, "wallet1")?;
|
||||
compare_wallet_restore(
|
||||
test_dir,
|
||||
|
||||
@@ -18,42 +18,34 @@ extern crate grin_wallet_controller as wallet;
|
||||
extern crate grin_wallet_impls as impls;
|
||||
|
||||
use grin_wallet_util::grin_core as core;
|
||||
use grin_wallet_util::grin_keychain as keychain;
|
||||
use grin_wallet_util::grin_util as util;
|
||||
|
||||
use self::core::global;
|
||||
use self::core::global::ChainTypes;
|
||||
use self::keychain::ExtKeychain;
|
||||
use grin_wallet_libwallet as libwallet;
|
||||
use impls::test_framework::{self, LocalWalletClient, WalletProxy};
|
||||
use impls::test_framework::{self, LocalWalletClient};
|
||||
use libwallet::InitTxArgs;
|
||||
use std::fs;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
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);
|
||||
}
|
||||
#[macro_use]
|
||||
mod common;
|
||||
use common::{create_wallet_proxy, setup};
|
||||
|
||||
/// self send impl
|
||||
fn self_send_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
fn self_send_test_impl(test_dir: &'static str) -> Result<(), libwallet::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);
|
||||
let mut wallet_proxy = create_wallet_proxy(test_dir);
|
||||
let chain = wallet_proxy.chain.clone();
|
||||
|
||||
// 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 =
|
||||
test_framework::create_wallet(&format!("{}/wallet1", test_dir), client1.clone(), None);
|
||||
wallet_proxy.add_wallet("wallet1", client1.get_send_instance(), wallet1.clone());
|
||||
create_wallet_and_add!(
|
||||
client1,
|
||||
wallet1,
|
||||
test_dir,
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -74,7 +66,7 @@ fn self_send_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
|
||||
// Get some mining done
|
||||
{
|
||||
let mut w = wallet1.lock();
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("mining")?;
|
||||
}
|
||||
let mut bh = 10u64;
|
||||
@@ -123,7 +115,7 @@ fn self_send_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
|
||||
// Check total in 'listener' account
|
||||
{
|
||||
let mut w = wallet1.lock();
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("listener")?;
|
||||
}
|
||||
wallet::controller::owner_single_use(wallet1.clone(), |api| {
|
||||
|
||||
@@ -19,50 +19,42 @@ extern crate grin_wallet_impls as impls;
|
||||
extern crate grin_wallet_libwallet as libwallet;
|
||||
|
||||
use grin_wallet_util::grin_core as core;
|
||||
use grin_wallet_util::grin_keychain as keychain;
|
||||
use grin_wallet_util::grin_util as util;
|
||||
|
||||
use self::core::core::transaction;
|
||||
use self::core::global;
|
||||
use self::core::global::ChainTypes;
|
||||
use self::keychain::ExtKeychain;
|
||||
use self::libwallet::{InitTxArgs, OutputStatus, Slate};
|
||||
use impls::test_framework::{self, LocalWalletClient, WalletProxy};
|
||||
use std::fs;
|
||||
use impls::test_framework::{self, LocalWalletClient};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
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);
|
||||
}
|
||||
mod common;
|
||||
use common::{create_wallet_proxy, setup};
|
||||
|
||||
/// Exercises the Transaction API fully with a test NodeClient operating
|
||||
/// directly on a chain instance
|
||||
/// Callable with any type of wallet
|
||||
fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
fn basic_transaction_api(test_dir: &'static str) -> Result<(), libwallet::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);
|
||||
let mut wallet_proxy = create_wallet_proxy(test_dir);
|
||||
let chain = wallet_proxy.chain.clone();
|
||||
|
||||
// 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 =
|
||||
test_framework::create_wallet(&format!("{}/wallet1", test_dir), client1.clone(), None);
|
||||
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 =
|
||||
test_framework::create_wallet(&format!("{}/wallet2", test_dir), client2.clone(), None);
|
||||
wallet_proxy.add_wallet("wallet2", client2.get_send_instance(), wallet2.clone());
|
||||
create_wallet_and_add!(
|
||||
client1,
|
||||
wallet1,
|
||||
test_dir,
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
test_dir,
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -349,24 +341,28 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
|
||||
/// Test rolling back transactions and outputs when a transaction is never
|
||||
/// posted to a chain
|
||||
fn tx_rollback(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
fn tx_rollback(test_dir: &'static str) -> Result<(), libwallet::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);
|
||||
let mut wallet_proxy = create_wallet_proxy(test_dir);
|
||||
let chain = wallet_proxy.chain.clone();
|
||||
|
||||
// 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 =
|
||||
test_framework::create_wallet(&format!("{}/wallet1", test_dir), client1.clone(), None);
|
||||
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 =
|
||||
test_framework::create_wallet(&format!("{}/wallet2", test_dir), client2.clone(), None);
|
||||
wallet_proxy.add_wallet("wallet2", client2.get_send_instance(), wallet2.clone());
|
||||
create_wallet_and_add!(
|
||||
client1,
|
||||
wallet1,
|
||||
test_dir,
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
test_dir,
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy
|
||||
);
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
|
||||
Reference in New Issue
Block a user