Skip to content

Commit

Permalink
Adjust creation of fixture and target wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Stachyra committed Mar 15, 2022
1 parent e30b14c commit 4bc2c8a
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 50 deletions.
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: 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
81 changes: 64 additions & 17 deletions test/e2e/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,6 @@ def create_shelley_wallet(name = "Wallet from mnemonic_sentence", mnemonic_sente
WalletFactory.create(:shelley, payload)['id']
end


def create_fixture_shelley_wallet
SHELLEY.wallets.create({ name: "Fixture wallet with funds",
passphrase: PASS,
mnemonic_sentence: get_fixture_wallet_mnemonics("shelley")
})['id']
end

def wait_for_shelley_wallet_to_sync(wid)
puts "Syncing Shelley wallet..."
retry_count = 10
Expand Down Expand Up @@ -233,15 +225,6 @@ def create_byron_wallet(style = "random", name = "Wallet from mnemonic_sentence"
WalletFactory.create(:byron, payload)['id']
end


def create_fixture_byron_wallet(style = "random")
BYRON.wallets.create({ style: style,
name: "Fixture byron wallets with funds",
passphrase: PASS,
mnemonic_sentence: get_fixture_wallet_mnemonics(style)
})['id']
end

def wait_for_byron_wallet_to_sync(wid)
puts "Syncing Byron wallet..."
retry_count = 10
Expand All @@ -266,6 +249,70 @@ def wait_for_all_byron_wallets(wids)
end
end

## FIXTURE AND TARGET WALLETS ##

##
# return wallet id from create wallet response even if it already exists
def return_wallet_id(create_wallet_response)
if create_wallet_response.code == 409
create_wallet_response['message'].split[10]
else
create_wallet_response['id']
end
end

##
# create fixture wallet or return it's id if it exists
# @param type [Symbol] :shelley, :random, :icarus
def create_fixture_wallet(type)
payload = { name: "Fixture wallet with funds",
passphrase: PASS,
mnemonic_sentence: get_fixture_wallet_mnemonics(:fixture, type.to_sym)
}
case type.to_sym
when :shelley
wallet = SHELLEY.wallets.create(payload)
return_wallet_id(wallet)
when :random, :icarus
payload[:style] = type
wallet = BYRON.wallets.create(payload)
return_wallet_id(wallet)
else
raise "Unsupported wallet type: #{type}"
end
end

##
# create target wallet or return it's id if it exists
# @param type [Symbol] :shelley, :shared
def create_target_wallet(type)
payload = { name: "Target wallet for txs",
passphrase: PASS,
mnemonic_sentence: get_fixture_wallet_mnemonics(:target, type.to_sym)
}
case type.to_sym
when :shelley
wallet = SHELLEY.wallets.create(payload)
return_wallet_id(wallet)
when :shared
script_template = { 'cosigners' =>
{ 'cosigner#0' => 'self' },
'template' =>
{ 'all' =>
[ 'cosigner#0'
]
}
}
payload[:account_index] = '0H'
payload[:payment_script_template] = script_template
payload[:delegation_script_template] = script_template
wallet = SHARED.wallets.create(payload)
return_wallet_id(wallet)
else
raise "Unsupported wallet type: #{type}"
end
end

##
# wait until action passed as &block returns true or TIMEOUT is reached
def eventually(label, &block)
Expand Down

0 comments on commit 4bc2c8a

Please sign in to comment.