Blockchain explorer for Ethereum based network and a tool for inspecting and analyzing EVM based blockchains.
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.
 
 
 
 
 
blockscout/test/explorer_web/controllers/block_transaction_controlle...

60 lines
2.8 KiB

defmodule ExplorerWeb.BlockTransactionControllerTest do
use ExplorerWeb.ConnCase
import ExplorerWeb.Router.Helpers, only: [block_transaction_path: 4]
describe "GET index/2" do
test "returns transactions for the block", %{conn: conn} do
transaction = insert(:transaction, hash: "0xsnacks")
insert(:receipt, transaction: transaction)
block = insert(:block)
insert(:block_transaction, transaction: transaction, block: block)
address = insert(:address)
insert(:to_address, transaction: transaction, address: address)
insert(:from_address, transaction: transaction, address: address)
conn = get(conn, block_transaction_path(ExplorerWeb.Endpoint, :index, :en, block.number))
assert conn.assigns.transactions.total_entries == 1
assert List.first(conn.assigns.transactions.entries).hash == "0xsnacks"
end
test "does not return unrelated transactions", %{conn: conn} do
insert(:transaction)
block = insert(:block)
conn = get(conn, block_transaction_path(ExplorerWeb.Endpoint, :index, :en, block.number))
assert conn.assigns.transactions.total_entries == 0
end
test "does not return related transactions without a receipt", %{conn: conn} do
transaction = insert(:transaction)
block = insert(:block)
insert(:block_transaction, transaction: transaction, block: block)
address = insert(:address)
insert(:to_address, transaction: transaction, address: address)
insert(:from_address, transaction: transaction, address: address)
conn = get(conn, block_transaction_path(ExplorerWeb.Endpoint, :index, :en, block.number))
assert conn.assigns.transactions.total_entries == 0
end
test "does not return related transactions without a from address", %{conn: conn} do
transaction = insert(:transaction)
insert(:receipt, transaction: transaction)
block = insert(:block)
insert(:block_transaction, transaction: transaction, block: block)
address = insert(:address)
insert(:to_address, transaction: transaction, address: address)
conn = get(conn, block_transaction_path(ExplorerWeb.Endpoint, :index, :en, block.number))
assert conn.assigns.transactions.total_entries == 0
end
test "does not return related transactions without a to address", %{conn: conn} do
transaction = insert(:transaction)
insert(:receipt, transaction: transaction)
block = insert(:block)
insert(:block_transaction, transaction: transaction, block: block)
address = insert(:address)
insert(:from_address, transaction: transaction, address: address)
conn = get(conn, block_transaction_path(ExplorerWeb.Endpoint, :index, :en, block.number))
assert conn.assigns.transactions.total_entries == 0
end
end
end