Skip to content

Commit

Permalink
feat: add missing attribute for cell output (#1624)
Browse files Browse the repository at this point in the history
Signed-off-by: Miles Zhang <[email protected]>
  • Loading branch information
zmcNotafraid authored Feb 7, 2024
1 parent 11621ff commit 8bb8267
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 36 deletions.
2 changes: 1 addition & 1 deletion app/models/cell_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def nrc_721_nft_info
type_hash:,
published: factory_cell&.verified,
display_name: factory_cell&.name,
nan: "",
uan: "",
}
when "nrc_721_token"
udt = Udt.find_by(type_hash:)
Expand Down
18 changes: 12 additions & 6 deletions app/serializers/cell_output_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ class CellOutputSerializer

attributes :cell_type, :tx_hash, :cell_index, :type_hash, :data

attribute :block_number do |object|
object.block.number.to_s
end

attribute :capacity do |object|
object.capacity.to_s
end
Expand All @@ -25,18 +29,20 @@ class CellOutputSerializer

attribute :extra_info do |object|
case object.cell_type
when "normal"
{ type: "ckb", capacity: object.capacity.to_s }
when "udt"
object.udt_info
object.udt_info.merge!(type: "udt")
when "cota_registry"
object.cota_registry_info
object.cota_registry_info.merge!(type: "cota")
when "cota_regular"
object.cota_regular_info
object.cota_regular_info.merge!(type: "cota")
when "m_nft_issuer", "m_nft_class", "m_nft_token"
object.m_nft_info
object.m_nft_info.merge!(type: "m_nft")
when "nrc_721_token", "nrc_721_factory"
object.nrc_721_nft_info
object.nrc_721_nft_info.merge!(type: "nrc_721")
when "omiga_inscription_info", "omiga_inscription"
object.omiga_inscription_info
object.omiga_inscription_info.merge!(type: "omiga_inscription")
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class AddressLiveCellsControllerTest < ActionDispatch::IntegrationTest
valid_get api_v1_address_live_cell_url(address.address_hash)
assert_equal ({ "cell_type" => "omiga_inscription_info",
"tx_hash" => transaction.tx_hash,
"block_number" => block.number.to_s,
"cell_index" => 0,
"type_hash" => info.type_hash,
"data" => "0x0814434b42204669737420496e736372697074696f6e04434b4249a69f54bf339dd121febe64cb0be3a2cf366a8b13ec1a5ae4bebdccb9039c7efa0040075af0750700000000000000000000e8764817000000000000000000000002",
Expand All @@ -65,7 +66,7 @@ class AddressLiveCellsControllerTest < ActionDispatch::IntegrationTest
"hash_type" => "type" },
"lock_script" => { "args" => address_lock.args, "code_hash" => address_lock.code_hash,
"hash_type" => "type" },
"extra_info" => { "symbol" => "CKBI", "name" => "CKB Fist Inscription", "decimal" => "8.0", "amount" => "0" } }),
"extra_info" => { "type" => "omiga_inscription", "symbol" => "CKBI", "name" => "CKB Fist Inscription", "decimal" => "8.0", "amount" => "0" } }),
json["data"].first["attributes"]
end

Expand Down
56 changes: 29 additions & 27 deletions test/models/ckb_transaction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CkbTransactionTest < ActiveSupport::TestCase
CkbSync::Api.any_instance.stubs(:get_block_cycles).returns(
[
"0x100", "0x200", "0x300", "0x400", "0x500", "0x600", "0x700", "0x800", "0x900"
]
],
)
end

