Merge pull request #3175 from poanetwork/vb-eip1967-update

eip1967 update: handle different size response from eth_getStorageAt for implementation address
pull/3178/head v3.3.0-beta
Victor Baranov 4 years ago committed by GitHub
commit f3870c0768
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 46
      apps/block_scout_web/test/block_scout_web/controllers/smart_contract_controller_test.exs
  2. 4
      apps/explorer/lib/explorer/chain.ex

@ -134,6 +134,42 @@ defmodule BlockScoutWeb.SmartContractControllerTest do
assert conn.status == 200
assert conn.assigns.read_only_functions == []
end
test "lists [] proxy read only functions if no verified eip-1967 implementation and eth_getStorageAt returns not nnormalized address hash" do
token_contract_address = insert(:contract_address)
insert(:smart_contract,
address_hash: token_contract_address.hash,
abi: [
%{
"type" => "function",
"stateMutability" => "nonpayable",
"payable" => false,
"outputs" => [%{"type" => "address", "name" => "", "internalType" => "address"}],
"name" => "implementation",
"inputs" => [],
"constant" => false
}
]
)
blockchain_get_implementation_mock_2()
path =
smart_contract_path(BlockScoutWeb.Endpoint, :index,
hash: token_contract_address.hash,
type: :proxy,
action: :read
)
conn =
build_conn()
|> put_req_header("x-requested-with", "xmlhttprequest")
|> get(path)
assert conn.status == 200
assert conn.assigns.read_only_functions == []
end
end
describe "GET show/3" do
@ -241,4 +277,14 @@ defmodule BlockScoutWeb.SmartContractControllerTest do
end
)
end
defp blockchain_get_implementation_mock_2 do
expect(
EthereumJSONRPC.Mox,
:json_rpc,
fn %{id: _, method: _, params: [_, _, _]}, _options ->
{:ok, "0x000000000000000000000000cebb2CCCFe291F0c442841cBE9C1D06EED61Ca02"}
end
)
end
end

@ -4388,7 +4388,11 @@ defmodule Explorer.Chain do
json_rpc_named_arguments
)
if String.length(implementation_address) > 42 do
"0x" <> String.slice(implementation_address, -40, 40)
else
implementation_address
end
else
implementation_address =
case Reader.query_contract(proxy_address_hash, abi, %{

Loading…
Cancel
Save