Merge pull request #2800 from poanetwork/ab-read-contract-not-found

return not found for not verified contract for token read_contract
pull/2826/head
Victor Baranov 5 years ago committed by GitHub
commit a50a61df36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 8
      apps/block_scout_web/lib/block_scout_web/controllers/address_read_contract_controller.ex
  3. 4
      apps/block_scout_web/lib/block_scout_web/controllers/tokens/read_contract_controller.ex
  4. 17
      apps/block_scout_web/test/block_scout_web/controllers/address_read_contract_controller_test.exs
  5. 25
      apps/block_scout_web/test/block_scout_web/controllers/tokens/read_contract_controller_test.exs

@ -5,6 +5,7 @@
- [#2449](https://github.com/poanetwork/blockscout/pull/2449) - add ability to send notification events through postgres notify
### Fixes
- [#2800](https://github.com/poanetwork/blockscout/pull/2800) - return not found for not verified contract for token read_contract
- [#2806](https://github.com/poanetwork/blockscout/pull/2806) - Fix blocks fetching on the main page
- [#2803](https://github.com/poanetwork/blockscout/pull/2803) - Fix block validator custom tooltip

@ -26,7 +26,8 @@ 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
{:ok, address} <- Chain.find_contract_address(address_hash, address_options, true),
false <- is_nil(address.smart_contract) do
{transaction_count, validation_count} = transaction_and_validation_count(address_hash)
render(
@ -39,10 +40,7 @@ defmodule BlockScoutWeb.AddressReadContractController do
validation_count: validation_count
)
else
:error ->
not_found(conn)
{:error, :not_found} ->
_ ->
not_found(conn)
end
end

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

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

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