return not found for not verified contract for token read_contract

pull/2800/head
Ayrat Badykov 5 years ago
parent 4f987c213a
commit 05d439c650
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 4
      apps/block_scout_web/lib/block_scout_web/controllers/tokens/read_contract_controller.ex
  2. 25
      apps/block_scout_web/test/block_scout_web/controllers/tokens/read_contract_controller_test.exs

@ -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)

@ -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 =

Loading…
Cancel
Save