Skip to content

Commit

Permalink
Add possibility to search tokens by address hash (blockscout#8768)
Browse files Browse the repository at this point in the history
* Add possibility to search tokens by address hash

* Changelog + remove dbg calls

* Refactor searching queries set of selected fields

* Final polishing

---------

Co-authored-by: Viktor Baranov <[email protected]>
  • Loading branch information
nikitosing and vbaranov authored Nov 9, 2023
1 parent f9d5377 commit 150533e
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 150 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Features

- [#8795](https://github.com/blockscout/blockscout/pull/8795) - Disable catchup indexer by env
- [#8768](https://github.com/blockscout/blockscout/pull/8768) - Add possibility to search tokens by address hash
- [#8750](https://github.com/blockscout/blockscout/pull/8750) - Support new eth-bytecode-db request metadata fields
- [#8609](https://github.com/blockscout/blockscout/pull/8609) - Change logs format to JSON; Add endpoint url to the block_scout_web logging

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ defmodule BlockScoutWeb.Account.Api.V1.UserControllerTest do

response_1 =
conn
|> get("/api/account/v2/user/watchlist", response["next_page_params"] |> dbg())
|> get("/api/account/v2/user/watchlist", response["next_page_params"])
|> json_response(200)

check_paginated_response(response, response_1, tags_address)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule BlockScoutWeb.API.V2.SearchControllerTest do

alias Explorer.Chain.{Address, Block}
alias Explorer.Repo
alias Explorer.Tags.AddressTag

setup do
insert(:block)
Expand Down Expand Up @@ -171,6 +172,35 @@ defmodule BlockScoutWeb.API.V2.SearchControllerTest do
assert item["is_verified_via_admin_panel"] == token.is_verified_via_admin_panel
end

test "search token by hash", %{conn: conn} do
token = insert(:unique_token)

request = get(conn, "/api/v2/search?q=#{token.contract_address_hash}")
assert response = json_response(request, 200)

assert Enum.count(response["items"]) == 2
assert response["next_page_params"] == nil

item = Enum.at(response["items"], 0)

assert item["type"] == "token"
assert item["name"] == token.name
assert item["symbol"] == token.symbol
assert item["address"] == Address.checksum(token.contract_address_hash)
assert item["token_url"] =~ Address.checksum(token.contract_address_hash)
assert item["address_url"] =~ Address.checksum(token.contract_address_hash)
assert item["token_type"] == token.type
assert item["is_smart_contract_verified"] == token.contract_address.verified
assert item["exchange_rate"] == (token.fiat_value && to_string(token.fiat_value))
assert item["total_supply"] == to_string(token.total_supply)
assert item["icon_url"] == token.icon_url
assert item["is_verified_via_admin_panel"] == token.is_verified_via_admin_panel

item_1 = Enum.at(response["items"], 1)

assert item_1["type"] == "address"
end

test "search transaction", %{conn: conn} do
tx = insert(:transaction)

Expand Down Expand Up @@ -222,6 +252,26 @@ defmodule BlockScoutWeb.API.V2.SearchControllerTest do
assert item["url"] =~ Address.checksum(tag.address.hash)
assert item["is_smart_contract_verified"] == tag.address.verified
end

test "check that simultaneous search of ", %{conn: conn} do
block = insert(:block)

insert(:smart_contract, name: to_string(block.number))
insert(:token, name: to_string(block.number))

insert(:address_to_tag,
tag: %AddressTag{
label: "qwerty",
display_name: to_string(block.number)
}
)

request = get(conn, "/api/v2/search?q=#{block.number}")
assert response = json_response(request, 200)

assert Enum.count(response["items"]) == 4
assert response["next_page_params"] == nil
end
end

describe "/search/check-redirect" do
Expand Down
Loading

0 comments on commit 150533e

Please sign in to comment.