From 9149b0a5f58a182e0cd2f3578052aec8a2ad92e8 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Mon, 31 May 2021 15:39:31 +0200 Subject: [PATCH 1/2] Sanity e2e check for utxo snapshot --- test/e2e/Gemfile | 2 +- test/e2e/Gemfile.lock | 4 ++-- test/e2e/spec/byron_spec.rb | 5 +++++ test/e2e/spec/shelley_spec.rb | 6 ++++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/test/e2e/Gemfile b/test/e2e/Gemfile index 4fffa92a385..d66bd8c28a2 100644 --- a/test/e2e/Gemfile +++ b/test/e2e/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -gem 'cardano_wallet', '~> 0.3.8' +gem 'cardano_wallet', '~> 0.3.9' # gem 'cardano_wallet', path: "~/wb/cardano_wallet" gem 'bip_mnemonic', '0.0.4' gem 'rake', '12.3.3' diff --git a/test/e2e/Gemfile.lock b/test/e2e/Gemfile.lock index c640202459b..c5f06cdd864 100644 --- a/test/e2e/Gemfile.lock +++ b/test/e2e/Gemfile.lock @@ -2,7 +2,7 @@ GEM remote: https://rubygems.org/ specs: bip_mnemonic (0.0.4) - cardano_wallet (0.3.8) + cardano_wallet (0.3.9) httparty (~> 0.18.0) diff-lcs (1.4.4) httparty (0.18.1) @@ -32,7 +32,7 @@ PLATFORMS DEPENDENCIES bip_mnemonic (= 0.0.4) - cardano_wallet (~> 0.3.8) + cardano_wallet (~> 0.3.9) rake (= 12.3.3) rspec (= 3.10.0) diff --git a/test/e2e/spec/byron_spec.rb b/test/e2e/spec/byron_spec.rb index 96f2a4a58b7..9c7c0082a4b 100644 --- a/test/e2e/spec/byron_spec.rb +++ b/test/e2e/spec/byron_spec.rb @@ -72,7 +72,12 @@ id = create_byron_wallet utxo = BYRON.wallets.utxo(id) expect(utxo).to be_correct_and_respond 200 + end + it "Can see utxo snapshot" do + id = create_byron_wallet + utxo = BYRON.wallets.utxo_snapshot(id) + expect(utxo).to be_correct_and_respond 200 end end diff --git a/test/e2e/spec/shelley_spec.rb b/test/e2e/spec/shelley_spec.rb index 93dabe58204..0835ce82e5e 100644 --- a/test/e2e/spec/shelley_spec.rb +++ b/test/e2e/spec/shelley_spec.rb @@ -111,6 +111,12 @@ utxo = SHELLEY.wallets.utxo(id) expect(utxo).to be_correct_and_respond 200 end + + it "Can see utxo snapshot" do + id = create_shelley_wallet + utxo = SHELLEY.wallets.utxo_snapshot(id) + expect(utxo).to be_correct_and_respond 200 + end end describe CardanoWallet::Shelley::Addresses do From 690b0de412a3ea1edcd96c36a217cb7e8d305c31 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Mon, 31 May 2021 17:06:29 +0200 Subject: [PATCH 2/2] Test receive funds to shared wallet --- test/e2e/spec/e2e_spec.rb | 60 ++++++++++++++++++++++++++++++++++++ test/e2e/spec/spec_helper.rb | 24 +++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/test/e2e/spec/e2e_spec.rb b/test/e2e/spec/e2e_spec.rb index 0e980cea22e..29161563c74 100644 --- a/test/e2e/spec/e2e_spec.rb +++ b/test/e2e/spec/e2e_spec.rb @@ -18,6 +18,10 @@ @target_id_rnd_assets = create_shelley_wallet("Target asset tx wallet") @target_id_ic_assets = create_shelley_wallet("Target asset tx wallet") + # shared tests + @wid_sha = create_active_shared_wallet(mnemonic_sentence(24), '0H', 'self') + + @nightly_shared_wallets = [ @wid_sha ] @nighly_byron_wallets = [ @wid_rnd, @wid_ic ] @nightly_shelley_wallets = [ @wid, @@ -34,6 +38,7 @@ ] wait_for_all_byron_wallets(@nighly_byron_wallets) wait_for_all_shelley_wallets(@nightly_shelley_wallets) + wait_for_all_shared_wallets(@nightly_shared_wallets) # @wid_rnd = "94c0af1034914f4455b7eb795ebea74392deafe9" # @wid_ic = "a468e96ab85ad2043e48cf2e5f3437b4356769f4" @@ -47,6 +52,61 @@ @nightly_shelley_wallets.each do |wid| SHELLEY.wallets.delete wid end + @nightly_shared_wallets.each do |wid| + SHARED.wallets.delete wid + end + end + + describe "E2E Shared" do + it "I can receive transaction to shared wallet" do + asset_quantity = 1 + ada_amt = 3000000 + address = SHARED.addresses.list(@wid_sha)[1]['id'] + payload = [{ "address" => address, + "amount" => { "quantity" => ada_amt, "unit" => "lovelace" }, + "assets" => [ { "policy_id" => ASSETS[0]["policy_id"], + "asset_name" => ASSETS[0]["asset_name"], + "quantity" => asset_quantity + }, + { "policy_id" => ASSETS[1]["policy_id"], + "asset_name" => ASSETS[1]["asset_name"], + "quantity" => asset_quantity + } + ] + } + ] + + tx_sent = SHELLEY.transactions.create(@wid, PASS, payload) + + expect(tx_sent).to be_correct_and_respond 202 + expect(tx_sent.to_s).to include "pending" + + eventually "Assets are on target shared wallet: #{@wid_sha}" do + first = ASSETS[0]["policy_id"] + ASSETS[0]["asset_name"] + second = ASSETS[1]["policy_id"] + ASSETS[1]["asset_name"] + shared_wallet = SHARED.wallets.get(@wid_sha) + total_assets = shared_wallet['assets']['total'] + available_assets = shared_wallet['assets']['available'] + total_ada = shared_wallet['balance']['total']['quantity'] + available_ada = shared_wallet['balance']['available']['quantity'] + total = Hash.new + available = Hash.new + + unless total_assets.empty? + total[first] = total_assets.select { |a| a['policy_id'] == ASSETS[0]["policy_id"] && a['asset_name'] == ASSETS[0]["asset_name"] }.first["quantity"] + total[second] = total_assets.select { |a| a['policy_id'] == ASSETS[1]["policy_id"] && a['asset_name'] == ASSETS[1]["asset_name"] }.first["quantity"] + end + + unless available_assets.empty? + available[first] = available_assets.select { |a| a['policy_id'] == ASSETS[0]["policy_id"] && a['asset_name'] == ASSETS[0]["asset_name"] }.first["quantity"] + available[second] = available_assets.select { |a| a['policy_id'] == ASSETS[1]["policy_id"] && a['asset_name'] == ASSETS[1]["asset_name"] }.first["quantity"] + end + + (total[first] == asset_quantity) && (total[second] == asset_quantity) && + (available[first] == asset_quantity) && (available[second] == asset_quantity) && + (available_ada == ada_amt) && (total_ada == ada_amt) + end + end end describe "E2E Shelley" do diff --git a/test/e2e/spec/spec_helper.rb b/test/e2e/spec/spec_helper.rb index c8e51abf74d..2727f5db726 100644 --- a/test/e2e/spec/spec_helper.rb +++ b/test/e2e/spec/spec_helper.rb @@ -142,6 +142,30 @@ def create_active_shared_wallet(m, acc_ix, acc_xpub) SHARED.wallets.create(payload)['id'] end +def wait_for_shared_wallet_to_sync(wid) + puts "Syncing Shared wallet..." + retry_count = 10 + begin + while (SHARED.wallets.get(wid)['state']['status'] == "syncing") do + w = SHARED.wallets.get(wid) + puts " Syncing... #{w['state']['progress']['quantity']}%" if w['state']['progress'] + sleep 5 + end + rescue NoMethodError + puts "Retry #{retry_count}" + retry_count -= 1 + puts "SHARED.wallets.get(#{wid}) returned:" + puts SHARED.wallets.get(wid) + retry if retry_count > 0 + end +end + +def wait_for_all_shared_wallets(wids) + wids.each do |w| + wait_for_shared_wallet_to_sync(w) + end +end + def create_shelley_wallet(name = "Wallet from mnemonic_sentence") SHELLEY.wallets.create({ name: name, passphrase: PASS,