Skip to content

Commit

Permalink
Merge #3287 #3289
Browse files Browse the repository at this point in the history
3287: E2e tests for upgrading passphrase using mnemonics r=piotr-iohk a=piotr-iohk

<!--
Detail in a few bullet points the work accomplished in this PR.

Before you submit, don't forget to:

* Make sure the GitHub PR fields are correct:
   ✓ Set a good Title for your PR.
   ✓ Assign yourself to the PR.
   ✓ Assign one or more reviewer(s).
   ✓ Link to a Jira issue, and/or other GitHub issues or PRs.
   ✓ In the PR description delete any empty sections
     and all text commented in <!--, so that this text does not appear
     in merge commit messages.

* Don't waste reviewers' time:
   ✓ If it's a draft, select the Create Draft PR option.
   ✓ Self-review your changes to make sure nothing unexpected slipped through.

* Try to make your intent clear:
   ✓ Write a good Description that explains what this PR is meant to do.
   ✓ Jira will detect and link to this PR once created, but you can also
     link this PR in the description of the corresponding Jira ticket.
   ✓ Highlight what Testing you have done.
   ✓ Acknowledge any changes required to the Documentation.
-->


- [x] I have added e2e tests for updating passphrase using mnemonics for Shelley ~and Byron~ wallets

### Comments
 - tests for Shelley wallets work fine against #3279
 - ~tests for Byron wallets fail for now~ no tests for Byron wallets

### Issue Number

ADP-1658


3289: Update Building.md on how to build without scrypt r=piotr-iohk a=piotr-iohk

- [x] Update Building.md on how to build without scrypt.

### Comments

 - works for me locally on Linux
 - apparently works on M1 as well based on #2578 (comment)

### Issue Number

ADP-1383


Co-authored-by: Piotr Stachyra <piotr.stachyra@iohk.io>
  • Loading branch information
