Fix remaining controller tests that were failing from frontend redesign

pull/199/head
Tim Mecklem 7 years ago
parent 69d5fd8901
commit 5150cb9acb
  1. 3
      apps/explorer_web/test/explorer_web/controllers/address_internal_transaction_controller_test.exs
  2. 69
      apps/explorer_web/test/explorer_web/controllers/address_transaction_controller_test.exs
  3. 20
      apps/explorer_web/test/explorer_web/controllers/block_transaction_controller_test.exs
  4. 50
      apps/explorer_web/test/explorer_web/controllers/pending_transaction_controller_test.exs
  5. 14
      apps/explorer_web/test/explorer_web/controllers/transaction_controller_test.exs
  6. 14
      apps/explorer_web/test/explorer_web/features/viewing_blocks_test.exs
  7. 1
      apps/explorer_web/test/explorer_web/features/viewing_transactions_test.ex

@ -30,8 +30,7 @@ defmodule ExplorerWeb.AddressInternalTransactionControllerTest do
to_internal_transaction =
insert(:internal_transaction, transaction_hash: transaction.hash, to_address_hash: address.hash, index: 2)
path = address_internal_transaction_path(ExplorerWeb.Endpoint, :index, :en, address)
path = address_internal_transaction_path(conn, :index, :en, address)
conn = get(conn, path)
actual_transaction_ids =

@ -2,6 +2,7 @@ defmodule ExplorerWeb.AddressTransactionControllerTest do
use ExplorerWeb.ConnCase
import ExplorerWeb.Router.Helpers, only: [address_transaction_path: 4]
import ExplorerWeb.Factory
describe "GET index/2" do
test "with invalid address hash", %{conn: conn} do
@ -16,36 +17,30 @@ defmodule ExplorerWeb.AddressTransactionControllerTest do
assert html_response(conn, 404)
end
test "returns transactions to this address", %{conn: conn} do
test "returns transactions for the address", %{conn: conn} do
address = insert(:address)
block = insert(:block)
transaction = insert(:transaction, block_hash: block.hash, index: 0, to_address_hash: address.hash)
insert(:receipt, transaction_hash: transaction.hash, transaction_index: transaction.index)
conn = get(conn, address_transaction_path(ExplorerWeb.Endpoint, :index, :en, address))
from_transaction =
:transaction
|> insert(block_hash: block.hash, from_address_hash: address.hash, index: 0)
|> with_receipt()
assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 1
to_transaction =
:transaction
|> insert(block_hash: block.hash, to_address_hash: address.hash, index: 1)
|> with_receipt()
transaction_hash_divs = Floki.find(html, "td.transactions__column--hash div.transactions__hash a")
conn = get(conn, address_transaction_path(conn, :index, :en, address))
assert length(transaction_hash_divs) == 1
actual_transaction_hashes =
conn.assigns.page
|> Enum.map(fn transaction -> transaction.hash end)
assert List.first(transaction_hash_divs) |> Floki.attribute("href") == [
"/en/transactions/#{Phoenix.Param.to_param(transaction)}"
]
end
test "does not return transactions from this address", %{conn: conn} do
block = insert(:block)
transaction = insert(:transaction, block_hash: block.hash, index: 0)
insert(:receipt, transaction_hash: transaction.hash, transaction_index: transaction.index)
address = insert(:address)
conn = get(conn, address_transaction_path(ExplorerWeb.Endpoint, :index, :en, address))
assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 0
assert html_response(conn, 200)
assert Enum.member?(actual_transaction_hashes, from_transaction.hash)
assert Enum.member?(actual_transaction_hashes, to_transaction.hash)
end
test "does not return related transactions without a receipt", %{conn: conn} do
@ -62,32 +57,8 @@ defmodule ExplorerWeb.AddressTransactionControllerTest do
conn = get(conn, address_transaction_path(ExplorerWeb.Endpoint, :index, :en, address))
assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 0
end
test "does not return related transactions without a from address", %{conn: conn} do
block = insert(:block)
transaction = insert(:transaction, block_hash: block.hash, index: 0)
insert(:receipt, transaction_hash: transaction.hash, transaction_index: transaction.index)
address = insert(:address)
conn = get(conn, address_transaction_path(ExplorerWeb.Endpoint, :index, :en, address), filter: "from")
assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 0
end
test "does not return related transactions without a to address", %{conn: conn} do
address = insert(:address)
block = insert(:block)
transaction = insert(:transaction, block_hash: block.hash, index: 0, from_address_hash: address.hash, index: 0)
insert(:receipt, transaction_hash: transaction.hash, transaction_index: transaction.index)
conn = get(conn, address_transaction_path(ExplorerWeb.Endpoint, :index, :en, address), filter: "to")
assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 0
assert html_response(conn, 200)
assert Enum.empty?(conn.assigns.page)
end
end
end

