Skip to content

Commit

Permalink
Merge #2682
Browse files Browse the repository at this point in the history
2682: E2e testing utxo snapshot / shared wallet receive transaction r=piotr-iohk a=piotr-iohk

# Issue Number

<!-- Put here a reference to the issue that this PR relates to and which requirements it tackles. Jira issues of the form ADP- will be auto-linked. -->


# Overview

- 9149b0a
  Sanity e2e check for utxo snapshot
  
- 690b0de
  Test receive funds to shared wallet



# Comments

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

<!--
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Jira will detect and link to this PR once created, but you can also link this PR in the description of the corresponding ticket
 ✓ Acknowledge any changes required to the Wiki
 ✓ Finally, in the PR description delete any empty sections and all text commented in <!--, so that this text does not appear in merge commit messages.
-->


Co-authored-by: Piotr Stachyra <[email protected]>
  • Loading branch information
iohk-bors[bot] and Piotr Stachyra authored May 31, 2021
2 parents 0b8cadb + 690b0de commit 77a7fd8
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/e2e/Gemfile
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions test/e2e/spec/byron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
60 changes: 60 additions & 0 deletions test/e2e/spec/e2e_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/spec/shelley_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions test/e2e/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 77a7fd8

Please sign in to comment.