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

39 lines
1.2 KiB

defmodule Explorer.AddressTest do
use Explorer.DataCase
alias Explorer.Address
describe "changeset/2" do
test "with valid attributes" do
params = params_for(:address)
changeset = Address.changeset(%Address{}, params)
assert changeset.valid?
end
test "with invalid attributes" do
changeset = Address.changeset(%Address{}, %{dog: "woodstock"})
refute changeset.valid?
end
end
describe "find_or_create_by_hash/1" do
test "that it creates a new address when one does not exist" do
Address.find_or_create_by_hash("0xFreshPrince")
last_address = Address |> order_by(desc: :inserted_at) |> Repo.one
assert last_address.hash == "0xfreshprince"
end
test "when the address already exists it doesn't insert a new address" do
insert(:address, %{hash: "bigmouthbillybass"})
Address.find_or_create_by_hash("bigmouthbillybass")
number_of_addresses = Address |> Repo.all |> length
assert number_of_addresses == 1
end
test "when there is no hash it blows up" do
assert_raise Ecto.InvalidChangesetError, fn ->
Address.find_or_create_by_hash("")
end
end
end
end