Skip to content

Commit

Permalink
Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Github Action committed Jun 14, 2024
1 parent b5b9f00 commit 255a4ab
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 37 deletions.
7 changes: 6 additions & 1 deletion test/e2e/helpers/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,16 @@ def absolute_path(path)
# @param info_type [Symbol] wallet type = :mnemonics, :payment_template, :delegation_template
def get_fixture_wallet(kind, wallet_type, info_type = :mnemonics)
fixture = ENV.fetch('TESTS_E2E_FIXTURES_FILE', nil)
log "Using fixture file: #{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." unless File.exist? fixture

wallets = from_json(fixture)
log "Using #{kind} wallet of type #{wallet_type} with #{info_type} info."
log "Wallets: #{wallets}"
if linux?
wallets[:linux][kind][wallet_type][info_type]
r = wallets[:linux][kind][wallet_type][info_type]
log "Wallet info: #{r}"
r
elsif mac?
wallets[:macos][kind][wallet_type][info_type]
elsif win?
Expand Down
82 changes: 46 additions & 36 deletions test/e2e/spec/e2e_shared_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@

RSpec.describe 'Cardano Wallet E2E tests - Shared wallets', :all, :e2e, :shared do
before(:all) do
log "Shared wallets E2E tests setup"
# shelley wallets
@wid = create_fixture_wallet(:shelley)
@target_id = create_target_wallet(:shelley)

log "Shelley wallets created #{@wid}, #{@target_id}"
# shared wallets
@wid_sha = create_fixture_wallet(:shared, :payment_cosigner0_all0, :delegation_cosigner0_all0)
log "Shared wallet created"
@wid_sha_cos0_all = create_fixture_wallet(:shared, :payment_cosigner0_all, :delegation_cosigner0_all)
log "Shared wallet 0 created"
@wid_sha_cos1_all = create_fixture_wallet(:shared2, :payment_cosigner1_all, :delegation_cosigner1_all)
@wid_sha_cos0_any = create_fixture_wallet(:shared, :payment_cosigner0_any, :delegation_cosigner0_any)
log "Shared wallet 1 created"
cos0 = shared_acc_pubkey(@wid_sha_cos0_all)
@wid_sha_cos0_any = create_fixture_wallet(:shared, :payment_cosigner0_any, :delegation_cosigner0_any)
log "Shared wallet 2 created"
log "Cosigner 0 created"
cos1 = shared_acc_pubkey(@wid_sha_cos1_all)
patch_if_incomplete(@wid_sha_cos0_all, { 'cosigner#1' => cos1 }, { 'cosigner#1' => cos1 })
patch_if_incomplete(@wid_sha_cos1_all, { 'cosigner#0' => cos0 }, { 'cosigner#0' => cos0 })
Expand Down Expand Up @@ -1191,7 +1197,7 @@
balance = get_shared_balances(@wid_sha)
expected_deposit = CARDANO_CLI.protocol_params['stakeAddressDeposit']
puts "Expected deposit #{expected_deposit}"

# Check wallet stake keys before joing stake pool
wallet = SHARED.wallets.get(@wid_sha)
expect(wallet['delegation']['active']['status']).to eq 'not_delegating'
Expand Down Expand Up @@ -1241,7 +1247,7 @@
expect(tx_decoded['withdrawals']).to eq []
expect(tx_decoded['mint']).to eq({ 'tokens' => [] })
expect(tx_decoded['burn']).to eq({ 'tokens' => [] })

# Certificates
expect(tx_decoded['certificates']).to include(have_key('certificate_type')).twice
expect(tx_decoded['certificates']).to include(have_value('register_reward_account')).once
Expand Down Expand Up @@ -1297,7 +1303,7 @@
quit_pool,
nil, # mint_burn
nil) # validity_interval

# Check fee and deposit on quitting
decoded_tx = SHARED.transactions.decode(@wid_sha, tx_constructed['transaction'])
expect(decoded_tx).to be_correct_and_respond 202
Expand Down Expand Up @@ -1411,37 +1417,41 @@
end

