From 05d439c650e41b1c5d45d3d0b58d619ac67eebbc Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Thu, 24 Oct 2019 11:16:12 +0300 Subject: [PATCH] return not found for not verified contract for token read_contract --- .../tokens/read_contract_controller.ex | 4 +++ .../tokens/read_contract_controller_test.exs | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/tokens/read_contract_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/tokens/read_contract_controller.ex index c83df0f540..9d14b42e5f 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/tokens/read_contract_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/tokens/read_contract_controller.ex @@ -7,6 +7,7 @@ defmodule BlockScoutWeb.Tokens.ReadContractController do options = [necessity_by_association: %{[contract_address: :smart_contract] => :optional}] with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string), + :ok <- Chain.check_verified_smart_contract_exists(address_hash), {:ok, token} <- Chain.token_from_address_hash(address_hash, options) do render( conn, @@ -15,6 +16,9 @@ defmodule BlockScoutWeb.Tokens.ReadContractController do counters_path: token_path(conn, :token_counters, %{"id" => to_string(address_hash)}) ) else + :not_found -> + not_found(conn) + :error -> not_found(conn) diff --git a/apps/block_scout_web/test/block_scout_web/controllers/tokens/read_contract_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/tokens/read_contract_controller_test.exs index abbbe9bc5e..08901b2306 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/tokens/read_contract_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/tokens/read_contract_controller_test.exs @@ -8,9 +8,34 @@ defmodule BlockScoutWeb.Tokens.ReadContractControllerTest do assert html_response(conn, 404) end + test "with unverified address hash returns not found", %{conn: conn} do + address = insert(:address) + + token = insert(:token, contract_address: address) + + transaction = + :transaction + |> insert() + |> with_block() + + insert( + :token_transfer, + to_address: build(:address), + transaction: transaction, + token_contract_address: address, + token: token + ) + + conn = get(conn, token_read_contract_path(BlockScoutWeb.Endpoint, :index, token.contract_address_hash)) + + assert html_response(conn, 404) + end + test "successfully renders the page when the token is a verified smart contract", %{conn: conn} do token_contract_address = insert(:contract_address) + insert(:smart_contract, address_hash: token_contract_address.hash) + token = insert(:token, contract_address: token_contract_address) transaction =