diff --git a/.github/workflows/helm_deploy_dispatch.yml b/.github/workflows/helm_deploy_dispatch.yml index 08776b8914a6..f9ea92d1e8c7 100644 --- a/.github/workflows/helm_deploy_dispatch.yml +++ b/.github/workflows/helm_deploy_dispatch.yml @@ -1,6 +1,6 @@ --- name: 'Deploy Helm Chart' -run-name: 'helmfile ${{ github.event.inputs.action }} on ${{ github.event.inputs.deployment }} - ${{ github.event.inputs.image-commit }}' +run-name: 'helmfile ${{ github.event.inputs.action }} on ${{ github.event.inputs.deployment }} - ${{ github.sha }}' on: workflow_dispatch: diff --git a/apps/block_scout_web/.iex.exs b/apps/block_scout_web/.iex.exs index 14a25ccc3256..2c7af5c90a28 100644 --- a/apps/block_scout_web/.iex.exs +++ b/apps/block_scout_web/.iex.exs @@ -10,6 +10,6 @@ defmodule Clabs.Debug do def token_tx_for_valora_address do {:ok,hsh} = Address.cast("0x6131a6d616a4be3737b38988847270a64bc10caa") - Explorer.GraphQL.token_txtransfers_query_for_address(hsh, 26) + Explorer.GraphQL.token_txtransfers_query_for_address(hsh, 26, 0) end end \ No newline at end of file diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/verified_contracts_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/verified_contracts_controller.ex index c75b25e27ecb..44cb6699c6fd 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/verified_contracts_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/verified_contracts_controller.ex @@ -50,7 +50,8 @@ defmodule BlockScoutWeb.VerifiedContractsController do page_number: params |> fetch_page_number() |> Integer.to_string(), contracts_count: Chain.count_contracts_from_cache(), verified_contracts_count: Chain.count_verified_contracts_from_cache(), - new_contracts_count: Chain.count_new_contracts_from_cache(), + # celo: disabling new contract count + new_contracts_count: nil, new_verified_contracts_count: Chain.count_new_verified_contracts_from_cache() ) end diff --git a/apps/block_scout_web/lib/block_scout_web/resolvers/token_transfer_tx.ex b/apps/block_scout_web/lib/block_scout_web/resolvers/token_transfer_tx.ex index 44d2256e299f..46ce04441ef2 100644 --- a/apps/block_scout_web/lib/block_scout_web/resolvers/token_transfer_tx.ex +++ b/apps/block_scout_web/lib/block_scout_web/resolvers/token_transfer_tx.ex @@ -4,11 +4,17 @@ defmodule BlockScoutWeb.Resolvers.TokenTransferTx do alias Absinthe.Relay.Connection alias Explorer.{GraphQL, Repo} - def get_by(_, %{address_hash: address_hash, first: first} = args, _) do + def get_by(_, %{address_hash: address_hash, first: limit} = args, _) do connection_args = Map.take(args, [:after, :before, :first, :last]) + offset = + case Connection.offset(args) do + {:ok, offset} when is_integer(offset) -> offset + _ -> 0 + end + address_hash - |> GraphQL.token_txtransfers_query_for_address(first) + |> GraphQL.token_txtransfers_query_for_address(offset, limit) |> Connection.from_query(&Repo.all/1, connection_args, options(args)) end diff --git a/apps/block_scout_web/lib/block_scout_web/templates/verified_contracts/_stats.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/verified_contracts/_stats.html.eex index d69ebe0ec188..830e6250b9d7 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/verified_contracts/_stats.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/verified_contracts/_stats.html.eex @@ -9,8 +9,10 @@ <span class="text-muted"><%= gettext ("Total") %></span> </div> <div class="d-flex flex-column"> - <h1 class="text-success"><%= if 0 |> Decimal.new() |> Decimal.lt?(@new_contracts_count), do: "+" %><%= BlockScoutWeb.Cldr.Number.to_string!(@new_contracts_count, format: "#,###") %></h1> - <span class="text-muted"><%= gettext ("Last 24h") %></span> + <%= if ! is_nil(@new_contracts_count) do %> + <h1 class="text-success"><%= if 0 |> Decimal.new() |> Decimal.lt?(@new_contracts_count), do: "+" %><%= BlockScoutWeb.Cldr.Number.to_string!(@new_contracts_count, format: "#,###") %></h1> + <span class="text-muted"><%= gettext ("Last 24h") %></span> + <% end %> </div> </div> </div> diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index fb2de45418f4..198e0e6f4c43 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -1496,8 +1496,8 @@ msgstr "" msgid "Is Yul contract" msgstr "" -#: lib/block_scout_web/templates/verified_contracts/_stats.html.eex:13 -#: lib/block_scout_web/templates/verified_contracts/_stats.html.eex:26 +#: lib/block_scout_web/templates/verified_contracts/_stats.html.eex:14 +#: lib/block_scout_web/templates/verified_contracts/_stats.html.eex:28 #, elixir-autogen, elixir-format msgid "Last 24h" msgstr "" @@ -2723,7 +2723,7 @@ msgid "Topics" msgstr "" #: lib/block_scout_web/templates/verified_contracts/_stats.html.eex:9 -#: lib/block_scout_web/templates/verified_contracts/_stats.html.eex:22 +#: lib/block_scout_web/templates/verified_contracts/_stats.html.eex:24 #, elixir-autogen, elixir-format msgid "Total" msgstr "" @@ -2994,7 +2994,7 @@ msgstr "" msgid "Verified" msgstr "" -#: lib/block_scout_web/templates/verified_contracts/_stats.html.eex:18 +#: lib/block_scout_web/templates/verified_contracts/_stats.html.eex:20 #: lib/block_scout_web/templates/verified_contracts/index.html.eex:5 #, elixir-autogen, elixir-format msgid "Verified Contracts" diff --git a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po index 72b95eeb6867..62a3ddd33596 100644 --- a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po +++ b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po @@ -1496,8 +1496,8 @@ msgstr "" msgid "Is Yul contract" msgstr "" -#: lib/block_scout_web/templates/verified_contracts/_stats.html.eex:13 -#: lib/block_scout_web/templates/verified_contracts/_stats.html.eex:26 +#: lib/block_scout_web/templates/verified_contracts/_stats.html.eex:14 +#: lib/block_scout_web/templates/verified_contracts/_stats.html.eex:28 #, elixir-autogen, elixir-format msgid "Last 24h" msgstr "" @@ -2723,7 +2723,7 @@ msgid "Topics" msgstr "" #: lib/block_scout_web/templates/verified_contracts/_stats.html.eex:9 -#: lib/block_scout_web/templates/verified_contracts/_stats.html.eex:22 +#: lib/block_scout_web/templates/verified_contracts/_stats.html.eex:24 #, elixir-autogen, elixir-format msgid "Total" msgstr "" @@ -2994,7 +2994,7 @@ msgstr "" msgid "Verified" msgstr "" -#: lib/block_scout_web/templates/verified_contracts/_stats.html.eex:18 +#: lib/block_scout_web/templates/verified_contracts/_stats.html.eex:20 #: lib/block_scout_web/templates/verified_contracts/index.html.eex:5 #, elixir-autogen, elixir-format msgid "Verified Contracts" diff --git a/apps/block_scout_web/test/block_scout_web/controllers/verified_contracts_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/verified_contracts_controller_test.exs index dd5327ca7cca..35718edbecae 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/verified_contracts_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/verified_contracts_controller_test.exs @@ -7,7 +7,7 @@ defmodule BlockScoutWeb.VerifiedContractsControllerTest do alias Explorer.Chain.Cache.{ ContractsCounter, - NewContractsCounter, + # NewContractsCounter, NewVerifiedContractsCounter, VerifiedContractsCounter } @@ -16,8 +16,9 @@ defmodule BlockScoutWeb.VerifiedContractsControllerTest do test "returns 200", %{conn: conn} do start_supervised!(ContractsCounter) ContractsCounter.consolidate() - start_supervised!(NewContractsCounter) - NewContractsCounter.consolidate() + # celo: disable new contracts count + # start_supervised!(NewContractsCounter) + # NewContractsCounter.consolidate() start_supervised!(NewVerifiedContractsCounter) NewVerifiedContractsCounter.consolidate() start_supervised!(VerifiedContractsCounter) diff --git a/apps/explorer/lib/explorer/application.ex b/apps/explorer/lib/explorer/application.ex index a0729dfc672f..9c6b220f7e8d 100644 --- a/apps/explorer/lib/explorer/application.ex +++ b/apps/explorer/lib/explorer/application.ex @@ -98,7 +98,8 @@ defmodule Explorer.Application do configure(Explorer.Market.History.Cataloger), configure(Explorer.Chain.Cache.TokenExchangeRate), configure(Explorer.Chain.Cache.ContractsCounter), - configure(Explorer.Chain.Cache.NewContractsCounter), + # celo: disable new contract count + # configure(Explorer.Chain.Cache.NewContractsCounter), configure(Explorer.Chain.Cache.VerifiedContractsCounter), configure(Explorer.Chain.Cache.NewVerifiedContractsCounter), configure(Explorer.Chain.Transaction.History.Historian), diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 2ac86657e764..b1df4b4af82e 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -80,7 +80,7 @@ defmodule Explorer.Chain do BlockNumber, Blocks, ContractsCounter, - NewContractsCounter, + # NewContractsCounter, celo: disable new contracts counter NewVerifiedContractsCounter, Transactions, Uncles, @@ -1428,7 +1428,10 @@ defmodule Explorer.Chain do address_verified_twin_contract_updated = address_verified_twin_contract |> Map.put(:address_hash, hash) - |> Map.put_new(:metadata_from_verified_twin, true) + |> Map.put(:metadata_from_verified_twin, true) + |> Map.put(:implementation_address_hash, nil) + |> Map.put(:implementation_name, nil) + |> Map.put(:implementation_fetched_at, nil) address_result |> Map.put(:smart_contract, address_verified_twin_contract_updated) @@ -1963,7 +1966,10 @@ defmodule Explorer.Chain do address_verified_twin_contract_updated = address_verified_twin_contract |> Map.put(:address_hash, hash) - |> Map.put_new(:metadata_from_verified_twin, true) + |> Map.put(:metadata_from_verified_twin, true) + |> Map.put(:implementation_address_hash, nil) + |> Map.put(:implementation_name, nil) + |> Map.put(:implementation_fetched_at, nil) address_result |> Map.put(:smart_contract, address_verified_twin_contract_updated) @@ -4575,9 +4581,10 @@ defmodule Explorer.Chain do if address_verified_twin_contract do address_verified_twin_contract |> Map.put(:address_hash, address_hash) - |> Map.put(:implementation_address_hash, current_smart_contract.implementation_address_hash) - |> Map.put(:implementation_name, current_smart_contract.implementation_name) - |> Map.put(:implementation_fetched_at, current_smart_contract.implementation_fetched_at) + |> Map.put(:metadata_from_verified_twin, true) + |> Map.put(:implementation_address_hash, nil) + |> Map.put(:implementation_name, nil) + |> Map.put(:implementation_fetched_at, nil) else current_smart_contract end @@ -7161,7 +7168,8 @@ defmodule Explorer.Chain do end def count_new_contracts_from_cache do - NewContractsCounter.fetch() + 0 + # celo: disable new contract count NewContractsCounter.fetch() end def address_counters(address) do diff --git a/apps/explorer/lib/explorer/chain/smart_contract.ex b/apps/explorer/lib/explorer/chain/smart_contract.ex index 56724590e797..1d60f393dbed 100644 --- a/apps/explorer/lib/explorer/chain/smart_contract.ex +++ b/apps/explorer/lib/explorer/chain/smart_contract.ex @@ -261,6 +261,7 @@ defmodule Explorer.Chain.SmartContract do field(:implementation_address_hash, Hash.Address, default: nil) field(:autodetect_constructor_args, :boolean, virtual: true) field(:is_yul, :boolean, virtual: true) + field(:metadata_from_verified_twin, :boolean, virtual: true) has_many( :decompiled_smart_contracts, @@ -529,7 +530,11 @@ defmodule Explorer.Chain.SmartContract do def proxy_contract?(_), do: false - def get_implementation_address_hash(%__MODULE__{abi: nil}), do: false + def get_implementation_address_hash(%__MODULE__{abi: nil}), do: {nil, nil} + + def get_implementation_address_hash(%__MODULE__{metadata_from_verified_twin: true} = smart_contract) do + get_implementation_address_hash({:updated, smart_contract}) + end def get_implementation_address_hash( %__MODULE__{ @@ -540,7 +545,7 @@ defmodule Explorer.Chain.SmartContract do updated_smart_contract = if Application.get_env(:explorer, :enable_caching_implementation_data_of_proxy) && check_implementation_refetch_neccessity(implementation_fetched_at) do - Chain.address_hash_to_smart_contract(address_hash) + Chain.address_hash_to_smart_contract_without_twin(address_hash) else smart_contract end @@ -555,11 +560,13 @@ defmodule Explorer.Chain.SmartContract do abi: abi, implementation_address_hash: implementation_address_hash_from_db, implementation_name: implementation_name_from_db, - implementation_fetched_at: implementation_fetched_at + implementation_fetched_at: implementation_fetched_at, + metadata_from_verified_twin: metadata_from_verified_twin }} ) do if check_implementation_refetch_neccessity(implementation_fetched_at) do - get_implementation_address_hash_task = Task.async(fn -> get_implementation_address_hash(address_hash, abi) end) + get_implementation_address_hash_task = + Task.async(fn -> get_implementation_address_hash(address_hash, abi, metadata_from_verified_twin) end) timeout = Application.get_env(:explorer, :implementation_data_fetching_timeout) @@ -624,8 +631,9 @@ defmodule Explorer.Chain.SmartContract do end end - @spec get_implementation_address_hash(Hash.Address.t(), list()) :: {String.t() | nil, String.t() | nil} - defp get_implementation_address_hash(proxy_address_hash, abi) + @spec get_implementation_address_hash(Hash.Address.t(), list(), boolean() | nil) :: + {String.t() | nil, String.t() | nil} + defp get_implementation_address_hash(proxy_address_hash, abi, metadata_from_verified_twin) when not is_nil(proxy_address_hash) and not is_nil(abi) do implementation_method_abi = abi @@ -651,10 +659,10 @@ defmodule Explorer.Chain.SmartContract do get_implementation_address_hash_eip_1967(proxy_address_hash) end - save_implementation_data(implementation_address, proxy_address_hash) + save_implementation_data(implementation_address, proxy_address_hash, metadata_from_verified_twin) end - defp get_implementation_address_hash(proxy_address_hash, abi) when is_nil(proxy_address_hash) or is_nil(abi) do + defp get_implementation_address_hash(_proxy_address_hash, _abi, _) do {nil, nil} end @@ -794,28 +802,30 @@ defmodule Explorer.Chain.SmartContract do abi_decode_address_output(implementation_address) end - defp save_implementation_data(nil, _), do: {nil, nil} + defp save_implementation_data(nil, _, _), do: {nil, nil} - defp save_implementation_data(empty_address_hash_string, proxy_address_hash) + defp save_implementation_data(empty_address_hash_string, proxy_address_hash, metadata_from_verified_twin) when empty_address_hash_string in [ "0x", "0x0", "0x0000000000000000000000000000000000000000000000000000000000000000", @burn_address_hash_str ] do - proxy_address_hash - |> Chain.address_hash_to_smart_contract_without_twin() - |> changeset(%{ - implementation_name: nil, - implementation_address_hash: nil, - implementation_fetched_at: DateTime.utc_now() - }) - |> Repo.update() + if is_nil(metadata_from_verified_twin) or !metadata_from_verified_twin do + proxy_address_hash + |> Chain.address_hash_to_smart_contract_without_twin() + |> changeset(%{ + implementation_name: nil, + implementation_address_hash: nil, + implementation_fetched_at: DateTime.utc_now() + }) + |> Repo.update() + end {:empty, :empty} end - defp save_implementation_data(implementation_address_hash_string, proxy_address_hash) + defp save_implementation_data(implementation_address_hash_string, proxy_address_hash, _) when is_binary(implementation_address_hash_string) do with {:ok, address_hash} <- Chain.string_to_address_hash(implementation_address_hash_string), proxy_contract <- Chain.address_hash_to_smart_contract_without_twin(proxy_address_hash), @@ -845,6 +855,12 @@ defmodule Explorer.Chain.SmartContract do {implementation_address_hash_string, nil} + true -> + {:ok, address_hash} = Chain.string_to_address_hash(implementation_address_hash_string) + smart_contract = Chain.address_hash_to_smart_contract(address_hash) + + {implementation_address_hash_string, smart_contract && smart_contract.name} + _ -> {implementation_address_hash_string, nil} end diff --git a/apps/explorer/lib/explorer/graphql.ex b/apps/explorer/lib/explorer/graphql.ex index 1ecba32bb683..c1733a86fa28 100644 --- a/apps/explorer/lib/explorer/graphql.ex +++ b/apps/explorer/lib/explorer/graphql.ex @@ -232,8 +232,9 @@ defmodule Explorer.GraphQL do ) end - def token_txtransfers_query_for_address(address_hash, first) do - tt_limit = first * 2 + def token_txtransfers_query_for_address(address_hash, offset, limit) do + page = floor(offset / limit) + 1 + growing_limit = limit * (page + 1) tokens = from( @@ -254,8 +255,7 @@ defmodule Explorer.GraphQL do desc: tt.from_address_hash, desc: tt.to_address_hash ], - limit: ^tt_limit, - offset: 0 + limit: ^growing_limit ) from( @@ -282,8 +282,7 @@ defmodule Explorer.GraphQL do input: tx.input, nonce: tx.nonce, block_number: tt.block_number - }, - limit: ^first + } ) |> order_by([transaction: t], desc: t.block_number, @@ -425,7 +424,7 @@ defmodule Explorer.GraphQL do nonce: tx.nonce, block_number: tt.block_number, token_type: token.type, - token_id: tt.token_id + token_id: fragment("COALESCE(?, (COALESCE(?, ARRAY[]::Decimal[]))[1])", tt.token_id, tt.token_ids) }, order_by: [desc: tt.block_number, desc: tt.amount, desc: tt.log_index] ) diff --git a/apps/explorer/test/explorer/chain/cache/new_contracts_counter_test.exs b/apps/explorer/test/explorer/chain/cache/new_contracts_counter_test.exs index b21d87d42013..b5adb69f308f 100644 --- a/apps/explorer/test/explorer/chain/cache/new_contracts_counter_test.exs +++ b/apps/explorer/test/explorer/chain/cache/new_contracts_counter_test.exs @@ -4,6 +4,8 @@ defmodule Explorer.Chain.Cache.NewContractsCounterTest do alias Explorer.Chain.Cache.NewContractsCounter alias Explorer.Chain + # celo: disabling new contract count + @tag :skip test "populates the cache with the number of new contracts (last 24h)" do :transaction |> insert(created_contract_code_indexed_at: Timex.shift(Timex.now(), hours: -1)) diff --git a/apps/explorer/test/explorer/chain/smart_contract_test.exs b/apps/explorer/test/explorer/chain/smart_contract_test.exs index 38ff09e3b1e3..b0744f9d8328 100644 --- a/apps/explorer/test/explorer/chain/smart_contract_test.exs +++ b/apps/explorer/test/explorer/chain/smart_contract_test.exs @@ -136,6 +136,165 @@ defmodule Explorer.Chain.SmartContractTest do verify!(EthereumJSONRPC.Mox) assert_empty_implementation(smart_contract.address_hash) end + + test "test get_implementation_adddress_hash/1 for twins contract" do + # return nils for nil + assert {nil, nil} = SmartContract.get_implementation_address_hash(nil) + smart_contract = insert(:smart_contract) + another_address = insert(:contract_address) + + twin = Chain.address_hash_to_smart_contract(another_address.hash) + implementation_smart_contract = insert(:smart_contract, name: "proxy") + + Application.put_env(:explorer, :fallback_ttl_cached_implementation_data_of_proxy, :timer.seconds(20)) + Application.put_env(:explorer, :implementation_data_fetching_timeout, :timer.seconds(20)) + + # fetch nil implementation + get_eip1967_implementation_zero_addresses() + assert {nil, nil} = SmartContract.get_implementation_address_hash(twin) + verify!(EthereumJSONRPC.Mox) + assert_implementation_never_fetched(smart_contract.address_hash) + + get_eip1967_implementation_zero_addresses() + assert {nil, nil} = SmartContract.get_implementation_address_hash(twin) + verify!(EthereumJSONRPC.Mox) + assert_implementation_never_fetched(smart_contract.address_hash) + + string_implementation_address_hash = to_string(implementation_smart_contract.address_hash) + + expect(EthereumJSONRPC.Mox, :json_rpc, fn %{ + id: 0, + method: "eth_getStorageAt", + params: [ + _, + "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc", + "latest" + ] + }, + _options -> + {:ok, string_implementation_address_hash} + end) + + assert {^string_implementation_address_hash, "proxy"} = SmartContract.get_implementation_address_hash(twin) + + verify!(EthereumJSONRPC.Mox) + + assert_implementation_never_fetched(smart_contract.address_hash) + + get_eip1967_implementation_error_response() + + assert {nil, nil} = SmartContract.get_implementation_address_hash(twin) + + verify!(EthereumJSONRPC.Mox) + + assert_implementation_never_fetched(smart_contract.address_hash) + + {:ok, addr} = Chain.hash_to_address(another_address.hash) + twin = addr.smart_contract + + implementation_smart_contract = insert(:smart_contract, name: "proxy") + + Application.put_env(:explorer, :fallback_ttl_cached_implementation_data_of_proxy, :timer.seconds(20)) + Application.put_env(:explorer, :implementation_data_fetching_timeout, :timer.seconds(20)) + + # fetch nil implementation + get_eip1967_implementation_zero_addresses() + assert {nil, nil} = SmartContract.get_implementation_address_hash(twin) + verify!(EthereumJSONRPC.Mox) + assert_implementation_never_fetched(smart_contract.address_hash) + + get_eip1967_implementation_zero_addresses() + assert {nil, nil} = SmartContract.get_implementation_address_hash(twin) + verify!(EthereumJSONRPC.Mox) + assert_implementation_never_fetched(smart_contract.address_hash) + + string_implementation_address_hash = to_string(implementation_smart_contract.address_hash) + + expect(EthereumJSONRPC.Mox, :json_rpc, fn %{ + id: 0, + method: "eth_getStorageAt", + params: [ + _, + "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc", + "latest" + ] + }, + _options -> + {:ok, string_implementation_address_hash} + end) + + assert {^string_implementation_address_hash, "proxy"} = SmartContract.get_implementation_address_hash(twin) + + verify!(EthereumJSONRPC.Mox) + + assert_implementation_never_fetched(smart_contract.address_hash) + + get_eip1967_implementation_error_response() + + assert {nil, nil} = SmartContract.get_implementation_address_hash(twin) + + verify!(EthereumJSONRPC.Mox) + + assert_implementation_never_fetched(smart_contract.address_hash) + + {:ok, addr} = + Chain.find_contract_address( + another_address.hash, + [ + necessity_by_association: %{ + :smart_contract => :optional + } + ], + true + ) + + twin = addr.smart_contract + + implementation_smart_contract = insert(:smart_contract, name: "proxy") + + Application.put_env(:explorer, :fallback_ttl_cached_implementation_data_of_proxy, :timer.seconds(20)) + Application.put_env(:explorer, :implementation_data_fetching_timeout, :timer.seconds(20)) + + # fetch nil implementation + get_eip1967_implementation_zero_addresses() + assert {nil, nil} = SmartContract.get_implementation_address_hash(twin) + verify!(EthereumJSONRPC.Mox) + assert_implementation_never_fetched(smart_contract.address_hash) + + get_eip1967_implementation_zero_addresses() + assert {nil, nil} = SmartContract.get_implementation_address_hash(twin) + verify!(EthereumJSONRPC.Mox) + assert_implementation_never_fetched(smart_contract.address_hash) + + string_implementation_address_hash = to_string(implementation_smart_contract.address_hash) + + expect(EthereumJSONRPC.Mox, :json_rpc, fn %{ + id: 0, + method: "eth_getStorageAt", + params: [ + _, + "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc", + "latest" + ] + }, + _options -> + {:ok, string_implementation_address_hash} + end) + + assert {^string_implementation_address_hash, "proxy"} = SmartContract.get_implementation_address_hash(twin) + + verify!(EthereumJSONRPC.Mox) + + assert_implementation_never_fetched(smart_contract.address_hash) + + get_eip1967_implementation_error_response() + + assert {nil, nil} = SmartContract.get_implementation_address_hash(twin) + + verify!(EthereumJSONRPC.Mox) + + assert_implementation_never_fetched(smart_contract.address_hash) + end end def get_eip1967_implementation_zero_addresses do @@ -216,6 +375,13 @@ defmodule Explorer.Chain.SmartContractTest do refute contract.implementation_address_hash end + def assert_implementation_never_fetched(address_hash) do + contract = Chain.address_hash_to_smart_contract(address_hash) + refute contract.implementation_fetched_at + refute contract.implementation_name + refute contract.implementation_address_hash + end + def assert_implementation_address(address_hash) do contract = Chain.address_hash_to_smart_contract(address_hash) assert contract.implementation_fetched_at diff --git a/apps/explorer/test/support/factory.ex b/apps/explorer/test/support/factory.ex index 80a10f5811cb..9ffe69c6d4f1 100644 --- a/apps/explorer/test/support/factory.ex +++ b/apps/explorer/test/support/factory.ex @@ -833,7 +833,8 @@ defmodule Explorer.Factory do def smart_contract_factory do contract_code_info = contract_code_info() - bytecode_md5 = Helper.contract_code_md5(contract_code_info.bytecode) + {:ok, data} = Explorer.Chain.Data.cast(contract_code_info.bytecode) + bytecode_md5 = Helper.contract_code_md5(data.bytes) %SmartContract{ address_hash: insert(:address, contract_code: contract_code_info.bytecode, verified: true).hash,