diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs index b8a3a85845..7e88d4717f 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs @@ -47,6 +47,8 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do |> get("/api", params) |> json_response(200) + schema = listaccounts_schema() + assert :ok = ExJsonSchema.Validator.validate(schema, response) assert response["message"] == "OK" assert response["status"] == "1" assert response["result"] == [] @@ -63,6 +65,8 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do |> get("/api", params) |> json_response(200) + schema = listaccounts_schema() + assert :ok = ExJsonSchema.Validator.validate(schema, response) assert response["message"] == "OK" assert response["status"] == "1" @@ -120,6 +124,8 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do |> get("/api", params) |> json_response(200) + schema = listaccounts_schema() + assert :ok = ExJsonSchema.Validator.validate(schema, response) assert response["message"] == "OK" assert response["status"] == "1" @@ -158,6 +164,8 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do |> get("/api", params) |> json_response(200) + schema = balance_schema() + assert :ok = ExJsonSchema.Validator.validate(schema, response) assert response["message"] =~ "'address' is required" assert response["status"] == "0" assert Map.has_key?(response, "result") @@ -176,6 +184,8 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do |> get("/api", params) |> json_response(200) + schema = balance_schema() + assert :ok = ExJsonSchema.Validator.validate(schema, response) assert response["message"] =~ "Invalid address hash" assert response["status"] == "0" assert Map.has_key?(response, "result") @@ -194,6 +204,8 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do |> get("/api", params) |> json_response(200) + schema = balance_schema() + assert :ok = ExJsonSchema.Validator.validate(schema, response) assert response["result"] == "0" assert response["status"] == "1" assert response["message"] == "OK" @@ -213,6 +225,8 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do |> get("/api", params) |> json_response(200) + schema = balance_schema() + assert :ok = ExJsonSchema.Validator.validate(schema, response) assert response["result"] == "#{address.fetched_coin_balance.value}" assert response["status"] == "1" assert response["message"] == "OK" @@ -245,6 +259,8 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do |> get("/api", params) |> json_response(200) + schema = balance_schema() + assert :ok = ExJsonSchema.Validator.validate(schema, response) assert response["result"] == expected_result assert response["status"] == "1" assert response["message"] == "OK" @@ -289,6 +305,8 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do |> get("/api", params) |> json_response(200) + schema = balance_schema() + assert :ok = ExJsonSchema.Validator.validate(schema, response) assert response["message"] =~ "Invalid address hash" assert response["status"] == "0" assert Map.has_key?(response, "result") @@ -315,6 +333,9 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do |> get("/api", params) |> json_response(200) + schema = balance_schema() + assert :ok = ExJsonSchema.Validator.validate(schema, response) + assert :ok = ExJsonSchema.Validator.validate(schema, response) assert response["result"] == expected_result assert response["status"] == "1" assert response["message"] == "OK" @@ -350,6 +371,9 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == expected_result assert response["status"] == "1" assert response["message"] == "OK" + + schema = balance_schema() + assert :ok = ExJsonSchema.Validator.validate(schema, response) end test "with an address that exists and one that doesn't", %{conn: conn} do @@ -375,6 +399,9 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == expected_result assert response["status"] == "1" assert response["message"] == "OK" + + schema = balance_schema() + assert :ok = ExJsonSchema.Validator.validate(schema, response) end test "up to a maximum of 20 addresses in a single request", %{conn: conn} do @@ -399,6 +426,9 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert length(response["result"]) == 20 assert response["status"] == "1" assert response["message"] == "OK" + + schema = balance_schema() + assert :ok = ExJsonSchema.Validator.validate(schema, response) end test "with a single address", %{conn: conn} do @@ -422,6 +452,9 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == expected_result assert response["status"] == "1" assert response["message"] == "OK" + + schema = balance_schema() + assert :ok = ExJsonSchema.Validator.validate(schema, response) end test "supports GET and POST requests", %{conn: conn} do @@ -471,6 +504,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "0" assert Map.has_key?(response, "result") refute response["result"] + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "with an invalid address hash", %{conn: conn} do @@ -489,6 +523,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "0" assert Map.has_key?(response, "result") refute response["result"] + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "with an address that doesn't exist", %{conn: conn} do @@ -506,6 +541,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == [] assert response["status"] == "0" assert response["message"] == "No transactions found" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "with a valid address", %{conn: conn} do @@ -556,6 +592,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == expected_result assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "includes correct confirmations value", %{conn: conn} do @@ -580,12 +617,14 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do expected_confirmations = block_height - transaction.block_number assert %{"result" => [returned_transaction]} = + response = conn |> get("/api", params) |> json_response(200) assert returned_transaction["confirmations"] == "#{expected_confirmations}" assert returned_transaction["hash"] == "#{hash}" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "returns '1' for 'isError' with failed transaction", %{conn: conn} do @@ -605,6 +644,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do } assert %{"result" => [returned_transaction]} = + response = conn |> get("/api", params) |> json_response(200) @@ -612,6 +652,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert returned_transaction["isError"] == "1" assert returned_transaction["txreceipt_status"] == "0" assert returned_transaction["hash"] == "#{hash}" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "with address with multiple transactions", %{conn: conn} do @@ -648,6 +689,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "orders transactions by block, in ascending order", %{conn: conn} do @@ -688,6 +730,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert block_numbers_order == Enum.sort(block_numbers_order, &(&1 <= &2)) assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "orders transactions by block, in descending order", %{conn: conn} do @@ -728,6 +771,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert block_numbers_order == Enum.sort(block_numbers_order, &(&1 >= &2)) assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "ignores invalid sort option, defaults to ascending", %{conn: conn} do @@ -768,6 +812,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert block_numbers_order == Enum.sort(block_numbers_order, &(&1 <= &2)) assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "with valid pagination params", %{conn: conn} do @@ -821,6 +866,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "ignores pagination params when invalid", %{conn: conn} do @@ -862,6 +908,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert length(response["result"]) == 6 assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "ignores offset param if offset is less than 1", %{conn: conn} do @@ -889,6 +936,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert length(response["result"]) == 6 assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "ignores offset param if offset is over 10,000", %{conn: conn} do @@ -916,6 +964,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert length(response["result"]) == 6 assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "with page number with no results", %{conn: conn} do @@ -957,6 +1006,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == [] assert response["status"] == "0" assert response["message"] == "No transactions found" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "with startblock and endblock params", %{conn: conn} do @@ -995,6 +1045,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "with startblock but without endblock", %{conn: conn} do @@ -1032,6 +1083,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "with endblock but without startblock", %{conn: conn} do @@ -1069,6 +1121,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "ignores invalid startblock and endblock", %{conn: conn} do @@ -1097,6 +1150,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert length(response["result"]) == 8 assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "with starttimestamp and endtimestamp params", %{conn: conn} do @@ -1144,6 +1198,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "with starttimestamp but without endtimestamp", %{conn: conn} do @@ -1191,6 +1246,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "with endtimestamp but without starttimestamp", %{conn: conn} do @@ -1236,6 +1292,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "with filterby=to option", %{conn: conn} do @@ -1263,6 +1320,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert length(response["result"]) == 1 assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "with filterby=from option", %{conn: conn} do @@ -1293,6 +1351,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert length(response["result"]) == 2 assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response) end test "supports GET and POST requests", %{conn: conn} do @@ -1338,6 +1397,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "0" assert Map.has_key?(response, "result") refute response["result"] + assert :ok = ExJsonSchema.Validator.validate(txlistinternal_schema(), response) end end @@ -1358,6 +1418,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "0" assert Map.has_key?(response, "result") refute response["result"] + assert :ok = ExJsonSchema.Validator.validate(txlistinternal_schema(), response) end test "with a txhash that doesn't exist", %{conn: conn} do @@ -1375,6 +1436,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == [] assert response["status"] == "0" assert response["message"] == "No internal transactions found" + assert :ok = ExJsonSchema.Validator.validate(txlistinternal_schema(), response) end test "response includes all the expected fields", %{conn: conn} do @@ -1427,6 +1489,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == expected_result assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlistinternal_schema(), response) end test "isError is true if internal transaction has an error", %{conn: conn} do @@ -1459,6 +1522,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert found_internal_transaction["isError"] == "1" assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlistinternal_schema(), response) end test "with transaction with multiple internal transactions", %{conn: conn} do @@ -1486,6 +1550,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert length(found_internal_transactions) == 3 assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlistinternal_schema(), response) end end @@ -1506,6 +1571,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "0" assert Map.has_key?(response, "result") refute response["result"] + assert :ok = ExJsonSchema.Validator.validate(txlistinternal_schema(), response) end test "with a address that doesn't exist", %{conn: conn} do @@ -1523,6 +1589,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == [] assert response["status"] == "0" assert response["message"] == "No internal transactions found" + assert :ok = ExJsonSchema.Validator.validate(txlistinternal_schema(), response) end test "response includes all the expected fields", %{conn: conn} do @@ -1575,6 +1642,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == expected_result assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlistinternal_schema(), response) end test "isError is true if internal transaction has an error", %{conn: conn} do @@ -1610,6 +1678,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert found_internal_transaction["isError"] == "1" assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlistinternal_schema(), response) end test "with transaction with multiple internal transactions", %{conn: conn} do @@ -1645,6 +1714,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert length(found_internal_transactions) == 3 assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(txlistinternal_schema(), response) end end @@ -1664,6 +1734,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "0" assert Map.has_key?(response, "result") refute response["result"] + assert :ok = ExJsonSchema.Validator.validate(tokentx_schema(), response) end test "with an invalid address hash", %{conn: conn} do @@ -1682,6 +1753,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "0" assert Map.has_key?(response, "result") refute response["result"] + assert :ok = ExJsonSchema.Validator.validate(tokentx_schema(), response) end test "with an address that doesn't exist", %{conn: conn} do @@ -1699,6 +1771,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == [] assert response["status"] == "0" assert response["message"] == "No token transfers found" + assert :ok = ExJsonSchema.Validator.validate(tokentx_schema(), response) end test "has correct value for ERC-721", %{conn: conn} do @@ -1734,6 +1807,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert result["value"] == to_string(token_transfer.token_id) assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(tokentx_schema(), response) end test "returns all the required fields", %{conn: conn} do @@ -1785,6 +1859,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == expected_result assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(tokentx_schema(), response) end test "with an invalid contract address", %{conn: conn} do @@ -1804,6 +1879,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "0" assert Map.has_key?(response, "result") refute response["result"] + assert :ok = ExJsonSchema.Validator.validate(tokentx_schema(), response) end test "filters results by contract address", %{conn: conn} do @@ -1837,6 +1913,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert result["contractAddress"] == to_string(contract_address.hash) assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(tokentx_schema(), response) end end @@ -1856,6 +1933,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "0" assert Map.has_key?(response, "result") refute response["result"] + assert :ok = ExJsonSchema.Validator.validate(tokenbalance_schema(), response) end test "with contractaddress but without address", %{conn: conn} do @@ -1874,6 +1952,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "0" assert Map.has_key?(response, "result") refute response["result"] + assert :ok = ExJsonSchema.Validator.validate(tokenbalance_schema(), response) end test "with address but without contractaddress", %{conn: conn} do @@ -1892,6 +1971,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "0" assert Map.has_key?(response, "result") refute response["result"] + assert :ok = ExJsonSchema.Validator.validate(tokenbalance_schema(), response) end test "with an invalid contractaddress hash", %{conn: conn} do @@ -1911,6 +1991,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "0" assert Map.has_key?(response, "result") refute response["result"] + assert :ok = ExJsonSchema.Validator.validate(tokenbalance_schema(), response) end test "with an invalid address hash", %{conn: conn} do @@ -1930,6 +2011,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "0" assert Map.has_key?(response, "result") refute response["result"] + assert :ok = ExJsonSchema.Validator.validate(tokenbalance_schema(), response) end test "with a contractaddress and address that doesn't exist", %{conn: conn} do @@ -1948,6 +2030,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == "0" assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(tokenbalance_schema(), response) end test "with contractaddress and address without row in token_balances table", %{conn: conn} do @@ -1969,6 +2052,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == "0" assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(tokenbalance_schema(), response) end test "with contractaddress and address with existing balance in token_balances table", %{conn: conn} do @@ -1989,6 +2073,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == to_string(token_balance.value) assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(tokenbalance_schema(), response) end end @@ -2008,6 +2093,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "0" assert Map.has_key?(response, "result") refute response["result"] + assert :ok = ExJsonSchema.Validator.validate(tokenlist_schema(), response) end test "with an invalid address hash", %{conn: conn} do @@ -2026,6 +2112,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "0" assert Map.has_key?(response, "result") refute response["result"] + assert :ok = ExJsonSchema.Validator.validate(tokenlist_schema(), response) end test "with an address that doesn't exist", %{conn: conn} do @@ -2043,6 +2130,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == [] assert response["status"] == "0" assert response["message"] == "No tokens found" + assert :ok = ExJsonSchema.Validator.validate(tokenlist_schema(), response) end test "with an address without row in token_balances table", %{conn: conn} do @@ -2062,6 +2150,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == [] assert response["status"] == "0" assert response["message"] == "No tokens found" + assert :ok = ExJsonSchema.Validator.validate(tokenlist_schema(), response) end test "with address with existing balance in token_balances table", %{conn: conn} do @@ -2092,6 +2181,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == expected_result assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(tokenlist_schema(), response) end test "with address with multiple tokens", %{conn: conn} do @@ -2115,6 +2205,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert length(response["result"]) == 2 assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(tokenlist_schema(), response) end end @@ -2134,6 +2225,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "0" assert Map.has_key?(response, "result") refute response["result"] + assert :ok = ExJsonSchema.Validator.validate(block_schema(), response) end test "with an invalid address hash", %{conn: conn} do @@ -2152,6 +2244,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["status"] == "0" assert Map.has_key?(response, "result") refute response["result"] + assert :ok = ExJsonSchema.Validator.validate(block_schema(), response) end test "with an address that doesn't exist", %{conn: conn} do @@ -2169,6 +2262,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == [] assert response["status"] == "0" assert response["message"] == "No blocks found" + assert :ok = ExJsonSchema.Validator.validate(block_schema(), response) end test "returns all the required fields", %{conn: conn} do @@ -2208,6 +2302,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == expected_result assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(block_schema(), response) end test "with a block with one transaction", %{conn: conn} do @@ -2247,6 +2342,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == expected_result assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(block_schema(), response) end test "with pagination options", %{conn: conn} do @@ -2297,6 +2393,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert response["result"] == expected_result assert response["status"] == "1" assert response["message"] == "OK" + assert :ok = ExJsonSchema.Validator.validate(block_schema(), response) end end @@ -2439,4 +2536,162 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do assert result == {:required_params, {:ok, params}} end end + + defp listaccounts_schema do + resolve_schema(%{ + "type" => "array", + "items" => %{ + "type" => "object", + "properties" => %{ + "address" => %{"type" => "string"}, + "balance" => %{"type" => "string"}, + "stale" => %{"type" => "boolean"} + } + } + }) + end + + defp balance_schema do + resolve_schema(%{ + "type" => ["string", "null", "array"], + "items" => %{ + "type" => "object", + "properties" => %{ + "account" => %{"type" => "string"}, + "balance" => %{"type" => "string"}, + "stale" => %{"type" => "boolean"} + } + } + }) + end + + defp txlist_schema do + resolve_schema(%{ + "type" => ["null", "array"], + "items" => %{ + "type" => "object", + "properties" => %{ + "blockNumber" => %{"type" => "string"}, + "timeStamp" => %{"type" => "string"}, + "hash" => %{"type" => "string"}, + "nonce" => %{"type" => "string"}, + "blockHash" => %{"type" => "string"}, + "transactionIndex" => %{"type" => "string"}, + "from" => %{"type" => "string"}, + "to" => %{"type" => "string"}, + "value" => %{"type" => "string"}, + "gas" => %{"type" => "string"}, + "gasPrice" => %{"type" => "string"}, + "isError" => %{"type" => "string"}, + "txreceipt_status" => %{"type" => "string"}, + "input" => %{"type" => "string"}, + "contractAddress" => %{"type" => "string"}, + "cumulativeGasUsed" => %{"type" => "string"}, + "gasUsed" => %{"type" => "string"}, + "confirmations" => %{"type" => "string"} + } + } + }) + end + + defp txlistinternal_schema do + resolve_schema(%{ + "type" => ["array", "null"], + "items" => %{ + "type" => "object", + "properties" => %{ + "blockNumber" => %{"type" => "string"}, + "timeStamp" => %{"type" => "string"}, + "from" => %{"type" => "string"}, + "to" => %{"type" => "string"}, + "value" => %{"type" => "string"}, + "contractAddress" => %{"type" => "string"}, + "transactionHash" => %{"type" => "string"}, + "index" => %{"type" => "string"}, + "input" => %{"type" => "string"}, + "type" => %{"type" => "string"}, + "gas" => %{"type" => "string"}, + "gasUsed" => %{"type" => "string"}, + "isError" => %{"type" => "string"}, + "errCode" => %{"type" => "string"} + } + } + }) + end + + defp tokentx_schema do + resolve_schema(%{ + "type" => ["array", "null"], + "items" => %{ + "type" => "object", + "properties" => %{ + "blockNumber" => %{"type" => "string"}, + "timeStamp" => %{"type" => "string"}, + "hash" => %{"type" => "string"}, + "nonce" => %{"type" => "string"}, + "blockHash" => %{"type" => "string"}, + "from" => %{"type" => "string"}, + "contractAddress" => %{"type" => "string"}, + "to" => %{"type" => "string"}, + "logIndex" => %{"type" => "string"}, + "value" => %{"type" => "string"}, + "tokenName" => %{"type" => "string"}, + "tokenSymbol" => %{"type" => "string"}, + "tokenDecimal" => %{"type" => "string"}, + "transactionIndex" => %{"type" => "string"}, + "gas" => %{"type" => "string"}, + "gasPrice" => %{"type" => "string"}, + "gasUsed" => %{"type" => "string"}, + "cumulativeGasUsed" => %{"type" => "string"}, + "input" => %{"type" => "string"}, + "confirmations" => %{"type" => "string"} + } + } + }) + end + + defp tokenbalance_schema, do: resolve_schema(%{"type" => ["string", "null"]}) + + defp tokenlist_schema do + resolve_schema(%{ + "type" => ["array", "null"], + "items" => %{ + "type" => "object", + "properties" => %{ + "balance" => %{"type" => "string"}, + "contractAddress" => %{"type" => "string"}, + "name" => %{"type" => "string"}, + "decimals" => %{"type" => "string"}, + "symbol" => %{"type" => "string"}, + "type" => %{"type" => "string"} + } + } + }) + end + + defp block_schema do + resolve_schema(%{ + "type" => ["array", "null"], + "items" => %{ + "type" => "object", + "properties" => %{ + "blockNumber" => %{"type" => "string"}, + "timeStamp" => %{"type" => "string"}, + "blockReward" => %{"type" => "string"} + } + } + }) + end + + defp resolve_schema(result \\ %{}) do + %{ + "type" => "object", + "properties" => %{ + "message" => %{"type" => "string"}, + "status" => %{"type" => "string"} + } + } + |> put_in(["properties", "result"], result) + |> ExJsonSchema.Schema.resolve() + end end