Skip to content

Commit

Permalink
Merge #3281
Browse files Browse the repository at this point in the history
3281: Walletid e2e testing r=piotr-iohk a=piotr-iohk

- [x] I have added some e2e tests for walletid checking cardano-wallet and cardano-addresses comply

### Comments

<!-- Additional comments, links, or screenshots to attach, if any. -->

### Issue Number

adp-1621


Co-authored-by: Piotr Stachyra <piotr.stachyra@iohk.io>
  • Loading branch information
iohk-bors[bot] and Piotr Stachyra committed May 23, 2022
2 parents 94c51d9 + c25983f commit ce949e8
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 1 deletion.
23 changes: 23 additions & 0 deletions test/e2e/helpers/cardano_addresses.rb
@@ -0,0 +1,23 @@
##
# cardano-address cmd helper wrapper
#
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", '')
end

def key_public(key, with_chain_code = true)
cmd(%(echo #{key}| cardano-address key public #{with_chain_code ? "--with-chain-code" : "--without-chain-code"})).gsub("\n", '')
end

def key_child(key, derivation_path)
cmd(%(echo #{key}| cardano-address key child #{derivation_path})).gsub("\n", '')
end

def key_walletid(key, templates = '')
cmd(%(echo #{key}| cardano-address key walletid #{templates})).gsub("\n", '')
end
end
44 changes: 44 additions & 0 deletions test/e2e/spec/byron_spec.rb
Expand Up @@ -76,6 +76,50 @@
utxo = BYRON.wallets.utxo_snapshot(id)
expect(utxo).to be_correct_and_respond 200
end

describe "Wallet id" do
matrix = [
["Byron", "random"],
["Icarus", "icarus"]
]
matrix.each do |m|
wallet_type = m[0]
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)

# based on root prv key
root_xsk = CA.prv_key_from_recovery_phrase(mnemonics, wallet_type)
ca_wid_root_xsk = CA.key_walletid(root_xsk)
expect(wid).to eq ca_wid_root_xsk

# based on pub key
pub_key = CA.key_public(root_xsk, with_chain_code = true)
ca_wid_pub_key = CA.key_walletid(pub_key)
expect(wid).to eq ca_wid_pub_key
end

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

# based on acct prv key
root_xsk = CA.prv_key_from_recovery_phrase(mnemonics, wallet_type)
acct_key = CA.key_child(root_xsk, "1852H/1815H/0H")
ca_wid_acct_key = CA.key_walletid(acct_key)

# based on pub key from acct prv key
pub_key = CA.key_public(acct_key, with_chain_code = true)
ca_wid_pub_key = CA.key_walletid(pub_key)

# wallet id from cardano-wallet is not the same
expect(ca_wid_acct_key).to eq ca_wid_pub_key
expect(wid).not_to eq ca_wid_acct_key
end
end
end

end

describe CardanoWallet::Byron::Addresses do
Expand Down
92 changes: 91 additions & 1 deletion test/e2e/spec/shared_spec.rb
Expand Up @@ -2,7 +2,7 @@
after(:each) do
teardown
end

describe CardanoWallet::Shared::Wallets do

describe "Create wallets" do
Expand Down Expand Up @@ -333,6 +333,96 @@

expect(WalletFactory.delete(:shared, wid)).to be_correct_and_respond 204
end

describe "Wallet id" do
it "Shared walletid with only spending template from cardano-addresses" do
mnemonics = mnemonic_sentence(24)
acc_ix = '0H'
script_template = { "cosigners" => { "cosigner#0" => "self" },
"template" =>
{ "all" =>
[ "cosigner#0",
{ "active_from" => 120 }
]
}
}

payload = { mnemonic_sentence: mnemonics,
passphrase: PASS,
name: "Shared wallet",
account_index: acc_ix,
payment_script_template: script_template,
}

wallet = WalletFactory.create(:shared, payload)
expect(wallet).to be_correct_and_respond 201
wid = wallet["id"]

# based on acct prv key
template = '--spending "all [cosigner#0, active_from 120]"'
root_xsk = CA.prv_key_from_recovery_phrase(mnemonics, "Shared")
acct_key = CA.key_child(root_xsk, "1854H/1815H/#{acc_ix}")
ca_wid_acct_key = CA.key_walletid(acct_key, template)

# based on pub key from acct prv key
pub_key = CA.key_public(acct_key, with_chain_code = true)
ca_wid_pub_key = CA.key_walletid(pub_key, template)

# wallet id from cardano-wallet is the same
expect(ca_wid_acct_key).to eq ca_wid_acct_key
expect(wid).to eq ca_wid_acct_key
end

it "Shared walletid with spending and delegation template from cardano-addresses" do
mnemonics = mnemonic_sentence(24)
acc_ix = '0H'
script_template = { "cosigners" => { "cosigner#0" => "self" },
"template" =>
{ "all" =>
[ "cosigner#0",
{ "active_from" => 120 }
]
}
}

delegation_template = { "cosigners" => { "cosigner#1" => 'self' },
"template" =>
{ "any" =>
[ "cosigner#0",
"cosigner#1"
]
}
}

payload = { mnemonic_sentence: mnemonics,
passphrase: PASS,
name: "Shared wallet",
account_index: acc_ix,
payment_script_template: script_template,
delegation_script_template: delegation_template
}

wallet = WalletFactory.create(:shared, payload)
expect(wallet).to be_correct_and_respond 201
wid = wallet["id"]

# based on acct prv key
template = '--spending "all [cosigner#0, active_from 120]" --staking "any [cosigner#0, cosigner#1]"'
root_xsk = CA.prv_key_from_recovery_phrase(mnemonics, "Shared")
acct_key = CA.key_child(root_xsk, "1854H/1815H/#{acc_ix}")
ca_wid_acct_key = CA.key_walletid(acct_key, template)

# based on pub key from acct prv key
pub_key = CA.key_public(acct_key, with_chain_code = true)
ca_wid_pub_key = CA.key_walletid(pub_key, template)

# wallet id from cardano-wallet is the same
expect(ca_wid_acct_key).to eq ca_wid_acct_key
expect(wid).to eq ca_wid_acct_key
end

end

end

describe "Addresses" do
Expand Down
36 changes: 36 additions & 0 deletions test/e2e/spec/shelley_spec.rb
Expand Up @@ -84,6 +84,42 @@
expect(g).to be_correct_and_respond 200
expect(WalletFactory.delete(:shelley, wid)).to be_correct_and_respond 204
end

describe "Wallet id" do
it "I can get Shelley walletid using cardano-addresses" do
mnemonics = mnemonic_sentence(24)
wid = create_shelley_wallet("Shelley Wallet", mnemonics)

# based on root prv key
root_xsk = CA.prv_key_from_recovery_phrase(mnemonics, "Shelley")
ca_wid_root_xsk = CA.key_walletid(root_xsk)
expect(wid).to eq ca_wid_root_xsk

# based on pub key
pub_key = CA.key_public(root_xsk, with_chain_code = true)
ca_wid_pub_key = CA.key_walletid(pub_key)
expect(wid).to eq ca_wid_pub_key
end

it "Shelley walletid is not based on acct key" do
mnemonics = mnemonic_sentence(24)
wid = create_shelley_wallet("Shelley Wallet", mnemonics)

# based on acct prv key
root_xsk = CA.prv_key_from_recovery_phrase(mnemonics, "Shelley")
acct_key = CA.key_child(root_xsk, "1852H/1815H/0H")
ca_wid_acct_key = CA.key_walletid(acct_key)

# based on pub key from acct prv key
pub_key = CA.key_public(acct_key, with_chain_code = true)
ca_wid_pub_key = CA.key_walletid(pub_key)

# wallet id from cardano-wallet is not the same
expect(ca_wid_acct_key).to eq ca_wid_pub_key
expect(wid).not_to eq ca_wid_acct_key
end
end

end

describe "Update wallet" do
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/spec/spec_helper.rb
Expand Up @@ -9,6 +9,7 @@
require_relative "../helpers/matchers"
require_relative "../helpers/context"
require_relative "../helpers/wallet_factory"
require_relative "../helpers/cardano_addresses"

include Helpers::Utils

Expand Down Expand Up @@ -41,6 +42,7 @@
UTILS = CW.misc.utils
NETWORK = CW.misc.network
PROXY = CW.misc.proxy
CA = CardanoAddresses.new

CONTEXT = Context.new

Expand Down

0 comments on commit ce949e8

Please sign in to comment.