Merge pull request #966 from poanetwork/sa-block-getblockreward-api-200-errors

block#getblockreward API returns 200 for errors
853-css-custom-properties
Luke Imhoff 6 years ago committed by GitHub
commit 3a077592ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/block_controller.ex
  2. 24
      apps/block_scout_web/test/block_scout_web/controllers/api/rpc/block_controller_test.exs

@ -14,19 +14,13 @@ defmodule BlockScoutWeb.API.RPC.BlockController do
render(conn, :block_reward, block: block, reward: reward)
else
{:block_param, :error} ->
conn
|> put_status(400)
|> render(:error, error: "Query parameter 'blockno' is required")
render(conn, :error, error: "Query parameter 'blockno' is required")
{:error, :invalid} ->
conn
|> put_status(400)
|> render(:error, error: "Invalid block number")
render(conn, :error, error: "Invalid block number")
{:error, :not_found} ->
conn
|> put_status(404)
|> render(:error, error: "Block does not exist")
render(conn, :error, error: "Block does not exist")
end
end
end

@ -5,10 +5,10 @@ defmodule BlockScoutWeb.API.RPC.BlockControllerTest do
describe "getblockreward" do
test "with missing block number", %{conn: conn} do
assert response =
conn
|> get("/api", %{"module" => "block", "action" => "getblockreward"})
|> json_response(400)
response =
conn
|> get("/api", %{"module" => "block", "action" => "getblockreward"})
|> json_response(200)
assert response["message"] =~ "'blockno' is required"
assert response["status"] == "0"
@ -17,10 +17,10 @@ defmodule BlockScoutWeb.API.RPC.BlockControllerTest do
end
test "with an invalid block number", %{conn: conn} do
assert response =
conn
|> get("/api", %{"module" => "block", "action" => "getblockreward", "blockno" => "badnumber"})
|> json_response(400)
response =
conn
|> get("/api", %{"module" => "block", "action" => "getblockreward", "blockno" => "badnumber"})
|> json_response(200)
assert response["message"] =~ "Invalid block number"
assert response["status"] == "0"
@ -29,10 +29,10 @@ defmodule BlockScoutWeb.API.RPC.BlockControllerTest do
end
test "with a block that doesn't exist", %{conn: conn} do
assert response =
conn
|> get("/api", %{"module" => "block", "action" => "getblockreward", "blockno" => "42"})
|> json_response(404)
response =
conn
|> get("/api", %{"module" => "block", "action" => "getblockreward", "blockno" => "42"})
|> json_response(200)
assert response["message"] =~ "Block does not exist"
assert response["status"] == "0"

Loading…
Cancel
Save