Skip to content

Commit

Permalink
Test cardano-wallet mnemonic_snd_factor parity with cardano-addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Stachyra committed Sep 30, 2022
1 parent 101921f commit 84ade7a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
5 changes: 2 additions & 3 deletions test/e2e/helpers/cardano_addresses.rb
Expand Up @@ -4,9 +4,8 @@
class CardanoAddresses
##
# @param mnemonics
# @param type = Byron | Icarus | Shelley | Shared
def prv_key_from_recovery_phrase(mnemonics, type)
cmd(%(echo #{mnemonics.join(' ')}| cardano-address key from-recovery-phrase #{type})).gsub("\n", '')
def prv_key_from_recovery_phrase(mnemonics, cmd_params)
cmd(%(echo #{mnemonics.join(' ')}| cardano-address key from-recovery-phrase #{cmd_params})).gsub("\n", '')
end

def key_public(key, with_chain_code = true)
Expand Down
52 changes: 48 additions & 4 deletions test/e2e/spec/shelley_spec.rb
Expand Up @@ -569,6 +569,20 @@
end
end

it "Create account public key - non_extended" do
m24 = mnemonic_sentence(24)
wid = create_shelley_wallet("Wallet", m24)
["0H", "1H", "2147483647H", "44H"].each do |index|
payload = { passphrase: PASS, format: 'non_extended' }
res = SHELLEY.keys.create_acc_public_key(wid, index, payload)
expect(res.to_s).to include cardano_address_get_acc_xpub(m24,
"1852H/1815H/#{index}",
hex = false,
"Shelley",
"--without-chain-code")
end
end

it "Create account public key - extended with purpose" do
m24 = mnemonic_sentence(24)
wid = create_shelley_wallet("Wallet", m24)
Expand Down Expand Up @@ -614,10 +628,40 @@
end

it "Get account public key - wallet from mnemonics" do
wid = create_shelley_wallet
res = SHELLEY.keys.get_acc_public_key(wid, { format: "extended" })
expect(res).to be_correct_and_respond 200
expect(res.to_s).to include "acct_xvk"
m24 = mnemonic_sentence(24)
wid = create_shelley_wallet("Wallet", m24)

# Get account pub key from the wallet
w_acct_key = SHELLEY.keys.get_acc_public_key(wid, { format: "extended" })
expect(w_acct_key).to be_correct_and_respond 200

# Get equivalent account pub key using cardano-addresses
root_xsk = CA.prv_key_from_recovery_phrase(m24, "Shelley")
acct_key = CA.key_child(root_xsk, "1852H/1815H/0H")
pub_key = CA.key_public(acct_key, with_chain_code = true)

expect(pub_key).to eq w_acct_key.parsed_response
end

it "Get account public key (mnemonic_snd_factor)" do
m24 = mnemonic_sentence(24)
m12 = mnemonic_sentence(12)
wid = create_shelley_wallet("Wallet", m24, m12)

# Get account pub key from the wallet
w_acct_key = SHELLEY.keys.get_acc_public_key(wid, {format: 'extended'})
expect(w_acct_key).to be_correct_and_respond 200

# Get equivalent account pub key using cardano-addresses
pub_key = Dir.mktmpdir do |dir|
sndfactor_file = File.join(dir, 'sndfactor.prv')
File.open(sndfactor_file, 'w') { |file| file.write(m12.join ' ') }
root_xsk = CA.prv_key_from_recovery_phrase(m24, "Shelley --passphrase from-mnemonic --from-file #{sndfactor_file}")
acct_key = CA.key_child(root_xsk, "1852H/1815H/0H")
CA.key_public(acct_key, with_chain_code = true)
end

expect(pub_key).to eq w_acct_key.parsed_response
end

it "I can create and get policy key and it's hash" do
Expand Down
1 change: 1 addition & 0 deletions test/e2e/spec/spec_helper.rb
Expand Up @@ -4,6 +4,7 @@
require "blake2b"
require "mustache"
require "cbor"
require 'tmpdir'
require_relative "../env"
require_relative "../helpers/utils"
require_relative "../helpers/matchers"
Expand Down

0 comments on commit 84ade7a

Please sign in to comment.