Skip to content

Commit

Permalink
Add test for different mnemonic
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Nov 7, 2023
1 parent dab7a8a commit d871f37
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mutiny-wasm/src/indexed_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl IndexedDbStorage {

// if we hae an override mnemonic, then we need to check that it matches the one in indexed db
if override_mnemonic.is_some_and(|m| m != seed) {
panic!("Mnemonic already exists in indexed db, cannot override");
return Err(MutinyError::InvalidMnemonic);
}

seed
Expand Down
58 changes: 56 additions & 2 deletions mutiny-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ impl MutinyWallet {

let mnemonic =
IndexedDbStorage::get_mnemonic(override_mnemonic, password.as_deref(), cipher.clone())
.await
.map_err(|_| MutinyJsError::IncorrectPassword)?;
.await?;

let seed = mnemonic.to_seed("");
let xprivkey = ExtendedPrivKey::new_master(network, &seed).unwrap();
Expand Down Expand Up @@ -1601,6 +1600,61 @@ mod tests {
uninit().await;
}

#[test]
async fn fail_to_create_wallet_different_seed() {
MutinyWallet::new(
None,
None,
None,
Some("regtest".to_owned()),
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
)
.await
.expect("mutiny wallet should initialize");
super::utils::sleep(1_000).await;
assert!(MutinyWallet::has_node_manager(None).await);
uninit().await;

let seed = mutiny_core::generate_seed(12).unwrap();
let result = MutinyWallet::new(
None,
Some(seed.to_string()),
None,
Some("regtest".to_owned()),
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
)
.await;

match result {
Err(MutinyJsError::InvalidMnemonic) => {}
Err(e) => panic!("should have failed to create wallet with different seed {e:?}"),
Ok(_) => panic!("should have failed to create wallet with different seed"),
}

IndexedDbStorage::clear()
.await
.expect("failed to clear storage");
uninit().await;
}

#[test]
async fn fail_to_create_2_mutiny_wallets() {
log!("trying to create 2 mutiny wallets!");
Expand Down

0 comments on commit d871f37

Please sign in to comment.