Skip to content

Commit

Permalink
Merge pull request #3171 from input-output-hk/piotr/adp-1513/e2e-test…
Browse files Browse the repository at this point in the history
…s-from-cached-wallet-db

E2e tests against cached wallet db
  • Loading branch information
piotr-iohk authored Mar 16, 2022
2 parents 1aa542b + b51b140 commit 3e59eb3
Show file tree
Hide file tree
Showing 14 changed files with 335 additions and 236 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/e2e-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ jobs:
node-db-docker-${{ env.NETWORK }}-
node-db-Linux-${{ env.NETWORK }}-
- name: 💾 Cache wallet db
id: cache-wallet
uses: actions/cache@v2.1.4
with:
path: test/e2e/state/wallet_db/${{ env.NETWORK }}
key: wallet-db-${{ runner.os }}-${{ env.NETWORK }}-${{ steps.date-time.outputs.value }}
restore-keys: |
wallet-db-${{ runner.os }}-${{ env.NETWORK }}-
wallet-db-Linux-${{ env.NETWORK }}-
- name: 🚀 Start node and wallet
run: |
echo "Wallet: $WALLET"
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/e2e-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ jobs:
restore-keys: |
node-db-${{ runner.os }}-${{ env.NETWORK }}-
- name: 💾 Cache wallet db
id: cache-wallet
uses: actions/cache@v2.1.4
with:
path: test/e2e/state/wallet_db/${{ env.NETWORK }}
key: wallet-db-${{ runner.os }}-${{ env.NETWORK }}-${{ steps.date-time.outputs.value }}
restore-keys: |
wallet-db-${{ runner.os }}-${{ env.NETWORK }}-
- name: ⚙️ Setup (get latest bins and configs and decode fixtures)
run: rake setup[$NETWORK,$PR]

Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/e2e-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ jobs:
node-db-${{ runner.os }}-${{ env.NETWORK }}-
node-db-Linux-${{ env.NETWORK }}-
- name: 💾 Cache wallet db
id: cache-wallet
uses: actions/cache@v2.1.4
with:
path: test/e2e/state/wallet_db/${{ env.NETWORK }}
key: wallet-db-${{ runner.os }}-${{ env.NETWORK }}-${{ steps.date-time.outputs.value }}
restore-keys: |
wallet-db-${{ runner.os }}-${{ env.NETWORK }}-
- name: ⚙️ Setup (get latest bins and configs and decode fixtures)
run: rake setup[$NETWORK,$PR]

Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/e2e-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ jobs:
node-db-${{ runner.os }}-${{ env.NETWORK }}-
node-db-Linux-${{ env.NETWORK }}-
- name: 💾 Cache wallet db
id: cache-wallet
uses: actions/cache@v2.1.4
with:
path: test/e2e/state/wallet_db/${{ env.NETWORK }}
key: wallet-db-${{ runner.os }}-${{ env.NETWORK }}-${{ steps.date-time.outputs.value }}
restore-keys: |
wallet-db-${{ runner.os }}-${{ env.NETWORK }}-
- name: ⚙️ Setup (get latest bins and configs and decode fixtures)
run: rake setup[%NETWORK%,%PR%]

Expand Down
37 changes: 28 additions & 9 deletions test/e2e/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,34 @@ end
task :fixture_wallets_template do
puts "\n >> Creating #{FIXTURES_FILE}"

