use local chain_type and global chain_type as necessary

This commit is contained in:
antiochp
2020-05-22 14:35:35 +01:00
parent 2769436117
commit 72ff4b4e13
19 changed files with 79 additions and 49 deletions
+5 -9
View File
@@ -54,7 +54,6 @@ pub struct GlobalArgs {
pub api_secret: Option<String>,
pub node_api_secret: Option<String>,
pub show_spent: bool,
pub chain_type: global::ChainTypes,
pub password: Option<ZeroingString>,
pub tls_conf: Option<TLSConfig>,
}
@@ -71,7 +70,7 @@ pub struct InitArgs {
pub fn init<L, C, K>(
owner_api: &mut Owner<L, C, K>,
g_args: &GlobalArgs,
_g_args: &GlobalArgs,
args: InitArgs,
) -> Result<(), Error>
where
@@ -79,15 +78,12 @@ where
C: NodeClient + 'static,
K: keychain::Keychain + 'static,
{
// Assume global chain type has already been initialized.
let chain_type = global::get_chain_type();
let mut w_lock = owner_api.wallet_inst.lock();
let p = w_lock.lc_provider()?;
p.create_config(
&g_args.chain_type,
WALLET_CONFIG_FILE_NAME,
None,
None,
None,
)?;
p.create_config(&chain_type, WALLET_CONFIG_FILE_NAME, None, None, None)?;
p.create_wallet(
None,
args.recovery_phrase,
+9 -1
View File
@@ -84,7 +84,15 @@ pub fn clean_output_dir(test_dir: &str) {
pub fn setup(test_dir: &str) {
util::init_test_logger();
clean_output_dir(test_dir);
global::set_mining_mode(ChainTypes::AutomatedTesting);
global::set_local_chain_type(ChainTypes::AutomatedTesting);
}
/// Some tests require the global chain_type to be configured due to threads being spawned internally.
/// It is recommended to avoid relying on this if at all possible as global chain_type
/// leaks across multiple tests and will likely have unintended consequences.
#[allow(dead_code)]
pub fn setup_global_chain_type() {
global::init_global_chain_type(global::ChainTypes::AutomatedTesting);
}
pub fn create_wallet_proxy(
+5 -1
View File
@@ -29,7 +29,7 @@ use std::time::Duration;
#[macro_use]
mod common;
use common::{clean_output_dir, create_wallet_proxy, setup};
use common::{clean_output_dir, create_wallet_proxy, setup, setup_global_chain_type};
/// updater thread test impl
fn updater_thread_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
@@ -110,6 +110,10 @@ fn updater_thread_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err
#[test]
fn updater_thread() {
// The "updater" kicks off a new thread so we need to ensure the global chain_type
// is set for this to work correctly.
setup_global_chain_type();
let test_dir = "test_output/updater_thread";
setup(test_dir);
if let Err(e) = updater_thread_test_impl(test_dir) {