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

32 lines
994 B

defmodule Explorer.BlockTest do
use Explorer.DataCase
alias Explorer.Block
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
end