Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy to testnet #2023

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/controllers/api/v1/xudts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ def index

if params[:tags].present?
tags = parse_tags
scope = scope.joins(:xudt_tag).where("xudt_tags.tags && ARRAY[?]::varchar[]", tags).select("udts.*") unless tags.empty?
if params[:union].present?
scope = scope.joins(:xudt_tag).where("xudt_tags.tags && ARRAY[?]::varchar[]", tags).select("udts.*") unless tags.empty?
else
scope = scope.joins(:xudt_tag).where("xudt_tags.tags @> array[?]::varchar[]", tags).select("udts.*") unless tags.empty?
end
end

if stale?(scope)
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/api/v2/nft/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ def index
end
if params[:tags].present?
tags = parse_tags
scope = scope.where("tags && ARRAY[?]::varchar[]", tags) unless tags.empty?
if params[:union].present?
scope = scope.where("tags && ARRAY[?]::varchar[]", tags) unless tags.empty?
else
scope = scope.where("tags @> array[?]::varchar[]", tags) unless tags.empty?
end
end
pagy, collections = pagy(sort_collections(scope))

Expand Down
13 changes: 12 additions & 1 deletion test/controllers/api/v1/xudts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,23 @@ class XudtsControllerTest < ActionDispatch::IntegrationTest
assert_equal 1, json["data"].length
end

test "filter union xudt by symbol and tags" do
udt = create(:udt, :xudt, symbol: "CKBB")
create(:xudt_tag, udt:, tags: ["duplicate", "layer-1-asset", "supply-limited"])
udt2 = create(:udt, :xudt, symbol: "RPGG")
create(:xudt_tag, udt: udt2, tags: ["duplicate", "layer-2-asset", "supply-limited"])
valid_get api_v1_xudts_url, params: { symbol: "CKBB", tags: "duplicate,supply-limited", union: true }
assert_response :success
assert_equal "CKBB", json["data"].first["attributes"]["symbol"]
assert_equal ["duplicate", "layer-1-asset", "supply-limited"], json["data"].first["attributes"]["xudt_tags"]
end

test "filter xudt by symbol and tags" do
udt = create(:udt, :xudt, symbol: "CKBB")
create(:xudt_tag, udt:, tags: ["duplicate", "layer-1-asset", "supply-limited"])
udt2 = create(:udt, :xudt, symbol: "RPGG")
create(:xudt_tag, udt: udt2, tags: ["duplicate", "layer-2-asset", "supply-limited"])
valid_get api_v1_xudts_url, params: { symbol: "CKBB", "tags": "duplicate,supply-limited" }
valid_get api_v1_xudts_url, params: { symbol: "CKBB", tags: "layer-1-asset,supply-limited,NOT EXIST" }
assert_response :success
assert_equal "CKBB", json["data"].first["attributes"]["symbol"]
assert_equal ["duplicate", "layer-1-asset", "supply-limited"], json["data"].first["attributes"]["xudt_tags"]
Expand Down
13 changes: 11 additions & 2 deletions test/controllers/api/v2/nft/collections_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@ class NFT::CollectionsControllerTest < ActionDispatch::IntegrationTest
assert_equal ["invalid"], JSON.parse(response.body)["data"].last["tags"]
end

test "should filter by tags" do
test "should filter by union tags" do
create :token_collection, name: "token1", tags: ["layer-1-asset", "rgbpp-compatible"]
create :token_collection, name: "token2", tags: ["layer-1-asset", "rgbpp-compatible"]

get api_v2_nft_collections_url, params: { tags: "layer-1-asset,rgbpp-compatible" }
get api_v2_nft_collections_url, params: { tags: "layer-1-asset,rgbpp-compatible", union: true }
assert_response :success
assert_equal JSON.parse(response.body)["data"].size, 2
end

test "should filter by tags but not match" do
create :token_collection, name: "token1", tags: ["layer-1-asset", "rgbpp-compatible"]
create :token_collection, name: "token2", tags: ["layer-1-asset", "rgbpp-compatible"]

get api_v2_nft_collections_url, params: { tags: "layer-1-asset,invalid" }
assert_response :success
assert_equal JSON.parse(response.body)["data"].size, 0
end

test "sort by block_timestamp asc" do
block1 = create(:block, :with_block_hash, timestamp: 10.days.ago.to_i * 1000)
block3 = create(:block, :with_block_hash, timestamp: 1.day.ago.to_i * 1000)
Expand Down
Loading