@ -23,15 +23,8 @@ defmodule ExplorerWeb.BlockTransactionControllerTest do
conn = get(conn, block_transaction_path(ExplorerWeb.Endpoint, :index, :en, block.number))
assert html = html_response(conn, 200)
transaction_hash_divs = Floki.find(html, "td.transactions__column--hash div.transactions__hash a")
assert length(transaction_hash_divs) == 1
assert List.first(transaction_hash_divs) |> Floki.attribute("href") == [
"/en/transactions/#{Phoenix.Param.to_param(transaction)}"
]
assert html_response(conn, 200)
assert 1 == length(conn.assigns.page.entries)
end
test "does not return unrelated transactions", %{conn: conn} do
@ -40,7 +33,8 @@ defmodule ExplorerWeb.BlockTransactionControllerTest do
conn = get(conn, block_transaction_path(ExplorerWeb.Endpoint, :index, :en, block))
refute html_response(conn, 200) =~ ~r/transactions__row/
assert html_response(conn, 200)
assert Enum.empty?(conn.assigns.page)
end
test "does not return related transactions without a receipt", %{conn: conn} do
@ -49,7 +43,8 @@ defmodule ExplorerWeb.BlockTransactionControllerTest do
conn = get(conn, block_transaction_path(ExplorerWeb.Endpoint, :index, :en, block))
refute html_response(conn, 200) =~ ~r/transactions__row/
assert html_response(conn, 200)
assert Enum.empty?(conn.assigns.page)
end
test "does not return related transactions without a to address", %{conn: conn} do
@ -59,7 +54,8 @@ defmodule ExplorerWeb.BlockTransactionControllerTest do
conn = get(conn, block_transaction_path(ExplorerWeb.Endpoint, :index, :en, block))
refute html_response(conn, 200) =~ ~r/transactions__row/
assert html_response(conn, 200)
assert Enum.empty?(conn.assigns.page)
end
end
end

