Merge pull request #2834 from poanetwork/ab-add-checksum-plug

always redirect to checksummed hash
pull/2999/head
Victor Baranov 5 years ago committed by GitHub
commit 7784db8996
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 3
      apps/block_scout_web/config/config.exs
  3. 50
      apps/block_scout_web/lib/block_scout_web/checksum_address.ex
  4. 1
      apps/block_scout_web/lib/block_scout_web/web_router.ex
  5. 4
      apps/block_scout_web/test/block_scout_web/controllers/address_coin_balance_by_day_controller_test.exs
  6. 9
      apps/block_scout_web/test/block_scout_web/controllers/address_contract_controller_test.exs
  7. 3
      apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs
  8. 48
      apps/block_scout_web/test/block_scout_web/controllers/address_internal_transaction_controller_test.exs
  9. 9
      apps/block_scout_web/test/block_scout_web/controllers/address_read_contract_controller_test.exs
  10. 6
      apps/block_scout_web/test/block_scout_web/controllers/address_token_balance_controller_test.exs
  11. 12
      apps/block_scout_web/test/block_scout_web/controllers/address_token_controller_test.exs
  12. 70
      apps/block_scout_web/test/block_scout_web/controllers/address_token_transfer_controller_test.exs
  13. 22
      apps/block_scout_web/test/block_scout_web/controllers/address_transaction_controller_test.exs
  14. 8
      apps/block_scout_web/test/block_scout_web/controllers/smart_contract_controller_test.exs
  15. 6
      apps/block_scout_web/test/block_scout_web/controllers/tokens/token_controller_test.exs
  16. 6
      apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs

