Improves API test coverage

Why:

* For Etherscan compatibility, the existing API calls support GET and
POST requests. This commit adds test coverage to ensure we support both
GET and POST requests.
* Issue link: related to
https://github.com/poanetwork/poa-explorer/issues/138

This change addresses the need by:

* Adding GET/POST requests tests to `API.RPC.AddressControllerTest`
pull/508/head
Sebastian Abondano 6 years ago
parent 8525f3d5fd
commit 8551b64120
  1. 78
      apps/explorer_web/test/explorer_web/controllers/api/rpc/address_controller_test.exs

@ -117,6 +117,28 @@ defmodule ExplorerWeb.API.RPC.AddressControllerTest do
assert response["status"] == "1"
assert response["message"] == "OK"
end
test "supports GET and POST requests", %{conn: conn} do
address = insert(:address, fetched_balance: 100)
params = %{
"module" => "account",
"action" => "balance",
"address" => "#{address.hash}"
}
assert get_response =
conn
|> get("/api", params)
|> json_response(200)
assert post_response =
conn
|> post("/api", params)
|> json_response(200)
assert get_response == post_response
end
end
describe "balancemulti" do
@ -284,6 +306,36 @@ defmodule ExplorerWeb.API.RPC.AddressControllerTest do
assert response["status"] == "1"
assert response["message"] == "OK"
end
test "supports GET and POST requests", %{conn: conn} do
addresses =
for _ <- 1..4 do
insert(:address, fetched_balance: Enum.random(1..1_000))
end
address_param =
addresses
|> Enum.map(&"#{&1.hash}")
|> Enum.join(",")
params = %{
"module" => "account",
"action" => "balancemulti",
"address" => address_param
}
assert get_response =
conn
|> get("/api", params)
|> json_response(200)
assert post_response =
conn
|> post("/api", params)
|> json_response(200)
assert get_response == post_response
end
end
describe "txlist" do
@ -956,5 +1008,31 @@ defmodule ExplorerWeb.API.RPC.AddressControllerTest do
assert response["status"] == "1"
assert response["message"] == "OK"
end
test "supports GET and POST requests", %{conn: conn} do
address = insert(:address)
:transaction
|> insert(from_address: address)
|> with_block()
params = %{
"module" => "account",
"action" => "txlist",
"address" => "#{address.hash}"
}
assert get_response =
conn
|> get("/api", params)
|> json_response(200)
assert post_response =
conn
|> post("/api", params)
|> json_response(200)
assert get_response == post_response
end
end
end

Loading…
Cancel
Save