Skip to content

Commit

Permalink
feat: remove udt name and symbol validation (#1562)
Browse files Browse the repository at this point in the history
Signed-off-by: Miles Zhang <[email protected]>
  • Loading branch information
zmcNotafraid authored Jan 10, 2024
1 parent d30f834 commit e789ecc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
2 changes: 0 additions & 2 deletions app/models/udt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class Udt < ApplicationRecord
omiga_inscription: 4 }

validates_presence_of :total_amount
validates_length_of :symbol, minimum: 1, maximum: 16, allow_nil: true
validates_length_of :full_name, minimum: 1, maximum: 100, allow_nil: true
validates :decimal,
numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 39 }, allow_nil: true
validates :total_amount, numericality: { greater_than_or_equal_to: 0 }
Expand Down
2 changes: 0 additions & 2 deletions app/models/udt_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ class UdtAccount < ApplicationRecord
belongs_to :udt

validates_presence_of :amount
validates_length_of :symbol, minimum: 1, maximum: 16, allow_nil: true
validates_length_of :full_name, minimum: 1, maximum: 100, allow_nil: true
validates :decimal,
numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 39 }, allow_nil: true
validates :amount, numericality: { greater_than_or_equal_to: 0 }
Expand Down
2 changes: 0 additions & 2 deletions test/models/udt_account_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ class UdtAccountTest < ActiveSupport::TestCase
should validate_presence_of(:amount)
should validate_numericality_of(:decimal).allow_nil.is_greater_than_or_equal_to(0).is_less_than_or_equal_to(39)
should validate_numericality_of(:amount).is_greater_than_or_equal_to(0)
should validate_length_of(:symbol).allow_nil.is_at_least(1).is_at_most(16)
should validate_length_of(:full_name).allow_nil.is_at_least(1).is_at_most(100)
end
end
22 changes: 10 additions & 12 deletions test/models/udt_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ class UdtTest < ActiveSupport::TestCase
should validate_presence_of(:total_amount)
should validate_numericality_of(:decimal).allow_nil.is_greater_than_or_equal_to(0).is_less_than_or_equal_to(39)
should validate_numericality_of(:total_amount).is_greater_than_or_equal_to(0)
should validate_length_of(:symbol).allow_nil.is_at_least(1).is_at_most(16)
should validate_length_of(:full_name).allow_nil.is_at_least(1).is_at_most(100)
end

test "should return node type script when the udt is published" do
udt = create(:udt, published: true)
node_type_script = {
args: udt.args,
code_hash: udt.code_hash,
hash_type: udt.hash_type
hash_type: udt.hash_type,
}

assert_equal node_type_script, udt.type_script
Expand All @@ -32,19 +30,19 @@ class UdtTest < ActiveSupport::TestCase
30.times do |number|
block = create(:block, :with_block_hash)
if number % 2 == 0
tx = create(:ckb_transaction, block: block, tags: ["udt"], contained_udt_ids: [udt.id],
tx = create(:ckb_transaction, block:, tags: ["udt"], contained_udt_ids: [udt.id],
contained_address_ids: [address.id])
create(:cell_output, block: block, ckb_transaction: tx, cell_type: "udt", type_hash: udt.type_hash,
address: address)
create(:cell_output, block:, ckb_transaction: tx, cell_type: "udt", type_hash: udt.type_hash,
address:)
else
tx = create(:ckb_transaction, block: block, tags: ["udt"], contained_udt_ids: [udt.id],
tx = create(:ckb_transaction, block:, tags: ["udt"], contained_udt_ids: [udt.id],
contained_address_ids: [address.id])
tx1 = create(:ckb_transaction, block: block, tags: ["udt"], contained_udt_ids: [udt.id],
tx1 = create(:ckb_transaction, block:, tags: ["udt"], contained_udt_ids: [udt.id],
contained_address_ids: [address.id])
create(:cell_output, block: block, ckb_transaction: tx1, cell_type: "udt", type_hash: udt.type_hash,
address: address)
create(:cell_output, block: block, ckb_transaction: tx, cell_type: "udt", type_hash: udt.type_hash,
consumed_by_id: tx1, address: address)
create(:cell_output, block:, ckb_transaction: tx1, cell_type: "udt", type_hash: udt.type_hash,
address:)
create(:cell_output, block:, ckb_transaction: tx, cell_type: "udt", type_hash: udt.type_hash,
consumed_by_id: tx1, address:)
end
end

Expand Down

0 comments on commit e789ecc

Please sign in to comment.