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

feat: remove unnamed tag #2181

Merged
merged 1 commit into from
Sep 9, 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
2 changes: 1 addition & 1 deletion app/models/xudt_tag.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class XudtTag < ApplicationRecord
belongs_to :udt

VALID_TAGS = ["unnamed", "invalid", "suspicious", "out-of-length-range", "rgb++", "layer-1-asset", "supply-limited", "utility", "layer-2-asset", "supply-unlimited"]
VALID_TAGS = ["invalid", "suspicious", "out-of-length-range", "rgb++", "layer-1-asset", "supply-limited", "utility", "layer-2-asset", "supply-unlimited"]
end

# == Schema Information
Expand Down
10 changes: 4 additions & 6 deletions app/workers/xudt_tag_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ def perform
end

def mark_tags(udt)
if udt.symbol.blank?
["unnamed"]
elsif invalid_char?(udt.symbol)
if invalid_char?(udt.symbol)
["invalid"]
elsif invisible_char?(udt.symbol)
["suspicious"]
Expand All @@ -36,15 +34,15 @@ def mark_tags(udt)
end

def invalid_char?(symbol)
!symbol.ascii_only?
symbol.present? && !symbol.ascii_only?
end

def invisible_char?(symbol)
(symbol =~ /^[\x21-\x7E]+(?:\s[\x21-\x7E]+)?$/).nil?
symbol.present? && (symbol =~ /^[\x21-\x7E]+(?:\s[\x21-\x7E]+)?$/).nil?
end

def out_of_length?(symbol)
symbol.length > 60
symbol.present? && symbol.length > 60
end

def rgbpp_lock?(issuer_address)
Expand Down
10 changes: 1 addition & 9 deletions test/workers/xudt_tag_worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,12 @@ class XudtTagWorkerTest < ActiveJob::TestCase
@address = create(:address, address_hash: "ckb1qz7xc452rgxs5z0ks3xun46dmdp58sepg0ljtae8ck0d7nah945nvqgqqqqqqx3l3v4")
end

test "add tag to xudt compatible" do
create(:udt, :xudt_compatible, symbol: nil)
assert_changes -> { XudtTag.count }, from: 0, to: 1 do
XudtTagWorker.new.perform
end
assert_equal ["unnamed"], XudtTag.last.tags
end

test "when xudt with no symbol" do
create(:udt, :xudt, symbol: nil)
assert_changes -> { XudtTag.count }, from: 0, to: 1 do
XudtTagWorker.new.perform
end
assert_equal ["unnamed", "rgb++"], XudtTag.last.tags
assert_equal ["rgb++", "layer-2-asset", "supply-unlimited"], XudtTag.last.tags
end

test "insert to xudt_tags successfully" do
Expand Down
Loading