@ -10,10 +10,8 @@ defmodule ExplorerWeb.PendingTransactionControllerTest do
conn = get(conn, pending_transaction_path(ExplorerWeb.Endpoint, :index, :en))
assert html = html_response(conn, 200)
assert html =~ ~r/Showing 0 Pending Transactions/
refute html =~ ~r/transactions__row/
assert html_response(conn, 200)
assert Enum.empty?(conn.assigns.transactions)
end
test "does not count transactions that have a receipt", %{conn: conn} do
@ -23,10 +21,8 @@ defmodule ExplorerWeb.PendingTransactionControllerTest do
conn = get(conn, pending_transaction_path(ExplorerWeb.Endpoint, :index, :en))
assert html = html_response(conn, 200)
assert html =~ ~r/Showing 0 Pending Transactions/
refute html =~ ~r/transactions__row/
assert html_response(conn, 200)
assert Enum.empty?(conn.assigns.transactions)
end
test "returns pending transactions", %{conn: conn} do
@ -34,7 +30,12 @@ defmodule ExplorerWeb.PendingTransactionControllerTest do
conn = get(conn, pending_transaction_path(ExplorerWeb.Endpoint, :index, :en))
assert html_response(conn, 200) =~ to_string(transaction.hash)
actual_transaction_hashes =
conn.assigns.transactions
|> Enum.map(fn transaction -> transaction.hash end)
assert html_response(conn, 200)
assert Enum.member?(actual_transaction_hashes, transaction.hash)
end
test "returns a count of pending transactions", %{conn: conn} do
@ -42,7 +43,8 @@ defmodule ExplorerWeb.PendingTransactionControllerTest do
conn = get(conn, pending_transaction_path(ExplorerWeb.Endpoint, :index, :en))
assert html_response(conn, 200) =~ ~r/Showing 1 Pending Transactions/
assert html_response(conn, 200)
assert 1 == conn.assigns.transaction_count
end
test "paginates transactions using the last seen transaction", %{conn: conn} do
@ -51,41 +53,21 @@ defmodule ExplorerWeb.PendingTransactionControllerTest do
{:ok, second_inserted_at, 0} = DateTime.from_iso8601("2016-01-23T23:50:07Z")
insert(:transaction, inserted_at: second_inserted_at)
first_response_conn =
conn =
get(
conn,
pending_transaction_path(ExplorerWeb.Endpoint, :index, :en),
last_seen_pending_inserted_at: Timex.format!(first_inserted_at, "{ISO:Extended:Z}")
)
assert first_html = html_response(first_response_conn, 200)
assert first_html |> Floki.find("table.transactions__table tbody tr") |> Enum.count() == 1
second_response_conn =
get(
conn,
pending_transaction_path(ExplorerWeb.Endpoint, :index, :en),
last_seen_pending_inserted_at: Timex.format!(second_inserted_at, "{ISO:Extended:Z}")
)
assert second_html = html_response(second_response_conn, 200)
assert second_html |> Floki.find("table.transactions__table tbody tr") |> Enum.count() == 0
end
test "sends back an estimate of the number of transactions", %{conn: conn} do
insert(:transaction)
conn = get(conn, pending_transaction_path(ExplorerWeb.Endpoint, :index, :en))
assert html_response(conn, 200) =~ ~r/Showing 1 Pending Transactions/
assert html_response(conn, 200)
assert 1 == length(conn.assigns.transactions.entries)
end
test "works when there are no transactions", %{conn: conn} do
conn = get(conn, pending_transaction_path(conn, :index, :en))
assert html = html_response(conn, 200)
assert html =~ ~r/Showing 0 Pending Transactions/
refute html =~ ~r/transactions__row/
assert html_response(conn, 200)
end
end
end

@ -97,11 +97,9 @@ defmodule ExplorerWeb.TransactionControllerTest do
conn = get(conn, transaction_path(conn, :show, :en, transaction))
assert html = html_response(conn, 200)
assert html |> Floki.find("div.transaction__header h3") |> Floki.text() == to_string(transaction.hash)
assert html |> Floki.find("span.transaction__item--primary a") |> Floki.text() == to_string(block.number)
assert html_response(conn, 200)
assert transaction.hash == conn.assigns.transaction.hash
assert block.number == conn.assigns.transaction.block.number
end
test "returns a transaction without associated block data", %{conn: conn} do
@ -109,10 +107,8 @@ defmodule ExplorerWeb.TransactionControllerTest do
conn = get(conn, transaction_path(conn, :show, :en, transaction))
assert html = html_response(conn, 200)
assert html |> Floki.find("div.transaction__header h3") |> Floki.text() == to_string(transaction.hash)
assert html |> Floki.find("span.transaction__item--primary a") |> Floki.text() == ""
assert html_response(conn, 200)
assert transaction.hash == conn.assigns.transaction.hash
end
test "returns internal transactions for the transaction", %{conn: conn} do

@ -9,13 +9,13 @@ defmodule ExplorerWeb.ViewingBlocksTest do
block =
insert(:block, %{
gas_limit: 5_030_101,
gas_used: 1_010_101,
nonce: 123_456_789,
number: 311,
size: 9_999_999,
timestamp: timestamp
})
gas_limit: 5_030_101,
gas_used: 1_010_101,
nonce: 123_456_789,
number: 311,
size: 9_999_999,
timestamp: timestamp
})
{:ok, block: block}
end

@ -85,6 +85,7 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
|> TransactionListPage.visit_page()
|> TransactionListPage.click_pending()
|> assert_has(TransactionListPage.transaction(pending))
# |> click(css(".transactions__link", text: to_string(pending.hash)))
end
end

Loading…
Cancel
Save