diff --git a/test/e2e/helpers/matchers.rb b/test/e2e/helpers/matchers.rb index 2821a78472d..5c7cffd9f51 100644 --- a/test/e2e/helpers/matchers.rb +++ b/test/e2e/helpers/matchers.rb @@ -1,8 +1,12 @@ require "rspec/expectations" -RSpec::Matchers.define :have_http do |code| +RSpec::Matchers.define :be_correct_and_respond do |code| match do |response| - response.code == code + if code == 204 + response.code == code + else + ((response.code == code) && ({ 'content-type' => ['application/json;charset=utf-8'] } <= response.headers)) + end end failure_message do |response| method = response.request.http_method.to_s.split('::').last.upcase @@ -11,7 +15,7 @@ headers = response.request.options[:headers] " - The response did not return expected HTTP code! + The response did not return expected HTTP code or header 'content-type: application/json'! Expected code = #{code} Actual code = #{response.code} @@ -23,14 +27,17 @@ Actual response: #{response} + Actual response headers: + #{response.headers} + Time: #{Time.now} " end end -RSpec::Matchers.define :have_expected_headers do +RSpec::Matchers.define :respond_with do |code| match do |response| - { 'content-type' => ['application/json;charset=utf-8'] } <= response.headers + response.code == code end failure_message do |response| method = response.request.http_method.to_s.split('::').last.upcase @@ -39,9 +46,9 @@ headers = response.request.options[:headers] " - The response did not return expected HTTP header! - Expected response headers = #{expected_headers} - Actual response headers = #{response.headers} + The response did not return expected HTTP code! + Expected code = #{code} + Actual code = #{response.code} Actual request: #{method} #{uri} @@ -51,6 +58,9 @@ Actual response: #{response} + Actual response headers: + #{response.headers} + Time: #{Time.now} " end diff --git a/test/e2e/spec/byron_spec.rb b/test/e2e/spec/byron_spec.rb index 17b4c0a521b..9e163c03239 100644 --- a/test/e2e/spec/byron_spec.rb +++ b/test/e2e/spec/byron_spec.rb @@ -8,20 +8,17 @@ it "I can list byron wallets" do l = BYRON.wallets.list - expect(l).to have_http 200 - expect(l).to have_expected_headers + expect(l).to be_correct_and_respond 200 end it "I could get a wallet" do g = BYRON.wallets.get "db66f3d0d796c6aa0ad456a36d5a3ee88d62bd5d" - expect(g).to have_http 404 - expect(g).to have_expected_headers + expect(g).to be_correct_and_respond 404 end it "I could delete a wallet" do g = BYRON.wallets.delete "db66f3d0d796c6aa0ad456a36d5a3ee88d62bd5d" - expect(g).to have_http 404 - expect(g).to have_expected_headers + expect(g).to be_correct_and_respond 404 end it "I can create, get and delete byron icarus wallet from mnemonics" do @@ -30,14 +27,12 @@ passphrase: "Secure Passphrase", mnemonic_sentence: mnemonic_sentence(15), }) - expect(wallet).to have_http 201 - expect(wallet).to have_expected_headers + expect(wallet).to be_correct_and_respond 201 + wid = wallet['id'] g = BYRON.wallets.get(wid) - expect(g).to have_http 200 - expect(g).to have_expected_headers - - expect(BYRON.wallets.delete(wid)).to have_http 204 + expect(g).to be_correct_and_respond 200 + expect(BYRON.wallets.delete(wid)).to be_correct_and_respond 204 end it "I can create, get and delete byron random wallet from mnemonics" do @@ -46,23 +41,23 @@ passphrase: "Secure Passphrase", mnemonic_sentence: mnemonic_sentence(12), }) - expect(wallet).to have_http 201 - expect(wallet).to have_expected_headers + expect(wallet).to be_correct_and_respond 201 + wid = wallet['id'] g = BYRON.wallets.get(wid) - expect(g).to have_http 200 - expect(g).to have_expected_headers + expect(g).to be_correct_and_respond 200 - expect(BYRON.wallets.delete(wid)).to have_http 204 + + expect(BYRON.wallets.delete(wid)).to be_correct_and_respond 204 end it "Can update_metadata" do w = BYRON.wallets id = create_byron_wallet u = w.update_metadata(id, { name: "New wallet name" }) - expect(u).to have_http 200 - expect(u).to have_expected_headers + expect(u).to be_correct_and_respond 200 + end it "Can update_passphrase" do @@ -70,14 +65,14 @@ id = create_byron_wallet upd = w.update_passphrase(id, { old_passphrase: "Secure Passphrase", new_passphrase: "Securer Passphrase" }) - expect(upd).to have_http 204 + expect(upd).to be_correct_and_respond 204 end it "Can see utxo" do id = create_byron_wallet utxo = BYRON.wallets.utxo(id) - expect(utxo).to have_http 200 - expect(utxo).to have_expected_headers + expect(utxo).to be_correct_and_respond 200 + end end @@ -90,14 +85,14 @@ it "Can list addresses - random" do id = create_byron_wallet addresses = BYRON.addresses.list id - expect(addresses).to have_http 200 - expect(addresses).to have_expected_headers + expect(addresses).to be_correct_and_respond 200 + expect(addresses.size).to eq 0 BYRON.addresses.create(id, { passphrase: PASS }) addresses = BYRON.addresses.list id - expect(addresses).to have_http 200 - expect(addresses).to have_expected_headers + expect(addresses).to be_correct_and_respond 200 + expect(addresses.size).to eq 1 expect(addresses.first['derivation_path'][0]).to eq '0H' expect(addresses.first['derivation_path'][1]).to end_with 'H' @@ -106,8 +101,8 @@ it "Can list addresses - icarus" do id = create_byron_wallet "icarus" addresses_unused = BYRON.addresses.list id, { state: "unused" } - expect(addresses_unused).to have_http 200 - expect(addresses_unused).to have_expected_headers + expect(addresses_unused).to be_correct_and_respond 200 + expect(addresses_unused.size).to eq 20 addresses_unused.each_with_index do |a, i| expect(a['derivation_path']).to eq ['44H', '1815H', '0H', '0', i.to_s] @@ -117,8 +112,8 @@ it "Can list addresses - ledger" do id = create_byron_wallet "ledger" addresses_unused = BYRON.addresses.list id, { state: "unused" } - expect(addresses_unused).to have_http 200 - expect(addresses_unused).to have_expected_headers + expect(addresses_unused).to be_correct_and_respond 200 + expect(addresses_unused.size).to eq 20 addresses_unused.each_with_index do |a, i| expect(a['derivation_path']).to eq ['44H', '1815H', '0H', '0', i.to_s] @@ -128,8 +123,8 @@ it "Can list addresses - trezor" do id = create_byron_wallet "trezor" addresses_unused = BYRON.addresses.list id, { state: "unused" } - expect(addresses_unused).to have_http 200 - expect(addresses_unused).to have_expected_headers + expect(addresses_unused).to be_correct_and_respond 200 + expect(addresses_unused.size).to eq 20 addresses_unused.each_with_index do |a, i| expect(a['derivation_path']).to eq ['44H', '1815H', '0H', '0', i.to_s] @@ -140,13 +135,11 @@ id = create_byron_wallet addr = BYRON.addresses.create(id, { passphrase: PASS, address_index: 2147483648 }) - expect(addr).to have_http 201 - expect(addr).to have_expected_headers + expect(addr).to be_correct_and_respond 201 expect(addr['derivation_path']).to eq ['0H', '0H'] addr_r = BYRON.addresses.create(id, { passphrase: PASS }) - expect(addr_r).to have_http 201 - expect(addr_r).to have_expected_headers + expect(addr_r).to be_correct_and_respond 201 expect(addr_r['derivation_path'][0]).to eq '0H' expect(addr_r['derivation_path'][1]).to end_with 'H' end @@ -155,11 +148,10 @@ id = create_fixture_byron_wallet addr = '37btjrVyb4KEciULDrqJDBh6SjgPqi9JJ5qQqWGgvtsB7GcsuqorKceMTBRudFK8zDu3btoC5FtN7K1PEHmko4neQPfV9TDVfivc9JTZVNPKtRd4w2' addr_import = BYRON.addresses.import(id, addr) - expect(addr_import).to have_http 204 + expect(addr_import).to be_correct_and_respond 204 addresses = BYRON.addresses.list id - expect(addresses).to have_http 200 - expect(addresses).to have_expected_headers + expect(addresses).to be_correct_and_respond 200 expect(addresses.size).to eq 1 expect(addresses.first['derivation_path']).to eq ['0H', '2147483647H'] end @@ -168,8 +160,7 @@ id = create_byron_wallet "icarus" addr = BYRON.addresses.list(id)[0]['id'] addr_import = BYRON.addresses.import(id, addr) - expect(addr_import).to have_http 403 - expect(addr_import).to have_expected_headers + expect(addr_import).to be_correct_and_respond 403 expect(addr_import.to_s).to include "invalid_wallet_type" end @@ -177,8 +168,7 @@ id = create_byron_wallet "ledger" addr = BYRON.addresses.list(id)[0]['id'] addr_import = BYRON.addresses.import(id, addr) - expect(addr_import).to have_http 403 - expect(addr_import).to have_expected_headers + expect(addr_import).to be_correct_and_respond 403 expect(addr_import.to_s).to include "invalid_wallet_type" end @@ -186,8 +176,7 @@ id = create_byron_wallet "trezor" addr = BYRON.addresses.list(id)[0]['id'] addr_import = BYRON.addresses.import(id, addr) - expect(addr_import).to have_http 403 - expect(addr_import).to have_expected_headers + expect(addr_import).to be_correct_and_respond 403 expect(addr_import.to_s).to include "invalid_wallet_type" end end @@ -208,8 +197,7 @@ rnd = BYRON.coin_selections.random wid, addr_amount - expect(rnd).to have_http 403 - expect(rnd).to have_expected_headers + expect(rnd).to be_correct_and_respond 403 expect(rnd.to_s).to include "not_enough_money" end @@ -227,8 +215,7 @@ wid = create_byron_wallet style txs = BYRON.transactions g = txs.get(wid, TXID) - expect(g).to have_http 404 - expect(g).to have_expected_headers + expect(g).to be_correct_and_respond 404 expect(g.to_s).to include "no_such_transaction" end @@ -236,13 +223,13 @@ id = create_byron_wallet style txs = BYRON.transactions - expect(txs.list(id)).to have_http 200 + expect(txs.list(id)).to be_correct_and_respond 200 expect(txs.list(id, { start: "2012-09-25T10:15:00Z", end: "2016-11-21T10:15:00Z", order: "ascending" }).code). to eq 200 - expect(txs.list(id, { order: "bad_order" })).to have_http 400 + expect(txs.list(id, { order: "bad_order" })).to be_correct_and_respond 400 end it "I could send tx if I had money - #{style}" do @@ -251,8 +238,7 @@ target_addr = BYRON.addresses.list(target_id)[0]['id'] tx_sent = BYRON.transactions.create(id, PASS, [{ target_addr => 1000000 }]) - expect(tx_sent).to have_http 403 - expect(tx_sent).to have_expected_headers + expect(tx_sent).to be_correct_and_respond 403 expect(tx_sent.to_s).to include "not_enough_money" end @@ -262,8 +248,7 @@ target_addr = BYRON.addresses.list(target_id)[0]['id'] fees = BYRON.transactions.payment_fees(id, [{ target_addr => 1000000 }]) - expect(fees).to have_http 403 - expect(fees).to have_expected_headers + expect(fees).to be_correct_and_respond 403 expect(fees.to_s).to include "not_enough_money" end @@ -271,8 +256,7 @@ id = create_byron_wallet style txs = BYRON.transactions res = txs.forget(id, TXID) - expect(res).to have_http 404 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 404 end end end @@ -285,8 +269,7 @@ it "I could calculate migration cost" do id = create_byron_wallet "icarus" cost = BYRON.migrations.cost(id) - expect(cost).to have_http 501 - expect(cost).to have_expected_headers + expect(cost).to be_correct_and_respond 501 end it "I could migrate all my funds" do @@ -294,8 +277,7 @@ target_wal_id = create_byron_wallet "icarus" addresses = BYRON.addresses.list(target_wal_id).map { |a| a['id'] } migr = BYRON.migrations.migrate(id, PASS, addresses) - expect(migr).to have_http 501 - expect(migr).to have_expected_headers + expect(migr).to be_correct_and_respond 501 end end end diff --git a/test/e2e/spec/e2e_spec.rb b/test/e2e/spec/e2e_spec.rb index a249d349e54..ac45e66b186 100644 --- a/test/e2e/spec/e2e_spec.rb +++ b/test/e2e/spec/e2e_spec.rb @@ -53,8 +53,7 @@ describe "Native Assets" do it "I can list native assets" do assets = SHELLEY.assets.get @wid - expect(assets).to have_http 200 - expect(assets).to have_expected_headers + expect(assets).to be_correct_and_respond 200 expect(assets.to_s).to include ASSETS[0]["policy_id"] expect(assets.to_s).to include ASSETS[0]["asset_name"] expect(assets.to_s).to include ASSETS[0]["metadata"]["name"] @@ -65,8 +64,7 @@ it "I can get native assets by policy_id" do assets = SHELLEY.assets.get(@wid, policy_id = ASSETS[0]["policy_id"]) - expect(assets).to have_http 200 - expect(assets).to have_expected_headers + expect(assets).to be_correct_and_respond 200 expect(assets["policy_id"]).to eq ASSETS[0]["policy_id"] expect(assets["asset_name"]).to eq ASSETS[0]["asset_name"] expect(assets["metadata"]).to eq ASSETS[0]["metadata"] @@ -76,8 +74,7 @@ it "I can get native assets by policy_id and asset_name" do assets = SHELLEY.assets.get(@wid, policy_id = ASSETS[1]["policy_id"], asset_name = ASSETS[1]["asset_name"]) - expect(assets).to have_http 200 - expect(assets).to have_expected_headers + expect(assets).to be_correct_and_respond 200 expect(assets["policy_id"]).to eq ASSETS[1]["policy_id"] expect(assets["asset_name"]).to eq ASSETS[1]["asset_name"] expect(assets["metadata"]).to eq ASSETS[1]["metadata"] @@ -104,8 +101,7 @@ tx_sent = SHELLEY.transactions.create(@wid, PASS, payload) - expect(tx_sent).to have_http 202 - expect(tx_sent).to have_expected_headers + expect(tx_sent).to be_correct_and_respond 202 expect(tx_sent.to_s).to include "pending" eventually "Assets are on target wallet: #{@target_id_assets}" do @@ -140,8 +136,7 @@ address = SHELLEY.addresses.list(@target_id)[0]['id'] tx_sent = SHELLEY.transactions.create(@wid, PASS, [{ address => amt }]) - expect(tx_sent).to have_http 202 - expect(tx_sent).to have_expected_headers + expect(tx_sent).to be_correct_and_respond 202 expect(tx_sent.to_s).to include "pending" eventually "Funds are on target wallet: #{@target_id}" do @@ -163,8 +158,7 @@ metadata = nil, ttl_in_s) - expect(tx_sent).to have_http 202 - expect(tx_sent).to have_expected_headers + expect(tx_sent).to be_correct_and_respond 202 expect(tx_sent.to_s).to include "pending" eventually "Funds are on target wallet: #{@target_id}" do @@ -187,8 +181,7 @@ metadata = nil, ttl_in_s) - expect(tx_sent).to have_http 202 - expect(tx_sent).to have_expected_headers + expect(tx_sent).to be_correct_and_respond 202 expect(tx_sent.to_s).to include "pending" eventually "TX `#{tx_sent['id']}' expires on `#{@wid}'" do @@ -196,10 +189,10 @@ end res = SHELLEY.transactions.forget(@wid, tx_sent['id']) - expect(res).to have_http 204 + expect(res).to be_correct_and_respond 204 fres = SHELLEY.transactions.get(@wid, tx_sent['id']) - expect(fres).to have_http 404 + expect(fres).to be_correct_and_respond 404 end it "I can send transaction using 'withdrawal' flag and funds are received" do @@ -208,8 +201,7 @@ tx_sent = SHELLEY.transactions.create(@wid, PASS, [{ address => amt }], 'self') - expect(tx_sent).to have_http 202 - expect(tx_sent).to have_expected_headers + expect(tx_sent).to be_correct_and_respond 202 expect(tx_sent.to_s).to include "pending" eventually "Funds are on target wallet: #{@target_id_withdrawal}" do @@ -231,8 +223,7 @@ metadata ) - expect(tx_sent).to have_http 202 - expect(tx_sent).to have_expected_headers + expect(tx_sent).to be_correct_and_respond 202 expect(tx_sent.to_s).to include "pending" eventually "Funds are on target wallet: #{@target_id_meta}" do @@ -256,16 +247,13 @@ txs = SHELLEY.transactions fees = txs.payment_fees(@wid, amt) - expect(fees).to have_http 202 - expect(fees).to have_expected_headers + expect(fees).to be_correct_and_respond 202 fees = txs.payment_fees(@wid, amt, 'self') - expect(fees).to have_http 202 - expect(fees).to have_expected_headers + expect(fees).to be_correct_and_respond 202 fees = txs.payment_fees(@wid, amt, 'self', metadata) - expect(fees).to have_http 202 - expect(fees).to have_expected_headers + expect(fees).to be_correct_and_respond 202 end end @@ -275,8 +263,7 @@ pools = SHELLEY.stake_pools join = pools.join(SPID, @wid, PASS) - expect(join).to have_http 404 - expect(join).to have_expected_headers + expect(join).to be_correct_and_respond 404 expect(join.to_s).to include "no_such_pool" end @@ -285,8 +272,7 @@ pools = SHELLEY.stake_pools fees = pools.delegation_fees(id) - expect(fees).to have_http 403 - expect(fees).to have_expected_headers + expect(fees).to be_correct_and_respond 403 expect(fees.to_s).to include "not_enough_money" end @@ -296,8 +282,7 @@ pool_id = pools.list({ stake: 1000 })[0]['id'] join = pools.join(pool_id, id, PASS) - expect(join).to have_http 403 - expect(join).to have_expected_headers + expect(join).to be_correct_and_respond 403 expect(join.to_s).to include "not_enough_money" end @@ -305,11 +290,9 @@ pools = SHELLEY.stake_pools l = pools.list({ stake: 1000 }) l_bad = pools.list - expect(l).to have_http 200 - expect(l).to have_expected_headers + expect(l).to be_correct_and_respond 200 - expect(l_bad).to have_http 400 - expect(l_bad).to have_expected_headers + expect(l_bad).to be_correct_and_respond 400 expect(l_bad.to_s).to include "query_param_missing" end @@ -322,7 +305,7 @@ PASS, [{ address => amt }]) - expect(tx_sent).to have_http 202 + expect(tx_sent).to be_correct_and_respond 202 expect(tx_sent.to_s).to include "pending" eventually "Funds are on target wallet: #{@target_id_pools}" do @@ -339,8 +322,7 @@ puts "Joining pool: #{pool_id}" join = pools.join(pool_id, @target_id_pools, PASS) - expect(join).to have_http 202 - expect(join).to have_expected_headers + expect(join).to be_correct_and_respond 202 expect(join.to_s).to include "status" join_tx_id = join['id'] @@ -353,8 +335,7 @@ puts "Quitting pool: #{pool_id}" quit = pools.quit(@target_id_pools, PASS) - expect(quit).to have_http 202 - expect(quit).to have_expected_headers + expect(quit).to be_correct_and_respond 202 expect(quit.to_s).to include "status" quit_tx_id = quit['id'] @@ -386,8 +367,7 @@ rnd = SHELLEY.coin_selections.random(@wid, payload, withdrawal = "self", m = METADATA) - expect(rnd).to have_http 200 - expect(rnd).to have_expected_headers + expect(rnd).to be_correct_and_respond 200 expect(rnd.to_s).to include "outputs" expect(rnd.to_s).to include "change" expect(rnd.to_s).to include "metadata" @@ -401,8 +381,7 @@ rnd = SHELLEY.coin_selections.random_deleg @wid, action_join - expect(rnd).to have_http 200 - expect(rnd).to have_expected_headers + expect(rnd).to be_correct_and_respond 200 expect(rnd.to_s).to include "outputs" expect(rnd.to_s).to include "change" expect(rnd['inputs']).not_to be_empty @@ -419,8 +398,7 @@ action_join = { action: "join", pool: pid } rnd = SHELLEY.coin_selections.random_deleg wid, action_join - expect(rnd).to have_http 403 - expect(rnd).to have_expected_headers + expect(rnd).to be_correct_and_respond 403 expect(rnd.to_s).to include "not_enough_money" end @@ -431,13 +409,11 @@ action_quit = { action: "quit" } rnd = SHELLEY.coin_selections.random_deleg wid, action_join - expect(rnd).to have_http 404 - expect(rnd).to have_expected_headers + expect(rnd).to be_correct_and_respond 404 expect(rnd.to_s).to include "no_such_pool" rnd = SHELLEY.coin_selections.random_deleg wid, action_quit - expect(rnd).to have_http 403 - expect(rnd).to have_expected_headers + expect(rnd).to be_correct_and_respond 403 expect(rnd.to_s).to include "not_delegating_to" end @@ -452,8 +428,7 @@ def test_byron_tx(source_wid, target_wid) tx_sent = BYRON.transactions.create(source_wid, PASS, [{ address => amt }]) - expect(tx_sent).to have_http 202 - expect(tx_sent).to have_expected_headers + expect(tx_sent).to be_correct_and_respond 202 expect(tx_sent.to_s).to include "pending" eventually "Funds are on target wallet: #{target_wid}" do @@ -482,8 +457,7 @@ def test_byron_assets_tx(source_id, target_id) tx_sent = BYRON.transactions.create(source_id, PASS, payload) - expect(tx_sent).to have_http 202 - expect(tx_sent).to have_expected_headers + expect(tx_sent).to be_correct_and_respond 202 expect(tx_sent.to_s).to include "pending" eventually "Assets are on target wallet: #{target_id}" do @@ -524,8 +498,7 @@ def test_byron_assets_tx(source_id, target_id) it "I can list assets -> random" do assets = BYRON.assets.get @wid_rnd - expect(assets).to have_http 200 - expect(assets).to have_expected_headers + expect(assets).to be_correct_and_respond 200 expect(assets.to_s).to include ASSETS[0]["policy_id"] expect(assets.to_s).to include ASSETS[0]["asset_name"] expect(assets.to_s).to include ASSETS[0]["metadata"]["name"] @@ -536,8 +509,7 @@ def test_byron_assets_tx(source_id, target_id) it "I can list assets -> icarus" do assets = BYRON.assets.get @wid_ic - expect(assets).to have_http 200 - expect(assets).to have_expected_headers + expect(assets).to be_correct_and_respond 200 expect(assets.to_s).to include ASSETS[0]["policy_id"] expect(assets.to_s).to include ASSETS[0]["asset_name"] expect(assets.to_s).to include ASSETS[0]["metadata"]["name"] @@ -548,8 +520,7 @@ def test_byron_assets_tx(source_id, target_id) it "I can get native assets by policy_id -> random" do assets = BYRON.assets.get(@wid_rnd, policy_id = ASSETS[0]["policy_id"]) - expect(assets).to have_http 200 - expect(assets).to have_expected_headers + expect(assets).to be_correct_and_respond 200 expect(assets["policy_id"]).to eq ASSETS[0]["policy_id"] expect(assets["asset_name"]).to eq ASSETS[0]["asset_name"] expect(assets["metadata"]).to eq ASSETS[0]["metadata"] @@ -559,8 +530,7 @@ def test_byron_assets_tx(source_id, target_id) it "I can get native assets by policy_id and asset_name -> random" do assets = BYRON.assets.get(@wid_rnd, policy_id = ASSETS[1]["policy_id"], asset_name = ASSETS[1]["asset_name"]) - expect(assets).to have_http 200 - expect(assets).to have_expected_headers + expect(assets).to be_correct_and_respond 200 expect(assets["policy_id"]).to eq ASSETS[1]["policy_id"] expect(assets["asset_name"]).to eq ASSETS[1]["asset_name"] expect(assets["metadata"]).to eq ASSETS[1]["metadata"] diff --git a/test/e2e/spec/misc_spec.rb b/test/e2e/spec/misc_spec.rb index 2646cc15937..c6738315176 100644 --- a/test/e2e/spec/misc_spec.rb +++ b/test/e2e/spec/misc_spec.rb @@ -4,20 +4,17 @@ it "Can get network information" do res = NETWORK.information - expect(res).to have_http 200 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 200 end it "Can check network clock offset" do res = NETWORK.clock - expect(res).to have_http 200 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 200 end it "Can check network parameters" do res = NETWORK.parameters - expect(res).to have_http 200 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 200 end end @@ -26,15 +23,13 @@ describe "SMASH health" do it "SMASH health - unreachable" do r = UTILS.smash_health({ url: "http://onet.pl" }) - expect(r).to have_http 200 - expect(r).to have_expected_headers + expect(r).to be_correct_and_respond 200 expect(r.to_s).to include "unreachable" end it "SMASH health - bad url" do r = UTILS.smash_health({ url: "dsds" }) - expect(r).to have_http 400 - expect(r).to have_expected_headers + expect(r).to be_correct_and_respond 400 expect(r.to_s).to include "bad_request" end end @@ -42,8 +37,7 @@ it "Inspect invalid address" do addr = "addr" res = UTILS.addresses addr - expect(res).to have_http 400 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 400 expect(res.to_s).to include "bad_request" end @@ -51,8 +45,7 @@ addr = "addr1qqlgm2dh3vpv07cjfcyuu6vhaqhf8998qcx6s8ucpkly6f8l0dw5r75vk42mv3ykq8vyjeaanvpytg79xqzymqy5acmqej0mk7" res = UTILS.addresses addr - expect(res).to have_http 200 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 200 expect(res['address_style']).to eq "Shelley" expect(res['stake_reference']).to eq "by value" expect(res['stake_key_hash']).to eq "ff7b5d41fa8cb555b6449601d84967bd9b0245a3c530044d8094ee36" @@ -64,8 +57,7 @@ addr = "stake_test1uzws33ghf8kugc8ea8p7h8mr7dcsl6ggw7tfy479y9t0d4qp48dkq" res = UTILS.addresses addr - expect(res).to have_http 200 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 200 expect(res['address_style']).to eq "Shelley" expect(res['stake_reference']).to eq "by value" expect(res['stake_key_hash']).to eq "9d08c51749edc460f9e9c3eb9f63f3710fe90877969257c52156f6d4" @@ -76,8 +68,7 @@ addr = "37btjrVyb4KEzz6YprjHfqz3DS4JvoDpAf3QWLABzQ7uzMEk7g3PD2AwL1SbYWekneuRFkyTipbyKMZyEMed5LroZtQAvA2LqcWmJuwaqt6oJLbssS" res = UTILS.addresses addr - expect(res).to have_http 200 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 200 expect(res['address_style']).to eq "Byron" expect(res['stake_reference']).to eq "none" expect(res['address_root']).to eq "c23a0f86c7bc977f0dee4721c9850467047a0e6acd928a991b5cbba8" @@ -89,8 +80,7 @@ addr = "2cWKMJemoBajQcoTotf4xYba7fV7Ztx7AvbnzvaQY6PbezPWM6DtJD6Df2bVejBCpykmt" res = UTILS.addresses addr - expect(res).to have_http 200 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 200 expect(res['address_style']).to eq "Icarus" expect(res['stake_reference']).to eq "none" expect(res['address_root']).to eq "88940c753ee50d556ecaefadd0d2fee9fabacf4366a7d4a8cdfa2b64" @@ -103,8 +93,7 @@ "payment": "script_vkh1yf07000d4ml3ywd3d439kmwp07xzgv6p35cwx8h605jfx0dtd4a" } res = UTILS.post_address(script) - expect(res).to have_http 202 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 202 expect(res.to_s).to include "addr_test1wp6eswctz5wzrv3ceh3h4y3na2t6d95sjn23dawy0zlzg0q569eke" end @@ -118,8 +107,7 @@ } } res = UTILS.post_address(script) - expect(res).to have_http 202 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 202 expect(res.to_s).to include "addr_test1wzt2z3pa7etaxp7jurdg0m8jhsmtp4r2z56pd3a5q3jhxyc2ykp4j" end @@ -133,8 +121,7 @@ } } res = UTILS.post_address(script) - expect(res).to have_http 202 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 202 expect(res.to_s).to include "addr_test1wp4h4mtdkxr2x68zx4tk0cgmd9hymjgsuhmzaxkg5tkl3scr8umfh" end @@ -152,8 +139,7 @@ } } res = UTILS.post_address(script) - expect(res).to have_http 202 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 202 expect(res.to_s).to include "addr_test1wq5np0m5x03tax3kcdh6e2cet98qcfs80wtv4cyvl5taclcp983gu" end @@ -167,8 +153,7 @@ } } res = UTILS.post_address(script) - expect(res).to have_http 202 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 202 expect(res.to_s).to include "stake_test17zt2z3pa7etaxp7jurdg0m8jhsmtp4r2z56pd3a5q3jhxyc2vgezc" end @@ -192,8 +177,7 @@ } } res = UTILS.post_address(script) - expect(res).to have_http 202 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 202 expect(res.to_s).to include "addr_test1xq5np0m5x03tax3kcdh6e2cet98qcfs80wtv4cyvl5tacluk59zrmajh6vra9cx6slk090pkkr2x59f5zmrmgpr9wvfsjg2j62" end @@ -202,8 +186,7 @@ "payment": "addr_vk1lqglg77z6kajsdz4739q22c0zm0yhuy567z6xk2vc0z5ucjtkwpschzd2j" } res = UTILS.post_address(script) - expect(res).to have_http 202 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 202 expect(res.to_s).to include "addr_test1vpqthemrg5kczwfjjnahwt65elhrl95e9hcgufnajtp6wfgdmxm9u" end @@ -212,8 +195,7 @@ "stake": "stake_vk16apaenn9ut6s40lcw3l8v68xawlrlq20z2966uzcx8jmv2q9uy7qau558d" } res = UTILS.post_address(script) - expect(res).to have_http 202 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 202 expect(res.to_s).to include "stake_test1uq6pmlvyl3wn4ca6807e26gy2gek9hqu0gastzh5tk0xx0gdfvj8f" end @@ -223,8 +205,7 @@ "stake": "stake_vk16apaenn9ut6s40lcw3l8v68xawlrlq20z2966uzcx8jmv2q9uy7qau558d" } res = UTILS.post_address(script) - expect(res).to have_http 202 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 202 expect(res.to_s).to include "addr_test1qpqthemrg5kczwfjjnahwt65elhrl95e9hcgufnajtp6wff5rh7cflza8t3m5wlaj45sg53nvtwpc73mqk90ghv7vv7ser7yl4" end @@ -243,8 +224,7 @@ "stake": "stake_vk16apaenn9ut6s40lcw3l8v68xawlrlq20z2966uzcx8jmv2q9uy7qau558d" } res = UTILS.post_address(script) - expect(res).to have_http 202 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 202 expect(res.to_s).to include "addr_test1zq5np0m5x03tax3kcdh6e2cet98qcfs80wtv4cyvl5tacle5rh7cflza8t3m5wlaj45sg53nvtwpc73mqk90ghv7vv7su0qjlj" end @@ -263,8 +243,7 @@ } } res = UTILS.post_address(script) - expect(res).to have_http 202 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 202 expect(res.to_s).to include "addr_test1ypqthemrg5kczwfjjnahwt65elhrl95e9hcgufnajtp6wfffxzlhgvlzh6drdsm04j43jk2wpsnqw7uketsgelghm3lsmpggt5" end @@ -276,8 +255,7 @@ binary_blob = "82839f8200d81858248258201d4ca4d72a1e02fbb79bec42392d9eb3da179f8a2316fd9e9a5ffe9c441d8bce01ff9f8282d818582883581c9c19ec69f7d3acad269e4bbbfcad67129c268bd772060b426b7e23cba102451a4170cb17001a1c281652018282d818582883581c95eaa323cac6cd8916a02c58b133d9b576ceb7bcb1f8c0716a701118a102451a4170cb17001a5e6fce581a0096048effa0818200d8185885825840b8cdd384ec1ef3dffe4db999d6bfce40afaa964543e2e1592c932f552fe9e8301233bbc1f45472837b904b719db5d32d947ec521e7fccd1aec6ad6cf884fc45858403964714f761d79a67b34c8e1fcc337af6ef44a894e6e740927dbec86d1be63e9987dc9ceb7905a53a0ddddf3a9ea4508e41a02d18ed3994461eb20cb0ba2710b" PROXY = CardanoWallet.new.misc.proxy res = PROXY.submit_external_transaction(binary_blob) - expect(res).to have_http 400 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 400 end end @@ -294,17 +272,15 @@ matrix.each do |strategy, smash_health_response| it "I can read and update settings to #{strategy} and verify SMASH health = #{smash_health_response}" do s = SETTINGS.update({ :pool_metadata_source => strategy }) - expect(s).to have_http 204 + expect(s).to be_correct_and_respond 204 g = SETTINGS.get expect(g['pool_metadata_source']).to eq strategy - expect(g).to have_http 200 - expect(g).to have_expected_headers + expect(g).to be_correct_and_respond 200 # check smash health r = UTILS.smash_health - expect(r).to have_http 200 - expect(r).to have_expected_headers + expect(r).to be_correct_and_respond 200 expect(r.to_s).to include smash_health_response end end diff --git a/test/e2e/spec/shelley_spec.rb b/test/e2e/spec/shelley_spec.rb index 42e71e9e119..8dc0001efac 100644 --- a/test/e2e/spec/shelley_spec.rb +++ b/test/e2e/spec/shelley_spec.rb @@ -8,14 +8,12 @@ it "I can list wallets" do l = SHELLEY.wallets.list - expect(l).to have_http 200 - expect(l).to have_expected_headers + expect(l).to be_correct_and_respond 200 expect(l.size).to eq 0 create_shelley_wallet l = SHELLEY.wallets.list - expect(l).to have_http 200 - expect(l).to have_expected_headers + expect(l).to be_correct_and_respond 200 expect(l.size).to eq 1 end @@ -23,12 +21,10 @@ wid = create_shelley_wallet SHELLEY.wallets.delete wid g = SHELLEY.wallets.get wid - expect(g).to have_http 404 - expect(g).to have_expected_headers + expect(g).to be_correct_and_respond 404 d = SHELLEY.wallets.delete wid - expect(d).to have_http 404 - expect(d).to have_expected_headers + expect(d).to be_correct_and_respond 404 end describe "Create wallets" do @@ -38,15 +34,13 @@ passphrase: "Secure Passphrase", mnemonic_sentence: mnemonic_sentence(15), }) - expect(wallet).to have_http 201 - expect(wallet).to have_expected_headers + expect(wallet).to be_correct_and_respond 201 wid = wallet['id'] g = w.get(wid) - expect(g).to have_http 200 - expect(g).to have_expected_headers + expect(g).to be_correct_and_respond 200 - expect(w.delete(wid)).to have_http 204 + expect(w.delete(wid)).to be_correct_and_respond 204 end it "I can create, get and delete wallet from mnemonics / second factor" do @@ -56,15 +50,13 @@ mnemonic_sentence: mnemonic_sentence(15), mnemonic_second_factor: mnemonic_sentence(12) }) - expect(wallet).to have_http 201 - expect(wallet).to have_expected_headers + expect(wallet).to be_correct_and_respond 201 wid = wallet['id'] g = w.get(wid) - expect(g).to have_http 200 - expect(g).to have_expected_headers + expect(g).to be_correct_and_respond 200 - expect(w.delete(wid)).to have_http 204 + expect(w.delete(wid)).to be_correct_and_respond 204 end it "I can set address pool gap" do @@ -75,10 +67,9 @@ mnemonic_sentence: mnemonic_sentence(15), address_pool_gap: pool_gap }) - expect(wallet).to have_http 201 + expect(wallet).to be_correct_and_respond 201 addr = SHELLEY.addresses.list(wallet['id']) - expect(addr).to have_http 200 - expect(addr).to have_expected_headers + expect(addr).to be_correct_and_respond 200 expect(addr.size).to eq pool_gap end @@ -88,14 +79,12 @@ account_public_key: "b47546e661b6c1791452d003d375756dde6cac2250093ce4630f16b9b9c0ac87411337bda4d5bc0216462480b809824ffb48f17e08d95ab9f1b91d391e48e66b", address_pool_gap: 20, }) - expect(wallet).to have_http 201 - expect(wallet).to have_expected_headers + expect(wallet).to be_correct_and_respond 201 wid = wallet['id'] g = w.get(wid) - expect(g).to have_http 200 - expect(g).to have_expected_headers - expect(w.delete(wid)).to have_http 204 + expect(g).to be_correct_and_respond 200 + expect(w.delete(wid)).to be_correct_and_respond 204 end end @@ -105,8 +94,7 @@ w = SHELLEY.wallets id = create_shelley_wallet u = w.update_metadata(id, { name: new_name }) - expect(u).to have_http 200 - expect(u).to have_expected_headers + expect(u).to be_correct_and_respond 200 expect(w.get(id)['name']).to eq new_name end @@ -115,15 +103,14 @@ id = create_shelley_wallet upd = w.update_passphrase(id, { old_passphrase: "Secure Passphrase", new_passphrase: "Securer Passphrase" }) - expect(upd).to have_http 204 + expect(upd).to be_correct_and_respond 204 end end it "Can see utxo" do id = create_shelley_wallet utxo = SHELLEY.wallets.utxo(id) - expect(utxo).to have_http 200 - expect(utxo).to have_expected_headers + expect(utxo).to be_correct_and_respond 200 end end @@ -137,21 +124,18 @@ id = create_shelley_wallet shelley_addr = CardanoWallet.new.shelley.addresses addresses = shelley_addr.list id - expect(addresses).to have_http 200 - expect(addresses).to have_expected_headers + expect(addresses).to be_correct_and_respond 200 expect(addresses.size).to eq 20 addresses.each_with_index do |a, i| expect(a['derivation_path']).to eq ['1852H', '1815H', '0H', '0', i.to_s] end addresses_unused = shelley_addr.list id, { state: "used" } - expect(addresses_unused).to have_http 200 - expect(addresses_unused).to have_expected_headers + expect(addresses_unused).to be_correct_and_respond 200 expect(addresses_unused.size).to eq 0 addresses_unused = shelley_addr.list id, { state: "unused" } - expect(addresses_unused).to have_http 200 - expect(addresses_unused).to have_expected_headers + expect(addresses_unused).to be_correct_and_respond 200 expect(addresses_unused.size).to eq 20 addresses_unused.each_with_index do |a, i| expect(a['derivation_path']).to eq ['1852H', '1815H', '0H', '0', i.to_s] @@ -174,8 +158,7 @@ ] rnd = SHELLEY.coin_selections.random wid, addr_amount - expect(rnd).to have_http 403 - expect(rnd).to have_expected_headers + expect(rnd).to be_correct_and_respond 403 expect(rnd.to_s).to include "not_enough_money" end end @@ -190,8 +173,7 @@ wid = create_shelley_wallet txs = SHELLEY.transactions g = txs.get(wid, TXID) - expect(g).to have_http 404 - expect(g).to have_expected_headers + expect(g).to be_correct_and_respond 404 expect(g.to_s).to include "no_such_transaction" end @@ -203,14 +185,9 @@ end: "2016-11-21T10:15:00Z", order: "ascending" }) l_bad = txs.list(id, { order: "bad_order" }) - expect(l).to have_http 200 - expect(l).to have_expected_headers - expect(l_ext).to have_http 200 - expect(l_ext).to have_expected_headers - expect(l_bad).to have_http 400 - expect(l_bad).to have_expected_headers - - + expect(l).to be_correct_and_respond 200 + expect(l_ext).to be_correct_and_respond 200 + expect(l_bad).to be_correct_and_respond 400 end it "I could create transaction - if I had money" do @@ -221,8 +198,7 @@ amt = [{ address => 1000000 }] tx_sent = txs.create(id, PASS, amt) - expect(tx_sent).to have_http 403 - expect(tx_sent).to have_expected_headers + expect(tx_sent).to be_correct_and_respond 403 expect(tx_sent.to_s).to include "not_enough_money" end @@ -234,8 +210,7 @@ amt = [{ address => 1000000 }] tx_sent = txs.create(id, PASS, amt, 'self') - expect(tx_sent).to have_http 403 - expect(tx_sent).to have_expected_headers + expect(tx_sent).to be_correct_and_respond 403 expect(tx_sent.to_s).to include "not_enough_money" end @@ -248,13 +223,11 @@ txs = SHELLEY.transactions fees = txs.payment_fees(id, amt) - expect(fees).to have_http 403 - expect(fees).to have_expected_headers + expect(fees).to be_correct_and_respond 403 expect(fees.to_s).to include "not_enough_money" fees = txs.payment_fees(id, amt, 'self') - expect(fees).to have_http 403 - expect(fees).to have_expected_headers + expect(fees).to be_correct_and_respond 403 expect(fees.to_s).to include "not_enough_money" metadata = { "0" => { "string" => "cardano" }, @@ -265,8 +238,7 @@ { "k" => { "int" => 14 }, "v" => { "int" => 42 } } ] } } fees = txs.payment_fees(id, amt, 'self', metadata) - expect(fees).to have_http 403 - expect(fees).to have_expected_headers + expect(fees).to be_correct_and_respond 403 expect(fees.to_s).to include "not_enough_money" end @@ -274,8 +246,7 @@ id = create_shelley_wallet txs = SHELLEY.transactions res = txs.forget(id, TXID) - expect(res).to have_http 404 - expect(res).to have_expected_headers + expect(res).to be_correct_and_respond 404 end end @@ -292,7 +263,7 @@ pools = SHELLEY.stake_pools s = settings.update({ :pool_metadata_source => "direct" }) - expect(s).to have_http 204 + expect(s).to be_correct_and_respond 204 eventually "Pools have metadata when 'pool_metadata_source' => 'direct'" do sps = pools.list({ stake: 1000 }) @@ -300,7 +271,7 @@ end s = settings.update({ :pool_metadata_source => "none" }) - expect(s).to have_http 204 + expect(s).to be_correct_and_respond 204 eventually "Pools have no metadata when 'pool_metadata_source' => 'none'" do sps = pools.list({ stake: 1000 }) @@ -308,7 +279,7 @@ end s = settings.update({ :pool_metadata_source => ENV['TESTS_E2E_SMASH'] }) - expect(s).to have_http 204 + expect(s).to be_correct_and_respond 204 eventually "Pools have metadata when 'pool_metadata_source' => '#{ENV['TESTS_E2E_SMASH']}'" do sps = pools.list({ stake: 1000 }) @@ -316,7 +287,7 @@ end s = settings.update({ :pool_metadata_source => "none" }) - expect(s).to have_http 204 + expect(s).to be_correct_and_respond 204 eventually "Pools have no metadata when 'pool_metadata_source' => 'none'" do sps = pools.list({ stake: 1000 }) @@ -334,10 +305,10 @@ pools = SHELLEY.stake_pools s = settings.update({ :pool_metadata_source => tc.keys.first }) - expect(s).to have_http 204 + expect(s).to be_correct_and_respond 204 t = pools.trigger_maintenance_actions({ maintenance_action: "gc_stake_pools" }) - expect(t).to have_http 204 + expect(t).to be_correct_and_respond 204 eventually "Maintenance action has status = #{tc.values.first}" do r = pools.view_maintenance_actions @@ -351,8 +322,7 @@ pools = SHELLEY.stake_pools quit = pools.quit(id, PASS) - expect(quit).to have_http 403 - expect(quit).to have_expected_headers + expect(quit).to be_correct_and_respond 403 expect(quit.to_s).to include "not_delegating_to" end @@ -366,8 +336,7 @@ it "I could calculate migration cost" do id = create_shelley_wallet cost = SHELLEY.migrations.cost(id) - expect(cost).to have_http 501 - expect(cost).to have_expected_headers + expect(cost).to be_correct_and_respond 501 expect(cost.to_s).to include "not_implemented" end @@ -376,8 +345,7 @@ target_id = create_shelley_wallet addrs = SHELLEY.addresses.list(target_id).map { |a| a['id'] } migr = SHELLEY.migrations.migrate(id, PASS, addrs) - expect(migr).to have_http 501 - expect(migr).to have_expected_headers + expect(migr).to be_correct_and_respond 501 expect(migr.to_s).to include "not_implemented" end end @@ -397,7 +365,7 @@ "Secure Passphrase", { "0" => { "string" => "cardano" } }) puts "#{wid}/#{role}/#{id}" - expect(res).to have_http 200 + expect(res).to respond_with 200 end end @@ -407,7 +375,7 @@ id = [*0..100000].sample res = SHELLEY.keys.get_public_key(wid, role, id) puts "#{wid}/#{role}/#{id}" - expect(res).to have_http 200 + expect(res).to be_correct_and_respond 200 end end @@ -415,7 +383,7 @@ wid = create_shelley_wallet ["0H", "1H", "2147483647H", "44H"].each do |index| res = SHELLEY.keys.create_acc_public_key(wid, index, PASS, extended = true) - expect(res).to have_http 202 + expect(res).to be_correct_and_respond 202 expect(res.to_s).to include "acc" end end @@ -424,7 +392,7 @@ wid = create_shelley_wallet ["0H", "1H", "2147483647H", "44H"].each do |index| res = SHELLEY.keys.create_acc_public_key(wid, index, PASS, extended = false) - expect(res).to have_http 202 + expect(res).to be_correct_and_respond 202 expect(res.to_s).to include "acc" end end