Ensure API create_wallet returns failure when provided with invalid mnemonic seeds (#319)
* Ensure returns failure with invalid mnemonic seeds, add tests * test fixes resulting from change
This commit is contained in:
@@ -183,7 +183,16 @@ where
|
||||
return Err(ErrorKind::WalletSeedExists(msg))?;
|
||||
}
|
||||
}
|
||||
let _ = WalletSeed::init_file(&data_dir_name, mnemonic_length, mnemonic.clone(), password);
|
||||
WalletSeed::init_file(
|
||||
&data_dir_name,
|
||||
mnemonic_length,
|
||||
mnemonic.clone(),
|
||||
password,
|
||||
test_mode,
|
||||
)
|
||||
.context(ErrorKind::Lifecycle(
|
||||
"Error creating wallet seed (is mnemonic valid?)".into(),
|
||||
))?;
|
||||
info!("Wallet seed file created");
|
||||
let mut wallet: LMDBBackend<'a, C, K> =
|
||||
match LMDBBackend::new(&data_dir_name, self.node_client.clone()) {
|
||||
@@ -327,6 +336,7 @@ where
|
||||
0,
|
||||
Some(ZeroingString::from(orig_mnemonic)),
|
||||
new.clone(),
|
||||
false,
|
||||
);
|
||||
info!("Wallet seed file created");
|
||||
|
||||
|
||||
@@ -150,6 +150,7 @@ impl WalletSeed {
|
||||
seed_length: usize,
|
||||
recovery_phrase: Option<util::ZeroingString>,
|
||||
password: util::ZeroingString,
|
||||
test_mode: bool,
|
||||
) -> Result<WalletSeed, Error> {
|
||||
// create directory if it doesn't exist
|
||||
fs::create_dir_all(data_file_dir).context(ErrorKind::IO)?;
|
||||
@@ -158,8 +159,9 @@ impl WalletSeed {
|
||||
|
||||
warn!("Generating wallet seed file at: {}", seed_file_path);
|
||||
let exists = WalletSeed::seed_file_exists(data_file_dir)?;
|
||||
if exists {
|
||||
if exists && !test_mode {
|
||||
let msg = format!("Wallet seed already exists at: {}", data_file_dir);
|
||||
error!("{}", msg);
|
||||
return Err(ErrorKind::WalletSeedExists(msg))?;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user