Skip to content

Commit

Permalink
Fix ckb utils test (#1588)
Browse files Browse the repository at this point in the history
* test: fix ckb_utils test

Signed-off-by: Miles Zhang <[email protected]>

* fix: remove not worked code

Signed-off-by: Miles Zhang <[email protected]>

---------

Signed-off-by: Miles Zhang <[email protected]>
  • Loading branch information
zmcNotafraid authored Jan 18, 2024
1 parent 1eff971 commit a96ade1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 54 deletions.
37 changes: 7 additions & 30 deletions app/models/ckb_sync/new_node_data_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,18 @@ def process_block(node_block, refresh_balance: true)
@contained_udt_ids = contained_udt_ids = []
@contained_address_ids = contained_address_ids = []

benchmark :process_ckb_txs, node_block, ckb_txs, contained_address_ids, contained_udt_ids, dao_address_ids, tags, udt_address_ids
benchmark :process_ckb_txs, node_block, ckb_txs, contained_address_ids,
contained_udt_ids, dao_address_ids, tags, udt_address_ids
addrs_changes = Hash.new { |hash, key| hash[key] = {} }



input_capacities, output_capacities = benchmark :build_cells_and_locks!, local_block, node_block, ckb_txs, inputs, outputs,
tags, udt_address_ids, dao_address_ids, contained_udt_ids, contained_address_ids, addrs_changes
tags, udt_address_ids, dao_address_ids, contained_udt_ids, contained_address_ids, addrs_changes

# update explorer data
benchmark :update_ckb_txs_rel_and_fee, ckb_txs, tags, input_capacities, output_capacities, udt_address_ids,
dao_address_ids, contained_udt_ids, contained_address_ids
dao_address_ids, contained_udt_ids, contained_address_ids
benchmark :update_block_info!, local_block
benchmark :update_block_reward_info!,local_block
benchmark :update_block_reward_info!, local_block
benchmark :update_mining_info, local_block
benchmark :update_table_records_count, local_block
benchmark :update_or_create_udt_accounts!, local_block
Expand All @@ -113,29 +112,6 @@ def process_block(node_block, refresh_balance: true)
end

add_transaction_tracer :process_block, category: :task
add_method_tracer :build_udts!, "OtherTransaction/build_udt!"
add_method_tracer :process_ckb_txs, "OtherTransaction/process_ckb_txs"
add_method_tracer :build_cells_and_locks!,
"OtherTransaction/build_cells_and_locks!"
add_method_tracer :update_ckb_txs_rel_and_fee,
"OtherTransaction/update_ckb_txs_rel_and_fee"
add_method_tracer :update_block_info!, "OtherTransaction/update_block_info!"
add_method_tracer :update_block_reward_info!,
"OtherTransaction/update_block_reward_info!"
add_method_tracer :update_mining_info, "OtherTransaction/update_mining_info"
add_method_tracer :update_table_records_count,
"OtherTransaction/update_table_records_count"
add_method_tracer :update_or_create_udt_accounts!,
"OtherTransaction/update_or_create_udt_accounts!"
add_method_tracer :update_udt_info, "OtherTransaction/update_udt_info"
add_method_tracer :process_dao_events!,
"OtherTransaction/process_dao_events!"
add_method_tracer :update_addresses_info,
"OtherTransaction/update_addresses_info"
add_method_tracer :generate_statistics_data,
"OtherTransaction/generate_statistics_data"
add_method_tracer :generate_deployed_cells_and_referring_cells,
"OtherTransaction/generate_deployed_cells_and_referring_cells"

def check_invalid_address(address)
if (address.balance < 0) || (address.balance_occupied < 0)
Expand Down Expand Up @@ -683,7 +659,8 @@ def build_udts!(local_block, outputs, outputs_data)
udts_attributes = Set.new
outputs.each do |tx_index, items|
items.each_with_index do |output, index|
cell_type = benchmark :cell_type, output.type, outputs_data[tx_index][index]
cell_type = benchmark :cell_type, output.type,
outputs_data[tx_index][index]
if cell_type == "omiga_inscription_info"
info = CkbUtils.parse_omiga_inscription_info(outputs_data[tx_index][index])
OmigaInscriptionInfo.upsert(info.merge(output.type.to_h),
Expand Down
24 changes: 0 additions & 24 deletions test/utils/ckb_utils_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,45 +310,21 @@ class CkbUtilsTest < ActiveSupport::TestCase
assert_equal 0, CkbUtils.parse_udt_cell_data("0x01")
end

test "cell_type should return testnet m_nft_issuer when type script code_hash match m_nft_issuer code_hash" do
type_script = CKB::Types::Script.new(
code_hash: Settings.testnet_issuer_script_code_hash, hash_type: "type", args: "0x",
)
assert_equal "m_nft_issuer", CkbUtils.cell_type(type_script, "0x")
end

test "cell_type should return mainnet m_nft_issuer when type script code_hash match m_nft_issuer code_hash" do
CkbSync::Api.any_instance.stubs(:get_blockchain_info).returns(OpenStruct.new(chain: "ckb"))
type_script = CKB::Types::Script.new(
code_hash: Settings.mainnet_issuer_script_code_hash, hash_type: "type", args: "0x",
)
assert_equal "m_nft_issuer", CkbUtils.cell_type(type_script, "0x")
end

test "cell_type should return testnet m_nft_class when type script code_hash match m_nft_class code_hash" do
type_script = CKB::Types::Script.new(
code_hash: Settings.testnet_token_class_script_code_hash, hash_type: "type", args: "0x",
)
assert_equal "m_nft_class", CkbUtils.cell_type(type_script, "0x")
end

test "cell_type should return mainnet m_nft_class when type script code_hash match m_nft_class code_hash" do
CkbSync::Api.any_instance.stubs(:get_blockchain_info).returns(OpenStruct.new(chain: "ckb"))
type_script = CKB::Types::Script.new(
code_hash: Settings.mainnet_token_class_script_code_hash, hash_type: "type", args: "0x",
)
assert_equal "m_nft_class", CkbUtils.cell_type(type_script, "0x")
end

test "cell_type should return testnet m_nft_token when type script code_hash match m_nft_token code_hash" do
type_script = CKB::Types::Script.new(
code_hash: Settings.testnet_token_script_code_hash, hash_type: "type", args: "0x",
)
assert_equal "m_nft_token", CkbUtils.cell_type(type_script, "0x")
end

test "cell_type should return mainnet m_nft_token when type script code_hash match m_nft_token code_hash" do
CkbSync::Api.any_instance.stubs(:get_blockchain_info).returns(OpenStruct.new(chain: "ckb"))
type_script = CKB::Types::Script.new(
code_hash: Settings.mainnet_token_script_code_hash, hash_type: "type", args: "0x",
)
Expand Down

0 comments on commit a96ade1

Please sign in to comment.