Expand All @@ -34,8 +34,8 @@ class CkbTransactionTest < ActiveSupport::TestCase
compact_target: "0x1000",
length: "0x07d0",
number: "0x0",
start_number: "0x0"
)
start_number: "0x0",
),
)
node_block = CkbSync::Api.instance.get_block_by_number(DEFAULT_NODE_BLOCK_NUMBER)
create(:block, :with_block_hash, number: node_block.header.number - 1)
Expand Down Expand Up @@ -116,7 +116,7 @@ class CkbTransactionTest < ActiveSupport::TestCase
prepare_node_data
block = Block.last
ckb_transaction = create(:ckb_transaction, :with_single_output,
is_cellbase: true, block: block)
is_cellbase: true, block:)
expected_attributes = %i(
id capacity occupied_capacity address_hash target_block_number
base_reward commit_reward proposal_reward secondary_reward status consumed_tx_hash
Expand Down Expand Up @@ -154,7 +154,7 @@ class CkbTransactionTest < ActiveSupport::TestCase
ckb_transaction = create(:ckb_transaction,
:with_multiple_inputs_and_outputs)
block = create(:block, :with_block_hash)
consumed_tx = create(:ckb_transaction, block: block)
consumed_tx = create(:ckb_transaction, block:)
ckb_transaction.outputs.update(consumed_by: consumed_tx, status: "dead")

assert_equal ["dead"], ckb_transaction.display_outputs.pluck(:status).uniq
Expand Down Expand Up @@ -211,13 +211,13 @@ class CkbTransactionTest < ActiveSupport::TestCase
compensation_ended_timestamp: ended_block.timestamp,
locked_until_block_number: ckb_transaction.block.number,
locked_until_block_timestamp: ckb_transaction.block.timestamp,
interest: interest,
interest:,
cell_type: nervos_dao_withdrawing_cell.cell_type,
cell_index: nervos_dao_withdrawing_cell.cell_index,
since: {
raw: "0x0000000000000000",
median_timestamp: "0"
}
median_timestamp: "0",
},
).sort
expected_attributes = %i(
id from_cellbase capacity occupied_capacity address_hash generated_tx_hash compensation_started_block_number
Expand All @@ -232,13 +232,13 @@ class CkbTransactionTest < ActiveSupport::TestCase
test "#display_inputs should return dao display input when previous cell type is nervos_dao_deposit" do
DaoCompensationCalculator.any_instance.stubs(:call).returns(100800000000)
block = create(:block, :with_block_hash, timestamp: Time.current.to_i)
ckb_transaction = create(:ckb_transaction, block: block,
ckb_transaction = create(:ckb_transaction, block:,
tx_hash: "0xe8a116ec65f7d2d0d4748ba2bbcf8691cbd31202908ccfa3a975414fef801042")
deposit_output_cell = create(:cell_output, block: ckb_transaction.block,
capacity: 138 * 10**8,
tx_hash: "0xe8a116ec65f7d2d0d4748ba2bbcf8691cbd31202908ccfa3a975414fef801042",
cell_index: 0,
ckb_transaction: ckb_transaction,
ckb_transaction:,
consumed_by: ckb_transaction,
status: "dead",
cell_type: "nervos_dao_deposit",
Expand Down Expand Up @@ -278,13 +278,13 @@ class CkbTransactionTest < ActiveSupport::TestCase
compensation_ended_block_number: ended_block.number,
compensation_started_timestamp: started_block.timestamp,
compensation_ended_timestamp: ended_block.timestamp,
interest: interest,
interest:,
cell_type: deposit_output_cell.cell_type,
cell_index: deposit_output_cell.cell_index,
since: {
raw: "0x0000000000000000",
median_timestamp: "0"
}
median_timestamp: "0",
},
).sort
expected_attributes = %i(
id from_cellbase capacity occupied_capacity address_hash generated_tx_hash interest cell_type
Expand All @@ -309,7 +309,7 @@ class CkbTransactionTest < ActiveSupport::TestCase
).sort
consumed_tx_hash = dao_output.live? ? nil : dao_output.consumed_by.tx_hash
expected_display_output = CkbUtils.hash_value_to_s(id: dao_output.id,
capacity: dao_output.capacity, occupied_capacity: dao_output.occupied_capacity, address_hash: dao_output.address_hash, status: dao_output.status, consumed_tx_hash: consumed_tx_hash, cell_type: dao_output.cell_type).sort
capacity: dao_output.capacity, occupied_capacity: dao_output.occupied_capacity, address_hash: dao_output.address_hash, status: dao_output.status, consumed_tx_hash:, cell_type: dao_output.cell_type).sort
display_outputs = ckb_transaction.display_outputs
assert_equal expected_attributes - display_outputs.first.keys, []
assert_equal expected_display_output, display_outputs.first.sort
Expand Down Expand Up @@ -352,7 +352,7 @@ class CkbTransactionTest < ActiveSupport::TestCase
cell_index: udt_cell_output.cell_index,
cell_type: udt_cell_output.cell_type,
since: { raw: "0x0000000000000000", median_timestamp: "0" },
extra_info: udt_cell_output.udt_info
extra_info: udt_cell_output.udt_info,
)
display_inputs = ckb_transaction.display_inputs
o = display_inputs.first
Expand Down Expand Up @@ -392,7 +392,7 @@ class CkbTransactionTest < ActiveSupport::TestCase
status: udt_cell_output.status,
consumed_tx_hash: nil,
cell_type: udt_cell_output.cell_type,
extra_info: udt_cell_output.udt_info
extra_info: udt_cell_output.udt_info,
)
o = udt_output_transaction.display_outputs.first
assert_equal expected_attributes - o.keys, []
Expand Down Expand Up @@ -434,7 +434,7 @@ class CkbTransactionTest < ActiveSupport::TestCase
cell_index: m_nft_cell_output.cell_index,
cell_type: m_nft_cell_output.cell_type,
since: { raw: "0x0000000000000000", median_timestamp: "0" },
extra_info: m_nft_cell_output.m_nft_info
extra_info: m_nft_cell_output.m_nft_info,
)
display_inputs = ckb_transaction.display_inputs
o = display_inputs.first
Expand Down Expand Up @@ -477,7 +477,7 @@ class CkbTransactionTest < ActiveSupport::TestCase
cell_index: m_nft_cell_output.cell_index,
cell_type: m_nft_cell_output.cell_type,
since: { raw: "0x0000000000000000", median_timestamp: "0" },
extra_info: m_nft_cell_output.m_nft_info
extra_info: m_nft_cell_output.m_nft_info,
)
display_inputs = ckb_transaction.display_inputs
o = display_inputs.first
Expand Down Expand Up @@ -539,9 +539,9 @@ class CkbTransactionTest < ActiveSupport::TestCase
cell_type: m_nft_cell_output.cell_type,
since: {
raw: "0x0000000000000000",
median_timestamp: "0"
median_timestamp: "0",
},
extra_info: m_nft_cell_output.m_nft_info
extra_info: m_nft_cell_output.m_nft_info,
)
display_inputs = ckb_transaction.display_inputs
o = display_inputs.first
Expand Down Expand Up @@ -571,7 +571,7 @@ class CkbTransactionTest < ActiveSupport::TestCase
status: m_nft_cell_output.status,
consumed_tx_hash: nil,
cell_type: m_nft_cell_output.cell_type,
extra_info: m_nft_cell_output.m_nft_info
extra_info: m_nft_cell_output.m_nft_info,
)
o = m_nft_output_transaction.display_outputs.first
assert_equal expected_attributes - o.keys, []
Expand Down Expand Up @@ -600,7 +600,7 @@ class CkbTransactionTest < ActiveSupport::TestCase
status: m_nft_cell_output.status,
consumed_tx_hash: nil,
cell_type: m_nft_cell_output.cell_type,
extra_info: m_nft_cell_output.m_nft_info
extra_info: m_nft_cell_output.m_nft_info,
)
o = m_nft_output_transaction.display_outputs.first
assert_equal expected_attributes - o.keys, []
Expand Down Expand Up @@ -654,7 +654,7 @@ class CkbTransactionTest < ActiveSupport::TestCase
status: m_nft_cell_output.status,
consumed_tx_hash: nil,
cell_type: m_nft_cell_output.cell_type,
extra_info: m_nft_cell_output.m_nft_info
extra_info: m_nft_cell_output.m_nft_info,
)
display_outputs = m_nft_output_transaction.display_outputs
o = display_outputs.first
Expand Down Expand Up @@ -704,16 +704,18 @@ class CkbTransactionTest < ActiveSupport::TestCase
udt_type: "nrc_721_token",
nrc_factory_cell_id: nrc_factory_cell.id)
address = create(:address)
udt_account = create(:udt_account, udt: udt,
address: address,
udt_account = create(:udt_account, udt:,
address:,
nft_token_id: "22c70f8e24a90dcccc7eb1ea669ac6cfecab095a1886af01d71612fdb3c836c8")

factory_info = {
symbol: "TTF", amount: "", decimal: "", type_hash: "0x", published: true,
display_name: "Test token factory", nan: "" }
display_name: "Test token factory", uan: ""
}
token_info = {
symbol: "TTF", amount: udt_account.nft_token_id, decimal: "6", type_hash: "0x", published: true,
display_name: "kingdom fat coin", uan: "" }
display_name: "kingdom fat coin", uan: ""
}
display_outputs = nrc_721_token_output_transaction.display_outputs
assert_equal factory_info.to_a,
display_outputs.first[:nrc_721_token_info].to_a
Expand Down
1 change: 0 additions & 1 deletion test/services/charts/daily_statistic_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,6 @@ class DailyStatisticGeneratorTest < ActiveSupport::TestCase
end
total_supply_temp = tip_parse_dao.c_i - MarketData::BURN_QUOTA - treasury_amount
total_supply = Charts::DailyStatisticGenerator.new(@datetime).call.total_supply
binding.pry
assert_equal total_supply_temp, total_supply
end

Expand Down

0 comments on commit 8bb8267

Please sign in to comment.