fixture_wallets = { :linux => { :shelley => mnemonic_sentence(24),
:icarus => mnemonic_sentence(15),
:byron => mnemonic_sentence(12) },
:macos => { :shelley => mnemonic_sentence(24),
:icarus => mnemonic_sentence(15),
:byron => mnemonic_sentence(12) },
:windows => { :shelley => mnemonic_sentence(24),
:icarus => mnemonic_sentence(15),
:byron => mnemonic_sentence(12) }
fixture_wallets = { :linux => {
:fixture => { :shelley => mnemonic_sentence(24),
:icarus => mnemonic_sentence(15),
:random => mnemonic_sentence(12)
},
:target => { :shelley => mnemonic_sentence(24),
:shared => mnemonic_sentence(24)
}
},
:macos => {
:fixture => { :shelley => mnemonic_sentence(24),
:icarus => mnemonic_sentence(15),
:random => mnemonic_sentence(12)
},
:target => { :shelley => mnemonic_sentence(24),
:shared => mnemonic_sentence(24)
}
},
:windows => {
:fixture => { :shelley => mnemonic_sentence(24),
:icarus => mnemonic_sentence(15),
:random => mnemonic_sentence(12)
},
:target => { :shelley => mnemonic_sentence(24),
:shared => mnemonic_sentence(24)
}
},
:currency_contract_wallet => mnemonic_sentence(24)
}
if File.exists?(FIXTURES_FILE)
err = "
Expand Down
Binary file modified test/e2e/fixtures/fixture_wallets.json.gpg
Binary file not shown.
19 changes: 19 additions & 0 deletions test/e2e/helpers/context.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
##
# Class for keeping track of wallet ids. WalletFactory keeps track of the context.
# CONTEXT = Context.new
# WalletFactory.create(:shelley, payload)
# CONTEXT.shelley.each do |wid|
# WalletFactory.delete(:shelley, wid)
# end
class Context
attr_accessor :shelley, :shared, :byron
def initialize
clear!
end

def clear!
@shelley = []
@shared = []
@byron = []
end
end
15 changes: 10 additions & 5 deletions test/e2e/helpers/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,25 @@ def absolute_path(path)
end
end

def get_fixture_wallet_mnemonics(type)
# Get wallet mnemonics from fixures file
# @param kind [Symbol] :fixture or :target (fixture wallet with funds or target wallet)
# @param type [Symbol] wallet type = :shelley, :shared, :icarus, :random
def get_fixture_wallet_mnemonics(kind, type)
fixture = ENV['TESTS_E2E_FIXTURES_FILE']
unless File.exists? fixture
raise "File #{fixture} does not exist! (Hint: Template fixture file can be created with 'rake fixture_wallets_template'). Make sure to feed it with mnemonics of wallets with funds and assets."
end
wallets = JSON.parse File.read(fixture)
k = kind.to_s
t = type.to_s
if is_linux?
wallets["linux"][type]
wallets["linux"][k][t]
elsif is_mac?
wallets["macos"][type]
wallets["macos"][k][t]
elsif is_win?
wallets["windows"][type]
wallets["windows"][k][t]
else
wallets["linux"][type]
wallets["linux"][k][t]
end
end

Expand Down
39 changes: 39 additions & 0 deletions test/e2e/helpers/wallet_factory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
##
# Factory helper for creating and deleting wallets and keeping their ids in shared context.
# Assumes CONTEXT, SHELLEY, SHARED, BYRON to be initialized.
class WalletFactory
def self.create(type, payload)
case type
when :shelley
wallet = SHELLEY.wallets.create(payload)
CONTEXT.shelley << wallet['id']
wallet
when :shared
wallet = SHARED.wallets.create(payload)
CONTEXT.shared << wallet['id']
wallet
when :byron
wallet = BYRON.wallets.create(payload)
CONTEXT.byron << wallet['id']
wallet
else
raise "Unsupported wallet type: #{type}."
end
end

def self.delete(type, wid)
case type
when :shelley
CONTEXT.shelley.delete(wid)
SHELLEY.wallets.delete(wid)
when :shared
CONTEXT.shared.delete(wid)
SHARED.wallets.delete(wid)
when :byron
CONTEXT.byron.delete(wid)
BYRON.wallets.delete(wid)
else
raise "Unsupported wallet type: #{type}."
end
end
end
57 changes: 20 additions & 37 deletions test/e2e/spec/byron_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
RSpec.describe CardanoWallet::Byron do
after(:each) do
teardown
end

describe CardanoWallet::Byron::Wallets do

after(:each) do
teardown
end

it "I can list byron wallets" do
l = BYRON.wallets.list
expect(l).to be_correct_and_respond 200
Expand All @@ -22,34 +21,32 @@
end

it "I can create, get and delete byron icarus wallet from mnemonics" do
wallet = BYRON.wallets.create({ style: "icarus",
name: "Wallet from mnemonic_sentence",
passphrase: "Secure Passphrase",
mnemonic_sentence: mnemonic_sentence(15),
})
payload = { style: "icarus",
name: "Wallet from mnemonic_sentence",
passphrase: "Secure Passphrase",
mnemonic_sentence: mnemonic_sentence(15)
}
wallet = WalletFactory.create(:byron, payload)
expect(wallet).to be_correct_and_respond 201

wid = wallet['id']
g = BYRON.wallets.get(wid)
expect(g).to be_correct_and_respond 200
expect(BYRON.wallets.delete(wid)).to be_correct_and_respond 204
expect(BYRON.wallets.get(wid)).to be_correct_and_respond 200
expect(WalletFactory.delete(:byron, wid)).to be_correct_and_respond 204
end

it "I can create, get and delete byron random wallet from mnemonics" do
wallet = BYRON.wallets.create({ style: "random",
name: "Wallet from mnemonic_sentence",
passphrase: "Secure Passphrase",
mnemonic_sentence: mnemonic_sentence(12),
})
payload = { style: "random",
name: "Wallet from mnemonic_sentence",
passphrase: "Secure Passphrase",
mnemonic_sentence: mnemonic_sentence(12)
}
wallet = WalletFactory.create(:byron, payload)
expect(wallet).to be_correct_and_respond 201


wid = wallet['id']
g = BYRON.wallets.get(wid)
expect(g).to be_correct_and_respond 200


expect(BYRON.wallets.delete(wid)).to be_correct_and_respond 204
expect(BYRON.wallets.get(wid)).to be_correct_and_respond 200
expect(WalletFactory.delete(:byron, wid)).to be_correct_and_respond 204
end

it "Can update_metadata" do
Expand Down Expand Up @@ -83,10 +80,6 @@

describe CardanoWallet::Byron::Addresses do

after(:each) do
teardown
end

it "Can list addresses - random" do
id = create_byron_wallet
addresses = BYRON.addresses.list id
Expand Down Expand Up @@ -154,7 +147,7 @@
derivation_path = '14H/42H'
id = create_byron_wallet_with(mnemonics)
addr = cardano_address_get_byron_addr(mnemonics, derivation_path)

addr_import = BYRON.addresses.import(id, addr)
expect(addr_import).to be_correct_and_respond 204

Expand Down Expand Up @@ -191,10 +184,6 @@

describe CardanoWallet::Byron::CoinSelections do

after(:each) do
teardown
end

it "I could trigger random coin selection - if had money" do
wid = create_byron_wallet "icarus"
addresses = BYRON.addresses.list(wid)
Expand All @@ -212,9 +201,6 @@
end

describe CardanoWallet::Byron::Transactions do
after(:each) do
teardown
end

# Run for random and icarus
["random", "icarus"].each do |style|
Expand Down Expand Up @@ -270,9 +256,6 @@
end

describe CardanoWallet::Byron::Migrations do
after(:each) do
teardown
end

it "I could create migration plan - icarus" do
id = create_byron_wallet "icarus"
Expand Down
39 changes: 11 additions & 28 deletions test/e2e/spec/e2e_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,26 @@

before(:all) do
# shelley wallets
@wid = create_fixture_shelley_wallet
@target_id = create_shelley_wallet("Target tx wallet")
@wid = create_fixture_wallet(:shelley)
@target_id = create_target_wallet(:shelley)

# byron wallets
@wid_rnd = create_fixture_byron_wallet "random"
@wid_ic = create_fixture_byron_wallet "icarus"
@wid_rnd = create_fixture_wallet(:random)
@wid_ic = create_fixture_wallet(:icarus)

# shared wallets
@wid_sha = create_active_shared_wallet(mnemonic_sentence(24), '0H', 'self')
@wid_sha = create_target_wallet(:shared)

@nightly_shared_wallets = [ @wid_sha ]
@nighly_byron_wallets = [ @wid_rnd, @wid_ic ]
@nightly_shelley_wallets = [ @wid, @target_id ]
wait_for_all_shelley_wallets(@nightly_shelley_wallets)
wait_for_all_shared_wallets(@nightly_shared_wallets)
wait_for_all_byron_wallets(@nighly_byron_wallets)

# @wid_sha = "f7b49bb7d58f7986e2394fefdc459a0ce67f42fa"
# @wid_rnd = "12cbebfdc4521766e63a7e07c4825b24deb4176c"
# @wid_ic = "f5da82c1eb3e391a535dd5ba2867fe9bdaf2f313"
# @wid = "a042bafdaf98844cfa8f6d4b1dc47519b21a4d95"
# @target_id = "d11ceb4d63f69fa0e8a02927d3f866f5fb5f6112"
# 1f82e83772b7579fc0854bd13db6a9cce21ccd95
# 2269611a3c10b219b0d38d74b004c298b76d16a9
# a042bafdaf98844cfa8f6d4b1dc47519b21a4d95
end

after(:all) do
@nighly_byron_wallets.each do |wid|
BYRON.wallets.delete wid
end
@nightly_shelley_wallets.each do |wid|
SHELLEY.wallets.delete wid
end
@nightly_shared_wallets.each do |wid|
SHARED.wallets.delete wid
end
after(:each) do
teardown
end

describe "E2E Balance -> Sign -> Submit" do
Expand Down Expand Up @@ -1163,8 +1146,8 @@ def test_byron_assets_tx(source_id, target_id)
expect(plan).to be_correct_and_respond 202
expect(plan['balance_selected']['assets']).not_to be []
expect(plan['balance_leftover']).to eq ({ "ada" => { "quantity" => 0,
"unit" => "lovelace" },
"assets" => [] })
"unit" => "lovelace" },
"assets" => [] })
end

it "I can create migration plan icarus -> shelley" do
Expand All @@ -1174,8 +1157,8 @@ def test_byron_assets_tx(source_id, target_id)
expect(plan).to be_correct_and_respond 202
expect(plan['balance_selected']['assets']).not_to be []
expect(plan['balance_leftover']).to eq ({ "ada" => { "quantity" => 0,
"unit" => "lovelace" },
"assets" => [] })
"unit" => "lovelace" },
"assets" => [] })
end
end

Expand Down
Loading

0 comments on commit 3e59eb3

Please sign in to comment.