diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index e1523dcd2f..a95a6f45f7 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -1324,16 +1324,13 @@ defmodule Explorer.Chain do @spec fetch_sum_coin_total_supply() :: non_neg_integer def fetch_sum_coin_total_supply do - {:ok, burn_address_hash} = Explorer.Chain.string_to_address_hash("0x0000000000000000000000000000000000000000") - query = from( a0 in Address, - select: fragment("SUM(a0.fetched_coin_balance)"), - where: a0.hash != ^burn_address_hash + select: fragment("SUM(a0.fetched_coin_balance)") ) - Repo.one!(query) + Repo.one!(query) || 0 end @doc """ diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index 88cd8e216d..acdd7836ee 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -1121,6 +1121,20 @@ defmodule Explorer.ChainTest do end end + describe "fetch_sum_coin_total_supply/0" do + test "fetches coin total supply" do + for index <- 0..4 do + insert(:address, fetched_coin_balance: index) + end + + assert "10" = Decimal.to_string(Chain.fetch_sum_coin_total_supply()) + end + + test "fetches coin total supply when there are no blocks" do + assert 0 = Chain.fetch_sum_coin_total_supply() + end + end + describe "address_hash_to_token_transfers/2" do test "returns just the token transfers related to the given contract address" do contract_address =