Fix is_verified for /addresses and /smart-contracts

pull/8678/head
Nikita Pozdniakov 1 year ago
parent c406eb93d7
commit 7cb58ecf15
No known key found for this signature in database
GPG Key ID: F344106F9804FE5F
  1. 8
      apps/block_scout_web/lib/block_scout_web/views/api/v2/smart_contract_view.ex
  2. 11
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/address_controller_test.exs
  3. 2
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/smart_contract_controller_test.exs
  4. 2
      apps/explorer/lib/explorer/chain.ex

@ -257,7 +257,13 @@ defmodule BlockScoutWeb.API.V2.SmartContractView do
token = smart_contract.address.token token = smart_contract.address.token
%{ %{
"address" => Helper.address_with_info(nil, smart_contract.address, smart_contract.address.hash, false), "address" =>
Helper.address_with_info(
nil,
%Address{smart_contract.address | smart_contract: smart_contract},
smart_contract.address.hash,
false
),
"compiler_version" => smart_contract.compiler_version, "compiler_version" => smart_contract.compiler_version,
"optimization_enabled" => smart_contract.optimization, "optimization_enabled" => smart_contract.optimization,
"tx_count" => smart_contract.address.transactions_count, "tx_count" => smart_contract.address.transactions_count,

@ -1668,6 +1668,17 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do
compare_item(address, address_json) compare_item(address, address_json)
end end
test "check smart contract preload", %{conn: conn} do
smart_contract = insert(:smart_contract, address_hash: insert(:contract_address, fetched_coin_balance: 1).hash)
request = get(conn, "/api/v2/addresses")
assert %{"items" => [address]} = json_response(request, 200)
assert String.downcase(address["hash"]) == to_string(smart_contract.address_hash)
assert address["is_contract"] == true
assert address["is_verified"] == true
end
end end
describe "/addresses/{address_hash}/tabs-counters" do describe "/addresses/{address_hash}/tabs-counters" do

@ -2375,6 +2375,8 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do
assert %{"items" => [sc], "next_page_params" => nil} = json_response(request, 200) assert %{"items" => [sc], "next_page_params" => nil} = json_response(request, 200)
compare_item(smart_contract, sc) compare_item(smart_contract, sc)
assert sc["address"]["is_verified"] == true
assert sc["address"]["is_contract"] == true
end end
test "check pagination", %{conn: conn} do test "check pagination", %{conn: conn} do

@ -2062,7 +2062,7 @@ defmodule Explorer.Chain do
from(a in Address, from(a in Address,
where: a.fetched_coin_balance > ^0, where: a.fetched_coin_balance > ^0,
order_by: [desc: a.fetched_coin_balance, asc: a.hash], order_by: [desc: a.fetched_coin_balance, asc: a.hash],
preload: [:names], preload: [:names, :smart_contract],
select: {a, fragment("coalesce(1 + ?, 0)", a.nonce)} select: {a, fragment("coalesce(1 + ?, 0)", a.nonce)}
) )

Loading…
Cancel
Save