From 734e321f470895058c4babb33b6a1e9ec7f43def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9F=D0=BE=D0=B7?= =?UTF-8?q?=D0=B4=D0=BD=D1=8F=D0=BA=D0=BE=D0=B2?= Date: Mon, 30 May 2022 18:20:40 +0300 Subject: [PATCH 1/2] Change to_param/1 implementation for Explorer.Chain.Address --- CHANGELOG.md | 1 + apps/block_scout_web/lib/phoenix/param.ex | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d1fcabb9d..0862746607 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - [#5538](https://github.com/blockscout/blockscout/pull/5538) - Fix internal transaction's tile bug ### Chore +- [#5625](https://github.com/blockscout/blockscout/pull/5625) - Get rid of some redirects to checksummed address url - [#5543](https://github.com/blockscout/blockscout/pull/5543) - Increase max_restarts to 1_000 (from 3 by default) for explorer, block_scout_web supervisors - [#5536](https://github.com/blockscout/blockscout/pull/5536) - NPM audit fix diff --git a/apps/block_scout_web/lib/phoenix/param.ex b/apps/block_scout_web/lib/phoenix/param.ex index f1968f40c9..e22fcac718 100644 --- a/apps/block_scout_web/lib/phoenix/param.ex +++ b/apps/block_scout_web/lib/phoenix/param.ex @@ -1,11 +1,17 @@ alias Explorer.Chain.{Address, Block, Hash, Transaction} -defimpl Phoenix.Param, for: [Address, Transaction] do +defimpl Phoenix.Param, for: Transaction do def to_param(%@for{hash: hash}) do @protocol.to_param(hash) end end +defimpl Phoenix.Param, for: Address do + def to_param(%@for{} = address) do + @for.checksum(address) + end +end + defimpl Phoenix.Param, for: Block do def to_param(%@for{consensus: true, number: number}) do to_string(number) From 4b7ac2b1ce5d6489ae2279f2aa3769700328d120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9F=D0=BE=D0=B7?= =?UTF-8?q?=D0=B4=D0=BD=D1=8F=D0=BA=D0=BE=D0=B2?= Date: Mon, 30 May 2022 18:34:59 +0300 Subject: [PATCH 2/2] Fix tests --- CHANGELOG.md | 2 +- .../controllers/tokens/holder_controller_test.exs | 4 ++-- .../controllers/transaction_log_controller_test.exs | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e44dd62d5d..b5039481e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,8 +16,8 @@ - [#5538](https://github.com/blockscout/blockscout/pull/5538) - Fix internal transaction's tile bug ### Chore -- [#5623](https://github.com/blockscout/blockscout/pull/5623) - Allow hyphen in DB password - [#5625](https://github.com/blockscout/blockscout/pull/5625) - Get rid of some redirects to checksummed address url +- [#5623](https://github.com/blockscout/blockscout/pull/5623) - Allow hyphen in DB password - [#5543](https://github.com/blockscout/blockscout/pull/5543) - Increase max_restarts to 1_000 (from 3 by default) for explorer, block_scout_web supervisors - [#5536](https://github.com/blockscout/blockscout/pull/5536) - NPM audit fix diff --git a/apps/block_scout_web/test/block_scout_web/controllers/tokens/holder_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/tokens/holder_controller_test.exs index ac25b1f0c4..45c23d6f09 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/tokens/holder_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/tokens/holder_controller_test.exs @@ -1,7 +1,7 @@ defmodule BlockScoutWeb.Tokens.HolderControllerTest do use BlockScoutWeb.ConnCase, async: true - alias Explorer.Chain.Hash + alias Explorer.Chain.{Address, Hash} describe "GET index/3" do test "with invalid address hash", %{conn: conn} do @@ -67,7 +67,7 @@ defmodule BlockScoutWeb.Tokens.HolderControllerTest do assert Enum.all?(second_page_token_balances, fn token_balance -> Enum.any?(token_balance_tiles, fn tile -> - String.contains?(tile, to_string(token_balance.address_hash)) + String.contains?(tile, Address.checksum(token_balance.address_hash)) end) end) end diff --git a/apps/block_scout_web/test/block_scout_web/controllers/transaction_log_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/transaction_log_controller_test.exs index f5b6118a2c..fc9ced3bba 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/transaction_log_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/transaction_log_controller_test.exs @@ -5,6 +5,7 @@ defmodule BlockScoutWeb.TransactionLogControllerTest do import BlockScoutWeb.WebRouter.Helpers, only: [transaction_log_path: 3] + alias Explorer.Chain.Address alias Explorer.ExchangeRates.Token describe "GET index/2" do @@ -44,7 +45,7 @@ defmodule BlockScoutWeb.TransactionLogControllerTest do {:ok, %{"items" => items}} = conn.resp_body |> Poison.decode() first_log = List.first(items) - assert String.contains?(first_log, to_string(address.hash)) + assert String.contains?(first_log, Address.checksum(address.hash)) end test "returns logs for the transaction with nil to_address", %{conn: conn} do @@ -67,7 +68,7 @@ defmodule BlockScoutWeb.TransactionLogControllerTest do {:ok, %{"items" => items}} = conn.resp_body |> Poison.decode() first_log = List.first(items) - assert String.contains?(first_log, to_string(address.hash)) + assert String.contains?(first_log, Address.checksum(address.hash)) end test "assigns no logs when there are none", %{conn: conn} do