Wallet API Test Client (#1242)

* beginnings to testclient implementation for more complete wallet API testing

* rework TestWalletClient to be message-based proxy

* test fix

* wallet tests now exercising the API directly as much as possible, capable of instantiating multiple wallets

* test in place to run both file and db wallets

* ensure all wallet api functions lock wallet as needed. Split up transaction creation from posting to chain
This commit is contained in:
Yeastplume
2018-07-12 16:49:37 +01:00
committed by GitHub
parent 25ca2de487
commit bacadfb5ab
13 changed files with 917 additions and 475 deletions
+31 -12
View File
@@ -41,7 +41,7 @@ pub mod tui;
use std::env::current_dir;
use std::process::exit;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Duration;
@@ -53,8 +53,10 @@ use core::core::amount_to_hr_string;
use core::global;
use tui::ui;
use util::{init_logger, LoggingConfig, LOGGER};
use wallet::{libwallet, wallet_db_exists, FileWallet,
HTTPWalletClient, LMDBBackend, WalletConfig, WalletInst};
use wallet::{
libwallet, wallet_db_exists, FileWallet, HTTPWalletClient, LMDBBackend, WalletConfig,
WalletInst,
};
// include build information
pub mod built_info {
@@ -606,8 +608,8 @@ fn wallet_command(wallet_args: &ArgMatches, global_config: GlobalConfig) {
info!(LOGGER, "Wallet seed file created");
if use_db {
let client = HTTPWalletClient::new(&wallet_config.check_node_api_http_addr);
let _: LMDBBackend<HTTPWalletClient, keychain::ExtKeychain> = LMDBBackend::new(wallet_config.clone(), "", client)
.unwrap_or_else(|e| {
let _: LMDBBackend<HTTPWalletClient, keychain::ExtKeychain> =
LMDBBackend::new(wallet_config.clone(), "", client).unwrap_or_else(|e| {
panic!(
"Error creating DB wallet: {} Config: {:?}",
e, wallet_config
@@ -658,7 +660,11 @@ fn wallet_command(wallet_args: &ArgMatches, global_config: GlobalConfig) {
// Handle single-use (command line) owner commands
{
let wallet = instantiate_wallet(wallet_config.clone(), passphrase, use_db);
let wallet = Arc::new(Mutex::new(instantiate_wallet(
wallet_config.clone(),
passphrase,
use_db,
)));
let _res = wallet::controller::owner_single_use(wallet, |api| {
match wallet_args.subcommand() {
("send", Some(send_args)) => {
@@ -689,21 +695,20 @@ fn wallet_command(wallet_args: &ArgMatches, global_config: GlobalConfig) {
dest,
max_outputs,
selection_strategy == "all",
fluff,
);
match result {
Ok(_) => {
let slate = match result {
Ok(s) => {
info!(
LOGGER,
"Tx sent: {} grin to {} (strategy '{}')",
"Tx created: {} grin to {} (strategy '{}')",
amount_to_hr_string(amount),
dest,
selection_strategy,
);
Ok(())
s
}
Err(e) => {
error!(LOGGER, "Tx not sent: {:?}", e);
error!(LOGGER, "Tx not created: {:?}", e);
match e.kind() {
// user errors, don't backtrace
libwallet::ErrorKind::NotEnoughFunds { .. } => {}
@@ -714,6 +719,20 @@ fn wallet_command(wallet_args: &ArgMatches, global_config: GlobalConfig) {
error!(LOGGER, "Backtrace: {}", e.backtrace().unwrap());
}
};
panic!();
}
};
let result = api.post_tx(&slate, fluff);
match result {
Ok(_) => {
info!(
LOGGER,
"Tx sent",
);
Ok(())
}
Err(e) => {
error!(LOGGER, "Tx not sent: {:?}", e);
Err(e)
}
}