do not fail if multuple matching tokens are found

pull/1669/head
Ayrat Badykov 6 years ago
parent e0b0cd8010
commit 6db00f9e48
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 6
      apps/explorer/lib/explorer/chain.ex
  2. 9
      apps/explorer/test/explorer/chain_test.exs

@ -691,10 +691,10 @@ defmodule Explorer.Chain do
)
query
|> Repo.one()
|> Repo.all()
|> case do
nil -> {:error, :not_found}
hash -> {:ok, hash}
[] -> {:error, :not_found}
hashes -> {:ok, List.first(hashes)}
end
end

@ -869,6 +869,15 @@ defmodule Explorer.ChainTest do
assert {:ok, _} = Chain.token_contract_address_from_token_name(name)
end
test "return only one result if multiple records are found" do
name = "TOKEN"
insert(:token, symbol: name)
insert(:token, symbol: name)
assert {:ok, _} = Chain.token_contract_address_from_token_name(name)
end
end
describe "find_or_insert_address_from_hash/1" do

Loading…
Cancel
Save