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/forms/transaction_form_test.exs

47 lines
1.4 KiB

defmodule Explorer.TransactionFormTest do
use Explorer.DataCase
alias Explorer.TransactionForm
describe "build/1 when the transaction has a block" do
test "that it returns the values we expect" do
insert(:block, number: 24)
time = Timex.now |> Timex.shift(hours: -2)
block = insert(:block, %{
number: 1,
gas_used: 99523,
timestamp: time,
})
transaction =
insert(:transaction)
|> with_block(block)
|> with_addresses(%{to: "0xsleepypuppy", from: "0xilovefrogs"})
form = TransactionForm.build(transaction)
assert(form == Map.merge(transaction, %{
block_number: 1,
age: "2 hours ago",
formatted_timestamp: block.timestamp |> Timex.format!("%b-%d-%Y %H:%M:%S %p %Z", :strftime),
cumulative_gas_used: "99,523",
to_address: "0xsleepypuppy",
from_address: "0xilovefrogs",
confirmations: 23,
}))
end
test "works when there is no block" do
transaction = insert(:transaction) |> with_addresses(%{to: "0xchadmuska", from: "0xtonyhawk"})
form = TransactionForm.build(transaction)
assert(form == Map.merge(transaction, %{
block_number: "",
age: "",
formatted_timestamp: "",
cumulative_gas_used: "",
to_address: "0xchadmuska",
from_address: "0xtonyhawk",
confirmations: 0,
}))
end
end
end