diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_read_contract_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_read_contract_controller.ex index 2625dbd47f..bbf9a0cf68 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_read_contract_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_read_contract_controller.ex @@ -27,17 +27,21 @@ defmodule BlockScoutWeb.AddressReadContractController do with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string), {:ok, address} <- Chain.find_contract_address(address_hash, address_options, true) do - {transaction_count, validation_count} = transaction_and_validation_count(address_hash) + if address.smart_contract do + {transaction_count, validation_count} = transaction_and_validation_count(address_hash) - render( - conn, - "index.html", - address: address, - coin_balance_status: CoinBalanceOnDemand.trigger_fetch(address), - exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(), - transaction_count: transaction_count, - validation_count: validation_count - ) + render( + conn, + "index.html", + address: address, + coin_balance_status: CoinBalanceOnDemand.trigger_fetch(address), + exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(), + transaction_count: transaction_count, + validation_count: validation_count + ) + else + not_found(conn) + end else :error -> not_found(conn) diff --git a/apps/block_scout_web/test/block_scout_web/controllers/address_read_contract_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/address_read_contract_controller_test.exs index 40e0c5b3db..bb28bb0085 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/address_read_contract_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/address_read_contract_controller_test.exs @@ -39,5 +39,22 @@ defmodule BlockScoutWeb.AddressReadContractControllerTest do assert %Token{} = conn.assigns.exchange_rate assert conn.assigns.transaction_count end + + test "returns not found for an unverified contract", %{conn: conn} do + contract_address = insert(:contract_address) + + transaction = insert(:transaction, from_address: contract_address) + + insert( + :internal_transaction_create, + index: 0, + transaction: transaction, + created_contract_address: contract_address + ) + + conn = get(conn, address_read_contract_path(BlockScoutWeb.Endpoint, :index, contract_address.hash)) + + assert html_response(conn, 404) + end end end