diff --git a/CHANGELOG.md b/CHANGELOG.md index d65bd7343e..96fd28fc08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,7 +39,7 @@ ### Chore - [#7699](https://github.com/blockscout/blockscout/pull/7699) - Add block_number index for address_coin_balances table -- [#7666](https://github.com/blockscout/blockscout/pull/7666), [#7740](https://github.com/blockscout/blockscout/pull/7740) - Search label query +- [#7666](https://github.com/blockscout/blockscout/pull/7666), [#7740](https://github.com/blockscout/blockscout/pull/7740), [#7741](https://github.com/blockscout/blockscout/pull/7741) - Search label query - [#7644](https://github.com/blockscout/blockscout/pull/7644) - Publish docker images CI for prod/staging branches - [#7594](https://github.com/blockscout/blockscout/pull/7594) - Stats service support in docker-compose config with new frontend - [#7576](https://github.com/blockscout/blockscout/pull/7576) - Check left blocks in pending block operations in order to decide, if we need to display indexing int tx banner at the top diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/v2/search_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/v2/search_controller_test.exs index 82d9e08f84..0f483454a4 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/v2/search_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/v2/search_controller_test.exs @@ -143,6 +143,23 @@ defmodule BlockScoutWeb.API.V2.SearchControllerTest do assert item["tx_hash"] == to_string(tx.hash) assert item["url"] =~ to_string(tx.hash) end + + test "search tags", %{conn: conn} do + tag = insert(:address_to_tag) + + request = get(conn, "/api/v2/search?q=#{tag.tag.display_name}") + assert response = json_response(request, 200) + + assert Enum.count(response["items"]) == 1 + assert response["next_page_params"] == nil + + item = Enum.at(response["items"], 0) + + assert item["type"] == "label" + assert item["address"] == Address.checksum(tag.address.hash) + assert item["name"] == tag.tag.display_name + assert item["url"] =~ Address.checksum(tag.address.hash) + end end describe "/search/check-redirect" do diff --git a/apps/explorer/lib/explorer/tags/address_tag.ex b/apps/explorer/lib/explorer/tags/address_tag.ex index 6174235608..cfb61d3324 100644 --- a/apps/explorer/lib/explorer/tags/address_tag.ex +++ b/apps/explorer/lib/explorer/tags/address_tag.ex @@ -12,14 +12,13 @@ defmodule Explorer.Tags.AddressTag do from: 2 ] - alias Explorer.Chain.Address alias Explorer.Repo alias Explorer.Tags.{AddressTag, AddressToTag} @typedoc """ * `:id` - id of Tag * `:label` - Tag's label - * `:label` - Label's display name + * `:display_name` - Label's display name """ @type t :: %AddressTag{ label: String.t() @@ -28,7 +27,6 @@ defmodule Explorer.Tags.AddressTag do schema "address_tags" do field(:label, :string) field(:display_name, :string) - has_many(:addresses, Address, foreign_key: :hash) has_many(:tag_id, AddressToTag, foreign_key: :id) timestamps() diff --git a/apps/explorer/test/support/factory.ex b/apps/explorer/test/support/factory.ex index 0c2004ba7a..c05d0f7077 100644 --- a/apps/explorer/test/support/factory.ex +++ b/apps/explorer/test/support/factory.ex @@ -44,7 +44,7 @@ defmodule Explorer.Factory do } alias Explorer.SmartContract.Helper - + alias Explorer.Tags.{AddressTag, AddressToTag} alias Explorer.Market.MarketHistory alias Explorer.Repo @@ -140,6 +140,16 @@ defmodule Explorer.Factory do %{"name" => sequence("name"), "transaction_hash" => to_string(insert(:transaction).hash)} end + def address_to_tag_factory do + %AddressToTag{ + tag: %AddressTag{ + label: sequence("label"), + display_name: sequence("display_name") + }, + address: build(:address) + } + end + def account_watchlist_address_factory do hash = build(:address).hash