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 udt name and symbol validation #1562

Merged
merged 1 commit into from
Jan 10, 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: 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