From 449fd8e4a2597dbef0c5493469c2e22268f87673 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Mon, 26 Aug 2024 15:14:03 +0800 Subject: [PATCH] feat: xudt tag length must less than 60 (#2146) Signed-off-by: Miles Zhang --- app/workers/xudt_tag_worker.rb | 4 ++-- test/factories/udt.rb | 6 +++++- test/workers/xudt_tag_worker_test.rb | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/workers/xudt_tag_worker.rb b/app/workers/xudt_tag_worker.rb index be35c1be8..b47bf491e 100644 --- a/app/workers/xudt_tag_worker.rb +++ b/app/workers/xudt_tag_worker.rb @@ -2,7 +2,7 @@ class XudtTagWorker include Sidekiq::Job def perform - udts = Udt.published_xudt.left_joins(:xudt_tag).where(xudt_tag: { id: nil }).limit(100) + udts = Udt.published_xudt.left_joins(:xudt_tag).where(xudt_tag: { id: nil }).where.not(issuer_address: nil).limit(100) if !udts.empty? attrs = udts.map do |udt| @@ -46,7 +46,7 @@ def invisible_char?(symbol) end def out_of_length?(symbol) - symbol.length > 5 || symbol.length < 4 + symbol.length > 60 end def first_xudt?(symbol, block_timestamp) diff --git a/test/factories/udt.rb b/test/factories/udt.rb index 094165fdc..210ed5861 100644 --- a/test/factories/udt.rb +++ b/test/factories/udt.rb @@ -9,6 +9,11 @@ symbol { "kfc" } decimal { 6 } h24_ckb_transactions_count { 0 } + issuer_address do + script = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, args: "0x#{SecureRandom.hex(20)}", + hash_type: "type") + CKB::Address.new(script).generate + end trait :with_transactions do after(:create) do |udt, _evaluator| @@ -71,6 +76,5 @@ symbol { "XC" } decimal { 8 } end - end end diff --git a/test/workers/xudt_tag_worker_test.rb b/test/workers/xudt_tag_worker_test.rb index d590969ba..bd6577b94 100644 --- a/test/workers/xudt_tag_worker_test.rb +++ b/test/workers/xudt_tag_worker_test.rb @@ -48,7 +48,7 @@ class XudtTagWorkerTest < ActiveJob::TestCase end test "insert out-of-length-range tag" do - create(:udt, :xudt, symbol: "CK BBBB") + create(:udt, :xudt, symbol: "CKBBBB" * 11) assert_changes -> { XudtTag.count }, from: 0, to: 1 do XudtTagWorker.new.perform end