You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.3 KiB
64 lines
2.3 KiB
7 years ago
|
defmodule ExplorerWeb.ChainControllerTest do
|
||
7 years ago
|
use ExplorerWeb.ConnCase
|
||
|
|
||
7 years ago
|
def build_transaction(block \\ nil) do
|
||
|
block = block || insert(:block)
|
||
|
transaction = insert(:transaction, block: block)
|
||
|
to_address = insert(:address)
|
||
|
from_address = insert(:address)
|
||
|
insert(:to_address, transaction: transaction, address: to_address)
|
||
|
insert(:from_address, transaction: transaction, address: from_address)
|
||
|
end
|
||
|
|
||
7 years ago
|
describe "GET index/2 without a locale" do
|
||
|
test "redirects to the en locale", %{conn: conn} do
|
||
7 years ago
|
conn = get conn, "/"
|
||
7 years ago
|
assert redirected_to(conn) == "/en"
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "GET index/2 with a locale" do
|
||
|
test "returns a welcome message", %{conn: conn} do
|
||
7 years ago
|
conn = get conn, ExplorerWeb.Router.Helpers.chain_path(ExplorerWeb.Endpoint, :show, %{locale: :en})
|
||
7 years ago
|
assert html_response(conn, 200) =~ "POA"
|
||
7 years ago
|
end
|
||
|
|
||
|
test "returns a block", %{conn: conn} do
|
||
7 years ago
|
insert(:block, %{number: 23})
|
||
7 years ago
|
conn = get conn, "/en"
|
||
7 years ago
|
|
||
7 years ago
|
assert(List.first(conn.assigns.blocks).number == 23)
|
||
7 years ago
|
end
|
||
|
|
||
|
test "excludes all but the most recent five blocks", %{conn: conn} do
|
||
|
old_block = insert(:block)
|
||
|
insert_list(5, :block)
|
||
7 years ago
|
conn = get conn, "/en"
|
||
7 years ago
|
refute(Enum.member?(conn.assigns.blocks, old_block))
|
||
|
end
|
||
7 years ago
|
|
||
|
test "returns a transaction", %{conn: conn} do
|
||
7 years ago
|
block = insert(:block, number: 33)
|
||
7 years ago
|
insert(:transaction, hash: "0xDECAFBAD", block: block) |> with_addresses(%{to: "0xsleepypuppy", from: "0xilovefrogs"})
|
||
|
|
||
7 years ago
|
conn = get conn, "/en"
|
||
|
|
||
|
assert(List.first(conn.assigns.transactions).hash == "0xDECAFBAD")
|
||
7 years ago
|
assert(List.first(conn.assigns.transactions).block.number == 33)
|
||
7 years ago
|
end
|
||
|
|
||
|
test "returns only the five most recent transactions", %{conn: conn} do
|
||
7 years ago
|
block_mined_today = insert(:block, timestamp: Timex.now |> Timex.shift(hours: -1))
|
||
7 years ago
|
insert(:transaction, hash: "0xStuff", inserted_at: Timex.now |> Timex.shift(hours: -1), block: block_mined_today) |> with_addresses
|
||
7 years ago
|
|
||
|
block_mined_last_week = insert(:block, timestamp: Timex.now |> Timex.shift(weeks: -1))
|
||
7 years ago
|
for _ <- 0..4, do: insert(:transaction, %{block: block_mined_last_week}) |> with_addresses
|
||
7 years ago
|
|
||
|
conn = get conn, "/en"
|
||
|
|
||
7 years ago
|
assert Enum.count(conn.assigns.transactions) == 5
|
||
|
assert List.first(conn.assigns.transactions).hash == "0xStuff"
|
||
7 years ago
|
end
|
||
7 years ago
|
end
|
||
|
end
|