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/block_test.exs

46 lines
1.4 KiB

defmodule Explorer.BlockTest do
use Explorer.DataCase
alias Explorer.Block
import Ecto.Query, only: [order_by: 2]
describe "changeset/2" do
test "with valid attributes" do
changeset = build(:block) |> Block.changeset(%{})
assert(changeset.valid?)
end
test "with invalid attributes" do
changeset = %Block{} |> Block.changeset(%{racecar: "yellow ham"})
refute(changeset.valid?)
end
test "with duplicate information" do
insert(:block, hash: "0x0")
{:error, changeset} = %Block{} |> Block.changeset(params_for(:block, hash: "0x0")) |> Repo.insert
refute changeset.valid?
assert changeset.errors == [hash: {"has already been taken", []}]
end
test "rejects duplicate blocks with mixed case" do
insert(:block, hash: "0xa")
{:error, changeset} = %Block{} |> Block.changeset(params_for(:block, hash: "0xA")) |> Repo.insert
refute changeset.valid?
assert changeset.errors == [hash: {"has already been taken", []}]
end
end
describe "null/0" do
test "returns a block with a number of 0" do
assert Block.null.number === -1
end
end
describe "latest/1" do
test "returns the blocks sorted by number" do
insert(:block, number: 1)
insert(:block, number: 5)
assert Block |> Block.latest |> Repo.all == Block |> order_by(desc: :number) |> Repo.all
end
end
end