chore: remove `has_methods` from `/addresses` (#10051)

* chore: remove `has_methods_` `read`/`read_proxy`/`write`/`write_proxy` from `/addresses`

* chore: move proxy contract test to `smart_contract_controller_test.exs`
pull/10059/head
Fedor Ivanov 6 months ago committed by GitHub
parent 2dd96493bd
commit 6fa60b4e4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      apps/block_scout_web/lib/block_scout_web/views/api/v2/address_view.ex
  2. 6
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/address_controller_test.exs
  3. 27
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/smart_contract_controller_test.exs
  4. 31
      apps/block_scout_web/test/block_scout_web/views/api/v2/address_view_test.exs

@ -122,9 +122,6 @@ defmodule BlockScoutWeb.API.V2.AddressView do
creation_tx = creator_hash && AddressView.transaction_hash(address)
token = address.token && TokenView.render("token.json", %{token: address.token})
write_custom_abi? = AddressView.has_address_custom_abi_with_write_functions?(conn, address.hash)
read_custom_abi? = AddressView.has_address_custom_abi_with_read_functions?(conn, address.hash)
# todo: added for backward compatibility, remove when frontend unbound from these props
{implementation_address, implementation_name} =
single_implementation(implementation_addresses, implementation_names)
@ -141,13 +138,6 @@ defmodule BlockScoutWeb.API.V2.AddressView do
"implementation_address" => implementation_address,
"implementation_addresses" => implementation_addresses,
"block_number_balance_updated_at" => address.fetched_coin_balance_block_number,
"has_custom_methods_read" => read_custom_abi?,
"has_custom_methods_write" => write_custom_abi?,
"has_methods_read" => AddressView.smart_contract_with_read_only_functions?(address),
"has_methods_write" => AddressView.smart_contract_with_write_functions?(address),
"has_methods_read_proxy" => is_proxy,
"has_methods_write_proxy" =>
AddressView.smart_contract_with_write_functions?(address_with_smart_contract) && is_proxy,
"has_decompiled_code" => AddressView.has_decompiled_code?(address),
"has_validated_blocks" => Counters.check_if_validated_blocks_at_address(address.hash, @api_true),
"has_logs" => Counters.check_if_logs_at_address(address.hash, @api_true),

@ -78,12 +78,6 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do
"implementation_address" => nil,
"implementation_addresses" => [],
"block_number_balance_updated_at" => nil,
"has_custom_methods_read" => false,
"has_custom_methods_write" => false,
"has_methods_read" => false,
"has_methods_write" => false,
"has_methods_read_proxy" => false,
"has_methods_write_proxy" => false,
"has_decompiled_code" => false,
"has_validated_blocks" => false,
"has_logs" => false,

@ -67,6 +67,33 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do
}
end
test "get an eip1967 proxy contract", %{conn: conn} do
implementation_address = insert(:contract_address)
proxy_address = insert(:contract_address)
_proxy_smart_contract =
insert(:smart_contract,
address_hash: proxy_address.hash,
contract_code_md5: "123"
)
implementation =
insert(:proxy_implementation,
proxy_address_hash: proxy_address.hash,
proxy_type: "eip1967",
address_hashes: [implementation_address.hash],
names: [nil]
)
assert implementation.proxy_type == :eip1967
request = get(conn, "/api/v2/smart-contracts/#{Address.checksum(proxy_address.hash)}")
response = json_response(request, 200)
assert response["has_methods_read_proxy"] == true
assert response["has_methods_write_proxy"] == true
end
test "get smart-contract", %{conn: conn} do
lib_address = build(:address)
lib_address_string = to_string(lib_address)

@ -1,31 +0,0 @@
defmodule BlockScoutWeb.API.V2.AddressViewTest do
use BlockScoutWeb.ConnCase, async: true
alias BlockScoutWeb.API.V2.AddressView
alias Explorer.{Repo, TestHelper}
test "for a proxy contract has_methods_read_proxy is true" do
implementation_address = insert(:contract_address)
proxy_address = insert(:contract_address) |> Repo.preload([:token])
_proxy_smart_contract =
insert(:smart_contract,
address_hash: proxy_address.hash,
contract_code_md5: "123"
)
implementation =
insert(:proxy_implementation,
proxy_address_hash: proxy_address.hash,
proxy_type: "eip1967",
address_hashes: [implementation_address.hash],
names: [nil]
)
assert implementation.proxy_type == :eip1967
TestHelper.get_eip1967_implementation_zero_addresses()
assert AddressView.prepare_address(proxy_address)["has_methods_read_proxy"] == true
end
end
Loading…
Cancel
Save