From 096f11c2e011806e754ce565378628afc7e13cff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Bo=CC=88ning?= Date: Thu, 23 Feb 2023 13:15:09 +0100 Subject: [PATCH 1/4] Fix health_endpoints specs - do not send project_id when requesting /health - /health endpoint is intended to be accessible without secret - switching from decommissioned testnet to preview testnet --- .../endpoints/cardano/health_endpoints.rb | 2 +- lib/blockfrostruby/request.rb | 2 +- spec/endpoints/health_endpoints_spec.rb | 18 +++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/blockfrostruby/endpoints/cardano/health_endpoints.rb b/lib/blockfrostruby/endpoints/cardano/health_endpoints.rb index fb28dc5..2160fa5 100644 --- a/lib/blockfrostruby/endpoints/cardano/health_endpoints.rb +++ b/lib/blockfrostruby/endpoints/cardano/health_endpoints.rb @@ -16,7 +16,7 @@ def get_root # # @return [Hash] formatted result with status and body keys. def get_health - Request.get_response("#{@url}/health", @project_id) + Request.get_response("#{@url}/health") end # Calls get request on (@url)/health/clock. diff --git a/lib/blockfrostruby/request.rb b/lib/blockfrostruby/request.rb index 3e21f42..740b0fe 100644 --- a/lib/blockfrostruby/request.rb +++ b/lib/blockfrostruby/request.rb @@ -17,7 +17,7 @@ class << self # @param project_id [String] the project_id to pass to url in headers. # @param params [Hash] params to add to request, allowed :order, :page, :count, :from, :to. # @return [Hash] formatted result with status and body keys. - def get_response(url, project_id, params = {}) + def get_response(url, project_id = nil, params = {}) params[:from_page] ? get_pages_multi(url, project_id, params) : get_response_from_url(url, project_id, params) end diff --git a/spec/endpoints/health_endpoints_spec.rb b/spec/endpoints/health_endpoints_spec.rb index a985b35..dc72570 100644 --- a/spec/endpoints/health_endpoints_spec.rb +++ b/spec/endpoints/health_endpoints_spec.rb @@ -7,8 +7,8 @@ RSpec.describe HealthEndpoints do let(:blockfrost_mainnet) { Blockfrostruby::CardanoMainNet.new(ENV['BF_MAINNET_PROJECT_ID']) } let(:blockfrost_mainnet_invalid) { Blockfrostruby::CardanoMainNet.new('invalid project_id') } - let(:blockfrost_testnet) { Blockfrostruby::CardanoTestNet.new(ENV['BF_TESTNET_PROJECT_ID']) } - let(:blockfrost_testnet_invalid) { Blockfrostruby::CardanoTestNet.new('invalid project_id') } + let(:blockfrost_testnet) { Blockfrostruby::CardanoPreview.new(ENV['BF_TESTNET_PROJECT_ID']) } + let(:blockfrost_testnet_invalid) { Blockfrostruby::CardanoPreview.new('invalid project_id') } context 'CardanoMainNet object' do context 'with valid project_id' do @@ -39,16 +39,16 @@ context 'with invalid project_id' do context 'when calls get_health method' do - it 'returns 403 status and body includes error' do + it 'return status 200 and is_healthy => true' do response = blockfrost_mainnet_invalid.get_health - expect(response[:status]).to eq(403) - expect(response[:body]).to include(:error) + expect(response[:status]).to eq(200) + expect(response[:body]).to eq({ is_healthy: true }) end end end end - context 'CardanoTestNet object' do + context 'CardanoPreview object' do context 'with valid project_id' do context 'when calls get_health method' do it 'return status 200 and is_healthy => true' do @@ -77,10 +77,10 @@ context 'with invalid project_id' do context 'when calls get_health method' do - it 'returns 403 status and body includes error' do + it 'return status 200 and is_healthy => true' do response = blockfrost_testnet_invalid.get_health - expect(response[:status]).to eq(403) - expect(response[:body]).to include(:error) + expect(response[:status]).to eq(200) + expect(response[:body]).to eq({ is_healthy: true }) end end end From 48e48a4ddebade4f39eac45c0907d7efa128ffae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Bo=CC=88ning?= Date: Thu, 23 Feb 2023 13:55:08 +0100 Subject: [PATCH 2/4] fix asset endpoint tests reflecting current API behaviour, namely response status 400 for invalid asset parameter. --- spec/endpoints/assets_endpoints_spec.rb | 36 ++++++++++++------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/spec/endpoints/assets_endpoints_spec.rb b/spec/endpoints/assets_endpoints_spec.rb index 7889f71..54b693d 100644 --- a/spec/endpoints/assets_endpoints_spec.rb +++ b/spec/endpoints/assets_endpoints_spec.rb @@ -45,9 +45,9 @@ end context 'with invalid asset' do - it 'returns status 404, response body includes error' do + it 'returns status 400, response body includes error' do response = blockfrost_mainnet.get_specific_asset(invalid_asset) - expect(response[:status]).to eq(404) + expect(response[:status]).to eq(400) expect(response[:body]).to include(:error) end end @@ -72,16 +72,16 @@ context 'with invalid asset' do context 'without params' do - it 'returns status 404, response body includes error' do + it 'returns status 400, response body includes error' do response = blockfrost_mainnet.get_asset_history(invalid_asset) - expect(response[:status]).to eq(404) + expect(response[:status]).to eq(400) expect(response[:body]).to include(:error) end end context 'with params' do - it 'returns status 404, response body includes error' do + it 'returns status 400, response body includes error' do response = blockfrost_mainnet.get_asset_history(invalid_asset, { count: 7, page: 3 }) - expect(response[:status]).to eq(404) + expect(response[:status]).to eq(400) expect(response[:body]).to include(:error) end end @@ -107,16 +107,16 @@ context 'with invalid asset' do context 'without params' do - it 'returns status 404, response body includes error' do + it 'returns status 400, response body includes error' do response = blockfrost_mainnet.get_asset_transactions(invalid_asset) - expect(response[:status]).to eq(404) + expect(response[:status]).to eq(400) expect(response[:body]).to include(:error) end end context 'with params' do - it 'returns status 404, response body includes error' do + it 'returns status 400, response body includes error' do response = blockfrost_mainnet.get_asset_transactions(invalid_asset, { count: 7, page: 3 }) - expect(response[:status]).to eq(404) + expect(response[:status]).to eq(400) expect(response[:body]).to include(:error) end end @@ -142,16 +142,16 @@ context 'with invalid asset' do context 'without params' do - it 'returns status 404, response body includes error' do + it 'returns status 400, response body includes error' do response = blockfrost_mainnet.get_asset_addresses(invalid_asset) - expect(response[:status]).to eq(404) + expect(response[:status]).to eq(400) expect(response[:body]).to include(:error) end end context 'with params' do - it 'returns status 404, response body includes error' do + it 'returns status 400, response body includes error' do response = blockfrost_mainnet.get_asset_addresses(invalid_asset, { count: 7, page: 3 }) - expect(response[:status]).to eq(404) + expect(response[:status]).to eq(400) expect(response[:body]).to include(:error) end end @@ -177,16 +177,16 @@ context 'with invalid policy_id' do context 'without params' do - it 'returns status 404, response body includes error' do + it 'returns status 400, response body includes error' do response = blockfrost_mainnet.get_assets_of_policy(invalid_policy_id) - expect(response[:status]).to eq(404) + expect(response[:status]).to eq(400) expect(response[:body]).to include(:error) end end context 'with params' do - it 'returns status 404, response body includes error' do + it 'returns status 400, response body includes error' do response = blockfrost_mainnet.get_assets_of_policy(invalid_policy_id, { count: 7, page: 3 }) - expect(response[:status]).to eq(404) + expect(response[:status]).to eq(400) expect(response[:body]).to include(:error) end end From 7f0ea0045cd485cfbfd21f766880f0ce3c24aff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Bo=CC=88ning?= Date: Thu, 23 Feb 2023 14:02:05 +0100 Subject: [PATCH 3/4] fix block endpoint tests and activate skipped examples - reflecting current API behaviour (response code 400 for malformatted params) --- spec/endpoints/blocks_endpoints_spec.rb | 26 ++++++++++++------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/spec/endpoints/blocks_endpoints_spec.rb b/spec/endpoints/blocks_endpoints_spec.rb index 790f40b..45c7fe6 100644 --- a/spec/endpoints/blocks_endpoints_spec.rb +++ b/spec/endpoints/blocks_endpoints_spec.rb @@ -49,9 +49,9 @@ end end context 'with invalid hash_or_number' do - it 'returns status 404, response body includes error' do + it 'returns status 400, response body includes error' do response = blockfrost_mainnet.get_block(invalid_hash_or_number) - expect(response[:status]).to eq(404) + expect(response[:status]).to eq(400) expect(response[:body]).to include(:error) end end @@ -65,10 +65,9 @@ end end context 'with invalid slot number' do - it 'returns status 404, response body includes error' do - skip 'Returns 500 instead of 404' + it 'returns status 400, response body includes error' do response = blockfrost_mainnet.get_block_in_slot(invalid_slot_number) - expect(response[:status]).to eq(404) + expect(response[:status]).to eq(400) expect(response[:body]).to include(:error) end end @@ -82,10 +81,9 @@ end end context 'with invalid slot and epoch number' do - it 'returns status 404, response body includes error' do - skip 'Returns 500 instead of 404' + it 'returns status 400, response body includes error' do response = blockfrost_mainnet.get_block_in_slot_in_epoch(invalid_slot_number, invalid_epoch_number) - expect(response[:status]).to eq(404) + expect(response[:status]).to eq(400) expect(response[:body]).to include(:error) end end @@ -109,9 +107,9 @@ end end context 'with invalid hash_or_number' do - it 'returns status 404, response body includes error' do + it 'returns status 400, response body includes error' do response = blockfrost_mainnet.get_list_of_next_blocks(invalid_hash_or_number) - expect(response[:status]).to eq(404) + expect(response[:status]).to eq(400) expect(response[:body]).to include(:error) end end @@ -135,9 +133,9 @@ end end context 'with invalid hash_or_number' do - it 'returns status 404, response body includes error' do + it 'returns status 400, response body includes error' do response = blockfrost_mainnet.get_list_of_previous_blocks(invalid_hash_or_number) - expect(response[:status]).to eq(404) + expect(response[:status]).to eq(400) expect(response[:body]).to include(:error) end end @@ -161,9 +159,9 @@ end end context 'with invalid hash_or_number' do - it 'returns status 404, response body includes error' do + it 'returns status 400, response body includes error' do response = blockfrost_mainnet.get_block_transactions(invalid_hash_or_number) - expect(response[:status]).to eq(404) + expect(response[:status]).to eq(400) expect(response[:body]).to include(:error) end end From 38c25897a1e016b428510d6be3252cac2f79b0af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Bo=CC=88ning?= Date: Fri, 5 Jan 2024 22:29:20 +0100 Subject: [PATCH 4/4] fix ledger, metrics and nutlink specs --- .env.example | 2 +- spec/endpoints/ledger_endpoints_spec.rb | 6 +++--- spec/endpoints/metrics_endpoints_spec.rb | 6 +++--- spec/endpoints/network_endpoints_spec.rb | 4 ++-- spec/endpoints/nutlink_endpoints_spec.rb | 16 ++++------------ 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/.env.example b/.env.example index cb09d8b..af23d78 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,3 @@ BF_IPFS_PROJECT_ID= BF_MAINNET_PROJECT_ID= -BF_TESTNET_PROJECT_ID= \ No newline at end of file +BF_TESTNET_PROJECT_ID= diff --git a/spec/endpoints/ledger_endpoints_spec.rb b/spec/endpoints/ledger_endpoints_spec.rb index a4de8cb..03cfe68 100644 --- a/spec/endpoints/ledger_endpoints_spec.rb +++ b/spec/endpoints/ledger_endpoints_spec.rb @@ -7,8 +7,8 @@ RSpec.describe LedgerEndpoints do let(:blockfrost_mainnet) { Blockfrostruby::CardanoMainNet.new(ENV['BF_MAINNET_PROJECT_ID']) } let(:blockfrost_mainnet_invalid) { Blockfrostruby::CardanoMainNet.new('invalid project_id') } - let(:blockfrost_testnet) { Blockfrostruby::CardanoTestNet.new(ENV['BF_TESTNET_PROJECT_ID']) } - let(:blockfrost_testnet_invalid) { Blockfrostruby::CardanoTestNet.new('invalid project_id') } + let(:blockfrost_testnet) { Blockfrostruby::CardanoPreview.new(ENV['BF_TESTNET_PROJECT_ID']) } + let(:blockfrost_testnet_invalid) { Blockfrostruby::CardanoPreview.new('invalid project_id') } context 'CardanoMainNet object' do context 'with valid project_id' do @@ -32,7 +32,7 @@ end end - context 'CardanoTestNet object' do + context 'CardanoPreview object' do context 'with valid project_id' do context 'when calls get_genesis method' do it 'return status 200 and response body includes active_slots_coefficient' do diff --git a/spec/endpoints/metrics_endpoints_spec.rb b/spec/endpoints/metrics_endpoints_spec.rb index 08f99e9..b48205c 100644 --- a/spec/endpoints/metrics_endpoints_spec.rb +++ b/spec/endpoints/metrics_endpoints_spec.rb @@ -7,8 +7,8 @@ RSpec.describe MetricsEndpoints do let(:blockfrost_mainnet) { Blockfrostruby::CardanoMainNet.new(ENV['BF_MAINNET_PROJECT_ID']) } let(:blockfrost_mainnet_invalid) { Blockfrostruby::CardanoMainNet.new('invalid project_id') } - let(:blockfrost_testnet) { Blockfrostruby::CardanoTestNet.new(ENV['BF_TESTNET_PROJECT_ID']) } - let(:blockfrost_testnet_invalid) { Blockfrostruby::CardanoTestNet.new('invalid project_id') } + let(:blockfrost_testnet) { Blockfrostruby::CardanoPreview.new(ENV['BF_TESTNET_PROJECT_ID']) } + let(:blockfrost_testnet_invalid) { Blockfrostruby::CardanoPreview.new('invalid project_id') } context 'CardanoMainNet object' do context 'with valid project_id' do @@ -38,7 +38,7 @@ end end - context 'CardanoTestNet object' do + context 'CardanoPreview object' do context 'with valid project_id' do context 'when calls get_metrics method' do it 'return status 200' do diff --git a/spec/endpoints/network_endpoints_spec.rb b/spec/endpoints/network_endpoints_spec.rb index 98b36b3..29f04a3 100644 --- a/spec/endpoints/network_endpoints_spec.rb +++ b/spec/endpoints/network_endpoints_spec.rb @@ -7,8 +7,8 @@ RSpec.describe NetworkEndpoints do let(:blockfrost_mainnet) { Blockfrostruby::CardanoMainNet.new(ENV['BF_MAINNET_PROJECT_ID']) } let(:blockfrost_mainnet_invalid) { Blockfrostruby::CardanoMainNet.new('invalid project_id') } - let(:blockfrost_testnet) { Blockfrostruby::CardanoTestNet.new(ENV['BF_TESTNET_PROJECT_ID']) } - let(:blockfrost_testnet_invalid) { Blockfrostruby::CardanoTestNet.new('invalid project_id') } + let(:blockfrost_testnet) { Blockfrostruby::CardanoPreview.new(ENV['BF_TESTNET_PROJECT_ID']) } + let(:blockfrost_testnet_invalid) { Blockfrostruby::CardanoPreview.new('invalid project_id') } context 'CardanoMainNet object' do context 'with valid project_id' do diff --git a/spec/endpoints/nutlink_endpoints_spec.rb b/spec/endpoints/nutlink_endpoints_spec.rb index 8d48fdb..b409f45 100644 --- a/spec/endpoints/nutlink_endpoints_spec.rb +++ b/spec/endpoints/nutlink_endpoints_spec.rb @@ -6,19 +6,17 @@ RSpec.describe NutlinkEndpoints do let(:blockfrost_mainnet) { Blockfrostruby::CardanoMainNet.new(ENV['BF_MAINNET_PROJECT_ID']) } - let(:blockfrost_mainnet_invalid) { Blockfrostruby::CardanoMainNet.new('invalid project_id') } - let(:valid_address) { 'addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz' } - let(:invalid_address) { 'invalid_number' } - let(:valid_ticker) { 'valid_ticker' } - let(:invalid_ticker) { 'invalid_number' } + let(:valid_address) { 'addr1q85yx2w7ragn5sx6umgmtjpc3865s9sg59sz4rrh6f90kgwfwlzu3w8ttacqg89mkdgwshwnplj5c5n9f8dhp0h55q2q7qm63t' } + let(:invalid_address) { 'invalid' } + let(:valid_ticker) { 'ADABTC' } + let(:invalid_ticker) { 'invalid' } context 'CardanoMainNet object' do context 'with valid project_id' do context 'when calls get_address_metadata_list method' do context 'with valid address' do it 'returns status 200' do - skip 'Return 404 now' response = blockfrost_mainnet.get_address_metadata_list(valid_address) expect(response[:status]).to eq(200) end @@ -36,14 +34,12 @@ context 'with valid address' do context 'without params' do it 'returns status 200' do - skip 'Return 404 now' response = blockfrost_mainnet.get_address_metadata_tickers_list(valid_address) expect(response[:status]).to eq(200) end end context 'with params { count: 5 }' do it 'returns status 200' do - skip 'Return 404 now' response = blockfrost_mainnet.get_address_metadata_tickers_list(valid_address, { count: 5 }) expect(response[:status]).to eq(200) end @@ -62,14 +58,12 @@ context 'with valid address and ticker' do context 'without params' do it 'returns status 200' do - skip 'Return 404 now' response = blockfrost_mainnet.get_ticker_records_by_address(valid_address, valid_ticker) expect(response[:status]).to eq(200) end end context 'with params { count: 5 }' do it 'returns status 200' do - skip 'Return 404 now' response = blockfrost_mainnet.get_ticker_records_by_address(valid_address, valid_ticker, { count: 5 }) expect(response[:status]).to eq(200) end @@ -88,14 +82,12 @@ context 'with valid address and ticker' do context 'without params' do it 'returns status 200' do - skip 'Return 404 now' response = blockfrost_mainnet.get_ticker_records(valid_ticker) expect(response[:status]).to eq(200) end end context 'with params { count: 5 }' do it 'returns status 200' do - skip 'Return 404 now' response = blockfrost_mainnet.get_ticker_records(valid_ticker, { count: 5 }) expect(response[:status]).to eq(200) end