iohk-bors[bot] and Piotr Stachyra committed May 26, 2022
3 parents 9f1d5c2 + 912e513 + 88dc61a commit c0c056d
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 29 deletions.
7 changes: 7 additions & 0 deletions docs/developers/Building.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ See [`nix/overlays/build-tools.nix`](https://github.com/input-output-hk/cardano-
$ cabal install --install-method=copy --installdir=/usr/local/bin
```

7. Build without `scrypt` (for compatibility with Apple M1 chip)

```console
$ cabal configure --disable-tests --disable-benchmarks -f-scrypt -O2
$ cabal build cardano-wallet:exe:cardano-wallet
```

#### Syncing `stack` and `cabal` dependencies

1. Install [stack2cabal](https://hackage.haskell.org/package/stack2cabal)
Expand Down
44 changes: 29 additions & 15 deletions test/e2e/spec/byron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,33 @@
expect(WalletFactory.delete(:byron, wid)).to be_correct_and_respond 204
end

it "Can update_metadata" do
w = BYRON.wallets
id = create_byron_wallet
u = w.update_metadata(id, { name: "New wallet name" })
expect(u).to be_correct_and_respond 200
describe "Update wallet" do
matrix = ["random", "icarus"]
matrix.each do |wallet_style|
it "Can update_metadata of #{wallet_style} wallet" do
w = BYRON.wallets
id = create_byron_wallet(wallet_style)
u = w.update_metadata(id, { name: "New wallet name" })
expect(u).to be_correct_and_respond 200
end

end
it "Can update_passphrase of #{wallet_style} wallet" do
w = BYRON.wallets
id = create_byron_wallet(wallet_style)
upd = w.update_passphrase(id, { old_passphrase: "Secure Passphrase",
new_passphrase: "Securer Passphrase" })
expect(upd).to be_correct_and_respond 204
end

it "Can update_passphrase" do
w = BYRON.wallets
id = create_byron_wallet
upd = w.update_passphrase(id, { old_passphrase: "Secure Passphrase",
new_passphrase: "Securer Passphrase" })
expect(upd).to be_correct_and_respond 204
it "Cannot update_passphrase of #{wallet_style} wallet not knowing old pass" do
w = BYRON.wallets
id = create_byron_wallet(wallet_style)
upd = w.update_passphrase(id, { old_passphrase: "wrong-passphrase",
new_passphrase: "Securer Passphrase" })
expect(upd).to be_correct_and_respond 403
expect(upd.to_s).to include 'wrong_encryption_passphrase'
end
end
end

it "Can see utxo" do
Expand All @@ -87,7 +100,7 @@
wallet_style = m[1]
it "I can get #{wallet_type} #{wallet_style} walletid using cardano-addresses" do
mnemonics = mnemonic_sentence(24)
wid = create_byron_wallet_with(mnemonics, style = wallet_style)
wid = create_byron_wallet(style = wallet_style, "Wallet - ID", mnemonics)

# based on root prv key
root_xsk = CA.prv_key_from_recovery_phrase(mnemonics, wallet_type)
Expand All @@ -102,7 +115,7 @@

it "#{wallet_type} walletid is not based on acct key" do
mnemonics = mnemonic_sentence(24)
wid = create_byron_wallet_with(mnemonics, style = wallet_style)
wid = create_byron_wallet(style = wallet_style, "Wallet - ID", mnemonics)

# based on acct prv key
root_xsk = CA.prv_key_from_recovery_phrase(mnemonics, wallet_type)
Expand Down Expand Up @@ -189,7 +202,8 @@
it "I can import address - random" do
mnemonics = mnemonic_sentence(15)
derivation_path = '14H/42H'
id = create_byron_wallet_with(mnemonics)
id = create_byron_wallet("random", "Wallet - import", mnemonics)

addr = cardano_address_get_byron_addr(mnemonics, derivation_path)

addr_import = BYRON.addresses.import(id, addr)
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/spec/e2e_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,17 @@ def get_policy_id_from_decode(tx_decoded_mint_or_burn)
end

end

describe "Update passphrase" do
it "I can update passphrase with mnemonic and the wallet does not have to re-sync" do
mnemonics = get_fixture_wallet_mnemonics(:fixture, :shelley)
upd = SHELLEY.wallets.update_passphrase(@wid, { mnemonic_sentence: mnemonics,
new_passphrase: PASS })
expect(upd).to be_correct_and_respond 204
wallet = SHELLEY.wallets.get(@wid)
expect(wallet['state']['status']).to eq 'ready'
end
end
end

describe "E2E Byron" do
Expand Down
120 changes: 119 additions & 1 deletion test/e2e/spec/shelley_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,127 @@
w = SHELLEY.wallets
id = create_shelley_wallet
upd = w.update_passphrase(id, { old_passphrase: "Secure Passphrase",
new_passphrase: "Securer Passphrase" })
new_passphrase: "Securer Passphrase" })
expect(upd).to be_correct_and_respond 204
end

it "Cannot update_passphrase not knowing old pass" do
w = SHELLEY.wallets
id = create_shelley_wallet
upd = w.update_passphrase(id, { old_passphrase: "wrong-passphrase",
new_passphrase: "Securer Passphrase" })
expect(upd).to be_correct_and_respond 403
expect(upd.to_s).to include 'wrong_encryption_passphrase'
end

it "Can update_passphrase, mnemonics" do
w = SHELLEY.wallets
mnemonics = mnemonic_sentence(24)
id = create_shelley_wallet('Wallet', mnemonics)
upd = w.update_passphrase(id, { mnemonic_sentence: mnemonics,
new_passphrase: "Securer Passphrase" })
expect(upd).to be_correct_and_respond 204
end

it "Can update_passphrase, mnemonics, mnemonic_second_factor" do
w = SHELLEY.wallets
mnemonics = mnemonic_sentence(24)
mnemonic_second_factor = mnemonic_sentence(12)
id = create_shelley_wallet('Wallet', mnemonics, mnemonic_second_factor)
upd = w.update_passphrase(id, { mnemonic_sentence: mnemonics,
mnemonic_second_factor: mnemonic_second_factor,
new_passphrase: "Securer Passphrase" })
expect(upd).to be_correct_and_respond 204
end

it "Cannot update_passphrase with wrong mnemonics" do
w = SHELLEY.wallets
mnemonics = mnemonic_sentence(24)
wrong_mnemonics = mnemonic_sentence(24)
id = create_shelley_wallet('Wallet', mnemonics)
upd = w.update_passphrase(id, { mnemonic_sentence: wrong_mnemonics,
new_passphrase: "Securer Passphrase" })
expect(upd).to be_correct_and_respond 403
expect(upd.to_s).to include 'wrong_mnemonic'
end

it "Cannot update_passphrase with wrong mnemonic_second_factor" do
w = SHELLEY.wallets
mnemonics = mnemonic_sentence(24)
mnemonic_second_factor = mnemonic_sentence(12)
wrong_mnemonic_second_factor = mnemonic_sentence(12)
id = create_shelley_wallet('Wallet', mnemonics, mnemonic_second_factor)
upd = w.update_passphrase(id, { mnemonic_sentence: mnemonics,
mnemonic_second_factor: wrong_mnemonic_second_factor,
new_passphrase: "Securer Passphrase" })
expect(upd).to be_correct_and_respond 403
expect(upd.to_s).to include 'wrong_mnemonic'
end

it "Cannot update_passphrase of wallet from pub key" do
payload = { name: "Wallet from pub key",
account_public_key: "b47546e661b6c1791452d003d375756dde6cac2250093ce4630f16b9b9c0ac87411337bda4d5bc0216462480b809824ffb48f17e08d95ab9f1b91d391e48e66b",
address_pool_gap: 20
}
wallet = WalletFactory.create(:shelley, payload)
expect(wallet).to be_correct_and_respond 201

wid = wallet['id']
upd = SHELLEY.wallets.update_passphrase(wid, { old_passphrase: "Secure Passphrase",
new_passphrase: "Securer Passphrase" })
expect(upd).to be_correct_and_respond 403
expect(upd.to_s).to include 'no_root_key'
end

it "Can update_passphrase of wallet from pub key using mnemonics from which pub key is derived" do
mnemonics = mnemonic_sentence(24)
root_xsk = CA.prv_key_from_recovery_phrase(mnemonics, "Shelley")
acct_key = CA.key_child(root_xsk, "1852H/1815H/0H")
pub_key = CA.key_public(acct_key, with_chain_code = true)
acc_pub_key_base16 = bech32_to_base16(pub_key)

payload = { name: "Wallet from pub key",
account_public_key: acc_pub_key_base16,
address_pool_gap: 20
}
wallet = WalletFactory.create(:shelley, payload)
expect(wallet).to be_correct_and_respond 201

wid = wallet['id']

# I can update passphrase using mnemonics
upd = SHELLEY.wallets.update_passphrase(wid, { mnemonic_sentence: mnemonics,
new_passphrase: "Secure Passphrase" })
expect(upd).to be_correct_and_respond 204

# Once password is set I can perform passphrase-protected operations,
# like update passphrase using old passprase
upd2 = SHELLEY.wallets.update_passphrase(wid, { old_passphrase: "Secure Passphrase",
new_passphrase: "Securer Passphrase" })
expect(upd2).to be_correct_and_respond 204
end

it "Cannot update_passphrase of wallet from pub key using wrong mnemonics" do
mnemonics = mnemonic_sentence(24)
root_xsk = CA.prv_key_from_recovery_phrase(mnemonics, "Shelley")
acct_key = CA.key_child(root_xsk, "1852H/1815H/0H")
pub_key = CA.key_public(acct_key, with_chain_code = true)
acc_pub_key_base16 = bech32_to_base16(pub_key)

payload = { name: "Wallet from pub key",
account_public_key: acc_pub_key_base16,
address_pool_gap: 20
}
wallet = WalletFactory.create(:shelley, payload)
expect(wallet).to be_correct_and_respond 201

wid = wallet['id']
wrong_mnemonics = mnemonic_sentence(24)
upd = SHELLEY.wallets.update_passphrase(wid, { mnemonic_sentence: wrong_mnemonics,
new_passphrase: "Securer Passphrase" })
expect(upd).to be_correct_and_respond 403
expect(upd.to_s).to include 'wrong_mnemonic'
end
end

it "Can see utxo" do
Expand Down
21 changes: 8 additions & 13 deletions test/e2e/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,14 @@ def wait_for_all_shared_wallets(wids)
end
end

def create_shelley_wallet(name = "Wallet from mnemonic_sentence", mnemonic_sentence = mnemonic_sentence(24))
def create_shelley_wallet(name = "Wallet from mnemonic_sentence",
mnemonic_sentence = mnemonic_sentence(24),
mnemonic_second_factor = nil)
payload = { name: name,
passphrase: PASS,
mnemonic_sentence: mnemonic_sentence
}
payload[:mnemonic_second_factor] = mnemonic_second_factor if mnemonic_second_factor
WalletFactory.create(:shelley, payload)['id']
end

Expand Down Expand Up @@ -208,21 +211,13 @@ def wait_for_all_shelley_wallets(wids)
end
end

def create_byron_wallet_with(mnem, style = "random", name = "Wallet from mnemonic_sentence")
def create_byron_wallet(style = "random",
name = "Wallet from mnemonic_sentence",
mnemonics = mnemonic_sentence(24))
payload = { style: style,
name: name,
passphrase: PASS,
mnemonic_sentence: mnem
}
WalletFactory.create(:byron, payload)['id']
end

def create_byron_wallet(style = "random", name = "Wallet from mnemonic_sentence")
style == "random" ? mnem = mnemonic_sentence(12) : mnem = mnemonic_sentence(15)
payload = { style: style,
name: name,
passphrase: PASS,
mnemonic_sentence: mnem
mnemonic_sentence: mnemonics
}
WalletFactory.create(:byron, payload)['id']
end
Expand Down

0 comments on commit c0c056d

Please sign in to comment.