@ -1,8 +1,8 @@
## Current
### Features
- [#2875](https://github.com/poanetwork/blockscout/pull/2875) - Save contract code from Parity genesis file
- [#2834](https://github.com/poanetwork/blockscout/pull/2834) - always redirect to checksummed hash
### Fixes
- [#2996](https://github.com/poanetwork/blockscout/pull/2996) - Fix awesomplete lib loading in Firefox

@ -12,7 +12,8 @@ config :block_scout_web,
version: System.get_env("BLOCKSCOUT_VERSION"),
release_link: System.get_env("RELEASE_LINK"),
decompiled_smart_contract_token: System.get_env("DECOMPILED_SMART_CONTRACT_TOKEN"),
show_percentage: if(System.get_env("SHOW_ADDRESS_MARKETCAP_PERCENTAGE", "true") == "false", do: false, else: true)
show_percentage: if(System.get_env("SHOW_ADDRESS_MARKETCAP_PERCENTAGE", "true") == "false", do: false, else: true),
checksum_address_hashes: if(System.get_env("CHECKSUM_ADDRESS_HASHES", "true") == "false", do: false, else: true)
config :block_scout_web, BlockScoutWeb.Chain,
network: System.get_env("NETWORK"),

@ -0,0 +1,50 @@
defmodule BlockScoutWeb.ChecksumAddress do
@moduledoc """
Adds checksummed version of address hashes.
"""
import Plug.Conn
alias Explorer.Chain
alias Explorer.Chain.Address
alias Phoenix.Controller
alias Plug.Conn
def init(opts), do: opts
def call(%Conn{params: %{"id" => id}} = conn, _opts) do
check_checksum(conn, id, "id")
end
def call(%Conn{params: %{"address_id" => id}} = conn, _opts) do
check_checksum(conn, id, "address_id")
end
def call(conn, _), do: conn
defp check_checksum(conn, id, param_name) do
if Application.get_env(:block_scout_web, :checksum_address_hashes) do
case Chain.string_to_address_hash(id) do
{:ok, address_hash} ->
checksummed_hash = Address.checksum(address_hash)
if checksummed_hash != id do
conn = %{conn | params: Map.merge(conn.params, %{param_name => checksummed_hash})}
new_path = String.replace(conn.request_path, id, checksummed_hash)
conn
|> Controller.redirect(to: new_path)
|> halt
else
conn
end
_ ->
conn
end
else
conn
end
end
end

@ -10,6 +10,7 @@ defmodule BlockScoutWeb.WebRouter do
plug(:fetch_flash)
plug(:protect_from_forgery)
plug(BlockScoutWeb.CSPHeader)
plug(BlockScoutWeb.ChecksumAddress)
end
# Disallows Iframes (write routes)

@ -1,6 +1,8 @@
defmodule BlockScoutWeb.AddressCoinBalanceByDayControllerTest do
use BlockScoutWeb.ConnCase
alias Explorer.Chain.Address
describe "GET index/2" do
test "returns the coin balance history grouped by date", %{conn: conn} do
address = insert(:address)
@ -10,7 +12,7 @@ defmodule BlockScoutWeb.AddressCoinBalanceByDayControllerTest do
insert(:fetched_balance, address_hash: address.hash, value: 1000, block_number: block.number)
insert(:fetched_balance, address_hash: address.hash, value: 2000, block_number: block_one_day_ago.number)
conn = get(conn, address_coin_balance_by_day_path(conn, :index, address), %{"type" => "JSON"})
conn = get(conn, address_coin_balance_by_day_path(conn, :index, Address.checksum(address)), %{"type" => "JSON"})
response = json_response(conn, 200)

@ -3,7 +3,7 @@ defmodule BlockScoutWeb.AddressContractControllerTest do
import BlockScoutWeb.WebRouter.Helpers, only: [address_contract_path: 3]
alias Explorer.Chain.Hash
alias Explorer.Chain.{Address, Hash}
alias Explorer.ExchangeRates.Token
alias Explorer.Factory
@ -11,7 +11,8 @@ defmodule BlockScoutWeb.AddressContractControllerTest do
test "returns not found for nonexistent address", %{conn: conn} do
nonexistent_address_hash = Hash.to_string(Factory.address_hash())
conn = get(conn, address_contract_path(BlockScoutWeb.Endpoint, :index, nonexistent_address_hash))
conn =
get(conn, address_contract_path(BlockScoutWeb.Endpoint, :index, Address.checksum(nonexistent_address_hash)))
assert html_response(conn, 404)
end
@ -27,7 +28,7 @@ defmodule BlockScoutWeb.AddressContractControllerTest do
test "returns not found when the address isn't a contract", %{conn: conn} do
address = insert(:address)
conn = get(conn, address_contract_path(BlockScoutWeb.Endpoint, :index, address))
conn = get(conn, address_contract_path(BlockScoutWeb.Endpoint, :index, Address.checksum(address)))
assert html_response(conn, 404)
end
@ -46,7 +47,7 @@ defmodule BlockScoutWeb.AddressContractControllerTest do
block_index: 0
)
conn = get(conn, address_contract_path(BlockScoutWeb.Endpoint, :index, address))
conn = get(conn, address_contract_path(BlockScoutWeb.Endpoint, :index, Address.checksum(address)))
assert html_response(conn, 200)
assert address.hash == conn.assigns.address.hash

@ -3,6 +3,7 @@ defmodule BlockScoutWeb.AddressControllerTest do
# ETS tables are shared in `Explorer.Counters.*`
async: false
alias Explorer.Chain.Address
alias Explorer.Counters.AddressesCounter
describe "GET index/2" do
@ -50,7 +51,7 @@ defmodule BlockScoutWeb.AddressControllerTest do
test "returns address counters" do
address = insert(:address)
conn = get(conn, "/address_counters", %{"id" => to_string(address.hash)})
conn = get(conn, "/address_counters", %{"id" => Address.checksum(address.hash)})
assert conn.status == 200
{:ok, response} = Jason.decode(conn.resp_body)

@ -4,7 +4,7 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do
import BlockScoutWeb.WebRouter.Helpers,
only: [address_internal_transaction_path: 3, address_internal_transaction_path: 4]
alias Explorer.Chain.{Block, InternalTransaction, Transaction}
alias Explorer.Chain.{Address, Block, InternalTransaction, Transaction}
alias Explorer.ExchangeRates.Token
describe "GET index/3" do
@ -17,7 +17,15 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do
end
test "with valid address hash without address", %{conn: conn} do
conn = get(conn, address_internal_transaction_path(conn, :index, "0x8bf38d4764929064f2d4d3a56520a76ab3df415b"))
conn =
get(
conn,
address_internal_transaction_path(
conn,
:index,
Address.checksum("0x8bf38d4764929064f2d4d3a56520a76ab3df415b")
)
)
assert html_response(conn, 404)
end
@ -25,7 +33,8 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do
test "includes USD exchange rate value for address in assigns", %{conn: conn} do
address = insert(:address)
conn = get(conn, address_internal_transaction_path(BlockScoutWeb.Endpoint, :index, address.hash))
conn =
get(conn, address_internal_transaction_path(BlockScoutWeb.Endpoint, :index, Address.checksum(address.hash)))
assert %Token{} = conn.assigns.exchange_rate
end
@ -60,7 +69,7 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do
block_index: 2
)
path = address_internal_transaction_path(conn, :index, address, %{"type" => "JSON"})
path = address_internal_transaction_path(conn, :index, Address.checksum(address), %{"type" => "JSON"})
conn = get(conn, path)
internal_transaction_tiles = json_response(conn, 200)["items"]
@ -103,7 +112,12 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do
block_index: 2
)
path = address_internal_transaction_path(conn, :index, address, %{"filter" => "from", "type" => "JSON"})
path =
address_internal_transaction_path(conn, :index, Address.checksum(address), %{
"filter" => "from",
"type" => "JSON"
})
conn = get(conn, path)
internal_transaction_tiles = json_response(conn, 200)["items"]
@ -149,7 +163,9 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do
block_index: 2
)
path = address_internal_transaction_path(conn, :index, address, %{"filter" => "to", "type" => "JSON"})
path =
address_internal_transaction_path(conn, :index, Address.checksum(address), %{"filter" => "to", "type" => "JSON"})
conn = get(conn, path)
internal_transaction_tiles = json_response(conn, 200)["items"]
@ -196,7 +212,9 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do
block_index: 2
)
path = address_internal_transaction_path(conn, :index, address, %{"filter" => "to", "type" => "JSON"})
path =
address_internal_transaction_path(conn, :index, Address.checksum(address), %{"filter" => "to", "type" => "JSON"})
conn = get(conn, path)
internal_transaction_tiles = json_response(conn, 200)["items"]
@ -293,7 +311,7 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do
)
conn =
get(conn, address_internal_transaction_path(BlockScoutWeb.Endpoint, :index, address.hash), %{
get(conn, address_internal_transaction_path(BlockScoutWeb.Endpoint, :index, Address.checksum(address.hash)), %{
"block_number" => Integer.to_string(b_block.number),
"transaction_index" => Integer.to_string(transaction_3.index),
"index" => Integer.to_string(index),
@ -335,7 +353,12 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do
end)
conn =
get(conn, address_internal_transaction_path(BlockScoutWeb.Endpoint, :index, address.hash, %{"type" => "JSON"}))
get(
conn,
address_internal_transaction_path(BlockScoutWeb.Endpoint, :index, Address.checksum(address.hash), %{
"type" => "JSON"
})
)
expected_response =
address_internal_transaction_path(BlockScoutWeb.Endpoint, :index, address.hash, %{
@ -368,7 +391,12 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do
end)
conn =
get(conn, address_internal_transaction_path(BlockScoutWeb.Endpoint, :index, address.hash, %{"type" => "JSON"}))
get(
conn,
address_internal_transaction_path(BlockScoutWeb.Endpoint, :index, Address.checksum(address.hash), %{
"type" => "JSON"
})
)
assert %{"next_page_path" => nil} = json_response(conn, 200)
end

@ -2,6 +2,7 @@ defmodule BlockScoutWeb.AddressReadContractControllerTest do
use BlockScoutWeb.ConnCase, async: true
alias Explorer.ExchangeRates.Token
alias Explorer.Chain.Address
describe "GET index/3" do
test "with invalid address hash", %{conn: conn} do
@ -13,7 +14,7 @@ defmodule BlockScoutWeb.AddressReadContractControllerTest do
test "with valid address that is not a contract", %{conn: conn} do
address = insert(:address)
conn = get(conn, address_read_contract_path(BlockScoutWeb.Endpoint, :index, address.hash))
conn = get(conn, address_read_contract_path(BlockScoutWeb.Endpoint, :index, Address.checksum(address.hash)))
assert html_response(conn, 404)
end
@ -34,7 +35,8 @@ defmodule BlockScoutWeb.AddressReadContractControllerTest do
insert(:smart_contract, address_hash: contract_address.hash)
conn = get(conn, address_read_contract_path(BlockScoutWeb.Endpoint, :index, contract_address.hash))
conn =
get(conn, address_read_contract_path(BlockScoutWeb.Endpoint, :index, Address.checksum(contract_address.hash)))
assert html_response(conn, 200)
assert contract_address.hash == conn.assigns.address.hash
@ -55,7 +57,8 @@ defmodule BlockScoutWeb.AddressReadContractControllerTest do
block_index: 0
)
conn = get(conn, address_read_contract_path(BlockScoutWeb.Endpoint, :index, contract_address.hash))
conn =
get(conn, address_read_contract_path(BlockScoutWeb.Endpoint, :index, Address.checksum(contract_address.hash)))
assert html_response(conn, 404)
end

@ -8,7 +8,7 @@ defmodule BlockScoutWeb.AddressTokenBalanceControllerTest do
test "without AJAX", %{conn: conn} do
%Address{hash: hash} = Factory.insert(:address)
response_conn = get(conn, address_token_balance_path(conn, :index, to_string(hash)))
response_conn = get(conn, address_token_balance_path(conn, :index, Address.checksum(hash)))
assert html_response(response_conn, 404)
end
@ -24,7 +24,7 @@ defmodule BlockScoutWeb.AddressTokenBalanceControllerTest do
test "with AJAX with valid address without address still returns token balances", %{conn: conn} do
ajax_conn = ajax(conn)
response_conn = get(ajax_conn, address_token_balance_path(ajax_conn, :index, Factory.address_hash()))
response_conn = get(ajax_conn, address_token_balance_path(ajax_conn, :index, Address.checksum(address_hash())))
assert html_response(response_conn, 200)
end
@ -34,7 +34,7 @@ defmodule BlockScoutWeb.AddressTokenBalanceControllerTest do
ajax_conn = ajax(conn)
response_conn = get(ajax_conn, address_token_balance_path(ajax_conn, :index, hash))
response_conn = get(ajax_conn, address_token_balance_path(ajax_conn, :index, Address.checksum(hash)))
assert html_response(response_conn, 200)
end

@ -3,7 +3,7 @@ defmodule BlockScoutWeb.AddressTokenControllerTest do
import BlockScoutWeb.WebRouter.Helpers, only: [address_token_path: 3]
alias Explorer.Chain.{Token}
alias Explorer.Chain.{Address, Token}
describe "GET index/2" do
test "with invalid address hash", %{conn: conn} do
@ -13,7 +13,7 @@ defmodule BlockScoutWeb.AddressTokenControllerTest do
end
test "with valid address hash without address", %{conn: conn} do
conn = get(conn, address_token_path(conn, :index, "0x8bf38d4764929064f2d4d3a56520a76ab3df415b"))
conn = get(conn, address_token_path(conn, :index, Address.checksum("0x8bf38d4764929064f2d4d3a56520a76ab3df415b")))
assert html_response(conn, 404)
end
@ -57,7 +57,7 @@ defmodule BlockScoutWeb.AddressTokenControllerTest do
to_address: address
)
conn = get(conn, address_token_path(conn, :index, to_string(address.hash)), type: "JSON")
conn = get(conn, address_token_path(conn, :index, Address.checksum(address)), type: "JSON")
{:ok, %{"items" => items}} =
conn.resp_body
@ -99,7 +99,7 @@ defmodule BlockScoutWeb.AddressTokenControllerTest do
%Token{name: name, type: type, inserted_at: inserted_at} = token
conn =
get(conn, address_token_path(BlockScoutWeb.Endpoint, :index, to_string(address.hash)), %{
get(conn, address_token_path(BlockScoutWeb.Endpoint, :index, Address.checksum(address.hash)), %{
"token_name" => name,
"token_type" => type,
"token_inserted_at" => inserted_at,
@ -131,7 +131,7 @@ defmodule BlockScoutWeb.AddressTokenControllerTest do
insert(:token_transfer, token_contract_address: token.contract_address, from_address: address)
end)
conn = get(conn, address_token_path(BlockScoutWeb.Endpoint, :index, to_string(address.hash)), type: "JSON")
conn = get(conn, address_token_path(BlockScoutWeb.Endpoint, :index, Address.checksum(address.hash)), type: "JSON")
{:ok, %{"next_page_path" => next_page_path}} =
conn.resp_body
@ -145,7 +145,7 @@ defmodule BlockScoutWeb.AddressTokenControllerTest do
token = insert(:token)
insert(:token_transfer, token_contract_address: token.contract_address, from_address: address)
conn = get(conn, address_token_path(BlockScoutWeb.Endpoint, :index, address.hash), type: "JSON")
conn = get(conn, address_token_path(BlockScoutWeb.Endpoint, :index, Address.checksum(address.hash)), type: "JSON")
{:ok, %{"next_page_path" => next_page_path}} =
conn.resp_body

@ -17,7 +17,7 @@ defmodule BlockScoutWeb.AddressTokenTransferControllerTest do
test "with invalid token hash", %{conn: conn} do
address_hash = "0x8bf38d4764929064f2d4d3a56520a76ab3df415b"
conn = get(conn, address_token_transfers_path(conn, :index, address_hash, "invalid_address"))
conn = get(conn, address_token_transfers_path(conn, :index, Address.checksum(address_hash), "invalid_address"))
assert html_response(conn, 422)
end
@ -25,15 +25,20 @@ defmodule BlockScoutWeb.AddressTokenTransferControllerTest do
test "with an address that doesn't exist in our database", %{conn: conn} do
address_hash = "0x8bf38d4764929064f2d4d3a56520a76ab3df415b"
%Token{contract_address_hash: token_hash} = insert(:token)
conn = get(conn, address_token_transfers_path(conn, :index, to_string(address_hash), to_string(token_hash)))
conn =
get(
conn,
address_token_transfers_path(conn, :index, Address.checksum(address_hash), Address.checksum(token_hash))
)
assert html_response(conn, 404)
end
test "with an token that doesn't exist in our database", %{conn: conn} do
%Address{hash: address_hash} = insert(:address)
token_hash = "0x8bf38d4764929064f2d4d3a56520a76ab3df415b"
conn = get(conn, address_token_transfers_path(conn, :index, address_hash, token_hash))
token_hash = Address.checksum("0x8bf38d4764929064f2d4d3a56520a76ab3df415b")
conn = get(conn, address_token_transfers_path(conn, :index, Address.checksum(address_hash), token_hash))
assert html_response(conn, 404)
end
@ -45,9 +50,13 @@ defmodule BlockScoutWeb.AddressTokenTransferControllerTest do
%Token{contract_address_hash: token_hash} = insert(:token)
conn =
get(conn, address_token_transfers_path(conn, :index, to_string(address_hash), to_string(token_hash)), %{
get(
conn,
address_token_transfers_path(conn, :index, Address.checksum(address_hash), Address.checksum(token_hash)),
%{
type: "JSON"
})
}
)
assert json_response(conn, 200) == %{"items" => [], "next_page_path" => nil}
end
@ -78,7 +87,12 @@ defmodule BlockScoutWeb.AddressTokenTransferControllerTest do
conn =
get(
conn,
address_token_transfers_path(conn, :index, to_string(address.hash), to_string(token.contract_address_hash)),
address_token_transfers_path(
conn,
:index,
Address.checksum(address.hash),
Address.checksum(token.contract_address_hash)
),
%{type: "JSON"}
)
@ -122,7 +136,12 @@ defmodule BlockScoutWeb.AddressTokenTransferControllerTest do
conn =
get(
conn,
address_token_transfers_path(conn, :index, to_string(address.hash), to_string(token.contract_address_hash)),
address_token_transfers_path(
conn,
:index,
Address.checksum(address.hash),
Address.checksum(token.contract_address_hash)
),
%{type: "JSON"}
)
@ -173,15 +192,26 @@ defmodule BlockScoutWeb.AddressTokenTransferControllerTest do
conn =
get(
conn,
address_token_transfers_path(conn, :index, to_string(address.hash), to_string(token.contract_address_hash)),
address_token_transfers_path(
conn,
:index,
Address.checksum(address.hash),
Address.checksum(token.contract_address_hash)
),
%{type: "JSON"}
)
expected_path =
address_token_transfers_path(conn, :index, address.hash, token.contract_address_hash, %{
address_token_transfers_path(
conn,
:index,
Address.checksum(address.hash),
Address.checksum(token.contract_address_hash),
%{
block_number: page_last_transfer.block_number,
index: page_last_transfer.index
})
}
)
assert Map.get(json_response(conn, 200), "next_page_path") == expected_path
end
@ -201,7 +231,7 @@ defmodule BlockScoutWeb.AddressTokenTransferControllerTest do
address_hash = "0x8bf38d4764929064f2d4d3a56520a76ab3df415b"
conn =
get(conn, address_token_transfers_path(conn, :index, address_hash, "invalid_address"), %{
get(conn, address_token_transfers_path(conn, :index, Address.checksum(address_hash), "invalid_address"), %{
type: "JSON"
})
@ -213,9 +243,13 @@ defmodule BlockScoutWeb.AddressTokenTransferControllerTest do
%Token{contract_address_hash: token_hash} = insert(:token)
conn =
get(conn, address_token_transfers_path(conn, :index, to_string(address_hash), to_string(token_hash)), %{
get(
conn,
address_token_transfers_path(conn, :index, Address.checksum(address_hash), Address.checksum(token_hash)),
%{
type: "JSON"
})
}
)
assert html_response(conn, 404)
end
@ -225,9 +259,13 @@ defmodule BlockScoutWeb.AddressTokenTransferControllerTest do
token_hash = "0x8bf38d4764929064f2d4d3a56520a76ab3df415b"
conn =
get(conn, address_token_transfers_path(conn, :index, address_hash, token_hash), %{
get(
conn,
address_token_transfers_path(conn, :index, Address.checksum(address_hash), Address.checksum(token_hash)),
%{
type: "JSON"
})
}
)
assert html_response(conn, 404)
end

@ -3,7 +3,7 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
import BlockScoutWeb.WebRouter.Helpers, only: [address_transaction_path: 3, address_transaction_path: 4]
alias Explorer.Chain.Transaction
alias Explorer.Chain.{Address, Transaction}
alias Explorer.ExchangeRates.Token
describe "GET index/2" do
@ -17,7 +17,9 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
conn =
get(
conn,
address_transaction_path(conn, :index, "0x8bf38d4764929064f2d4d3a56520a76ab3df415b", %{"type" => "JSON"})
address_transaction_path(conn, :index, Address.checksum("0x8bf38d4764929064f2d4d3a56520a76ab3df415b"), %{
"type" => "JSON"
})
)
assert json_response(conn, 200)
@ -40,7 +42,7 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
|> insert(to_address: address)
|> with_block(block)
conn = get(conn, address_transaction_path(conn, :index, address, %{"type" => "JSON"}))
conn = get(conn, address_transaction_path(conn, :index, Address.checksum(address), %{"type" => "JSON"}))
transaction_tiles = json_response(conn, 200)["items"]
transaction_hashes = Enum.map([to_transaction.hash, from_transaction.hash], &to_string(&1))
@ -53,7 +55,7 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
test "includes USD exchange rate value for address in assigns", %{conn: conn} do
address = insert(:address)
conn = get(conn, address_transaction_path(BlockScoutWeb.Endpoint, :index, address.hash))
conn = get(conn, address_transaction_path(BlockScoutWeb.Endpoint, :index, Address.checksum(address.hash)))
assert %Token{} = conn.assigns.exchange_rate
end
@ -73,7 +75,7 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
|> with_block()
conn =
get(conn, address_transaction_path(BlockScoutWeb.Endpoint, :index, address.hash), %{
get(conn, address_transaction_path(BlockScoutWeb.Endpoint, :index, Address.checksum(address.hash)), %{
"block_number" => Integer.to_string(block_number),
"index" => Integer.to_string(index),
"type" => "JSON"
@ -94,7 +96,7 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
|> insert_list(:transaction, from_address: address)
|> with_block(block)
conn = get(conn, address_transaction_path(conn, :index, address.hash, %{"type" => "JSON"}))
conn = get(conn, address_transaction_path(conn, :index, Address.checksum(address.hash), %{"type" => "JSON"}))
assert json_response(conn, 200)["next_page_path"]
end
@ -106,7 +108,7 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
|> insert(from_address: address)
|> with_block()
conn = get(conn, address_transaction_path(conn, :index, address.hash, %{"type" => "JSON"}))
conn = get(conn, address_transaction_path(conn, :index, Address.checksum(address.hash), %{"type" => "JSON"}))
refute json_response(conn, 200)["next_page_path"]
end
@ -131,7 +133,7 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
block_index: 0
)
conn = get(conn, address_transaction_path(conn, :index, address), %{"type" => "JSON"})
conn = get(conn, address_transaction_path(conn, :index, Address.checksum(address)), %{"type" => "JSON"})
transaction_tiles = json_response(conn, 200)["items"]
@ -153,7 +155,7 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
insert(:token_transfer, transaction: transaction, from_address: address)
insert(:token_transfer, transaction: transaction, to_address: address)
conn = get(conn, "/token_transfers_csv", %{"address_id" => to_string(address.hash)})
conn = get(conn, "/token_transfers_csv", %{"address_id" => Address.checksum(address.hash)})
assert conn.resp_body |> String.split("\n") |> Enum.count() == 4
end
@ -171,7 +173,7 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
|> insert(from_address: address)
|> with_block()
conn = get(conn, "/transactions_csv", %{"address_id" => to_string(address.hash)})
conn = get(conn, "/transactions_csv", %{"address_id" => Address.checksum(address.hash)})
assert conn.resp_body |> String.split("\n") |> Enum.count() == 4
end

@ -3,7 +3,7 @@ defmodule BlockScoutWeb.SmartContractControllerTest do
import Mox
alias Explorer.Chain.Hash
alias Explorer.Chain.{Address, Hash}
alias Explorer.Factory
setup :verify_on_exit!
@ -63,7 +63,7 @@ defmodule BlockScoutWeb.SmartContractControllerTest do
describe "GET show/3" do
test "returns not found for nonexistent address" do
nonexistent_address_hash = Hash.to_string(Factory.address_hash())
nonexistent_address_hash = Address.checksum(Hash.to_string(Factory.address_hash()))
path =
smart_contract_path(
@ -107,7 +107,7 @@ defmodule BlockScoutWeb.SmartContractControllerTest do
smart_contract_path(
BlockScoutWeb.Endpoint,
:show,
smart_contract.address_hash,
Address.checksum(smart_contract.address_hash),
function_name: "get",
args: []
)
@ -127,7 +127,7 @@ defmodule BlockScoutWeb.SmartContractControllerTest do
smart_contract_path(
BlockScoutWeb.Endpoint,
:show,
smart_contract.address_hash,
Address.checksum(smart_contract.address_hash),
function_name: "get",
args: []
)

@ -1,11 +1,13 @@
defmodule BlockScoutWeb.Tokens.TokenControllerTest do
use BlockScoutWeb.ConnCase, async: true
alias Explorer.Chain.Address
describe "GET show/2" do
test "redirects to transfers page", %{conn: conn} do
contract_address = insert(:address)
conn = get(conn, token_path(conn, :show, contract_address.hash))
conn = get(conn, token_path(conn, :show, Address.checksum(contract_address.hash)))
assert conn.status == 302
end
@ -25,7 +27,7 @@ defmodule BlockScoutWeb.Tokens.TokenControllerTest do
token_id: token_id
)
conn = get(conn, "/token_counters", %{"id" => to_string(contract_address.hash)})
conn = get(conn, "/token_counters", %{"id" => Address.checksum(contract_address.hash)})
assert conn.status == 200
{:ok, response} = Jason.decode(conn.resp_body)

@ -7,6 +7,8 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
alias BlockScoutWeb.{AddressPage, AddressView, Notifier}
setup do
Application.put_env(:block_scout_web, :checksum_address_hashes, false)
block = insert(:block, number: 42)
lincoln = insert(:address, fetched_coin_balance: 5)
@ -38,6 +40,10 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
address_type: :validator
)
on_exit(fn ->
Application.put_env(:block_scout_web, :checksum_address_hashes, true)
end)
{:ok,
%{
addresses: %{lincoln: lincoln, taft: taft},

Loading…
Cancel
Save