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

45 lines
1.1 KiB

defmodule Explorer.ResourceTest do
use Explorer.DataCase
alias Explorer.Resource
describe "lookup/1" do
test "finds a block by block number with a valid block number" do
insert(:block, number: 37)
block = Resource.lookup("37")
assert block.number == 37
end
test "finds a transaction by hash" do
transaction = insert(:transaction)
resource = Resource.lookup(transaction.hash)
assert transaction.hash == resource.hash
end
test "finds an address by hash" do
address = insert(:address)
resource = Resource.lookup(address.hash)
assert address.hash == resource.hash
end
test "returns nil when garbage is passed in" do
item = Resource.lookup("any ol' thing")
assert is_nil(item)
end
test "returns nil when it does not find a match" do
transaction_hash = String.pad_trailing("0xnonsense", 43, "0")
address_hash = String.pad_trailing("0xbaddress", 42, "0")
assert is_nil(Resource.lookup("38999"))
assert is_nil(Resource.lookup(transaction_hash))
assert is_nil(Resource.lookup(address_hash))
end
end
end