diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c7b78a7c0..95218ccea2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ ### Fixes + - [#1669](https://github.com/poanetwork/blockscout/pull/1669) - do not fail if multiple matching tokens are found + ### Chore diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 4ff5d7abf1..1dc2dd9b80 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -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 diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index 78607c4fa9..9129fe7131 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -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