fix paging params

pull/1727/head
Ayrat Badykov 6 years ago
parent 4271d640b9
commit 8fed45b345
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 6
      apps/block_scout_web/lib/block_scout_web/chain.ex
  2. 16
      apps/block_scout_web/test/block_scout_web/controllers/api/rpc/transaction_controller_test.exs

@ -115,7 +115,7 @@ defmodule BlockScoutWeb.Chain do
end end
end end
def paging_options(%{"index" => index_string}) do def paging_options(%{"index" => index_string}) when is_binary(index_string) do
with {index, ""} <- Integer.parse(index_string) do with {index, ""} <- Integer.parse(index_string) do
[paging_options: %{@default_paging_options | key: {index}}] [paging_options: %{@default_paging_options | key: {index}}]
else else
@ -124,6 +124,10 @@ defmodule BlockScoutWeb.Chain do
end end
end end
def paging_options(%{"index" => index}) when is_integer(index) do
[paging_options: %{@default_paging_options | key: {index}}]
end
def paging_options(%{"inserted_at" => inserted_at_string, "hash" => hash_string}) do def paging_options(%{"inserted_at" => inserted_at_string, "hash" => hash_string}) do
with {:ok, inserted_at, _} <- DateTime.from_iso8601(inserted_at_string), with {:ok, inserted_at, _} <- DateTime.from_iso8601(inserted_at_string),
{:ok, hash} <- string_to_transaction_hash(hash_string) do {:ok, hash} <- string_to_transaction_hash(hash_string) do

@ -405,15 +405,10 @@ defmodule BlockScoutWeb.API.RPC.TransactionControllerTest do
"action" => "gettxinfo", "action" => "gettxinfo",
"index" => 49, "index" => 49,
"module" => "transaction", "module" => "transaction",
"txhash" => "0x0000000000000000000000000000000000000000000000000000000000000000" "txhash" => "#{transaction.hash}"
} }
params2 = %{ params2 = response1["result"]["next_page_params"]
"module" => "transaction",
"action" => "gettxinfo",
"txhash" => "#{transaction.hash}",
"next_page_params" => response1["result"]["next_page_params"]
}
assert response2 = assert response2 =
conn conn
@ -423,8 +418,8 @@ defmodule BlockScoutWeb.API.RPC.TransactionControllerTest do
assert response2["status"] == "1" assert response2["status"] == "1"
assert response2["message"] == "OK" assert response2["message"] == "OK"
assert Enum.count(response2["result"]["logs"]) == 50 assert Enum.count(response2["result"]["logs"]) == 50
IO.inspect("here") assert is_nil(response2["result"]["next_page_params"])
assert response2["result"]["next_page_params"] |> IO.inspect() assert response1["result"]["logs"] != response2["result"]["logs"]
end end
test "with a txhash with ok status", %{conn: conn} do test "with a txhash with ok status", %{conn: conn} do
@ -469,7 +464,8 @@ defmodule BlockScoutWeb.API.RPC.TransactionControllerTest do
"data" => "#{log.data}", "data" => "#{log.data}",
"topics" => ["first topic", "second topic", nil, nil] "topics" => ["first topic", "second topic", nil, nil]
} }
] ],
"next_page_params" => nil
} }
assert response = assert response =

Loading…
Cancel
Save