From 45c8368fad0fa9d268ddd82145f744abf9e99931 Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Fri, 20 Sep 2024 13:11:52 +0400 Subject: [PATCH] fix: decode addresses as checksummed (#10777) * fix: decode addresses as checksummed * chore: fix failing tests --- .../lib/block_scout_web/views/abi_encoded_value_view.ex | 6 +++++- .../controllers/api/v2/smart_contract_controller_test.exs | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/views/abi_encoded_value_view.ex b/apps/block_scout_web/lib/block_scout_web/views/abi_encoded_value_view.ex index 5fee550b6b..12bde16065 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/abi_encoded_value_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/abi_encoded_value_view.ex @@ -8,6 +8,7 @@ defmodule BlockScoutWeb.ABIEncodedValueView do use BlockScoutWeb, :view alias ABI.FunctionSelector + alias Explorer.Chain.{Address, Hash} alias Phoenix.HTML require Logger @@ -196,7 +197,10 @@ defmodule BlockScoutWeb.ABIEncodedValueView do end defp base_value_json(:address, value) do - hex_for_json(value) + case Hash.Address.cast(value) do + {:ok, address} -> Address.checksum(address) + :error -> "0x" + end end defp base_value_json(:bytes, value) do diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/v2/smart_contract_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/v2/smart_contract_controller_test.exs index 082f8db55d..58b7a38ca1 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/v2/smart_contract_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/v2/smart_contract_controller_test.exs @@ -263,7 +263,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do "constructor_args" => target_contract.constructor_arguments, "decoded_constructor_args" => [ ["0x0000000000000000000000000000000000000000", %{"name" => "_proxyStorage", "type" => "address"}], - ["0x2cf6e7c9ec35d0b08a1062e13854f74b1aaae54e", %{"name" => "_implementationAddress", "type" => "address"}] + ["0x2Cf6E7c9eC35D0B08A1062e13854f74b1aaae54e", %{"name" => "_implementationAddress", "type" => "address"}] ], "is_self_destructed" => false, "deployed_bytecode" => @@ -849,7 +849,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do assert response["decoded_constructor_args"] == [ [ - "0xc35dadb65012ec5796536bd9864ed8773abc74c4", + "0xc35DADB65012eC5796536bD9864eD8773aBc74C4", %{ "internalType" => "address", "name" => "_factory", @@ -857,7 +857,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do } ], [ - "0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6", + "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6", %{ "internalType" => "address", "name" => "_WETH",