it 'I can receive transaction to shared wallet' do
amt = 1
amt_ada = 3_000_000
address = SHARED.addresses.list(@wid_sha)[1]['id']
target_before = get_shared_balances(@wid_sha)
src_before = get_shelley_balances(@wid)

payload = [{ 'address' => address,
'amount' => { 'quantity' => amt_ada, 'unit' => 'lovelace' },
'assets' => [{ 'policy_id' => ASSETS[0]['policy_id'],
'asset_name' => ASSETS[0]['asset_name'],
'quantity' => amt },
{ 'policy_id' => ASSETS[1]['policy_id'],
'asset_name' => ASSETS[1]['asset_name'],
'quantity' => amt }] }]

tx_sent = SHELLEY.transactions.create(@wid, PASS, payload)

expect(tx_sent).to be_correct_and_respond 202
wait_for_tx_in_ledger(@wid, tx_sent['id'])

target_after = get_shared_balances(@wid_sha)
src_after = get_shelley_balances(@wid)
fee = SHELLEY.transactions.get(@wid, tx_sent['id'])['fee']['quantity']

verify_ada_balance(src_after, src_before,
target_after, target_before,
amt_ada, fee)

verify_asset_balance(src_after, src_before,
target_after, target_before,
amt)
log "Shared wallet: #{@wid_sha}"
# amt = 1
# amt_ada = 3_000_000
# address = SHARED.addresses.list(@wid_sha)[1]['id']
# log "Address: #{address}"
# target_before = get_shared_balances(@wid_sha)
# log 'target_before', target_before
# src_before = get_shelley_balances(@wid)
# log 'src_before', src_before

# payload = [{ 'address' => address,
# 'amount' => { 'quantity' => amt_ada, 'unit' => 'lovelace' },
# 'assets' => [{ 'policy_id' => ASSETS[0]['policy_id'],
# 'asset_name' => ASSETS[0]['asset_name'],
# 'quantity' => amt },
# { 'policy_id' => ASSETS[1]['policy_id'],
# 'asset_name' => ASSETS[1]['asset_name'],
# 'quantity' => amt }] }]

# tx_sent = SHELLEY.transactions.create(@wid, PASS, payload)

# expect(tx_sent).to be_correct_and_respond 202
# wait_for_tx_in_ledger(@wid, tx_sent['id'])

# target_after = get_shared_balances(@wid_sha)
# src_after = get_shelley_balances(@wid)
# fee = SHELLEY.transactions.get(@wid, tx_sent['id'])['fee']['quantity']

# verify_ada_balance(src_after, src_before,
# target_after, target_before,
# amt_ada, fee)

# verify_asset_balance(src_after, src_before,
# target_after, target_before,
# amt)
end

it 'I can list transactions and limit response with query parameters' do
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def create_incomplete_shared_wallet(m, acc_ix, acc_xpub)
end

def shared_acc_pubkey(wallet_id)
log SHARED.keys.get_acc_public_key(wallet_id, { format: 'extended' })
SHARED.keys.get_acc_public_key(wallet_id, { format: 'extended' }).parsed_response.delete_prefix('"').delete_suffix('"')
end

Expand Down Expand Up @@ -311,6 +312,7 @@ def return_wallet_id(create_wallet_response)
if create_wallet_response.code == 409
create_wallet_response['message'].split[10]
else
log "Wallet created with id: #{create_wallet_response}"
create_wallet_response['id']
end
end
Expand Down Expand Up @@ -358,7 +360,9 @@ def create_fixture_wallet(type, *templates)
end
end
payload[:account_index] = '0H'
log "Creating shared wallet with payload: #{payload}"
wallet = SHARED.wallets.create(payload)
log "Wallet created with id: #{wallet}"
return_wallet_id(wallet)
else
raise "Unsupported wallet type: #{type}"
Expand Down

0 comments on commit 255a4ab

Please sign in to comment.