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/workers/import_transaction_test.exs

57 lines
2.3 KiB

defmodule Explorer.Workers.ImportTransactionTest do
use Explorer.DataCase
import Mock
alias Explorer.Receipt
alias Explorer.Repo
alias Explorer.Transaction
alias Explorer.Workers.ImportTransaction
describe "perform/1" do
test "imports the requested transaction hash" do
use_cassette "import_transaction_perform_1" do
with_mock Exq, [enqueue: fn (_, _, _, _) -> :ok end] do
ImportTransaction.perform("0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926")
end
transaction = Transaction |> Repo.one
assert transaction.hash == "0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926"
end
end
test "when there is already a transaction with the requested hash" do
insert(:transaction, hash: "0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926")
use_cassette "import_transaction_perform_1" do
with_mock Exq, [enqueue: fn (_, _, _, _) -> :ok end] do
ImportTransaction.perform("0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926")
end
transaction_count = Transaction |> Repo.all |> Enum.count
assert transaction_count == 1
end
end
test "imports the receipt in another queue" do
transaction = insert(:transaction, hash: "0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926")
use_cassette "import_transaction_perform_1" do
with_mock Exq, [enqueue: fn (_, _, _, _) -> insert(:receipt, transaction: transaction) end] do
ImportTransaction.perform("0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926")
receipt = Repo.one(Receipt)
refute is_nil(receipt)
end
end
end
end
describe "perform_later/1" do
test "imports the transaction in another queue" do
use_cassette "import_transaction_perform_1" do
with_mock Exq, [enqueue: fn (_, _, _, _) -> insert(:transaction, hash: "0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926") end] do
ImportTransaction.perform_later("0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926")
transaction = Repo.one(Transaction)
assert transaction.hash == "0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926"
end
end
end
end
end