fix block transaction tests

pull/2012/head
Ayrat Badykov 6 years ago
parent e98c3f70c8
commit bb026b1812
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 75
      apps/block_scout_web/test/block_scout_web/controllers/block_transaction_controller_test.exs

@ -39,10 +39,15 @@ defmodule BlockScoutWeb.BlockTransactionControllerTest do
|> with_block(block) |> with_block(block)
|> with_contract_creation(insert(:contract_address)) |> with_contract_creation(insert(:contract_address))
conn = get(conn, block_transaction_path(BlockScoutWeb.Endpoint, :index, block.number)) conn = get(conn, block_transaction_path(BlockScoutWeb.Endpoint, :index, block), %{type: "JSON"})
assert html_response(conn, 200) assert json_response(conn, 200)
assert 2 == Enum.count(conn.assigns.transactions)
{:ok, %{"items" => items}} =
conn.resp_body
|> Poison.decode()
assert Enum.count(items) == 2
end end
test "non-consensus block number without consensus blocks is treated as consensus number above tip", %{conn: conn} do test "non-consensus block number without consensus blocks is treated as consensus number above tip", %{conn: conn} do
@ -77,10 +82,15 @@ defmodule BlockScoutWeb.BlockTransactionControllerTest do
|> insert() |> insert()
|> with_block(block) |> with_block(block)
conn = get(conn, block_transaction_path(conn, :index, block.hash)) conn = get(conn, block_transaction_path(BlockScoutWeb.Endpoint, :index, block), %{type: "JSON"})
assert json_response(conn, 200)
assert html_response(conn, 200) {:ok, %{"items" => items}} =
assert Enum.count(conn.assigns.transactions) == 1 conn.resp_body
|> Poison.decode()
assert Enum.count(items) == 1
end end
test "does not return transactions for non-consensus block hash", %{conn: conn} do test "does not return transactions for non-consensus block hash", %{conn: conn} do
@ -89,10 +99,15 @@ defmodule BlockScoutWeb.BlockTransactionControllerTest do
transaction = insert(:transaction) transaction = insert(:transaction)
insert(:transaction_fork, hash: transaction.hash, uncle_hash: block.hash) insert(:transaction_fork, hash: transaction.hash, uncle_hash: block.hash)
conn = get(conn, block_transaction_path(conn, :index, block.hash)) conn = get(conn, block_transaction_path(BlockScoutWeb.Endpoint, :index, block), %{type: "JSON"})
assert json_response(conn, 200)
{:ok, %{"items" => items}} =
conn.resp_body
|> Poison.decode()
assert html_response(conn, 200) assert Enum.empty?(items)
assert Enum.count(conn.assigns.transactions) == 0
end end
test "does not return transactions for invalid block hash", %{conn: conn} do test "does not return transactions for invalid block hash", %{conn: conn} do
@ -111,44 +126,62 @@ defmodule BlockScoutWeb.BlockTransactionControllerTest do
insert(:transaction) insert(:transaction)
block = insert(:block) block = insert(:block)
conn = get(conn, block_transaction_path(BlockScoutWeb.Endpoint, :index, block)) conn = get(conn, block_transaction_path(BlockScoutWeb.Endpoint, :index, block), %{type: "JSON"})
assert html_response(conn, 200) assert json_response(conn, 200)
assert Enum.empty?(conn.assigns.transactions)
{:ok, %{"items" => items}} =
conn.resp_body
|> Poison.decode()
assert Enum.empty?(items)
end end
test "does not return related transactions without a block", %{conn: conn} do test "does not return related transactions without a block", %{conn: conn} do
block = insert(:block) block = insert(:block)
insert(:transaction) insert(:transaction)
conn = get(conn, block_transaction_path(BlockScoutWeb.Endpoint, :index, block)) conn = get(conn, block_transaction_path(BlockScoutWeb.Endpoint, :index, block), %{type: "JSON"})
assert json_response(conn, 200)
assert html_response(conn, 200) {:ok, %{"items" => items}} =
assert Enum.empty?(conn.assigns.transactions) conn.resp_body
|> Poison.decode()
assert Enum.empty?(items)
end end
test "next_page_params exist if not on last page", %{conn: conn} do test "next_page_path exists if not on last page", %{conn: conn} do
block = %Block{number: number} = insert(:block) block = %Block{number: number} = insert(:block)
60 60
|> insert_list(:transaction) |> insert_list(:transaction)
|> with_block(block) |> with_block(block)
conn = get(conn, block_transaction_path(BlockScoutWeb.Endpoint, :index, block)) conn = get(conn, block_transaction_path(BlockScoutWeb.Endpoint, :index, block), %{type: "JSON"})
{:ok, %{"next_page_path" => next_page_path}} =
conn.resp_body
|> Poison.decode()
assert %{"block_number" => ^number, "index" => 10} = conn.assigns.next_page_params assert next_page_path
end end
test "next_page_params are empty if on last page", %{conn: conn} do test "next_page_path is empty if on last page", %{conn: conn} do
block = insert(:block) block = insert(:block)
:transaction :transaction
|> insert() |> insert()
|> with_block(block) |> with_block(block)
conn = get(conn, block_transaction_path(BlockScoutWeb.Endpoint, :index, block)) conn = get(conn, block_transaction_path(BlockScoutWeb.Endpoint, :index, block), %{type: "JSON"})
{:ok, %{"next_page_path" => next_page_path}} =
conn.resp_body
|> Poison.decode()
refute conn.assigns.next_page_params refute next_page_path
end end
test "displays miner primary address name", %{conn: conn} do test "displays miner primary address name", %{conn: conn} do

Loading…
Cancel
Save