|
|
|
@ -6,19 +6,19 @@ defmodule Explorer.TransactionTest do |
|
|
|
|
describe "changeset/2" do |
|
|
|
|
test "with valid attributes" do |
|
|
|
|
block = insert(:block) |
|
|
|
|
changeset = Transaction.changeset(%Transaction{}, %{block_id: block.id, hash: "0x0"}) |
|
|
|
|
assert(changeset.valid?) |
|
|
|
|
changeset = Transaction.changeset(%Transaction{}, %{hash: "0x0", block_id: block.id}) |
|
|
|
|
assert changeset.valid? |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "with an invalid block" do |
|
|
|
|
{:error, changeset} = Transaction.changeset(%Transaction{}, %{block_id: 0, hash: "0x0"}) |> Repo.insert |
|
|
|
|
assert changeset.errors == [block_id: {"does not exist", []}] |
|
|
|
|
test "with a block that does not exist in the database" do |
|
|
|
|
{:error, changeset} = Transaction.changeset(%Transaction{}, %{hash: "0x0", block_id: 0}) |> Repo.insert |
|
|
|
|
refute changeset.valid? |
|
|
|
|
assert [block_id: {"does not exist", []}] = changeset.errors |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "with invalid attributes" do |
|
|
|
|
changeset = Transaction.changeset(%Transaction{}, %{racecar: "yellow ham"}) |
|
|
|
|
refute(changeset.valid?) |
|
|
|
|
refute changeset.valid? |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|