From d30f834272c2740bb8e5ebd5f20ec4f954f249b1 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Tue, 9 Jan 2024 21:50:42 +0800 Subject: [PATCH] feat: parse udt amount of omiga inscription cell (#1561) Signed-off-by: Miles Zhang --- .../ckb_sync/new_node_data_processor.rb | 388 ++-- app/utils/ckb_utils.rb | 8 +- .../ckb_sync/node_data_processor_test.rb | 1665 +++++++++++------ test/utils/ckb_utils_test.rb | 6 + 4 files changed, 1296 insertions(+), 771 deletions(-) diff --git a/app/models/ckb_sync/new_node_data_processor.rb b/app/models/ckb_sync/new_node_data_processor.rb index b925777c8..60edaea99 100644 --- a/app/models/ckb_sync/new_node_data_processor.rb +++ b/app/models/ckb_sync/new_node_data_processor.rb @@ -42,15 +42,15 @@ def call ApplicationRecord.cache do process_block(target_block) end - self.reorg_started_at.delete + reorg_started_at.delete res else self.reorg_started_at = Time.now res = RevertBlockJob.perform_now(local_tip_block) - self.reorg_started_at.delete + reorg_started_at.delete res end - rescue => e + rescue StandardError => e Rails.logger.error e.message puts e.backtrace.join("\n") raise e @@ -68,7 +68,8 @@ def process_block(node_block, refresh_balance: true) outputs = @outputs = {} outputs_data = @outputs_data = {} @tx_cell_deps = {} - @ckb_txs = build_ckb_transactions!(node_block, local_block, inputs, outputs, outputs_data).to_a + @ckb_txs = build_ckb_transactions!(node_block, local_block, inputs, + outputs, outputs_data).to_a build_udts!(local_block, outputs, outputs_data) tags = [] @@ -117,9 +118,9 @@ def check_invalid_address(address) extra: { block: @tip_block_number, address: address.address_hash, - wrong_balance: wrong_balance, - wrong_balance_occupied: wrong_balance_occupied - } + wrong_balance:, + wrong_balance_occupied:, + }, ) end end @@ -128,7 +129,8 @@ def check_invalid_address(address) def generate_deployed_cells_and_referring_cells(local_block) local_block.ckb_transactions.each do |ckb_transaction| - DeployedCell.create_initial_data_for_ckb_transaction ckb_transaction, tx_cell_deps[ckb_transaction.tx_hash] + DeployedCell.create_initial_data_for_ckb_transaction ckb_transaction, + tx_cell_deps[ckb_transaction.tx_hash] ReferringCell.create_initial_data_for_ckb_transaction ckb_transaction end end @@ -166,7 +168,10 @@ def increase_records_count(local_block) block_counter.increment!(:count) ckb_transaction_counter = TableRecordCount.find_or_initialize_by(table_name: "ckb_transactions") normal_transactions = local_block.ckb_transactions.normal.count - ckb_transaction_counter.increment!(:count, normal_transactions.count) if normal_transactions.present? + if normal_transactions.present? + ckb_transaction_counter.increment!(:count, + normal_transactions.count) + end end def process_dao_events!(local_tip_block = @local_tip_block) @@ -174,28 +179,34 @@ def process_dao_events!(local_tip_block = @local_tip_block) new_dao_depositors = {} dao_contract = DaoContract.default_contract process_deposit_dao_events!(local_block, new_dao_depositors, dao_contract) - process_withdraw_dao_events!(local_block, new_dao_depositors, dao_contract) + process_withdraw_dao_events!(local_block, new_dao_depositors, + dao_contract) process_interest_dao_events!(local_block, dao_contract) - build_new_dao_depositor_events!(local_block, new_dao_depositors, dao_contract) + build_new_dao_depositor_events!(local_block, new_dao_depositors, + dao_contract) # update dao contract ckb_transactions_count dao_contract.increment!(:ckb_transactions_count, - local_block.ckb_transactions.where("tags @> array[?]::varchar[]", ["dao"]).count) + local_block.ckb_transactions.where( + "tags @> array[?]::varchar[]", ["dao"] + ).count) end - def build_new_dao_depositor_events!(local_block, new_dao_depositors, dao_contract) + def build_new_dao_depositor_events!(local_block, new_dao_depositors, +dao_contract) new_dao_events_attributes = [] new_dao_depositors.each do |address_id, ckb_transaction_id| new_dao_events_attributes << { - block_id: local_block.id, ckb_transaction_id: ckb_transaction_id, address_id: address_id, event_type: "new_dao_depositor", + block_id: local_block.id, ckb_transaction_id:, address_id:, event_type: "new_dao_depositor", value: 1, status: "processed", contract_id: dao_contract.id, block_timestamp: local_block.timestamp, created_at: Time.current, - updated_at: Time.current } + updated_at: Time.current + } end if new_dao_events_attributes.present? DaoEvent.insert_all!(new_dao_events_attributes) dao_contract.update!( - total_depositors_count: dao_contract.total_depositors_count + new_dao_events_attributes.size, depositors_count: dao_contract.depositors_count + new_dao_events_attributes.size + total_depositors_count: dao_contract.total_depositors_count + new_dao_events_attributes.size, depositors_count: dao_contract.depositors_count + new_dao_events_attributes.size, ) address_ids = [] new_dao_events_attributes.each do |dao_event_attr| @@ -208,7 +219,8 @@ def build_new_dao_depositor_events!(local_block, new_dao_depositors, dao_contrac # Process DAO withdraw # Warning:because DAO withdraw is also a cell, to the destination address of withdraw is the address of the withdraw cell output. # So it's possible that the deposit address is different with the withdraw address. - def process_withdraw_dao_events!(local_block, new_dao_depositors, dao_contract) + def process_withdraw_dao_events!(local_block, _new_dao_depositors, +dao_contract) dao_contract = DaoContract.default_contract withdraw_amount = 0 withdraw_transaction_ids = Set.new @@ -233,10 +245,13 @@ def process_withdraw_dao_events!(local_block, new_dao_depositors, dao_contract) addrs_withdraw_info[address.id] = { dao_deposit: address.dao_deposit.to_i - previous_cell_output.capacity, is_depositor: address.is_depositor, - created_at: address.created_at + created_at: address.created_at, } end - addrs_withdraw_info[address.id][:dao_deposit] = 0 if addrs_withdraw_info[address.id][:dao_deposit] < 0 + if addrs_withdraw_info[address.id][:dao_deposit] < 0 + addrs_withdraw_info[address.id][:dao_deposit] = + 0 + end dao_events_attributes << { ckb_transaction_id: dao_input.ckb_transaction_id, block_id: local_block.id, @@ -262,7 +277,7 @@ def process_withdraw_dao_events!(local_block, new_dao_depositors, dao_contract) status: "processed", contract_id: dao_contract.id, created_at: Time.current, - updated_at: Time.current + updated_at: Time.current, } else puts "Cannot find address dao for #{previous_cell_output.address_id}" @@ -277,7 +292,7 @@ def process_withdraw_dao_events!(local_block, new_dao_depositors, dao_contract) dao_contract.update!( total_deposit: dao_contract.total_deposit - withdraw_amount, withdraw_transactions_count: dao_contract.withdraw_transactions_count + withdraw_transaction_ids.size, - depositors_count: dao_contract.depositors_count - take_away_all_deposit_count + depositors_count: dao_contract.depositors_count - take_away_all_deposit_count, ) update_addresses_dao_info(addrs_withdraw_info) end @@ -304,7 +319,7 @@ def process_interest_dao_events!(local_block, dao_contract) addrs_withdraw_info[address.id] = { interest: address.interest.to_i + interest, is_depositor: address.is_depositor, - created_at: address.created_at + created_at: address.created_at, } end # addrs_withdraw_info[address.id][:dao_deposit] = 0 if addrs_withdraw_info[address.id][:dao_deposit] < 0 @@ -318,7 +333,7 @@ def process_interest_dao_events!(local_block, dao_contract) status: "processed", contract_id: dao_contract.id, created_at: Time.current, - updated_at: Time.current + updated_at: Time.current, } address_dao_deposit = Address.where(id: previous_cell_output.address_id).pick(:dao_deposit) claimed_compensation += interest @@ -327,12 +342,13 @@ def process_interest_dao_events!(local_block, dao_contract) end # update dao contract info dao_contract.update!( - claimed_compensation: dao_contract.claimed_compensation + claimed_compensation + claimed_compensation: dao_contract.claimed_compensation + claimed_compensation, ) update_addresses_dao_info(addrs_withdraw_info) end - def process_deposit_dao_events!(local_block, new_dao_depositors, dao_contract) + def process_deposit_dao_events!(local_block, new_dao_depositors, +dao_contract) deposit_amount = 0 deposit_transaction_ids = Set.new addresses_deposit_info = {} @@ -351,7 +367,7 @@ def process_deposit_dao_events!(local_block, new_dao_depositors, dao_contract) dao_deposit: address.dao_deposit.to_i + dao_output.capacity, interest: address.interest, is_depositor: address.is_depositor, - created_at: address.created_at + created_at: address.created_at, } end if address.dao_deposit.zero? && !new_dao_depositors.key?(address.id) @@ -369,7 +385,7 @@ def process_deposit_dao_events!(local_block, new_dao_depositors, dao_contract) contract_id: dao_contract.id, block_timestamp: local_block.timestamp, created_at: Time.current, - updated_at: Time.current + updated_at: Time.current, } end DaoEvent.insert_all!(deposit_dao_events_attributes) if deposit_dao_events_attributes.present? @@ -377,7 +393,7 @@ def process_deposit_dao_events!(local_block, new_dao_depositors, dao_contract) # update dao contract info dao_contract.update!( total_deposit: dao_contract.total_deposit + deposit_amount, - deposit_transactions_count: dao_contract.deposit_transactions_count + deposit_transaction_ids.size + deposit_transactions_count: dao_contract.deposit_transactions_count + deposit_transaction_ids.size, ) update_addresses_dao_info(addresses_deposit_info) end @@ -390,7 +406,7 @@ def update_addresses_dao_info(addrs_deposit_info) dao_deposit: address_info[:dao_deposit], interest: address_info[:interest], created_at: address_info[:created_at], - updated_at: Time.current + updated_at: Time.current, } end Address.upsert_all(addresses_deposit_attributes) if addresses_deposit_attributes.present? @@ -402,7 +418,8 @@ def update_udt_info(local_block) type_hashes << udt_output.type_hash end local_block.ckb_transactions.pluck(:id).each do |tx_id| - CellOutput.where(consumed_by_id: tx_id).udt.select(:id, :type_hash).each do |udt_output| + CellOutput.where(consumed_by_id: tx_id).udt.select(:id, + :type_hash).each do |udt_output| type_hashes << udt_output.type_hash end end @@ -412,16 +429,16 @@ def update_udt_info(local_block) addresses_count_info = UdtAccount.where(type_hash: type_hashes).group(:type_hash).count(:address_id) udts_attributes = Set.new type_hashes.each do |type_hash| - udt = Udt.where(type_hash: type_hash).select(:id).take! + udt = Udt.where(type_hash:).select(:id).take! ckb_transactions_count = Rails.cache.fetch("udt_txs_count_#{udt.id}", expires_in: 3600) do UdtTransaction.where(udt_id: udt.id).count end udts_attributes << { - type_hash: type_hash, + type_hash:, total_amount: amount_info[type_hash], addresses_count: addresses_count_info[type_hash], - ckb_transactions_count: ckb_transactions_count + ckb_transactions_count:, } end @@ -435,13 +452,15 @@ def update_udt_info(local_block) def update_or_create_udt_accounts!(local_block) new_udt_accounts_attributes = Set.new udt_accounts_attributes = Set.new - local_block.cell_outputs.select(:id, :address_id, :type_hash, :cell_type, :type_script_id).each do |udt_output| - next unless udt_output.cell_type.in?(%w(udt m_nft_token nrc_721_token spore_cell omiga_inscription)) + local_block.cell_outputs.select(:id, :address_id, :type_hash, :cell_type, + :type_script_id).each do |udt_output| + next unless udt_output.cell_type.in?(%w(udt m_nft_token nrc_721_token + spore_cell omiga_inscription)) address = Address.find(udt_output.address_id) udt_type = udt_type(udt_output.cell_type) - udt_account = address.udt_accounts.where(type_hash: udt_output.type_hash, udt_type: udt_type).select(:id, - :created_at).first + udt_account = address.udt_accounts.where(type_hash: udt_output.type_hash, udt_type:).select(:id, + :created_at).first amount = udt_account_amount(udt_type, udt_output.type_hash, address) nft_token_id = case udt_type @@ -450,40 +469,43 @@ def update_or_create_udt_accounts!(local_block) when "spore_cell" udt_output.type_script.args.hex end - udt = Udt.where(type_hash: udt_output.type_hash, udt_type: udt_type).select(:id, :udt_type, :full_name, - :symbol, :decimal, :published, :code_hash, :type_hash, :created_at).take! + udt = Udt.where(type_hash: udt_output.type_hash, udt_type:).select(:id, :udt_type, :full_name, + :symbol, :decimal, :published, :code_hash, :type_hash, :created_at).take! if udt_account.present? - udt_accounts_attributes << { id: udt_account.id, amount: amount, created_at: udt.created_at } + udt_accounts_attributes << { id: udt_account.id, amount:, + created_at: udt.created_at } else new_udt_accounts_attributes << { address_id: udt_output.address_id, udt_type: udt.udt_type, full_name: udt.full_name, symbol: udt.symbol, decimal: udt.decimal, - published: udt.published, code_hash: udt.code_hash, type_hash: udt.type_hash, amount: amount, udt_id: udt.id, nft_token_id: nft_token_id } + published: udt.published, code_hash: udt.code_hash, type_hash: udt.type_hash, amount:, udt_id: udt.id, nft_token_id: + } end end local_block.ckb_transactions.pluck(:id).each do |tx_id| # iterator over each tx id for better sql performance - CellOutput.where(consumed_by_id: tx_id).select(:id, :address_id, :type_hash, :cell_type).each do |udt_output| - next unless udt_output.cell_type.in?(%w(udt m_nft_token nrc_721_token spore_cell omiga_inscription)) + CellOutput.where(consumed_by_id: tx_id).select(:id, :address_id, + :type_hash, :cell_type).each do |udt_output| + next unless udt_output.cell_type.in?(%w(udt m_nft_token nrc_721_token + spore_cell omiga_inscription)) address = Address.find(udt_output.address_id) udt_type = udt_type(udt_output.cell_type) - udt_account = address.udt_accounts.where(type_hash: udt_output.type_hash, udt_type: udt_type).select(:id, - :created_at).first + udt_account = address.udt_accounts.where(type_hash: udt_output.type_hash, udt_type:).select(:id, + :created_at).first amount = udt_account_amount(udt_type, udt_output.type_hash, address) - udt = Udt.where(type_hash: udt_output.type_hash, udt_type: udt_type).select(:id, :udt_type, :full_name, - :symbol, :decimal, :published, :code_hash, :type_hash, :created_at).take! + udt = Udt.where(type_hash: udt_output.type_hash, udt_type:).select(:id, :udt_type, :full_name, + :symbol, :decimal, :published, :code_hash, :type_hash, :created_at).take! if udt_account.present? case udt_type - when "sudt" - udt_accounts_attributes << { id: udt_account.id, amount: amount, created_at: udt.created_at } + when "sudt", "omiga_inscription" + udt_accounts_attributes << { id: udt_account.id, amount:, + created_at: udt.created_at } when "m_nft_token" udt_account.destroy unless address.cell_outputs.live.m_nft_token.where(type_hash: udt_output.type_hash).exists? when "nrc_721_token" udt_account.destroy unless address.cell_outputs.live.nrc_721_token.where(type_hash: udt_output.type_hash).exists? when "spore_cell" udt_account.destroy unless address.cell_outputs.live.spore_cell.where(type_hash: udt_output.type_hash).exists? - when "omiga_inscription" - udt_account.destroy unless address.cell_outputs.live.omiga_inscription.where(type_hash: udt_output.type_hash).exists? end end end @@ -491,7 +513,8 @@ def update_or_create_udt_accounts!(local_block) if new_udt_accounts_attributes.present? UdtAccount.insert_all!(new_udt_accounts_attributes.map! do |attr| - attr.merge!(created_at: Time.current, updated_at: Time.current) + attr.merge!(created_at: Time.current, + updated_at: Time.current) end) end if udt_accounts_attributes.present? @@ -508,11 +531,13 @@ def udt_type(cell_type) def udt_account_amount(udt_type, type_hash, address) case udt_type when "sudt" - address.cell_outputs.live.udt.where(type_hash: type_hash).sum(:udt_amount) + address.cell_outputs.live.udt.where(type_hash:).sum(:udt_amount) + when "omiga_inscription" + address.cell_outputs.live.omiga_inscription.where(type_hash:).sum(:udt_amount) when "m_nft_token" - address.cell_outputs.live.m_nft_token.where(type_hash: type_hash).sum(:udt_amount) + address.cell_outputs.live.m_nft_token.where(type_hash:).sum(:udt_amount) when "spore_cell" - address.cell_outputs.live.spore_cell.where(type_hash: type_hash).sum(:udt_amount) + address.cell_outputs.live.spore_cell.where(type_hash:).sum(:udt_amount) else 0 end @@ -524,7 +549,10 @@ def update_table_records_count(local_block) block_counter.increment!(:count) ckb_transaction_counter = TableRecordCount.find_or_initialize_by(table_name: "ckb_transactions") normal_transactions = local_block.ckb_transactions.normal - ckb_transaction_counter.increment!(:count, normal_transactions.count) if normal_transactions.present? + if normal_transactions.present? + ckb_transaction_counter.increment!(:count, + normal_transactions.count) + end end def update_block_reward_info!(local_block) @@ -589,7 +617,7 @@ def update_addresses_info(addrs_change, local_block) balance_occupied: addr.balance_occupied + balance_occupied_diff, ckb_transactions_count: addr.ckb_transactions_count + ckb_txs_count, live_cells_count: addr.live_cells_count + live_cells_diff, - dao_transactions_count: addr.dao_transactions_count + dao_txs_count + dao_transactions_count: addr.dao_transactions_count + dao_txs_count, ) save_address_block_snapshot!(addr, local_block) @@ -604,11 +632,11 @@ def save_address_block_snapshot!(addr, local_block) balance_occupied: addr.balance_occupied, ckb_transactions_count: addr.ckb_transactions_count, live_cells_count: addr.live_cells_count, - dao_transactions_count: addr.dao_transactions_count - } + dao_transactions_count: addr.dao_transactions_count, + }, ).find_or_create_by!( address_id: addr.id, - block_id: local_block.id + block_id: local_block.id, ) end @@ -626,13 +654,16 @@ def build_udts!(local_block, outputs, outputs_data) cell_type = 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), unique_by: :udt_hash) + OmigaInscriptionInfo.upsert(info.merge(output.type.to_h), + unique_by: :udt_hash) end - next unless cell_type.in?(%w(udt m_nft_token nrc_721_token spore_cell omiga_inscription)) + next unless cell_type.in?(%w(udt m_nft_token nrc_721_token spore_cell + omiga_inscription)) type_hash = output.type.compute_hash - unless Udt.where(type_hash: type_hash).exists? - nft_token_attr = { full_name: nil, icon_file: nil, published: false, symbol: nil } + unless Udt.where(type_hash:).exists? + nft_token_attr = { full_name: nil, icon_file: nil, + published: false, symbol: nil } if cell_type == "m_nft_token" m_nft_class_type = TypeScript.where(code_hash: CkbSync::Api.instance.token_class_script_code_hash, args: output.type.args[0..49]).first @@ -644,7 +675,7 @@ def build_udts!(local_block, outputs, outputs_data) name: parsed_class_data.name, cell_id: m_nft_class_cell.id, icon_url: parsed_class_data.renderer, - creator_id: m_nft_class_cell.address_id + creator_id: m_nft_class_cell.address_id, ) nft_token_attr[:full_name] = parsed_class_data.name @@ -665,7 +696,7 @@ def build_udts!(local_block, outputs, outputs_data) name: parsed_cluster_data[:name], description: parsed_cluster_data[:description], cell_id: spore_cluster_cell.id, - creator_id: spore_cluster_cell.address_id + creator_id: spore_cluster_cell.address_id, ) nft_token_attr[:full_name] = parsed_cluster_data[:name] @@ -680,8 +711,10 @@ def build_udts!(local_block, outputs, outputs_data) args: factory_cell.args) if nrc_721_factory_cell.verified nft_token_attr[:full_name] = nrc_721_factory_cell.name - nft_token_attr[:symbol] = nrc_721_factory_cell.symbol.to_s[0, 16] - nft_token_attr[:icon_file] = "#{nrc_721_factory_cell.base_token_uri}/#{factory_cell.token_id}" + nft_token_attr[:symbol] = + nrc_721_factory_cell.symbol.to_s[0, 16] + nft_token_attr[:icon_file] = + "#{nrc_721_factory_cell.base_token_uri}/#{factory_cell.token_id}" nft_token_attr[:nrc_factory_cell_id] = nrc_721_factory_cell.id end nft_token_attr[:published] = true @@ -698,16 +731,17 @@ def build_udts!(local_block, outputs, outputs_data) # type_hash: type_hash, udt_type: udt_type(cell_type), block_timestamp: local_block.timestamp, args: output.type.args, # code_hash: output.type.code_hash, hash_type: output.type.hash_type }.merge(nft_token_attr) udt = Udt.create_or_find_by!({ - type_hash: type_hash, + type_hash:, udt_type: udt_type(cell_type), block_timestamp: local_block.timestamp, args: output.type.args, code_hash: output.type.code_hash, - hash_type: output.type.hash_type + hash_type: output.type.hash_type, }.merge(nft_token_attr)) if cell_type == "omiga_inscription" - info = OmigaInscriptionInfo.find_by(udt_hash: type_hash, udt_id: nil) + info = OmigaInscriptionInfo.find_by(udt_hash: type_hash, + udt_id: nil) info && info.update!(udt_id: udt.id) end end @@ -732,9 +766,15 @@ def update_ckb_txs_rel_and_fee( contained_addr_ids[tx_index].to_a.map do |a| { address_id: a, ckb_transaction_id: tx_id } end - full_dao_address_ids += dao_address_ids[tx_index].to_a.map { |a| { address_id: a, ckb_transaction_id: tx_id } } - full_tx_udt_ids += contained_udt_ids[tx_index].to_a.map { |u| { udt_id: u, ckb_transaction_id: tx_id } } - full_udt_address_ids += udt_address_ids[tx_index].to_a.map { |a| { address_id: a, ckb_transaction_id: tx_id } } + full_dao_address_ids += dao_address_ids[tx_index].to_a.map do |a| + { address_id: a, ckb_transaction_id: tx_id } + end + full_tx_udt_ids += contained_udt_ids[tx_index].to_a.map do |u| + { udt_id: u, ckb_transaction_id: tx_id } + end + full_udt_address_ids += udt_address_ids[tx_index].to_a.map do |a| + { address_id: a, ckb_transaction_id: tx_id } + end attr = { id: tx_id, @@ -749,7 +789,7 @@ def update_ckb_txs_rel_and_fee( output_capacities[tx_index]) end, created_at: tx["created_at"], - updated_at: Time.current + updated_at: Time.current, } # binding.pry if attr[:transaction_fee] < 0 @@ -758,19 +798,27 @@ def update_ckb_txs_rel_and_fee( end if ckb_transactions_attributes.present? - CkbTransaction.upsert_all(ckb_transactions_attributes, unique_by: [:id, :tx_status]) + CkbTransaction.upsert_all(ckb_transactions_attributes, + unique_by: %i[id tx_status]) end if full_tx_address_ids.present? - AccountBook.upsert_all full_tx_address_ids, unique_by: [:address_id, :ckb_transaction_id] + AccountBook.upsert_all full_tx_address_ids, + unique_by: %i[address_id ckb_transaction_id] + end + if full_tx_udt_ids.present? + UdtTransaction.upsert_all full_tx_udt_ids, + unique_by: %i[udt_id + ckb_transaction_id] end - UdtTransaction.upsert_all full_tx_udt_ids, unique_by: [:udt_id, :ckb_transaction_id] if full_tx_udt_ids.present? if full_dao_address_ids.present? AddressDaoTransaction.upsert_all full_dao_address_ids, - unique_by: [:address_id, :ckb_transaction_id] + unique_by: %i[address_id + ckb_transaction_id] end if full_udt_address_ids.present? AddressUdtTransaction.upsert_all full_udt_address_ids, - unique_by: [:address_id, :ckb_transaction_id] + unique_by: %i[address_id + ckb_transaction_id] end end @@ -788,17 +836,23 @@ def build_cells_and_locks!( type_script_ids = [] if lock_scripts_attributes.present? - lock_scripts_attributes.map! { |attr| attr.merge!(created_at: Time.current, updated_at: Time.current) } - lock_script_ids = LockScript.insert_all!(lock_scripts_attributes).map { |e| e["id"] } + lock_scripts_attributes.map! do |attr| + attr.merge!(created_at: Time.current, updated_at: Time.current) + end + lock_script_ids = LockScript.insert_all!(lock_scripts_attributes).map do |e| + e["id"] + end lock_script_ids.each do |lock_script_id| lock_script = LockScript.find lock_script_id contract = Contract.find_by code_hash: lock_script.code_hash - temp_hash = { script_hash: lock_script&.script_hash, is_contract: false } + temp_hash = { script_hash: lock_script&.script_hash, + is_contract: false } if contract - temp_hash = temp_hash.merge is_contract: true, contract_id: contract.id + temp_hash = temp_hash.merge is_contract: true, + contract_id: contract.id else contract = Contract.create code_hash: lock_script.script_hash temp_hash = temp_hash.merge contract_id: contract.id @@ -809,15 +863,21 @@ def build_cells_and_locks!( end if type_scripts_attributes.present? - type_scripts_attributes.map! { |attr| attr.merge!(created_at: Time.current, updated_at: Time.current) } - type_script_ids = TypeScript.insert_all!(type_scripts_attributes).map { |e| e["id"] } + type_scripts_attributes.map! do |attr| + attr.merge!(created_at: Time.current, updated_at: Time.current) + end + type_script_ids = TypeScript.insert_all!(type_scripts_attributes).map do |e| + e["id"] + end type_script_ids.each do |type_script_id| type_script = TypeScript.find(type_script_id) - temp_hash = { script_hash: type_script&.script_hash, is_contract: false } + temp_hash = { script_hash: type_script&.script_hash, + is_contract: false } contract = Contract.find_by code_hash: type_script.code_hash if contract - temp_hash = temp_hash.merge is_contract: true, contract_id: contract.id + temp_hash = temp_hash.merge is_contract: true, + contract_id: contract.id else contract = Contract.create code_hash: type_script.script_hash temp_hash = temp_hash.merge contract_id: contract.id @@ -832,8 +892,8 @@ def build_cells_and_locks!( build_cell_outputs!(node_block, outputs, ckb_txs, local_block, cell_outputs_attributes, output_capacities, tags, udt_address_ids, dao_address_ids, contained_udt_ids, contained_addr_ids, addrs_changes) if cell_outputs_attributes.present? - id_hashes = CellOutput.upsert_all(cell_outputs_attributes, unique_by: [:tx_hash, :cell_index], - returning: [:id, :data_hash]) + id_hashes = CellOutput.upsert_all(cell_outputs_attributes, unique_by: %i[tx_hash cell_index], + returning: %i[id data_hash]) cell_data_attrs = [] id_hashes.each do |row| @@ -841,7 +901,8 @@ def build_cells_and_locks!( if hash.present? hash[0] = "0" hash = CKB::Utils.hex_to_bin(hash) - cell_data_attrs << { cell_output_id: row["id"], data: @cell_datas[hash] } + cell_data_attrs << { cell_output_id: row["id"], + data: @cell_datas[hash] } end end @@ -856,15 +917,17 @@ def build_cells_and_locks!( input_capacities, tags, udt_address_ids, dao_address_ids, contained_udt_ids, contained_addr_ids, prev_outputs, addrs_changes) - CellInput.upsert_all(cell_inputs_attributes, unique_by: [:ckb_transaction_id, :index]) + CellInput.upsert_all(cell_inputs_attributes, + unique_by: %i[ckb_transaction_id index]) if prev_cell_outputs_attributes.present? - CellOutput.upsert_all(prev_cell_outputs_attributes, unique_by: [:tx_hash, :cell_index]) + CellOutput.upsert_all(prev_cell_outputs_attributes, + unique_by: %i[tx_hash cell_index]) end ScriptTransaction.create_from_scripts TypeScript.where(id: type_script_ids) ScriptTransaction.create_from_scripts LockScript.where(id: lock_script_ids) - return input_capacities, output_capacities + [input_capacities, output_capacities] end # def prepare_previous_outputs(inputs) @@ -905,10 +968,12 @@ def build_addresses!(outputs, local_block) # TODO use LockScript.where(script_hash: output.lock.compute_hash).select(:id)&.first replace search by code_hash, hash_type and args query after script_hash has been filled lock_script = LockScript.find_by(code_hash: item.lock.code_hash, hash_type: item.lock.hash_type, args: item.lock.args) - Address.find_or_create_address(item.lock, local_block.timestamp, lock_script.id) + Address.find_or_create_address(item.lock, local_block.timestamp, + lock_script.id) end local_cache.push("NodeData/#{block_number}/ContainedAddresses", - Address.new(id: address.id, created_at: address.created_at)) + Address.new(id: address.id, + created_at: address.created_at)) end end end @@ -963,7 +1028,7 @@ def build_scripts(outputs) end end - return locks_attributes.to_a.compact, types_attributes.to_a.compact + [locks_attributes.to_a.compact, types_attributes.to_a.compact] end def script_attributes(script, script_hash) @@ -971,7 +1036,7 @@ def script_attributes(script, script_hash) args: script.args, code_hash: script.code_hash, hash_type: script.hash_type, - script_hash: script_hash + script_hash:, } end @@ -990,7 +1055,8 @@ def build_cell_inputs( # attributes[3] is previous_cell_output type_hash # attributes[4] is previous_cell address_id # attributes[5] is previous_cell data - attributes = cell_input_attributes(item, ckb_txs[tx_index]["id"], local_block_id, prev_outputs, index) + attributes = cell_input_attributes(item, ckb_txs[tx_index]["id"], + local_block_id, prev_outputs, index) cell_inputs_attributes << attributes[:cell_input] previous_output = attributes[:previous_output] if previous_output.present? @@ -1004,7 +1070,9 @@ def build_cell_inputs( change_rec[:balance_diff] ||= 0 change_rec[:balance_diff] -= capacity change_rec[:balance_occupied_diff] ||= 0 - change_rec[:balance_occupied_diff] -= capacity if occupied?(type_hash, data) + change_rec[:balance_occupied_diff] -= capacity if occupied?( + type_hash, data + ) change_rec[:cells_diff] ||= 0 change_rec[:cells_diff] -= 1 change_rec[:ckb_txs] ||= Set.new @@ -1026,15 +1094,18 @@ def build_cell_inputs( when "udt" tags[tx_index] << "udt" udt_address_ids[tx_index] << address_id - contained_udt_ids[tx_index] << Udt.where(type_hash: type_hash, udt_type: "sudt").pick(:id) + contained_udt_ids[tx_index] << Udt.where(type_hash:, + udt_type: "sudt").pick(:id) when "omiga_inscription" tags[tx_index] << "omiga_inscription" udt_address_ids[tx_index] << address_id - contained_udt_ids[tx_index] << Udt.where(type_hash: type_hash, udt_type: "omiga_inscription").pick(:id) + contained_udt_ids[tx_index] << Udt.where(type_hash:, + udt_type: "omiga_inscription").pick(:id) when "nrc_721_token" tags[tx_index] << "nrc_721_token" udt_address_ids[tx_index] << address_id - contained_udt_ids[tx_index] << Udt.where(type_hash: type_hash, udt_type: "nrc_721_token").pick(:id) + contained_udt_ids[tx_index] << Udt.where(type_hash:, + udt_type: "nrc_721_token").pick(:id) end input_capacities[tx_index] += capacity.to_i if tx_index != 0 end @@ -1062,7 +1133,9 @@ def build_cell_outputs!( change_rec[:balance_diff] += item.capacity change_rec[:balance_occupied_diff] ||= 0 - change_rec[:balance_occupied_diff] += item.capacity if occupied?(item.type&.compute_hash, cell_data) + change_rec[:balance_occupied_diff] += item.capacity if occupied?( + item.type&.compute_hash, cell_data + ) change_rec[:cells_diff] ||= 0 change_rec[:cells_diff] += 1 @@ -1085,11 +1158,15 @@ def build_cell_outputs!( if attr[:cell_type] == "udt" tags[tx_index] << "udt" udt_address_ids[tx_index] << address.id - contained_udt_ids[tx_index] << Udt.where(type_hash: item.type.compute_hash, udt_type: "sudt").pick(:id) + contained_udt_ids[tx_index] << Udt.where( + type_hash: item.type.compute_hash, udt_type: "sudt", + ).pick(:id) elsif attr[:cell_type] == "omiga_inscription" - tags[tx_index] << "omiga_inscription" + tags[tx_index] << "omiga_inscription" udt_address_ids[tx_index] << address_id - contained_udt_ids[tx_index] << Udt.where(type_hash: item.type.compute_hash, udt_type: "omiga_inscription").pick(:id) + contained_udt_ids[tx_index] << Udt.where( + type_hash: item.type.compute_hash, udt_type: "omiga_inscription", + ).pick(:id) elsif attr[:cell_type].in?(%w(m_nft_token nrc_721_token spore_cell)) TokenTransferDetectWorker.perform_async(ckb_txs[tx_index]["id"]) end @@ -1104,15 +1181,20 @@ def occupied?(type_hash, cell_data) cell_data.present? && cell_data != "0x" || type_hash.present? end - def cell_output_attributes(output, address, ckb_transaction, local_block, cell_index, output_data) + def cell_output_attributes(output, address, ckb_transaction, local_block, +cell_index, output_data) lock_script = local_cache.fetch("NodeData/LockScript/#{output.lock.code_hash}-#{output.lock.hash_type}-#{output.lock.args}") type_script = if output.type.present? local_cache.fetch("NodeData/TypeScript/#{output.type.code_hash}-#{output.type.hash_type}-#{output.type.args}") end - udt_amount = udt_amount(cell_type(output.type, output_data), output_data, output.type&.args) + udt_amount = udt_amount(cell_type(output.type, output_data), output_data, + output.type&.args) cell_type = cell_type(output.type, output_data).to_s - update_nrc_factory_cell_info(output.type, output_data) if cell_type == "nrc_721_factory" + if cell_type == "nrc_721_factory" + update_nrc_factory_cell_info(output.type, + output_data) + end binary_data = CKB::Utils.hex_to_bin(output_data) attrs = { ckb_transaction_id: ckb_transaction["id"], @@ -1121,17 +1203,17 @@ def cell_output_attributes(output, address, ckb_transaction, local_block, cell_i address_id: address.id, block_id: local_block.id, tx_hash: ckb_transaction["tx_hash"], - cell_index: cell_index, - cell_type: cell_type, + cell_index:, + cell_type:, block_timestamp: local_block.timestamp, type_hash: output.type&.compute_hash, dao: local_block.dao, lock_script_id: lock_script.id, type_script_id: type_script&.id, - udt_amount: udt_amount, + udt_amount:, status: "live", created_at: Time.current, - updated_at: Time.current + updated_at: Time.current, } if binary_data && binary_data.bytesize > 0 @@ -1150,27 +1232,30 @@ def udt_amount(cell_type, output_data, type_script_args) case cell_type when "udt" CkbUtils.parse_udt_cell_data(output_data) + when "omiga_inscription" + CkbUtils.parse_omiga_inscription_data(output_data)[:mint_limit] when "m_nft_token" "0x#{type_script_args[-8..]}".hex end end - def cell_input_attributes(input, ckb_transaction_id, local_block_id, prev_outputs, index = nil) + def cell_input_attributes(input, ckb_transaction_id, local_block_id, +_prev_outputs, index = nil) if from_cell_base?(input) { cell_input: { - ckb_transaction_id: ckb_transaction_id, + ckb_transaction_id:, previous_tx_hash: nil, previous_index: 0, - index: index, + index:, since: input.since, block_id: local_block_id, from_cell_base: from_cell_base?(input), previous_cell_output_id: nil, cell_type: "normal", created_at: Time.current, - updated_at: Time.current - } + updated_at: Time.current, + }, } else # previous_output = prev_outputs["#{input.previous_output.tx_hash}-#{input.previous_output.index}"] @@ -1179,17 +1264,17 @@ def cell_input_attributes(input, ckb_transaction_id, local_block_id, prev_output { cell_input: { - ckb_transaction_id: ckb_transaction_id, + ckb_transaction_id:, previous_tx_hash: input.previous_output.tx_hash, previous_index: input.previous_output.index, - index: index, + index:, since: input.since, block_id: local_block_id, from_cell_base: from_cell_base?(input), previous_cell_output_id: previous_output.id, cell_type: previous_output.cell_type, created_at: Time.current, - updated_at: Time.current + updated_at: Time.current, }, previous_output: { id: previous_output.id, @@ -1200,17 +1285,18 @@ def cell_input_attributes(input, ckb_transaction_id, local_block_id, prev_output status: "dead", updated_at: Time.current, consumed_by_id: ckb_transaction_id, - consumed_block_timestamp: CkbTransaction.find(ckb_transaction_id).block_timestamp + consumed_block_timestamp: CkbTransaction.find(ckb_transaction_id).block_timestamp, }, capacity: previous_output.capacity, type_hash: previous_output.type_hash, - address_id: previous_output.address_id + address_id: previous_output.address_id, # data: previous_output.data } end end - def build_ckb_transactions!(node_block, local_block, inputs, outputs, outputs_data) + def build_ckb_transactions!(node_block, local_block, inputs, outputs, +outputs_data) cycles = CkbSync::Api.instance.get_block_cycles node_block.header.hash ckb_transactions_attributes = [] tx_index = 0 @@ -1237,25 +1323,28 @@ def build_ckb_transactions!(node_block, local_block, inputs, outputs, outputs_da # First update status thus we can use upsert later. otherwise, we may not be able to # locate correct record according to tx_hash binary_hashes = CkbUtils.hexes_to_bins_sql(hashes) - pending_txs = CkbTransaction.where("tx_hash IN (#{binary_hashes})").where(tx_status: :pending).pluck(:tx_hash, :created_at) + pending_txs = CkbTransaction.where("tx_hash IN (#{binary_hashes})").where(tx_status: :pending).pluck( + :tx_hash, :created_at + ) CkbTransaction.where("tx_hash IN (#{binary_hashes})").update_all tx_status: "committed" - txs = CkbTransaction.upsert_all(ckb_transactions_attributes, unique_by: [:tx_status, :tx_hash], + txs = CkbTransaction.upsert_all(ckb_transactions_attributes, unique_by: %i[tx_status tx_hash], returning: %w(id tx_hash block_timestamp created_at)) if pending_txs.any? hash_to_pool_times = pending_txs.to_h confirmation_time_attrs = - txs.select { |tx| + txs.select do |tx| tx["tx_hash"].tr("\\", "0").in?(hash_to_pool_times.keys) - }.map do |tx| + end.map do |tx| { id: tx["id"], tx_status: :committed, - confirmation_time: (tx["block_timestamp"].to_i / 1000) - hash_to_pool_times[tx["tx_hash"].tr("\\", "0")].to_i } + confirmation_time: (tx["block_timestamp"].to_i / 1000) - hash_to_pool_times[tx["tx_hash"].tr("\\", "0")].to_i + } end CkbTransaction.upsert_all(confirmation_time_attrs, update_only: [:confirmation_time], - unique_by: [:id, :tx_status]) + unique_by: %i[id tx_status]) end hash2id = {} @@ -1273,7 +1362,7 @@ def build_ckb_transactions!(node_block, local_block, inputs, outputs, outputs_da header_deps_attrs << { ckb_transaction_id: txid, index: i, - header_hash: dep + header_hash: dep, } end end @@ -1293,13 +1382,17 @@ def build_ckb_transactions!(node_block, local_block, inputs, outputs, outputs_da witnesses_attrs << { ckb_transaction_id: txid, index: i, - data: witness + data: witness, } end end end - Witness.upsert_all(witnesses_attrs, unique_by: %i[ckb_transaction_id index]) if witnesses_attrs.present? + if witnesses_attrs.present? + Witness.upsert_all(witnesses_attrs, + unique_by: %i[ckb_transaction_id + index]) + end txs end @@ -1318,7 +1411,7 @@ def ckb_transaction_attributes(local_block, tx, tx_index) # witnesses: tx.witnesses, is_cellbase: tx_index.zero?, live_cell_changes: live_cell_changes(tx, tx_index), - bytes: tx.serialized_size_in_block + bytes: tx.serialized_size_in_block, } end @@ -1339,10 +1432,10 @@ def build_uncle_blocks!(node_block, local_block_id) proposals: uncle_block.proposals, proposals_count: uncle_block.proposals.count, epoch: epoch_info.number, - dao: header.dao + dao: header.dao, ).find_or_create_by!( block_id: local_block_id, - block_hash: header.hash + block_hash: header.hash, ) end end @@ -1375,9 +1468,9 @@ def build_block!(node_block) proposals: node_block.proposals, proposals_count: node_block.proposals.count, cell_consumed: block_cell_consumed, - total_cell_capacity: total_cell_capacity, - miner_hash: miner_hash, - miner_lock_hash: miner_lock_hash, + total_cell_capacity:, + miner_hash:, + miner_lock_hash:, reward: base_reward, primary_reward: base_reward, secondary_reward: 0, @@ -1391,18 +1484,19 @@ def build_block!(node_block) block_size: 0, miner_message: CkbUtils.miner_message(cellbase), extension: node_block.extension, - median_timestamp: get_median_timestamp(header.hash) + median_timestamp: get_median_timestamp(header.hash), ).find_or_create_by!( block_hash: header.hash, - number: header.number + number: header.number, ) end block end def get_median_timestamp(block_hash) - response = CkbSync::Api.instance.directly_single_call_rpc method: "get_block_median_time", params: [block_hash] - return response["result"].to_i(16) + response = CkbSync::Api.instance.directly_single_call_rpc method: "get_block_median_time", + params: [block_hash] + response["result"].to_i(16) end def from_cell_base?(node_input) @@ -1437,7 +1531,7 @@ def generate_address_in_advance(cellbase, block_timestamp) lock = LockScript.find_or_create_by( code_hash: lock_script.code_hash, hash_type: lock_script.hash_type, - args: lock_script.args + args: lock_script.args, ) local_cache.fetch("NodeData/Address/#{lock_script.code_hash}-#{lock_script.hash_type}-#{lock_script.args}") do Address.find_or_create_address(lock_script, block_timestamp, lock.id) @@ -1469,14 +1563,14 @@ def update_nrc_factory_cell_info(type_script, output_data) factory_cell = NrcFactoryCell.find_or_create_by( code_hash: type_script.code_hash, hash_type: type_script.hash_type, - args: type_script.args + args: type_script.args, ) parsed_factory_data = CkbUtils.parse_nrc_721_factory_data(output_data) factory_cell.update( name: parsed_factory_data.name, symbol: parsed_factory_data.symbol, base_token_uri: parsed_factory_data.base_token_uri, - extra_data: parsed_factory_data.extra_data + extra_data: parsed_factory_data.extra_data, ) end diff --git a/app/utils/ckb_utils.rb b/app/utils/ckb_utils.rb index e4687e8b1..e54c92782 100644 --- a/app/utils/ckb_utils.rb +++ b/app/utils/ckb_utils.rb @@ -447,8 +447,6 @@ def self.cell_type(type_script, output_data) "spore_cell" when CkbSync::Api.instance.omiga_inscription_info_code_hash "omiga_inscription_info" - when CkbSync::Api.instance.omiga_inscription_info_code_hash - "omiga_inscription_info" when CkbSync::Api.instance.xudt_code_hash if OmigaInscriptionInfo.where(udt_hash: type_script.compute_hash).exists? "omiga_inscription" @@ -639,4 +637,10 @@ def self.parse_omiga_inscription_info(hex_data) { decimal:, name: name.presence, symbol: symbol.presence, udt_hash:, expected_supply:, mint_limit:, mint_status: } end + + def self.parse_omiga_inscription_data(hex_data) + data = hex_data.delete_prefix("0x") + mint_limit = [data].pack("H*").unpack1("Q<2") + { mint_limit: } + end end diff --git a/test/models/ckb_sync/node_data_processor_test.rb b/test/models/ckb_sync/node_data_processor_test.rb index 33c81f32a..8726562dc 100644 --- a/test/models/ckb_sync/node_data_processor_test.rb +++ b/test/models/ckb_sync/node_data_processor_test.rb @@ -8,13 +8,13 @@ class NodeDataProcessorTest < ActiveSupport::TestCase compact_target: "0x1000", length: "0x07d0", number: "0x0", - start_number: "0x0" - ) + start_number: "0x0", + ), ) CkbSync::Api.any_instance.stubs(:get_block_cycles).returns( [ "0x100", "0x200", "0x300", "0x400", "0x500", "0x600", "0x700", "0x800", "0x900" - ] + ], ) create(:table_record_count, :block_counter) create(:table_record_count, :ckb_transactions_counter) @@ -59,7 +59,9 @@ class NodeDataProcessorTest < ActiveSupport::TestCase VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}") do node_block = CkbSync::Api.instance.get_block_by_number(DEFAULT_NODE_BLOCK_NUMBER) create(:block, :with_block_hash, number: node_block.header.number - 1) - assert_difference -> { ckb_transaction_counter.reload.count }, node_block.transactions[1..-1].count do + assert_difference -> { + ckb_transaction_counter.reload.count + }, node_block.transactions[1..-1].count do node_data_processor.process_block(node_block) end end @@ -71,8 +73,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase compact_target: "0x1000", length: "0x3e8", number: "0x0", - start_number: "0x0" - ) + start_number: "0x0", + ), ) VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}") do node_block = CkbSync::Api.instance.get_block_by_number(DEFAULT_NODE_BLOCK_NUMBER) @@ -119,8 +121,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase compact_target: "0x1000", length: "0x07d0", number: "0x0", - start_number: "0x0" - ) + start_number: "0x0", + ), ) VCR.use_cassette("blocks/11") do node_block = CkbSync::Api.instance.get_block_by_number(11) @@ -140,18 +142,22 @@ class NodeDataProcessorTest < ActiveSupport::TestCase compact_target: "0x1000", length: "0x07d0", number: "0x0", - start_number: "0x0" - ) + start_number: "0x0", + ), ) VCR.use_cassette("blocks/11") do - tx = create(:pending_transaction, tx_hash: "0x4298daf91148df9093c844d2ae7d16bee6b74e7ab1ccccd108ce834d1ca1a56c") + tx = create(:pending_transaction, + tx_hash: "0x4298daf91148df9093c844d2ae7d16bee6b74e7ab1ccccd108ce834d1ca1a56c") node_block = CkbSync::Api.instance.get_block_by_number(11) create(:block, :with_block_hash, number: node_block.header.number - 1) node_block.transactions.first.hash = tx.tx_hash - assert_changes -> { tx.reload.tx_status }, from: "pending", to: "committed" do + assert_changes -> { + tx.reload.tx_status + }, from: "pending", to: "committed" do node_data_processor.process_block(node_block) end - assert_equal tx.reload.confirmation_time, tx.reload.block_timestamp.to_i / 1000 - tx.created_at.to_i + assert_equal tx.reload.confirmation_time, + tx.reload.block_timestamp.to_i / 1000 - tx.created_at.to_i end end @@ -161,8 +167,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase compact_target: "0x1000", length: "0x07d0", number: "0x0", - start_number: "0x0" - ) + start_number: "0x0", + ), ) VCR.use_cassette("blocks/11") do tx = create(:pending_transaction) @@ -180,8 +186,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase compact_target: "0x1000", length: "0x07d0", number: "0x0", - start_number: "0x0" - ) + start_number: "0x0", + ), ) VCR.use_cassette("blocks/11") do node_block = CkbSync::Api.instance.get_block_by_number(11) @@ -194,7 +200,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase end test "#process_block generated block's total_cell_capacity should equal to the sum of transactions output capacity" do - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do node_block = CkbSync::Api.instance.get_block_by_number(DEFAULT_NODE_BLOCK_NUMBER) create(:block, :with_block_hash, number: node_block.header.number - 1) @@ -212,7 +219,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase node_block.transactions.first local_block = node_data_processor.process_block(node_block) - assert_equal CkbUtils.base_reward(node_block.header.number, CkbUtils.parse_epoch_info(node_block.header).number), local_block.reward + assert_equal CkbUtils.base_reward(node_block.header.number, CkbUtils.parse_epoch_info(node_block.header).number), + local_block.reward end end @@ -223,12 +231,14 @@ class NodeDataProcessorTest < ActiveSupport::TestCase local_block = node_data_processor.process_block(node_block) - assert_equal CkbUtils.base_reward(node_block.header.number, CkbUtils.parse_epoch_info(node_block.header).number), local_block.primary_reward + assert_equal CkbUtils.base_reward(node_block.header.number, CkbUtils.parse_epoch_info(node_block.header).number), + local_block.primary_reward end end test "#process_block generated block should has correct secondary reward" do - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do node_block = CkbSync::Api.instance.get_block_by_number(DEFAULT_NODE_BLOCK_NUMBER) create(:block, :with_block_hash, number: node_block.header.number - 1) @@ -245,7 +255,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase local_block = node_data_processor.process_block(node_block) - assert_equal CkbUtils.block_cell_consumed(node_block.transactions), local_block.cell_consumed + assert_equal CkbUtils.block_cell_consumed(node_block.transactions), + local_block.cell_consumed end end @@ -255,7 +266,9 @@ class NodeDataProcessorTest < ActiveSupport::TestCase create(:block, :with_block_hash, number: node_block.header.number - 1) node_block_uncle_blocks = node_block.uncles - assert_difference -> { UncleBlock.count }, node_block_uncle_blocks.size do + assert_difference -> { + UncleBlock.count + }, node_block_uncle_blocks.size do node_data_processor.process_block(node_block) end end @@ -265,8 +278,12 @@ class NodeDataProcessorTest < ActiveSupport::TestCase VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}") do node_block = CkbSync::Api.instance.get_block_by_number(DEFAULT_NODE_BLOCK_NUMBER) create(:block, :with_block_hash, number: node_block.header.number - 1) - node_uncle_blocks = node_block.uncles.map { |uncle| uncle.to_h.deep_stringify_keys } - formatted_node_uncle_blocks = node_uncle_blocks.map { |uncle_block| format_node_block(uncle_block).sort } + node_uncle_blocks = node_block.uncles.map do |uncle| + uncle.to_h.deep_stringify_keys + end + formatted_node_uncle_blocks = node_uncle_blocks.map do |uncle_block| + format_node_block(uncle_block).sort + end local_block = node_data_processor.process_block(node_block) local_uncle_blocks = @@ -291,7 +308,9 @@ class NodeDataProcessorTest < ActiveSupport::TestCase node_block = CkbSync::Api.instance.get_block_by_number(DEFAULT_NODE_BLOCK_NUMBER) create(:block, :with_block_hash, number: node_block.header.number - 1) node_uncle_blocks = node_block.uncles - node_uncle_blocks_count = node_uncle_blocks.reduce(0) { |memo, uncle_block| memo + uncle_block.proposals.size } + node_uncle_blocks_count = node_uncle_blocks.reduce(0) do |memo, uncle_block| + memo + uncle_block.proposals.size + end local_block = node_data_processor.process_block(node_block) local_uncle_blocks = local_block.uncle_blocks @@ -310,7 +329,9 @@ class NodeDataProcessorTest < ActiveSupport::TestCase create(:block, :with_block_hash, number: node_block.header.number - 1) node_block_transactions = node_block.transactions - assert_difference -> { CkbTransaction.count }, node_block_transactions.count do + assert_difference -> { + CkbTransaction.count + }, node_block_transactions.count do node_data_processor.process_block(node_block) end end @@ -323,7 +344,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase local_block = node_data_processor.process_block(node_block) - assert_equal node_block.transactions.size, local_block.ckb_transactions_count + assert_equal node_block.transactions.size, + local_block.ckb_transactions_count end end @@ -342,7 +364,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase local_block.ckb_transactions.map do |ckb_transaction| attrs = ckb_transaction.attributes.select do |attribute| - attribute.in?(%w(tx_hash cell_deps header_deps version witnesses)) + attribute.in?(%w(tx_hash cell_deps header_deps version + witnesses)) end attrs["hash"] = attrs.delete("tx_hash") attrs["version"] = attrs["version"].to_i @@ -361,13 +384,13 @@ class NodeDataProcessorTest < ActiveSupport::TestCase create(:block, :with_block_hash, number: node_block.header.number - 1) block = create(:block, :with_block_hash) ckb_transaction1 = create(:ckb_transaction, - tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) ckb_transaction2 = create(:ckb_transaction, - tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) create(:cell_output, ckb_transaction: ckb_transaction1, cell_index: 1, - tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block, capacity: 4 * 10**8) + tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:, capacity: 4 * 10**8) create(:cell_output, ckb_transaction: ckb_transaction2, cell_index: 2, - tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) node_block_transactions = node_block.transactions local_block = node_data_processor.process_block(node_block) @@ -375,7 +398,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase node_block_transactions.each_with_index.map do |transaction, index| index.zero? ? 1 : transaction.outputs.count - transaction.inputs.count end - assert_equal expected_live_cell_changes, local_block.ckb_transactions.order(:id).map(&:live_cell_changes) + assert_equal expected_live_cell_changes, + local_block.ckb_transactions.order(:id).map(&:live_cell_changes) end end @@ -385,13 +409,13 @@ class NodeDataProcessorTest < ActiveSupport::TestCase create(:block, :with_block_hash, number: node_block.header.number - 1) block = create(:block, :with_block_hash) ckb_transaction1 = create(:ckb_transaction, - tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) ckb_transaction2 = create(:ckb_transaction, - tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) create(:cell_output, ckb_transaction: ckb_transaction1, cell_index: 1, - tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) create(:cell_output, ckb_transaction: ckb_transaction2, cell_index: 2, - tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) local_block = node_data_processor.process_block(node_block) expected_capacity_involved = local_block.ckb_transactions.normal.map(&:capacity_involved) @@ -407,16 +431,17 @@ class NodeDataProcessorTest < ActiveSupport::TestCase create(:block, :with_block_hash, number: node_block.header.number - 1) block = create(:block, :with_block_hash) ckb_transaction1 = create(:ckb_transaction, - tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) ckb_transaction2 = create(:ckb_transaction, - tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) create(:cell_output, ckb_transaction: ckb_transaction1, cell_index: 1, - tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block, capacity: 4 * 10**8) + tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:, capacity: 4 * 10**8) create(:cell_output, ckb_transaction: ckb_transaction2, cell_index: 2, - tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) local_block = node_data_processor.process_block(node_block) - assert_equal local_block.live_cell_changes, local_block.ckb_transactions.sum(&:live_cell_changes) + assert_equal local_block.live_cell_changes, + local_block.ckb_transactions.sum(&:live_cell_changes) end end @@ -441,27 +466,27 @@ class NodeDataProcessorTest < ActiveSupport::TestCase node_block = CkbSync::Api.instance.get_block_by_number(DEFAULT_NODE_BLOCK_NUMBER) create(:block, :with_block_hash, number: node_block.header.number - 1) node_transactions = node_block.transactions.map(&:to_h).map(&:deep_stringify_keys) - node_block_cell_inputs = node_transactions.map { |commit_transaction| + node_block_cell_inputs = node_transactions.map do |commit_transaction| commit_transaction["inputs"].map do |input| { "previous_tx_hash" => input["previous_output"]["tx_hash"] == CellOutput::SYSTEM_TX_HASH ? nil : input["previous_output"]["tx_hash"], "index" => input["previous_output"]["tx_hash"] == CellOutput::SYSTEM_TX_HASH ? 0 : input["previous_output"]["index"].hex, - "since" => input["since"].hex + "since" => input["since"].hex, } end - }.flatten + end.flatten local_block = node_data_processor.process_block(node_block) local_block_transactions = local_block.ckb_transactions - local_block_cell_inputs = local_block_transactions.map { |commit_transaction| + local_block_cell_inputs = local_block_transactions.map do |commit_transaction| commit_transaction.cell_inputs.map do |cell_input| { "previous_tx_hash" => cell_input.previous_tx_hash, "index" => cell_input.previous_index, - "since" => cell_input.since + "since" => cell_input.since, } end - }.flatten + end.flatten # binding.pry assert_equal node_block_cell_inputs, local_block_cell_inputs end @@ -488,21 +513,21 @@ class NodeDataProcessorTest < ActiveSupport::TestCase node_block = CkbSync::Api.instance.get_block_by_number(DEFAULT_NODE_BLOCK_NUMBER) create(:block, :with_block_hash, number: node_block.header.number - 1) node_block_transactions = node_block.transactions - node_block_cell_outputs = node_block_transactions.map { |commit_transaction| + node_block_cell_outputs = node_block_transactions.map do |commit_transaction| commit_transaction.to_h.deep_stringify_keys["outputs"].map do |output| format_node_block_cell_output(output).sort end - }.flatten + end.flatten local_block = node_data_processor.process_block(node_block) local_block_transactions = local_block.ckb_transactions - local_block_cell_outputs = local_block_transactions.map { |commit_transaction| + local_block_cell_outputs = local_block_transactions.map do |commit_transaction| commit_transaction.cell_outputs.map do |cell_output| attributes = cell_output.attributes attributes["capacity"] = attributes["capacity"] attributes.select { |attribute| attribute == "capacity" }.sort end - }.flatten + end.flatten assert_equal node_block_cell_outputs, local_block_cell_outputs end @@ -520,7 +545,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase local_block = node_data_processor.process_block(node_block) cell = local_block.cell_outputs.order(:id).first - assert_equal "0x3307186493c5da8b91917924253a5ffd35231151649d0c7e2941aa8801815063", cell.data + assert_equal "0x3307186493c5da8b91917924253a5ffd35231151649d0c7e2941aa8801815063", + cell.data end end @@ -541,10 +567,12 @@ class NodeDataProcessorTest < ActiveSupport::TestCase node_output = node_block.transactions.first.outputs.first node_output.type = CKB::Types::Script.new(code_hash: Settings.dao_code_hash, args: "0xb2e61ff569acf041b3c2c17724e2379c581eeac3", hash_type: "type") - node_block.transactions.first.outputs_data[0] = CKB::Utils.bin_to_hex("\x00" * 8) + node_block.transactions.first.outputs_data[0] = + CKB::Utils.bin_to_hex("\x00" * 8) local_block = node_data_processor.process_block(node_block) - assert_equal ["nervos_dao_deposit"], local_block.cell_outputs.pluck(:cell_type).uniq + assert_equal ["nervos_dao_deposit"], + local_block.cell_outputs.pluck(:cell_type).uniq end end @@ -555,10 +583,12 @@ class NodeDataProcessorTest < ActiveSupport::TestCase node_output = node_block.transactions.first.outputs.first node_output.type = CKB::Types::Script.new(code_hash: Settings.dao_type_hash, args: "0xb2e61ff569acf041b3c2c17724e2379c581eeac3", hash_type: "type") - node_block.transactions.first.outputs_data[0] = CKB::Utils.bin_to_hex("\x00" * 8) + node_block.transactions.first.outputs_data[0] = + CKB::Utils.bin_to_hex("\x00" * 8) local_block = node_data_processor.process_block(node_block) - assert_equal ["nervos_dao_deposit"], local_block.cell_outputs.pluck(:cell_type).uniq + assert_equal ["nervos_dao_deposit"], + local_block.cell_outputs.pluck(:cell_type).uniq end end @@ -569,10 +599,12 @@ class NodeDataProcessorTest < ActiveSupport::TestCase node_output = node_block.transactions.first.outputs.first node_output.type = CKB::Types::Script.new(code_hash: Settings.dao_type_hash, args: "0xb2e61ff569acf041b3c2c17724e2379c581eeac3", hash_type: "type") - node_block.transactions.first.outputs_data[0] = CKB::Utils.bin_to_hex("\x02" * 8) + node_block.transactions.first.outputs_data[0] = + CKB::Utils.bin_to_hex("\x02" * 8) local_block = node_data_processor.process_block(node_block) - assert_equal ["nervos_dao_withdrawing"], local_block.cell_outputs.pluck(:cell_type).uniq + assert_equal ["nervos_dao_withdrawing"], + local_block.cell_outputs.pluck(:cell_type).uniq end end @@ -582,19 +614,25 @@ class NodeDataProcessorTest < ActiveSupport::TestCase create(:block, :with_block_hash, number: node_block.header.number - 1) locks = node_block.transactions.map(&:outputs).flatten.map(&:lock) local_block = node_data_processor.process_block(node_block) - expected_lock_address = locks.map { |lock| Address.find_or_create_address(lock, node_block.header.timestamp) } + expected_lock_address = locks.map do |lock| + Address.find_or_create_address(lock, node_block.header.timestamp) + end - assert_equal expected_lock_address, local_block.cell_outputs.map(&:address) + assert_equal expected_lock_address, + local_block.cell_outputs.map(&:address) end end test "#process_block should create addresses for ckb transaction" do - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do node_block = CkbSync::Api.instance.get_block_by_number(DEFAULT_NODE_BLOCK_NUMBER) create(:block, :with_block_hash, number: node_block.header.number - 1) locks = node_block.transactions.map(&:outputs).flatten.map(&:lock) local_block = node_data_processor.process_block(node_block) - expected_lock_address = locks.map { |lock| Address.find_or_create_address(lock, node_block.header.timestamp) } + expected_lock_address = locks.map do |lock| + Address.find_or_create_address(lock, node_block.header.timestamp) + end assert_equal expected_lock_address, Address.where(id: local_block.ckb_transactions.map(&:contained_address_ids).flatten) @@ -607,10 +645,10 @@ class NodeDataProcessorTest < ActiveSupport::TestCase create(:block, :with_block_hash, number: node_block.header.number - 1) expected_lock_scripts = node_block.transactions.map(&:outputs).flatten.map(&:lock).map(&:to_h) local_block = node_data_processor.process_block(node_block) - actual_lock_scripts = local_block.cell_outputs.map { |cell_output| + actual_lock_scripts = local_block.cell_outputs.map do |cell_output| CKB::Types::Script.new(code_hash: cell_output.lock_script.code_hash, args: cell_output.lock_script.args, hash_type: "type") - }.map(&:to_h) + end.map(&:to_h) assert_equal expected_lock_scripts, actual_lock_scripts end @@ -621,21 +659,21 @@ class NodeDataProcessorTest < ActiveSupport::TestCase node_block = CkbSync::Api.instance.get_block_by_number(DEFAULT_NODE_BLOCK_NUMBER) create(:block, :with_block_hash, number: node_block.header.number - 1) node_block_transactions = node_block.transactions - node_block_lock_scripts = node_block_transactions.map { |commit_transaction| - commit_transaction.to_h.deep_stringify_keys["outputs"].map { |output| + node_block_lock_scripts = node_block_transactions.map do |commit_transaction| + commit_transaction.to_h.deep_stringify_keys["outputs"].map do |output| output["lock"] - }.sort - }.flatten + end.sort + end.flatten local_block = node_data_processor.process_block(node_block) local_block_transactions = local_block.ckb_transactions - local_block_lock_scripts = local_block_transactions.map { |commit_transaction| - commit_transaction.cell_outputs.map { |cell_output| + local_block_lock_scripts = local_block_transactions.map do |commit_transaction| + commit_transaction.cell_outputs.map do |cell_output| cell_output.lock_script.attributes.select do |attribute| attribute.in?(%w(args code_hash hash_type)) end - }.sort - }.flatten + end.sort + end.flatten assert_equal node_block_lock_scripts, local_block_lock_scripts end @@ -647,9 +685,13 @@ class NodeDataProcessorTest < ActiveSupport::TestCase create(:block, :with_block_hash, number: node_block.header.number - 1) node_block_transactions = node_block.transactions node_cell_outputs = node_block_transactions.map(&:outputs).flatten - node_cell_outputs_with_type_script = node_cell_outputs.select { |cell_output| cell_output.type.present? } + node_cell_outputs_with_type_script = node_cell_outputs.select do |cell_output| + cell_output.type.present? + end - assert_difference -> { TypeScript.count }, node_cell_outputs_with_type_script.size do + assert_difference -> { + TypeScript.count + }, node_cell_outputs_with_type_script.size do node_data_processor.process_block(node_block) end end @@ -661,21 +703,21 @@ class NodeDataProcessorTest < ActiveSupport::TestCase create(:block, :with_block_hash, number: node_block.header.number - 1) fake_node_block_with_type_script(node_block) node_block_transactions = node_block.transactions - node_block_type_scripts = node_block_transactions.map { |commit_transaction| - commit_transaction.to_h.deep_stringify_keys["outputs"].map { |output| + node_block_type_scripts = node_block_transactions.map do |commit_transaction| + commit_transaction.to_h.deep_stringify_keys["outputs"].map do |output| output["type"] - }.sort - }.flatten + end.sort + end.flatten local_block = node_data_processor.process_block(node_block) local_block_transactions = local_block.ckb_transactions - local_block_type_scripts = local_block_transactions.map { |commit_transaction| - commit_transaction.cell_outputs.map { |cell_output| + local_block_type_scripts = local_block_transactions.map do |commit_transaction| + commit_transaction.cell_outputs.map do |cell_output| cell_output.type_script.attributes.select do |attribute| attribute.in?(%w(args code_hash hash_type)) end - }.sort - }.flatten + end.sort + end.flatten assert_equal node_block_type_scripts, local_block_type_scripts end @@ -684,17 +726,18 @@ class NodeDataProcessorTest < ActiveSupport::TestCase test "#process_block should update block's total transaction fee" do node_block = fake_node_block("0x3307186493c5da8b91917924253a5ffd35231151649d0c7e2941aa8801815063") create(:block, :with_block_hash, number: node_block.header.number - 1) - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do block = create(:block, :with_block_hash) ckb_transaction1 = create(:ckb_transaction, - tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) ckb_transaction2 = create(:ckb_transaction, - tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) lock = create(:lock_script) create(:cell_output, ckb_transaction: ckb_transaction1, cell_index: 1, - tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block, lock_script_id: lock.id) + tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:, lock_script_id: lock.id) create(:cell_output, ckb_transaction: ckb_transaction2, cell_index: 2, - tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block, lock_script_id: lock.id) + tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:, lock_script_id: lock.id) local_block = node_data_processor.process_block(node_block) assert_equal 10**8 * 5, local_block.reload.total_transaction_fee @@ -704,24 +747,28 @@ class NodeDataProcessorTest < ActiveSupport::TestCase test "#process_block should update block's contained addresses's transactions count even if fee is a negative number" do node_block = fake_node_block("0x3307186493c5da8b91917924253a5ffd35231151649d0c7e2941aa8801815063") create(:block, :with_block_hash, number: node_block.header.number - 1) - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do block = create(:block, :with_block_hash) lock = node_block.transactions.last.outputs.first.lock - lock_script = create(:lock_script, code_hash: lock.code_hash, hash_type: lock.hash_type, args: lock.args) - addr = Address.find_or_create_address(lock, node_block.header.timestamp, lock_script.id) + lock_script = create(:lock_script, code_hash: lock.code_hash, + hash_type: lock.hash_type, args: lock.args) + addr = Address.find_or_create_address(lock, + node_block.header.timestamp, lock_script.id) ckb_transaction1 = create(:ckb_transaction, - tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block, contained_address_ids: [addr.id]) + tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:, contained_address_ids: [addr.id]) ckb_transaction2 = create(:ckb_transaction, - tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block, contained_address_ids: [addr.id]) + tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:, contained_address_ids: [addr.id]) addr.update(ckb_transactions_count: 2) create(:cell_output, ckb_transaction: ckb_transaction1, cell_index: 1, - tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block, capacity: 4 * 10**8, address: addr) + tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:, capacity: 4 * 10**8, address: addr) create(:cell_output, ckb_transaction: ckb_transaction2, cell_index: 2, - tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block, address: addr) + tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:, address: addr) local_block = node_data_processor.process_block(node_block) - assert_equal 5, local_block.contained_addresses.map(&:ckb_transactions_count).flatten.sum + assert_equal 5, + local_block.contained_addresses.map(&:ckb_transactions_count).flatten.sum end end @@ -731,26 +778,31 @@ class NodeDataProcessorTest < ActiveSupport::TestCase create(:block, :with_block_hash, number: node_block.header.number - 1) VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}") do lock = node_block.transactions.last.outputs.first.lock - lock_script = create(:lock_script, code_hash: lock.code_hash, hash_type: lock.hash_type, args: lock.args) - addr = Address.find_or_create_address(lock, node_block.header.timestamp, lock_script.id) + lock_script = create(:lock_script, code_hash: lock.code_hash, + hash_type: lock.hash_type, args: lock.args) + addr = Address.find_or_create_address(lock, + node_block.header.timestamp, lock_script.id) fake_dao_deposit_transaction(node_block) local_block = node_data_processor.process_block(node_block) - assert_equal 5, local_block.contained_addresses.map(&:ckb_transactions_count).flatten.sum + assert_equal 5, + local_block.contained_addresses.map(&:ckb_transactions_count).flatten.sum end end test "should create forked event when block is invalid " do node_block = fake_node_block - create(:block, :with_block_hash, number: node_block.header.number - 1, timestamp: 1557282351075) + create(:block, :with_block_hash, number: node_block.header.number - 1, + timestamp: 1557282351075) VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}") do fake_dao_deposit_transaction(node_block) node_data_processor.process_block(node_block) end local_block = Block.find_by(number: DEFAULT_NODE_BLOCK_NUMBER) local_block.update(block_hash: "0x419c632366c8eb9635acbb39ea085f7552ae62e1fdd480893375334a0f37d1bx") - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do assert_difference -> { ForkedEvent.count }, 1 do node_data_processor.call end @@ -761,7 +813,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase test "should revert dao contract total depositors count when block is invalid and there is dao cell" do CkbSync::Api.any_instance.stubs(:calculate_dao_maximum_withdraw).returns("0x2faf0be8") node_block = fake_node_block - create(:block, :with_block_hash, number: node_block.header.number - 1, timestamp: 1557282351075) + create(:block, :with_block_hash, number: node_block.header.number - 1, + timestamp: 1557282351075) VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}") do fake_dao_deposit_transaction(node_block) node_data_processor.process_block(node_block) @@ -770,8 +823,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase local_block = Block.find_by(number: DEFAULT_NODE_BLOCK_NUMBER) local_block.update(block_hash: "0x419c632366c8eb9635acbb39ea085f7552ae62e1fdd480893375334a0f37d1bx") - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do - assert_difference -> { dao_contract.reload.total_depositors_count }, -1 do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do + assert_difference -> { + dao_contract.reload.total_depositors_count + }, -1 do node_data_processor.call end @@ -781,18 +837,19 @@ class NodeDataProcessorTest < ActiveSupport::TestCase end test "#process_block should update cell status" do - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do node_block = fake_node_block("0x3307186493c5da8b91917924253a5ffd35231151649d0c7e2941aa8801815063") create(:block, :with_block_hash, number: node_block.header.number - 1) block = create(:block, :with_block_hash) ckb_transaction1 = create(:ckb_transaction, - tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) ckb_transaction2 = create(:ckb_transaction, - tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) create(:cell_output, ckb_transaction: ckb_transaction1, cell_index: 1, - tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) create(:cell_output, ckb_transaction: ckb_transaction2, cell_index: 2, - tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) assert_difference -> { CellOutput.dead.count }, 2 do node_data_processor.process_block(node_block) @@ -809,17 +866,18 @@ class NodeDataProcessorTest < ActiveSupport::TestCase node_block = fake_node_block("0x3307186493c5da8b91917924253a5ffd35231151649d0c7e2941aa8801815063") block = create(:block, :with_block_hash) ckb_transaction1 = create(:ckb_transaction, - tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) ckb_transaction2 = create(:ckb_transaction, - tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) create(:cell_output, ckb_transaction: ckb_transaction1, cell_index: 1, - tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) create(:cell_output, ckb_transaction: ckb_transaction2, cell_index: 2, - tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) create(:block, :with_block_hash, number: node_block.header.number - 1) local_block = node_data_processor.process_block(node_block) - assert_empty local_block.cell_inputs.where(from_cell_base: false, previous_cell_output_id: nil) + assert_empty local_block.cell_inputs.where(from_cell_base: false, + previous_cell_output_id: nil) end end @@ -829,12 +887,15 @@ class NodeDataProcessorTest < ActiveSupport::TestCase node_block = CkbSync::Api.instance.get_block_by_number(25) cellbase = node_block.transactions.first lock_script = CkbUtils.generate_lock_script_from_cellbase(cellbase) - miner_address = Address.find_or_create_address(lock_script, node_block.header.timestamp) + miner_address = Address.find_or_create_address(lock_script, + node_block.header.timestamp) assert_difference -> { MiningInfo.count }, 1 do node_data_processor.process_block(node_block) end - assert_equal "mined", MiningInfo.find_by(block_number: 25, address_id: miner_address.id).status + assert_equal "mined", + MiningInfo.find_by(block_number: 25, + address_id: miner_address.id).status end end @@ -844,7 +905,9 @@ class NodeDataProcessorTest < ActiveSupport::TestCase local_block.update(block_hash: "0x419c632366c8eb9635acbb39ea085f7552ae62e1fdd480893375334a0f37d1bx") VCR.use_cassette("blocks/25") do - assert_changes -> { MiningInfo.find_by(block_number: 24).status }, from: "mined", to: "reverted" do + assert_changes -> { + MiningInfo.find_by(block_number: 24).status + }, from: "mined", to: "reverted" do node_data_processor.call end end @@ -858,7 +921,9 @@ class NodeDataProcessorTest < ActiveSupport::TestCase local_block.target_block.update(miner_hash: addr.address_hash) VCR.use_cassette("blocks/25") do - assert_difference -> { local_block.miner_address.reload.mined_blocks_count }, -1 do + assert_difference -> { + local_block.miner_address.reload.mined_blocks_count + }, -1 do node_data_processor.call end end @@ -870,7 +935,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase node_block = CkbSync::Api.instance.get_block_by_number(25) cellbase = node_block.transactions.first lock_script = CkbUtils.generate_lock_script_from_cellbase(cellbase) - miner_address = Address.find_or_create_address(lock_script, node_block.header.timestamp) + miner_address = Address.find_or_create_address(lock_script, + node_block.header.timestamp) assert_difference -> { miner_address.reload.mined_blocks_count }, 1 do node_data_processor.process_block(node_block) @@ -884,7 +950,9 @@ class NodeDataProcessorTest < ActiveSupport::TestCase local_block.update(block_hash: "0x419c632366c8eb9635acbb39ea085f7552ae62e1fdd480893375334a0f37d1bx") VCR.use_cassette("blocks/13") do - assert_difference -> { local_block.contained_addresses.map(&:ckb_transactions_count).flatten.sum }, -1 do + assert_difference -> { + local_block.contained_addresses.map(&:ckb_transactions_count).flatten.sum + }, -1 do node_data_processor.call end end @@ -911,7 +979,9 @@ class NodeDataProcessorTest < ActiveSupport::TestCase local_block.update(block_hash: "0x419c632366c8eb9635acbb39ea085f7552ae62e1fdd480893375334a0f37d1bx") VCR.use_cassette("blocks/13") do - assert_difference -> { ckb_transactions_counter.reload.count }, -local_block.ckb_transactions.normal.count do + assert_difference -> { + ckb_transactions_counter.reload.count + }, -local_block.ckb_transactions.normal.count do node_data_processor.call end end @@ -927,7 +997,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase VCR.use_cassette("blocks/12", record: :new_episodes) do new_local_block = node_data_processor.call - assert_equal origin_balance - balance_diff, new_local_block.contained_addresses.sum(:balance) + assert_equal origin_balance - balance_diff, + new_local_block.contained_addresses.sum(:balance) end end @@ -938,11 +1009,14 @@ class NodeDataProcessorTest < ActiveSupport::TestCase VCR.use_cassette("blocks/13", record: :new_episodes) do new_local_block = node_data_processor.call - assert_equal origin_live_cells_count + 1, new_local_block.contained_addresses.sum(:live_cells_count) + assert_equal origin_live_cells_count + 1, + new_local_block.contained_addresses.sum(:live_cells_count) address = new_local_block.contained_addresses.first - snapshot = AddressBlockSnapshot.find_by(block_id: new_local_block.id, address_id: address.id) - assert_equal snapshot.final_state["live_cells_count"], address.live_cells_count + snapshot = AddressBlockSnapshot.find_by(block_id: new_local_block.id, + address_id: address.id) + assert_equal snapshot.final_state["live_cells_count"], + address.live_cells_count end end @@ -960,9 +1034,13 @@ class NodeDataProcessorTest < ActiveSupport::TestCase Address.find_or_create_address(lock2, node_block.header.timestamp) 300.times do |i| if i % 2 == 0 - node_block.transactions.first.outputs << CKB::Types::Output.new(capacity: 30000 * 10**8, lock: lock1) + node_block.transactions.first.outputs << CKB::Types::Output.new( + capacity: 30000 * 10**8, lock: lock1, + ) else - node_block.transactions.first.outputs << CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2) + node_block.transactions.first.outputs << CKB::Types::Output.new( + capacity: 40000 * 10**8, lock: lock2, + ) end node_block.transactions.first.outputs_data << "0x" end @@ -972,15 +1050,18 @@ class NodeDataProcessorTest < ActiveSupport::TestCase new_local_block.contained_addresses.sum(:balance) address = new_local_block.contained_addresses.first - snapshot = AddressBlockSnapshot.find_by(block_id: new_local_block.id, address_id: address.id) + snapshot = AddressBlockSnapshot.find_by(block_id: new_local_block.id, + address_id: address.id) assert_equal snapshot.final_state["balance"], address.balance end end test "#process_block should update block's contained address's dao_ckb_transactions_count" do - block1 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 2) + block1 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 2) tx1 = create(:ckb_transaction, block: block1) - block2 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 1) + block2 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 1) tx2 = create(:ckb_transaction, block: block2) tx3 = create(:ckb_transaction, block: block2) tx4 = create(:ckb_transaction, block: block2) @@ -1003,13 +1084,23 @@ class NodeDataProcessorTest < ActiveSupport::TestCase header = CKB::Types::BlockHeader.new(compact_target: "0x1000", hash: "0x#{SecureRandom.hex(32)}", number: DEFAULT_NODE_BLOCK_NUMBER, parent_hash: "0x#{SecureRandom.hex(32)}", nonce: 1757392074788233522, timestamp: CkbUtils.time_in_milliseconds(Time.current), transactions_root: "0x#{SecureRandom.hex(32)}", proposals_hash: "0x#{SecureRandom.hex(32)}", extra_hash: "0x#{SecureRandom.hex(32)}", version: 0, epoch: 1, dao: "0x01000000000000000000c16ff286230000a3a65e97fd03000057c138586f0000") inputs = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx1.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx2.tx_hash, index: 1)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx3.tx_hash, index: 2)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx1.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx2.tx_hash, index: 1, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx3.tx_hash, index: 2, + )), ] inputs1 = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx4.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx5.tx_hash, index: 0)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx4.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx5.tx_hash, index: 0, + )), ] lock1 = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") @@ -1017,38 +1108,44 @@ class NodeDataProcessorTest < ActiveSupport::TestCase args: "0x#{SecureRandom.hex(20)}") lock3 = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") - dao_type = CKB::Types::Script.new(code_hash: Settings.dao_type_hash, hash_type: "type", args: "0x") + dao_type = CKB::Types::Script.new(code_hash: Settings.dao_type_hash, + hash_type: "type", args: "0x") outputs = [ - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] outputs1 = [ - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] miner_lock = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") cellbase_inputs = [ CKB::Types::Input.new( previous_output: CKB::Types::OutPoint.new( - tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295 + tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295, ), since: 3000 - ) + ), ] cellbase_outputs = [ - CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock) + CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock), ] transactions = [ CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: cellbase_inputs, outputs: cellbase_outputs, outputs_data: %w[0x], witnesses: ["0x590000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd800000000"]), - CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs, - outputs: outputs, outputs_data: %w[0x0000000000000000 0x0000000000000000 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), + CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs:, + outputs:, outputs_data: %w[0x0000000000000000 0x0000000000000000 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs1, - outputs: outputs1, outputs_data: %w[0x0000000000000000 0x0000000000000000 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]) + outputs: outputs1, outputs_data: %w[0x0000000000000000 0x0000000000000000 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), ] - node_block = CKB::Types::Block.new(uncles: [], proposals: [], transactions: transactions, header: header) + node_block = CKB::Types::Block.new(uncles: [], proposals: [], + transactions:, header:) node_data_processor.process_block(node_block) address1 = Address.find_by(lock_hash: lock1.compute_hash) address2 = Address.find_by(lock_hash: lock2.compute_hash) @@ -1060,9 +1157,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase end test "should recalculate block's contained address's dao_ckb_transactions_count when block is invalid" do - block1 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 2) + block1 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 2) tx1 = create(:ckb_transaction, block: block1) - block2 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 1) + block2 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 1) tx2 = create(:ckb_transaction, block: block2) tx3 = create(:ckb_transaction, block: block2) tx4 = create(:ckb_transaction, block: block2) @@ -1086,13 +1185,23 @@ class NodeDataProcessorTest < ActiveSupport::TestCase header = CKB::Types::BlockHeader.new(compact_target: "0x1000", hash: "0x#{SecureRandom.hex(32)}", number: DEFAULT_NODE_BLOCK_NUMBER, parent_hash: "0x#{SecureRandom.hex(32)}", nonce: 1757392074788233522, timestamp: CkbUtils.time_in_milliseconds(Time.current), transactions_root: "0x#{SecureRandom.hex(32)}", proposals_hash: "0x#{SecureRandom.hex(32)}", extra_hash: "0x#{SecureRandom.hex(32)}", version: 0, epoch: 1, dao: "0x01000000000000000000c16ff286230000a3a65e97fd03000057c138586f0000") inputs = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx1.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx2.tx_hash, index: 1)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx3.tx_hash, index: 2)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx1.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx2.tx_hash, index: 1, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx3.tx_hash, index: 2, + )), ] inputs1 = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx4.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx5.tx_hash, index: 0)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx4.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx5.tx_hash, index: 0, + )), ] lock1 = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") @@ -1100,44 +1209,51 @@ class NodeDataProcessorTest < ActiveSupport::TestCase args: "0x#{SecureRandom.hex(20)}") lock3 = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") - dao_type = CKB::Types::Script.new(code_hash: Settings.dao_type_hash, hash_type: "type", args: "0x") + dao_type = CKB::Types::Script.new(code_hash: Settings.dao_type_hash, + hash_type: "type", args: "0x") outputs = [ - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] outputs1 = [ - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] miner_lock = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") cellbase_inputs = [ CKB::Types::Input.new( previous_output: CKB::Types::OutPoint.new( - tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295 + tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295, ), since: 3000 - ) + ), ] cellbase_outputs = [ - CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock) + CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock), ] transactions = [ CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: cellbase_inputs, outputs: cellbase_outputs, outputs_data: %w[0x], witnesses: ["0x590000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd800000000"]), - CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs, - outputs: outputs, outputs_data: %w[0x0000000000000000 0x0000000000000000 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), + CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs:, + outputs:, outputs_data: %w[0x0000000000000000 0x0000000000000000 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs1, - outputs: outputs1, outputs_data: %w[0x0000000000000000 0x0000000000000000 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]) + outputs: outputs1, outputs_data: %w[0x0000000000000000 0x0000000000000000 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), ] - node_block = CKB::Types::Block.new(uncles: [], proposals: [], transactions: transactions, header: header) + node_block = CKB::Types::Block.new(uncles: [], proposals: [], + transactions:, header:) block = node_data_processor.process_block(node_block) address1 = Address.find_by(lock_hash: lock1.compute_hash) address2 = Address.find_by(lock_hash: lock2.compute_hash) address3 = Address.find_by(lock_hash: lock3.compute_hash) CkbSync::Api.any_instance.stubs(:get_tip_block_number).returns(block.number + 1) - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do node_data_processor.call end @@ -1154,7 +1270,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase VCR.use_cassette("blocks/12", record: :new_episodes) do new_local_block = node_data_processor.call - assert_equal origin_live_cells_count - 1, new_local_block.contained_addresses.sum(:live_cells_count) + assert_equal origin_live_cells_count - 1, + new_local_block.contained_addresses.sum(:live_cells_count) end end @@ -1163,12 +1280,14 @@ class NodeDataProcessorTest < ActiveSupport::TestCase local_block = Block.find_by(number: 12) address = local_block.contained_addresses.first origin_balance_occupied = 300 * 10**8 - address.update(balance_occupied: origin_balance_occupied, mined_blocks_count: 1) + address.update(balance_occupied: origin_balance_occupied, + mined_blocks_count: 1) local_block.update(block_hash: "0x419c632366c8eb9635acbb39ea085f7552ae62e1fdd480893375334a0f37d1bx") VCR.use_cassette("blocks/12", record: :new_episodes) do new_local_block = node_data_processor.call - assert_equal 0, new_local_block.contained_addresses.sum(:balance_occupied) + assert_equal 0, + new_local_block.contained_addresses.sum(:balance_occupied) end end @@ -1178,7 +1297,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase local_block = node_data_processor.call target_block = local_block.target_block block_economic_state = CkbSync::Api.instance.get_block_economic_state(local_block.target_block.block_hash) - expected_reward = CkbUtils.block_reward(local_block.number, block_economic_state) + expected_reward = CkbUtils.block_reward(local_block.number, + block_economic_state) assert_equal expected_reward, target_block.reward end @@ -1191,7 +1311,9 @@ class NodeDataProcessorTest < ActiveSupport::TestCase target_block = local_block.target_block block_header = Struct.new(:hash, :number) block_economic_state = CkbSync::Api.instance.get_block_economic_state(local_block.target_block.block_hash) - expected_primary_reward = CkbUtils.primary_reward(local_block.target_block_number, block_economic_state) + expected_primary_reward = CkbUtils.primary_reward( + local_block.target_block_number, block_economic_state + ) assert_equal expected_primary_reward, target_block.primary_reward end @@ -1204,7 +1326,9 @@ class NodeDataProcessorTest < ActiveSupport::TestCase target_block = local_block.target_block block_header = Struct.new(:hash, :number) block_economic_state = CkbSync::Api.instance.get_block_economic_state(local_block.target_block.block_hash) - expected_secondary_reward = CkbUtils.secondary_reward(local_block.target_block_number, block_economic_state) + expected_secondary_reward = CkbUtils.secondary_reward( + local_block.target_block_number, block_economic_state + ) assert_equal expected_secondary_reward, target_block.secondary_reward end @@ -1213,8 +1337,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase test "should do nothing on the local tip block's target block reward status when there is no target block" do prepare_node_data(9) local_block = Block.find_by(number: 9) - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do - assert_no_changes -> { local_block.reload.target_block_reward_status } do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do + assert_no_changes -> { + local_block.reload.target_block_reward_status + } do node_data_processor.call end end @@ -1224,7 +1351,9 @@ class NodeDataProcessorTest < ActiveSupport::TestCase prepare_node_data(12) target_block = Block.find_by(number: 2) VCR.use_cassette("blocks/12", record: :new_episodes) do - assert_changes -> { target_block.reload.received_tx_fee }, from: 0, to: 20 do + assert_changes -> { + target_block.reload.received_tx_fee + }, from: 0, to: 20 do node_data_processor.call end end @@ -1232,7 +1361,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase test "should do nothing on the local tip block target block's received tx fee when there is no target block" do prepare_node_data(9) - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do assert_nothing_raised do node_data_processor.call end @@ -1243,7 +1373,9 @@ class NodeDataProcessorTest < ActiveSupport::TestCase prepare_node_data(12) target_block = Block.find_by(number: 2) VCR.use_cassette("blocks/12", record: :new_episodes) do - assert_changes -> { target_block.reload.reward_status }, from: "pending", to: "issued" do + assert_changes -> { + target_block.reload.reward_status + }, from: "pending", to: "issued" do node_data_processor.call end end @@ -1251,7 +1383,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase test "should do nothing on the local tip block target block's reward status when there is no target block" do prepare_node_data(9) - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do assert_nothing_raised do node_data_processor.call end @@ -1262,7 +1395,9 @@ class NodeDataProcessorTest < ActiveSupport::TestCase prepare_node_data(12) target_block = Block.find_by(number: 2) VCR.use_cassette("blocks/12", record: :new_episodes) do - assert_changes -> { target_block.reload.received_tx_fee_status }, from: "pending", to: "calculated" do + assert_changes -> { + target_block.reload.received_tx_fee_status + }, from: "pending", to: "calculated" do node_data_processor.call end end @@ -1270,7 +1405,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase test "should do nothing on the local tip block target block's received_tx_fee_status when there is no target block" do prepare_node_data(9) - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do assert_nothing_raised do node_data_processor.call end @@ -1285,24 +1421,24 @@ class NodeDataProcessorTest < ActiveSupport::TestCase primary: "0x174876e800", secondary: "0x0", tx_fee: "0x0", - proposal_reward: "0x0" - ) + proposal_reward: "0x0", + ), ) CkbSync::Api.any_instance.stubs(:get_block_economic_state).returns( OpenStruct.new(miner_reward: CKB::Types::MinerReward.new( primary: "0x174876e800", secondary: "0xa", committed: "0xa", - proposal: "0xa" - )) + proposal: "0xa", + )), ) CkbSync::Api.any_instance.stubs(:get_epoch_by_number).returns( CKB::Types::Epoch.new( compact_target: "0x1000", length: "0x07d0", number: "0x0", - start_number: "0x0" - ) + start_number: "0x0", + ), ) VCR.use_cassette("blocks/12") do node_block = CkbSync::Api.instance.get_block_by_number(12) @@ -1313,10 +1449,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase cellbase = Cellbase.new(block) expected_cellbase_display_inputs = [ CkbUtils.hash_value_to_s(id: nil, from_cellbase: true, capacity: nil, occupied_capacity: nil, - address_hash: nil, target_block_number: cellbase.target_block_number, generated_tx_hash: block.cellbase.tx_hash) + address_hash: nil, target_block_number: cellbase.target_block_number, generated_tx_hash: block.cellbase.tx_hash), ] - assert_equal expected_cellbase_display_inputs, block.cellbase.display_inputs + assert_equal expected_cellbase_display_inputs, + block.cellbase.display_inputs end end end @@ -1330,16 +1467,16 @@ class NodeDataProcessorTest < ActiveSupport::TestCase primary: "0x174876e800", secondary: "0x0", tx_fee: "0x0", - proposal_reward: "0x0" - ) + proposal_reward: "0x0", + ), ) CkbSync::Api.any_instance.stubs(:get_block_economic_state).returns( OpenStruct.new(miner_reward: CKB::Types::MinerReward.new( primary: "0x174876e800", secondary: "0xa", committed: "0xa", - proposal: "0xa" - )) + proposal: "0xa", + )), ) node_block = CkbSync::Api.instance.get_block_by_number(DEFAULT_NODE_BLOCK_NUMBER) create(:block, :with_block_hash, number: node_block.header.number - 1) @@ -1351,7 +1488,7 @@ class NodeDataProcessorTest < ActiveSupport::TestCase cellbase = Cellbase.new(local_block) expected_display_outputs = [ CkbUtils.hash_value_to_s(id: output.id, capacity: output.capacity, occupied_capacity: output.occupied_capacity, - address_hash: output.address_hash, target_block_number: cellbase.target_block_number, base_reward: cellbase.base_reward, commit_reward: cellbase.commit_reward, proposal_reward: cellbase.proposal_reward, secondary_reward: cellbase.secondary_reward, status: "live", consumed_tx_hash: nil) + address_hash: output.address_hash, target_block_number: cellbase.target_block_number, base_reward: cellbase.base_reward, commit_reward: cellbase.commit_reward, proposal_reward: cellbase.proposal_reward, secondary_reward: cellbase.secondary_reward, status: "live", consumed_tx_hash: nil), ] assert_equal expected_display_outputs, local_block_cell_outputs @@ -1365,24 +1502,24 @@ class NodeDataProcessorTest < ActiveSupport::TestCase primary: "0x174876e800", secondary: "0x0", tx_fee: "0x0", - proposal_reward: "0x0" - ) + proposal_reward: "0x0", + ), ) CkbSync::Api.any_instance.stubs(:get_block_economic_state).returns( OpenStruct.new(miner_reward: CKB::Types::MinerReward.new( primary: "0x174876e800", secondary: "0xa", committed: "0xa", - proposal: "0xa" - )) + proposal: "0xa", + )), ) CkbSync::Api.any_instance.stubs(:get_epoch_by_number).returns( CKB::Types::Epoch.new( compact_target: "0x1000", length: "0x07d0", number: "0x0", - start_number: "0x0" - ) + start_number: "0x0", + ), ) VCR.use_cassette("genesis_block") do node_block = CkbSync::Api.instance.get_block_by_number(0) @@ -1394,9 +1531,10 @@ class NodeDataProcessorTest < ActiveSupport::TestCase block.cellbase.cell_outputs.order(:id).map do |cell_output| consumed_tx_hash = cell_output.live? ? nil : cell_output.consumed_by.tx_hash CkbUtils.hash_value_to_s(id: cell_output.id, capacity: cell_output.capacity, occupied_capacity: cell_output.occupied_capacity, - address_hash: cell_output.address_hash, target_block_number: cellbase.target_block_number, base_reward: cellbase.base_reward, commit_reward: cellbase.commit_reward, proposal_reward: cellbase.proposal_reward, secondary_reward: cellbase.secondary_reward, status: cell_output.status, consumed_tx_hash: consumed_tx_hash) + address_hash: cell_output.address_hash, target_block_number: cellbase.target_block_number, base_reward: cellbase.base_reward, commit_reward: cellbase.commit_reward, proposal_reward: cellbase.proposal_reward, secondary_reward: cellbase.secondary_reward, status: cell_output.status, consumed_tx_hash:) end - assert_equal expected_cellbase_display_outputs, block.cellbase.display_outputs + assert_equal expected_cellbase_display_outputs, + block.cellbase.display_outputs end end @@ -1407,8 +1545,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase compact_target: "0x1000", length: "0x07d0", number: "0x0", - start_number: "0x0" - ) + start_number: "0x0", + ), ) CkbSync::Api.any_instance.stubs(:get_cellbase_output_capacity_details).returns( CKB::Types::BlockReward.new( @@ -1416,16 +1554,16 @@ class NodeDataProcessorTest < ActiveSupport::TestCase primary: "0x174876e800", secondary: "0x0", tx_fee: "0x0", - proposal_reward: "0x0" - ) + proposal_reward: "0x0", + ), ) CkbSync::Api.any_instance.stubs(:get_block_economic_state).returns( OpenStruct.new(miner_reward: CKB::Types::MinerReward.new( primary: "0x174876e800", secondary: "0xa", committed: "0xa", - proposal: "0xa" - )) + proposal: "0xa", + )), ) VCR.use_cassette("blocks/12") do assert_difference "Block.count", 1 do @@ -1437,10 +1575,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase cell_output = block.cellbase.cell_outputs.first expected_cellbase_display_outputs = [ CkbUtils.hash_value_to_s(id: cell_output.id, - capacity: cell_output.capacity, occupied_capacity: cell_output.occupied_capacity, address_hash: cell_output.address_hash, target_block_number: cellbase.target_block_number, base_reward: cellbase.base_reward, commit_reward: cellbase.commit_reward, proposal_reward: cellbase.proposal_reward, secondary_reward: cellbase.secondary_reward, status: "live", consumed_tx_hash: nil) + capacity: cell_output.capacity, occupied_capacity: cell_output.occupied_capacity, address_hash: cell_output.address_hash, target_block_number: cellbase.target_block_number, base_reward: cellbase.base_reward, commit_reward: cellbase.commit_reward, proposal_reward: cellbase.proposal_reward, secondary_reward: cellbase.secondary_reward, status: "live", consumed_tx_hash: nil), ] - assert_equal expected_cellbase_display_outputs, block.cellbase.display_outputs + assert_equal expected_cellbase_display_outputs, + block.cellbase.display_outputs end end end @@ -1452,8 +1591,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase assert_not_empty local_block.uncle_blocks - VCR.use_cassette("blocks/#{HAS_UNCLES_BLOCK_NUMBER}", record: :new_episodes) do - assert_changes -> { local_block.uncle_blocks.count }, from: local_block.uncle_blocks.count, to: 0 do + VCR.use_cassette("blocks/#{HAS_UNCLES_BLOCK_NUMBER}", + record: :new_episodes) do + assert_changes -> { + local_block.uncle_blocks.count + }, from: local_block.uncle_blocks.count, to: 0 do node_data_processor.call end end @@ -1466,8 +1608,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase assert_not_empty local_block.ckb_transactions - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do - assert_changes -> { local_block.ckb_transactions.count }, from: local_block.ckb_transactions.count, to: 0 do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do + assert_changes -> { + local_block.ckb_transactions.count + }, from: local_block.ckb_transactions.count, to: 0 do node_data_processor.call end end @@ -1480,8 +1625,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase assert_not_empty local_block.cell_inputs - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do - assert_changes -> { local_block.cell_inputs.count }, from: local_block.cell_inputs.count, to: 0 do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do + assert_changes -> { + local_block.cell_inputs.count + }, from: local_block.cell_inputs.count, to: 0 do node_data_processor.call end end @@ -1494,7 +1642,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase assert_not_empty local_block.cell_outputs - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do assert_changes -> { CellOutput.where(block: local_block).count }, from: CellOutput.where(block: local_block).count, to: 0 do @@ -1511,7 +1660,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase assert_not_empty origin_lock_scripts - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do assert_changes -> { CellOutput.where(block: local_block).map(&:lock_script).count }, from: origin_lock_scripts.count, to: 0 do @@ -1528,7 +1678,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase assert_not_empty origin_type_scripts - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do assert_changes -> { CellOutput.where(block: local_block).map(&:type_script).count }, from: origin_type_scripts.count, to: 0 do @@ -1542,7 +1693,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase local_block = Block.find_by(number: 30) local_block.update(number: 100_000_000) - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do assert_nil node_data_processor.call end end @@ -1564,8 +1716,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase # ApplicationRecord.connection.execute "CALL sync_full_account_book()" local_block.update(block_hash: "0x419c632366c8eb9635acbb39ea085f7552ae62e1fdd480893375334a0f37d1bx") - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do - assert_difference -> { local_block.contained_addresses.map(&:ckb_transactions_count).flatten.sum }, -1 do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do + assert_difference -> { + local_block.contained_addresses.map(&:ckb_transactions_count).flatten.sum + }, -1 do node_data_processor.call end end @@ -1578,8 +1733,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase ckb_transaction_ids = local_block.ckb_transactions.pluck(:id) balance_diff = CellOutput.where(ckb_transaction_id: ckb_transaction_ids).sum(:capacity) - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do - assert_difference -> { local_block.contained_addresses.sum(:balance) }, -balance_diff do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do + assert_difference -> { + local_block.contained_addresses.sum(:balance) + }, -balance_diff do node_data_processor.call end end @@ -1591,7 +1749,9 @@ class NodeDataProcessorTest < ActiveSupport::TestCase local_block.update(block_hash: "0x419c632366c8eb9635acbb39ea085f7552ae62e1fdd480893375334a0f37d1bx") target_block = local_block.target_block VCR.use_cassette("blocks/12", record: :new_episodes) do - assert_changes -> { target_block.reload.received_tx_fee }, from: target_block.received_tx_fee, to: 0 do + assert_changes -> { + target_block.reload.received_tx_fee + }, from: target_block.received_tx_fee, to: 0 do node_data_processor.call end end @@ -1601,7 +1761,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase prepare_node_data(19) local_block = Block.find_by(number: 19) local_block.update(block_hash: "0x419c632366c8eb9635acbb39ea085f7552ae62e1fdd480893375334a0f37d1bx") - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do assert_nothing_raised do node_data_processor.call end @@ -1614,7 +1775,9 @@ class NodeDataProcessorTest < ActiveSupport::TestCase local_block.update(block_hash: "0x419c632366c8eb9635acbb39ea085f7552ae62e1fdd480893375334a0f37d1bx") target_block = local_block.target_block VCR.use_cassette("blocks/12") do - assert_changes -> { target_block.reload.reward_status }, from: "issued", to: "pending" do + assert_changes -> { + target_block.reload.reward_status + }, from: "issued", to: "pending" do node_data_processor.call end end @@ -1624,7 +1787,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase prepare_node_data(19) local_block = Block.find_by(number: 19) local_block.update(block_hash: "0x419c632366c8eb9635acbb39ea085f7552ae62e1fdd480893375334a0f37d1bx") - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do assert_nothing_raised do node_data_processor.call end @@ -1637,7 +1801,9 @@ class NodeDataProcessorTest < ActiveSupport::TestCase local_block.update(block_hash: "0x419c632366c8eb9635acbb39ea085f7552ae62e1fdd480893375334a0f37d1bx") target_block = local_block.target_block VCR.use_cassette("blocks/12", record: :new_episodes) do - assert_changes -> { target_block.reload.received_tx_fee_status }, from: "calculated", to: "pending" do + assert_changes -> { + target_block.reload.received_tx_fee_status + }, from: "calculated", to: "pending" do node_data_processor.call end end @@ -1647,7 +1813,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase prepare_node_data(19) local_block = Block.find_by(number: 19) local_block.update(block_hash: "0x419c632366c8eb9635acbb39ea085f7552ae62e1fdd480893375334a0f37d1bx") - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do assert_nothing_raised do node_data_processor.call end @@ -1682,7 +1849,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase node_block = CkbSync::Api.instance.get_block_by_number(DEFAULT_NODE_BLOCK_NUMBER) create(:block, :with_block_hash, number: node_block.header.number - 1) node_output = node_block.transactions.first.outputs.first - node_block.transactions.first.outputs_data[0] = "0x421d0000000000000000000000000000" + node_block.transactions.first.outputs_data[0] = + "0x421d0000000000000000000000000000" node_output.type = CKB::Types::Script.new(code_hash: Settings.sudt_cell_type_hash, args: issuer_address.lock_hash, hash_type: "type") create(:udt, code_hash: Settings.sudt_cell_type_hash, type_hash: node_output.type.compute_hash, @@ -1700,7 +1868,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase node_block = CkbSync::Api.instance.get_block_by_number(DEFAULT_NODE_BLOCK_NUMBER) create(:block, :with_block_hash, number: node_block.header.number - 1) node_output = node_block.transactions.first.outputs.first - node_block.transactions.first.outputs_data[0] = "0x421d0000000000000000000000000000" + node_block.transactions.first.outputs_data[0] = + "0x421d0000000000000000000000000000" node_output.type = CKB::Types::Script.new(code_hash: Settings.sudt1_cell_type_hash, args: issuer_address.lock_hash, hash_type: "type") create(:udt, code_hash: Settings.sudt_cell_type_hash, type_hash: node_output.type.compute_hash, @@ -1718,7 +1887,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase node_block = CkbSync::Api.instance.get_block_by_number(DEFAULT_NODE_BLOCK_NUMBER) create(:block, :with_block_hash, number: node_block.header.number - 1) node_output = node_block.transactions.first.outputs.first - node_block.transactions.first.outputs_data[0] = "0x421d0000000000000000000000000000" + node_block.transactions.first.outputs_data[0] = + "0x421d0000000000000000000000000000" node_output.type = CKB::Types::Script.new(code_hash: Settings.sudt_cell_type_hash, args: issuer_address.lock_hash, hash_type: "type") create(:udt, code_hash: Settings.sudt_cell_type_hash, type_hash: node_output.type.compute_hash, @@ -1739,7 +1909,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase node_block = CkbSync::Api.instance.get_block_by_number(DEFAULT_NODE_BLOCK_NUMBER) create(:block, :with_block_hash, number: node_block.header.number - 1) node_output = node_block.transactions.first.outputs.first - node_block.transactions.first.outputs_data[0] = "0x421d0000000000000000000000000000" + node_block.transactions.first.outputs_data[0] = + "0x421d0000000000000000000000000000" node_output.type = CKB::Types::Script.new(code_hash: CkbSync::Api.instance.token_script_code_hash, args: "0x3ae8bce37310b44b4dec3ce6b03308ba39b603de000000020000000c", hash_type: "type") create(:udt, code_hash: CkbSync::Api.instance.token_script_code_hash, type_hash: node_output.type.compute_hash, @@ -1762,11 +1933,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}") do node_block = CkbSync::Api.instance.get_block_by_number(DEFAULT_NODE_BLOCK_NUMBER) create(:block, :with_block_hash, number: node_block.header.number - 1) - previous_ckb_transaction = create(:ckb_transaction, block: block) + previous_ckb_transaction = create(:ckb_transaction, block:) token_type_script = CKB::Types::Script.new(code_hash: CkbSync::Api.instance.token_script_code_hash, args: "0x3ae8bce37310b44b4dec3ce6b03308ba39b603de000000020000000c", hash_type: "type") previous_cell_output = create(:cell_output, capacity: 1000 * 10**8, tx_hash: previous_ckb_transaction.tx_hash, - ckb_transaction: previous_ckb_transaction, block: block, cell_type: "m_nft_token", address: address, udt_amount: "12", cell_index: 0, data: "0x421d0000000000000000000000000000", type_hash: token_type_script.compute_hash) + ckb_transaction: previous_ckb_transaction, block:, cell_type: "m_nft_token", address:, udt_amount: "12", cell_index: 0, data: "0x421d0000000000000000000000000000", type_hash: token_type_script.compute_hash) previous_cell_output_lock_script = create(:lock_script, code_hash: Settings.secp_cell_type_hash, args: "0xb2e61ff569acf041b3c2c17724e2379c581eeac3", hash_type: "type") previous_cell_output_type_script = create(:type_script, @@ -1774,8 +1945,9 @@ class NodeDataProcessorTest < ActiveSupport::TestCase previous_cell_output.type_script_id = previous_cell_output_type_script.id previous_cell_output.lock_script_id = previous_cell_output_lock_script.id type_hash = CKB::Types::Script.new(**previous_cell_output_type_script.to_node).compute_hash - udt = create(:udt, type_hash: type_hash, udt_type: "m_nft_token") - address.udt_accounts.create(udt_type: "m_nft_token", type_hash: type_hash, udt: udt) + udt = create(:udt, type_hash:, udt_type: "m_nft_token") + address.udt_accounts.create(udt_type: "m_nft_token", + type_hash:, udt:) input = CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: previous_cell_output.tx_hash, index: 0)) output = CKB::Types::Output.new(capacity: 150 * 10**8, @@ -1797,7 +1969,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase node_block = CkbSync::Api.instance.get_block_by_number(DEFAULT_NODE_BLOCK_NUMBER) create(:block, :with_block_hash, number: node_block.header.number - 1) node_output = node_block.transactions.first.outputs.first - node_block.transactions.first.outputs_data[0] = "0x421d0000000000000000000000000000" + node_block.transactions.first.outputs_data[0] = + "0x421d0000000000000000000000000000" type = create(:type_script, code_hash: CkbSync::Api.instance.token_class_script_code_hash, hash_type: "type", args: "0x3ae8bce37310b44b4dec3ce6b03308ba39b603de00000002") create(:cell_output, :with_full_transaction_but_no_type_script, type_script_id: type.id, @@ -1821,10 +1994,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase node_output = node_block.transactions.first.outputs.first node_output.type = CKB::Types::Script.new(code_hash: Settings.sudt_cell_type_hash, args: "0xb2e61ff569acf041b3c2c17724e2379c581eeac3") - create(:udt, code_hash: Settings.sudt_cell_type_hash, type_hash: node_output.type.compute_hash) + create(:udt, code_hash: Settings.sudt_cell_type_hash, + type_hash: node_output.type.compute_hash) address_hash = CkbUtils.generate_address(node_output.lock) address = Address.find_by_address_hash(address_hash) - create(:udt_account, code_hash: Settings.sudt_cell_type_hash, address: address, + create(:udt_account, code_hash: Settings.sudt_cell_type_hash, address:, type_hash: node_output.type.compute_hash) assert_difference -> { address.udt_accounts.count }, 0 do @@ -1841,11 +2015,13 @@ class NodeDataProcessorTest < ActiveSupport::TestCase node_output = node_block.transactions.first.outputs.first node_output.type = CKB::Types::Script.new(code_hash: Settings.sudt_cell_type_hash, args: "0xb2e61ff569acf041b3c2c17724e2379c581eeac3", hash_type: "type") - create(:udt, code_hash: Settings.sudt_cell_type_hash, type_hash: node_output.type.compute_hash) - node_block.transactions.first.outputs_data[0] = "0x000050ad321ea12e0000000000000000" + create(:udt, code_hash: Settings.sudt_cell_type_hash, + type_hash: node_output.type.compute_hash) + node_block.transactions.first.outputs_data[0] = + "0x000050ad321ea12e0000000000000000" address_hash = CkbUtils.generate_address(node_output.lock) address = Address.find_by_address_hash(address_hash) - create(:udt_account, code_hash: Settings.sudt_cell_type_hash, address: address, + create(:udt_account, code_hash: Settings.sudt_cell_type_hash, address:, type_hash: node_output.type.compute_hash) udt_account = address.udt_accounts.find_by(type_hash: node_output.type.compute_hash) @@ -1869,23 +2045,29 @@ class NodeDataProcessorTest < ActiveSupport::TestCase args: "0xb2e61ff569acf041b3c2c17724e2379c581eeac2", hash_type: "type") node_output.type = CKB::Types::Script.new(code_hash: Settings.sudt_cell_type_hash, args: "0xb2e61ff569acf041b3c2c17724e2379c581eeac3", hash_type: "type") - create(:udt, code_hash: Settings.sudt_cell_type_hash, type_hash: node_output.type.compute_hash) - create(:udt, code_hash: Settings.sudt_cell_type_hash, type_hash: new_node_output.type.compute_hash) - node_block.transactions.first.outputs_data[0] = "0x000050ad321ea12e0000000000000000" - node_block.transactions.first.outputs_data[1] = "0x0000909dceda82370000000000000000" + create(:udt, code_hash: Settings.sudt_cell_type_hash, + type_hash: node_output.type.compute_hash) + create(:udt, code_hash: Settings.sudt_cell_type_hash, + type_hash: new_node_output.type.compute_hash) + node_block.transactions.first.outputs_data[0] = + "0x000050ad321ea12e0000000000000000" + node_block.transactions.first.outputs_data[1] = + "0x0000909dceda82370000000000000000" address_hash = CkbUtils.generate_address(node_output.lock) address = Address.find_by_address_hash(address_hash) - create(:udt_account, code_hash: Settings.sudt_cell_type_hash, address: address, + create(:udt_account, code_hash: Settings.sudt_cell_type_hash, address:, type_hash: node_output.type.compute_hash) - create(:udt_account, code_hash: Settings.sudt_cell_type_hash, address: address, + create(:udt_account, code_hash: Settings.sudt_cell_type_hash, address:, type_hash: new_node_output.type.compute_hash) udt_account = address.udt_accounts.find_by(type_hash: node_output.type.compute_hash) udt_account1 = address.udt_accounts.find_by(type_hash: new_node_output.type.compute_hash) node_data_processor.process_block(node_block) - assert_equal CkbUtils.parse_udt_cell_data("0x000050ad321ea12e0000000000000000"), udt_account.reload.amount - assert_equal CkbUtils.parse_udt_cell_data("0x0000909dceda82370000000000000000"), udt_account1.reload.amount + assert_equal CkbUtils.parse_udt_cell_data("0x000050ad321ea12e0000000000000000"), + udt_account.reload.amount + assert_equal CkbUtils.parse_udt_cell_data("0x0000909dceda82370000000000000000"), + udt_account1.reload.amount end end @@ -1907,11 +2089,13 @@ class NodeDataProcessorTest < ActiveSupport::TestCase args: issuer_address1.lock_hash, hash_type: "type") udt = create(:udt, code_hash: Settings.sudt_cell_type_hash, type_hash: node_output.type.compute_hash, published: true, block_timestamp: node_block.header.timestamp) - node_block.transactions.first.outputs_data[0] = "0x000050ad321ea12e0000000000000000" - node_block.transactions.first.outputs_data[1] = "0x0000909dceda82370000000000000000" + node_block.transactions.first.outputs_data[0] = + "0x000050ad321ea12e0000000000000000" + node_block.transactions.first.outputs_data[1] = + "0x0000909dceda82370000000000000000" address_hash = CkbUtils.generate_address(node_output.lock) address = Address.find_by_address_hash(address_hash) - create(:udt_account, code_hash: Settings.sudt_cell_type_hash, address: address, + create(:udt_account, code_hash: Settings.sudt_cell_type_hash, address:, type_hash: node_output.type.compute_hash, published: true) node_data_processor.process_block(node_block) @@ -1935,22 +2119,28 @@ class NodeDataProcessorTest < ActiveSupport::TestCase args: "0xb2e61ff569acf041b3c2c17724e2379c581eeac2", hash_type: "type") node_output.type = CKB::Types::Script.new(code_hash: Settings.sudt_cell_type_hash, args: "0xb2e61ff569acf041b3c2c17724e2379c581eeac3", hash_type: "type") - udt1 = create(:udt, code_hash: Settings.sudt_cell_type_hash, type_hash: node_output.type.compute_hash) - udt2 = create(:udt, code_hash: Settings.sudt_cell_type_hash, type_hash: new_node_output.type.compute_hash) - node_block.transactions.first.outputs_data[0] = "0x000050ad321ea12e0000000000000000" - node_block.transactions.first.outputs_data[1] = "0x0000909dceda82370000000000000000" + udt1 = create(:udt, code_hash: Settings.sudt_cell_type_hash, + type_hash: node_output.type.compute_hash) + udt2 = create(:udt, code_hash: Settings.sudt_cell_type_hash, + type_hash: new_node_output.type.compute_hash) + node_block.transactions.first.outputs_data[0] = + "0x000050ad321ea12e0000000000000000" + node_block.transactions.first.outputs_data[1] = + "0x0000909dceda82370000000000000000" address_hash = CkbUtils.generate_address(node_output.lock) address = Address.find_by_address_hash(address_hash) - create(:udt_account, code_hash: Settings.sudt_cell_type_hash, address: address, + create(:udt_account, code_hash: Settings.sudt_cell_type_hash, address:, type_hash: node_output.type.compute_hash) - create(:udt_account, code_hash: Settings.sudt_cell_type_hash, address: address, + create(:udt_account, code_hash: Settings.sudt_cell_type_hash, address:, type_hash: new_node_output.type.compute_hash) node_data_processor.process_block(node_block) - assert_equal CkbUtils.parse_udt_cell_data("0x000050ad321ea12e0000000000000000"), udt1.reload.total_amount + assert_equal CkbUtils.parse_udt_cell_data("0x000050ad321ea12e0000000000000000"), + udt1.reload.total_amount assert_equal 1, udt1.addresses_count - assert_equal CkbUtils.parse_udt_cell_data("0x0000909dceda82370000000000000000"), udt2.reload.total_amount + assert_equal CkbUtils.parse_udt_cell_data("0x0000909dceda82370000000000000000"), + udt2.reload.total_amount assert_equal 1, udt2.addresses_count end end @@ -1961,12 +2151,14 @@ class NodeDataProcessorTest < ActiveSupport::TestCase CkbSync::Api.any_instance.stubs(:get_tip_block_number).returns(22) VCR.use_cassette("blocks/21") do node_block = CkbSync::Api.instance.get_block_by_number(21) - create(:block, :with_block_hash, number: node_block.header.number - 1, timestamp: 1557282351075) + create(:block, :with_block_hash, number: node_block.header.number - 1, + timestamp: 1557282351075) node_output = node_block.transactions.first.outputs.first node_output.type = CKB::Types::Script.new(code_hash: Settings.sudt_cell_type_hash, args: issuer_address.lock_hash, hash_type: "type") - node_block.transactions.first.outputs_data[0] = "0x000050ad321ea12e0000000000000000" + node_block.transactions.first.outputs_data[0] = + "0x000050ad321ea12e0000000000000000" create(:udt, code_hash: Settings.sudt_cell_type_hash, type_hash: node_output.type.compute_hash, block_timestamp: node_block.header.timestamp) node_data_processor.process_block(node_block) @@ -1991,12 +2183,14 @@ class NodeDataProcessorTest < ActiveSupport::TestCase CkbSync::Api.any_instance.stubs(:get_tip_block_number).returns(22) VCR.use_cassette("blocks/21") do node_block = CkbSync::Api.instance.get_block_by_number(21) - create(:block, :with_block_hash, number: node_block.header.number - 1, timestamp: 1557282351075) + create(:block, :with_block_hash, number: node_block.header.number - 1, + timestamp: 1557282351075) node_output = node_block.transactions.first.outputs.first node_output.type = CKB::Types::Script.new(code_hash: CkbSync::Api.instance.token_script_code_hash, args: "0x9cf6ef96c3f053f6d128903e608516d658cac2da0000000000000001", hash_type: "type") - node_block.transactions.first.outputs_data[0] = "0x000050ad321ea12e0000000000000000" + node_block.transactions.first.outputs_data[0] = + "0x000050ad321ea12e0000000000000000" node_data_processor.process_block(node_block) block = Block.find_by(number: 21) block.update(block_hash: "0x419c632366c8eb9635acbb39ea085f7552ae62e1fdd480893375334a0f37d1bx") @@ -2005,7 +2199,9 @@ class NodeDataProcessorTest < ActiveSupport::TestCase end VCR.use_cassette("blocks/22") do - assert_difference -> { address.reload.udt_accounts.m_nft_token.count }, -1 do + assert_difference -> { + address.reload.udt_accounts.m_nft_token.count + }, -1 do node_data_processor.call end end @@ -2018,7 +2214,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase CkbSync::Api.any_instance.stubs(:get_tip_block_number).returns(22) VCR.use_cassette("blocks/21") do node_block = CkbSync::Api.instance.get_block_by_number(21) - create(:block, :with_block_hash, number: node_block.header.number - 1, timestamp: 1557282351075) + create(:block, :with_block_hash, number: node_block.header.number - 1, + timestamp: 1557282351075) node_output = node_block.transactions.first.outputs.first new_node_output = node_output.dup @@ -2027,8 +2224,10 @@ class NodeDataProcessorTest < ActiveSupport::TestCase args: issuer_address1.lock_hash, hash_type: "type") node_output.type = CKB::Types::Script.new(code_hash: Settings.sudt_cell_type_hash, args: issuer_address2.lock_hash, hash_type: "type") - node_block.transactions.first.outputs_data[0] = "0x000050ad321ea12e0000000000000000" - node_block.transactions.first.outputs_data[1] = "0x0000909dceda82370000000000000000" + node_block.transactions.first.outputs_data[0] = + "0x000050ad321ea12e0000000000000000" + node_block.transactions.first.outputs_data[1] = + "0x0000909dceda82370000000000000000" create(:udt, code_hash: Settings.sudt_cell_type_hash, type_hash: node_output.type.compute_hash, block_timestamp: node_block.header.timestamp) create(:udt, code_hash: Settings.sudt_cell_type_hash, type_hash: new_node_output.type.compute_hash, @@ -2042,7 +2241,9 @@ class NodeDataProcessorTest < ActiveSupport::TestCase VCR.use_cassette("blocks/22") do old_total_amount = CkbUtils.parse_udt_cell_data("0x000050ad321ea12e0000000000000000") + CkbUtils.parse_udt_cell_data("0x0000909dceda82370000000000000000") - assert_changes -> { address.reload.udt_accounts.sum(:amount) }, from: old_total_amount, to: 0 do + assert_changes -> { + address.reload.udt_accounts.sum(:amount) + }, from: old_total_amount, to: 0 do node_data_processor.call end end @@ -2052,7 +2253,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase issuer_address = create(:address) udt_type_script = CKB::Types::Script.new(code_hash: Settings.sudt_cell_type_hash, args: issuer_address.lock_hash, hash_type: "type") - create(:udt, code_hash: Settings.sudt_cell_type_hash, type_hash: udt_type_script.compute_hash) + create(:udt, code_hash: Settings.sudt_cell_type_hash, + type_hash: udt_type_script.compute_hash) block = create(:block, :with_block_hash) previous_cell_output_lock_script = create(:lock_script, code_hash: Settings.secp_cell_type_hash, args: "0xb2e61ff569acf041b3c2c17724e2379c581eeac3", hash_type: "type") @@ -2060,14 +2262,15 @@ class NodeDataProcessorTest < ActiveSupport::TestCase udt_lock_script = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, args: "0x3954acece65096bfa81258983ddb83915fc56bd8", hash_type: "type") udt_amount = 1000000 - create(:udt_account, address: address, amount: udt_amount, type_hash: udt_type_script.compute_hash) - previous_ckb_transaction = create(:ckb_transaction, address: address) + create(:udt_account, address:, amount: udt_amount, + type_hash: udt_type_script.compute_hash) + previous_ckb_transaction = create(:ckb_transaction, address:) previous_cell_output = create(:cell_output, ckb_transaction: previous_ckb_transaction, - block: block, + block:, cell_type: "udt", - address: address, - udt_amount: udt_amount, + address:, + udt_amount:, cell_index: 0, tx_hash: previous_ckb_transaction.tx_hash, capacity: 300 * 10**8, @@ -2082,7 +2285,8 @@ class NodeDataProcessorTest < ActiveSupport::TestCase create(:block, :with_block_hash, number: node_block.header.number - 1) input = CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: previous_cell_output.tx_hash, index: 0)) - output = CKB::Types::Output.new(capacity: 150 * 10**8, lock: udt_lock_script, type: udt_type_script) + output = CKB::Types::Output.new(capacity: 150 * 10**8, + lock: udt_lock_script, type: udt_type_script) tx = CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", inputs: [input], outputs: [output], outputs_data: ["0x000050ad321ea12e0000000000000000"]) node_block.transactions << tx @@ -2098,16 +2302,19 @@ class NodeDataProcessorTest < ActiveSupport::TestCase node_data_processor.process_block(node_block) end - assert_equal 0, address.udt_accounts.find_by(type_hash: udt_type_script.compute_hash).amount + assert_equal 0, + address.udt_accounts.find_by(type_hash: udt_type_script.compute_hash).amount assert_equal 0, address.reload.balance_occupied assert_equal 150 * 10**8, output_address.reload.balance_occupied end end test "should update tx's contained address ids" do - block1 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 2) + block1 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 2) tx1 = create(:ckb_transaction, block: block1) - block2 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 1) + block2 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 1) tx2 = create(:ckb_transaction, block: block2) tx3 = create(:ckb_transaction, block: block2) tx4 = create(:ckb_transaction, block: block2) @@ -2131,13 +2338,23 @@ class NodeDataProcessorTest < ActiveSupport::TestCase header = CKB::Types::BlockHeader.new(compact_target: "0x1000", hash: "0x#{SecureRandom.hex(32)}", number: DEFAULT_NODE_BLOCK_NUMBER, parent_hash: "0x#{SecureRandom.hex(32)}", nonce: 1757392074788233522, timestamp: CkbUtils.time_in_milliseconds(Time.current), transactions_root: "0x#{SecureRandom.hex(32)}", proposals_hash: "0x#{SecureRandom.hex(32)}", extra_hash: "0x#{SecureRandom.hex(32)}", version: 0, epoch: 1, dao: "0x01000000000000000000c16ff286230000a3a65e97fd03000057c138586f0000") inputs = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx1.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx2.tx_hash, index: 1)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx3.tx_hash, index: 2)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx1.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx2.tx_hash, index: 1, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx3.tx_hash, index: 2, + )), ] inputs1 = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx4.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx5.tx_hash, index: 0)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx4.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx5.tx_hash, index: 0, + )), ] lock1 = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") @@ -2148,34 +2365,35 @@ class NodeDataProcessorTest < ActiveSupport::TestCase outputs = [ CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1), CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] outputs1 = [ CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1), CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] miner_lock = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") cellbase_inputs = [ CKB::Types::Input.new( previous_output: CKB::Types::OutPoint.new( - tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295 + tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295, ), since: 3000 - ) + ), ] cellbase_outputs = [ - CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock) + CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock), ] transactions = [ CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: cellbase_inputs, outputs: cellbase_outputs, outputs_data: %w[0x], witnesses: ["0x590000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd800000000"]), - CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs, - outputs: outputs, outputs_data: %w[0x 0x 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), + CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs:, + outputs:, outputs_data: %w[0x 0x 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs1, - outputs: outputs1, outputs_data: %w[0x 0x 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]) + outputs: outputs1, outputs_data: %w[0x 0x 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), ] - node_block = CKB::Types::Block.new(uncles: [], proposals: [], transactions: transactions, header: header) + node_block = CKB::Types::Block.new(uncles: [], proposals: [], + transactions:, header:) block = node_data_processor.process_block(node_block) address1 = Address.find_by(lock_hash: lock1.compute_hash) @@ -2190,9 +2408,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase end test "should update tx's tags when output have nervos_dao_deposit cells" do - block1 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 2) + block1 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 2) tx1 = create(:ckb_transaction, block: block1) - block2 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 1) + block2 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 1) tx2 = create(:ckb_transaction, block: block2) tx3 = create(:ckb_transaction, block: block2) tx4 = create(:ckb_transaction, block: block2) @@ -2215,13 +2435,23 @@ class NodeDataProcessorTest < ActiveSupport::TestCase header = CKB::Types::BlockHeader.new(compact_target: "0x1000", hash: "0x#{SecureRandom.hex(32)}", number: DEFAULT_NODE_BLOCK_NUMBER, parent_hash: "0x#{SecureRandom.hex(32)}", nonce: 1757392074788233522, timestamp: CkbUtils.time_in_milliseconds(Time.current), transactions_root: "0x#{SecureRandom.hex(32)}", proposals_hash: "0x#{SecureRandom.hex(32)}", extra_hash: "0x#{SecureRandom.hex(32)}", version: 0, epoch: 1, dao: "0x01000000000000000000c16ff286230000a3a65e97fd03000057c138586f0000") inputs = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx1.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx2.tx_hash, index: 1)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx3.tx_hash, index: 2)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx1.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx2.tx_hash, index: 1, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx3.tx_hash, index: 2, + )), ] inputs1 = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx4.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx5.tx_hash, index: 0)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx4.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx5.tx_hash, index: 0, + )), ] lock1 = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") @@ -2229,38 +2459,44 @@ class NodeDataProcessorTest < ActiveSupport::TestCase args: "0x#{SecureRandom.hex(20)}") lock3 = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") - dao_type = CKB::Types::Script.new(code_hash: Settings.dao_type_hash, hash_type: "type", args: "0x") + dao_type = CKB::Types::Script.new(code_hash: Settings.dao_type_hash, + hash_type: "type", args: "0x") outputs = [ - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] outputs1 = [ - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] miner_lock = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") cellbase_inputs = [ CKB::Types::Input.new( previous_output: CKB::Types::OutPoint.new( - tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295 + tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295, ), since: 3000 - ) + ), ] cellbase_outputs = [ - CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock) + CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock), ] transactions = [ CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: cellbase_inputs, outputs: cellbase_outputs, outputs_data: %w[0x], witnesses: ["0x590000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd800000000"]), - CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs, - outputs: outputs, outputs_data: %w[0x0000000000000000 0x0000000000000000 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), + CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs:, + outputs:, outputs_data: %w[0x0000000000000000 0x0000000000000000 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs1, - outputs: outputs1, outputs_data: %w[0x0000000000000000 0x0000000000000000 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]) + outputs: outputs1, outputs_data: %w[0x0000000000000000 0x0000000000000000 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), ] - node_block = CKB::Types::Block.new(uncles: [], proposals: [], transactions: transactions, header: header) + node_block = CKB::Types::Block.new(uncles: [], proposals: [], + transactions:, header:) block = node_data_processor.process_block(node_block) tx = block.ckb_transactions.where(is_cellbase: false).first @@ -2272,9 +2508,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase end test "should recalculate dao contract ckb_transactions_count when block is invalid and has dao txs" do - block1 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 2) + block1 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 2) tx1 = create(:ckb_transaction, block: block1) - block2 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 1) + block2 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 1) tx2 = create(:ckb_transaction, block: block2) tx3 = create(:ckb_transaction, block: block2) tx4 = create(:ckb_transaction, block: block2) @@ -2297,13 +2535,23 @@ class NodeDataProcessorTest < ActiveSupport::TestCase header = CKB::Types::BlockHeader.new(compact_target: "0x1000", hash: "0x#{SecureRandom.hex(32)}", number: DEFAULT_NODE_BLOCK_NUMBER, parent_hash: "0x#{SecureRandom.hex(32)}", nonce: 1757392074788233522, timestamp: CkbUtils.time_in_milliseconds(Time.current), transactions_root: "0x#{SecureRandom.hex(32)}", proposals_hash: "0x#{SecureRandom.hex(32)}", extra_hash: "0x#{SecureRandom.hex(32)}", version: 0, epoch: 1, dao: "0x01000000000000000000c16ff286230000a3a65e97fd03000057c138586f0000") inputs = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx1.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx2.tx_hash, index: 1)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx3.tx_hash, index: 2)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx1.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx2.tx_hash, index: 1, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx3.tx_hash, index: 2, + )), ] inputs1 = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx4.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx5.tx_hash, index: 0)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx4.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx5.tx_hash, index: 0, + )), ] lock1 = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") @@ -2311,52 +2559,63 @@ class NodeDataProcessorTest < ActiveSupport::TestCase args: "0x#{SecureRandom.hex(20)}") lock3 = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") - dao_type = CKB::Types::Script.new(code_hash: Settings.dao_type_hash, hash_type: "type", args: "0x") + dao_type = CKB::Types::Script.new(code_hash: Settings.dao_type_hash, + hash_type: "type", args: "0x") outputs = [ - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] outputs1 = [ - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] miner_lock = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") cellbase_inputs = [ CKB::Types::Input.new( previous_output: CKB::Types::OutPoint.new( - tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295 + tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295, ), since: 3000 - ) + ), ] cellbase_outputs = [ - CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock) + CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock), ] transactions = [ CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: cellbase_inputs, outputs: cellbase_outputs, outputs_data: %w[0x], witnesses: ["0x590000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd800000000"]), - CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs, - outputs: outputs, outputs_data: %w[0x0000000000000000 0x0000000000000000 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), + CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs:, + outputs:, outputs_data: %w[0x0000000000000000 0x0000000000000000 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs1, - outputs: outputs1, outputs_data: %w[0x0000000000000000 0x0000000000000000 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]) + outputs: outputs1, outputs_data: %w[0x0000000000000000 0x0000000000000000 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), ] - node_block = CKB::Types::Block.new(uncles: [], proposals: [], transactions: transactions, header: header) + node_block = CKB::Types::Block.new(uncles: [], proposals: [], + transactions:, header:) block = node_data_processor.process_block(node_block) CkbSync::Api.any_instance.stubs(:get_tip_block_number).returns(block.number + 1) - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do - assert_changes -> { DaoContract.default_contract.ckb_transactions_count }, from: 2, to: 0 do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do + assert_changes -> { + DaoContract.default_contract.ckb_transactions_count + }, from: 2, to: 0 do node_data_processor.call end end end test "should update tx's tags when output have udt cells" do - block1 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 2) + block1 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 2) tx1 = create(:ckb_transaction, block: block1) - block2 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 1) + block2 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 1) tx2 = create(:ckb_transaction, block: block2) tx3 = create(:ckb_transaction, block: block2) input_address1 = create(:address) @@ -2372,9 +2631,15 @@ class NodeDataProcessorTest < ActiveSupport::TestCase header = CKB::Types::BlockHeader.new(compact_target: "0x1000", hash: "0x#{SecureRandom.hex(32)}", number: DEFAULT_NODE_BLOCK_NUMBER, parent_hash: "0x#{SecureRandom.hex(32)}", nonce: 1757392074788233522, timestamp: CkbUtils.time_in_milliseconds(Time.current), transactions_root: "0x#{SecureRandom.hex(32)}", proposals_hash: "0x#{SecureRandom.hex(32)}", extra_hash: "0x#{SecureRandom.hex(32)}", version: 0, epoch: 1, dao: "0x01000000000000000000c16ff286230000a3a65e97fd03000057c138586f0000") inputs = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx1.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx2.tx_hash, index: 1)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx3.tx_hash, index: 2)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx1.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx2.tx_hash, index: 1, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx3.tx_hash, index: 2, + )), ] lock1 = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") @@ -2384,31 +2649,35 @@ class NodeDataProcessorTest < ActiveSupport::TestCase args: "0x#{SecureRandom.hex(20)}") udt_script = CKB::Types::Script.new(code_hash: Settings.sudt_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(32)}") - Address.create(lock_hash: udt_script.args, address_hash: "0x#{SecureRandom.hex(32)}") + Address.create(lock_hash: udt_script.args, + address_hash: "0x#{SecureRandom.hex(32)}") outputs = [ - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, type: udt_script), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, type: udt_script), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, + type: udt_script), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, + type: udt_script), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] miner_lock = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") cellbase_inputs = [ CKB::Types::Input.new( previous_output: CKB::Types::OutPoint.new( - tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295 + tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295, ), since: 3000 - ) + ), ] cellbase_outputs = [ - CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock) + CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock), ] transactions = [ CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: cellbase_inputs, outputs: cellbase_outputs, outputs_data: %w[0x], witnesses: ["0x590000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd800000000"]), - CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs, - outputs: outputs, outputs_data: %W[#{CKB::Utils.generate_sudt_amount(1000)} #{CKB::Utils.generate_sudt_amount(1000)} 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]) + CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs:, + outputs:, outputs_data: %W[#{CKB::Utils.generate_sudt_amount(1000)} #{CKB::Utils.generate_sudt_amount(1000)} 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), ] - node_block = CKB::Types::Block.new(uncles: [], proposals: [], transactions: transactions, header: header) + node_block = CKB::Types::Block.new(uncles: [], proposals: [], + transactions:, header:) block = node_data_processor.process_block(node_block) tx = block.ckb_transactions.where(is_cellbase: false).first @@ -2417,9 +2686,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase end test "should update tx's tags when output have udt cells and nervos_dao_deposit cell" do - block1 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 2) + block1 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 2) tx1 = create(:ckb_transaction, block: block1) - block2 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 1) + block2 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 1) tx2 = create(:ckb_transaction, block: block2) tx3 = create(:ckb_transaction, block: block2) input_address1 = create(:address) @@ -2435,9 +2706,15 @@ class NodeDataProcessorTest < ActiveSupport::TestCase header = CKB::Types::BlockHeader.new(compact_target: "0x1000", hash: "0x#{SecureRandom.hex(32)}", number: DEFAULT_NODE_BLOCK_NUMBER, parent_hash: "0x#{SecureRandom.hex(32)}", nonce: 1757392074788233522, timestamp: CkbUtils.time_in_milliseconds(Time.current), transactions_root: "0x#{SecureRandom.hex(32)}", proposals_hash: "0x#{SecureRandom.hex(32)}", extra_hash: "0x#{SecureRandom.hex(32)}", version: 0, epoch: 1, dao: "0x01000000000000000000c16ff286230000a3a65e97fd03000057c138586f0000") inputs = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx1.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx2.tx_hash, index: 1)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx3.tx_hash, index: 2)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx1.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx2.tx_hash, index: 1, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx3.tx_hash, index: 2, + )), ] lock1 = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") @@ -2445,34 +2722,40 @@ class NodeDataProcessorTest < ActiveSupport::TestCase args: "0x#{SecureRandom.hex(20)}") lock3 = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") - dao_type = CKB::Types::Script.new(code_hash: Settings.dao_type_hash, hash_type: "type", args: "0x") + dao_type = CKB::Types::Script.new(code_hash: Settings.dao_type_hash, + hash_type: "type", args: "0x") udt_script = CKB::Types::Script.new(code_hash: Settings.sudt_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(32)}") - Address.create(lock_hash: udt_script.args, address_hash: "0x#{SecureRandom.hex(32)}") + Address.create(lock_hash: udt_script.args, + address_hash: "0x#{SecureRandom.hex(32)}") outputs = [ - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3, type: udt_script) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3, + type: udt_script), ] miner_lock = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") cellbase_inputs = [ CKB::Types::Input.new( previous_output: CKB::Types::OutPoint.new( - tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295 + tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295, ), since: 3000 - ) + ), ] cellbase_outputs = [ - CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock) + CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock), ] transactions = [ CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: cellbase_inputs, outputs: cellbase_outputs, outputs_data: %w[0x], witnesses: ["0x590000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd800000000"]), - CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs, - outputs: outputs, outputs_data: %W[0x0000000000000000 0x0000000000000000 #{CKB::Utils.generate_sudt_amount(1000)}], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]) + CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs:, + outputs:, outputs_data: %W[0x0000000000000000 0x0000000000000000 #{CKB::Utils.generate_sudt_amount(1000)}], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), ] - node_block = CKB::Types::Block.new(uncles: [], proposals: [], transactions: transactions, header: header) + node_block = CKB::Types::Block.new(uncles: [], proposals: [], + transactions:, header:) block = node_data_processor.process_block(node_block) tx = block.ckb_transactions.where(is_cellbase: false).first @@ -2483,9 +2766,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase test "should update tx's tags when input have udt cells" do DaoContract.default_contract.update(total_deposit: 100000000000000) - block1 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 2) + block1 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 2) tx1 = create(:ckb_transaction, block: block1) - block2 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 1) + block2 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 1) tx2 = create(:ckb_transaction, block: block2) tx3 = create(:ckb_transaction, block: block2) tx4 = create(:ckb_transaction, block: block2) @@ -2510,10 +2795,12 @@ class NodeDataProcessorTest < ActiveSupport::TestCase args: "0x#{SecureRandom.hex(32)}") udt_script1 = CKB::Types::Script.new(code_hash: Settings.sudt_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(32)}") - create(:udt, code_hash: Settings.sudt_cell_type_hash, type_hash: udt_script.compute_hash) - create(:udt, code_hash: Settings.sudt_cell_type_hash, type_hash: udt_script1.compute_hash) + create(:udt, code_hash: Settings.sudt_cell_type_hash, + type_hash: udt_script.compute_hash) + create(:udt, code_hash: Settings.sudt_cell_type_hash, + type_hash: udt_script1.compute_hash) - output1 = create(:cell_output, ckb_transaction: tx1, block: block1, capacity: 50000 * 10**8, + output1 = create(:cell_output, ckb_transaction: tx1, block: block1, capacity: 50000 * 10**8, tx_hash: tx1.tx_hash, cell_index: 0, address: input_address1, cell_type: "udt", lock_script_id: lock1.id, type_hash: udt_script.compute_hash) output2 = create(:cell_output, ckb_transaction: tx2, block: block2, capacity: 60000 * 10**8, tx_hash: tx2.tx_hash, cell_index: 1, address: input_address2, cell_type: "udt", lock_script_id: lock2.id, type_hash: udt_script.compute_hash) @@ -2534,19 +2821,31 @@ class NodeDataProcessorTest < ActiveSupport::TestCase cell_output: output4) create(:type_script, args: udt_script1.args, code_hash: Settings.sudt_cell_type_hash, hash_type: "data", cell_output: output5) - Address.create(lock_hash: udt_script.args, address_hash: "0x#{SecureRandom.hex(32)}") - Address.create(lock_hash: udt_script1.args, address_hash: "0x#{SecureRandom.hex(32)}") + Address.create(lock_hash: udt_script.args, + address_hash: "0x#{SecureRandom.hex(32)}") + Address.create(lock_hash: udt_script1.args, + address_hash: "0x#{SecureRandom.hex(32)}") header = CKB::Types::BlockHeader.new(compact_target: "0x1000", hash: "0x#{SecureRandom.hex(32)}", number: DEFAULT_NODE_BLOCK_NUMBER, parent_hash: "0x#{SecureRandom.hex(32)}", nonce: 1757392074788233522, timestamp: CkbUtils.time_in_milliseconds(Time.current), transactions_root: "0x#{SecureRandom.hex(32)}", proposals_hash: "0x#{SecureRandom.hex(32)}", extra_hash: "0x#{SecureRandom.hex(32)}", version: 0, epoch: 1, dao: "0x01000000000000000000c16ff286230000a3a65e97fd03000057c138586f0000") inputs = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx1.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx2.tx_hash, index: 1)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx3.tx_hash, index: 2)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx1.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx2.tx_hash, index: 1, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx3.tx_hash, index: 2, + )), ] inputs1 = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx4.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx5.tx_hash, index: 0)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx4.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx5.tx_hash, index: 0, + )), ] lock1 = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") @@ -2558,35 +2857,36 @@ class NodeDataProcessorTest < ActiveSupport::TestCase outputs = [ CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1), CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] outputs1 = [ CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1), CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] miner_lock = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") cellbase_inputs = [ CKB::Types::Input.new( previous_output: CKB::Types::OutPoint.new( - tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295 + tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295, ), since: 3000 - ) + ), ] cellbase_outputs = [ - CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock) + CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock), ] transactions = [ CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: cellbase_inputs, outputs: cellbase_outputs, outputs_data: %w[0x], witnesses: ["0x590000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd800000000"]), - CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs, - outputs: outputs, outputs_data: %w[0x 0x 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), + CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs:, + outputs:, outputs_data: %w[0x 0x 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs1, - outputs: outputs1, outputs_data: %w[0x 0x 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]) + outputs: outputs1, outputs_data: %w[0x 0x 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), ] - node_block = CKB::Types::Block.new(uncles: [], proposals: [], transactions: transactions, header: header) + node_block = CKB::Types::Block.new(uncles: [], proposals: [], + transactions:, header:) block = node_data_processor.process_block(node_block) tx = block.ckb_transactions.where(is_cellbase: false).first @@ -2598,9 +2898,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase test "should update tx's tags when input have udt cells and nervos_dao_withdrawing cells" do DaoContract.default_contract.update(total_deposit: 100000000000000) - block1 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 2) + block1 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 2) tx1 = create(:ckb_transaction, block: block1) - block2 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 1) + block2 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 1) deposit_block = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 5, dao: "0x1c3a5eac4286070025e0edf5ca8823001c957f5b5000000000e3bad4847a0100") @@ -2637,12 +2939,12 @@ class NodeDataProcessorTest < ActiveSupport::TestCase udt_script = CKB::Types::Script.new( code_hash: Settings.sudt_cell_type_hash, hash_type: "type", - args: "0x#{SecureRandom.hex(32)}" + args: "0x#{SecureRandom.hex(32)}", ) udt_script1 = CKB::Types::Script.new( code_hash: Settings.sudt_cell_type_hash, hash_type: "type", - args: "0x#{SecureRandom.hex(32)}" + args: "0x#{SecureRandom.hex(32)}", ) create(:udt, code_hash: Settings.sudt_cell_type_hash, type_hash: udt_script.compute_hash) @@ -2683,19 +2985,19 @@ class NodeDataProcessorTest < ActiveSupport::TestCase block: block1, previous_output: { tx_hash: deposit_tx.tx_hash, - index: 0 + index: 0, }) create(:cell_input, ckb_transaction: tx2, block: block2, previous_output: { tx_hash: deposit_tx.tx_hash, - index: 1 + index: 1, }) create(:cell_input, ckb_transaction: tx2, block: block2, previous_output: { tx_hash: deposit_tx.tx_hash, - index: 2 + index: 2, }) # nervos_dao_withdrawing cells @@ -2752,13 +3054,13 @@ class NodeDataProcessorTest < ActiveSupport::TestCase block: block2, previous_output: { tx_hash: deposit_tx1.tx_hash, - index: 0 + index: 0, }) create(:cell_input, ckb_transaction: tx5, block: block2, previous_output: { tx_hash: deposit_tx1.tx_hash, - index: 1 + index: 1, }) # nervos_dao_withdrawing cell create(:cell_output, ckb_transaction: tx4, @@ -2796,8 +3098,10 @@ class NodeDataProcessorTest < ActiveSupport::TestCase create(:type_script, args: udt_script1.args, code_hash: Settings.sudt_cell_type_hash, hash_type: "data") - Address.create(lock_hash: udt_script.args, address_hash: "0x#{SecureRandom.hex(32)}") - Address.create(lock_hash: udt_script1.args, address_hash: "0x#{SecureRandom.hex(32)}") + Address.create(lock_hash: udt_script.args, + address_hash: "0x#{SecureRandom.hex(32)}") + Address.create(lock_hash: udt_script1.args, + address_hash: "0x#{SecureRandom.hex(32)}") header = CKB::Types::BlockHeader.new( compact_target: "0x1000", @@ -2811,57 +3115,57 @@ class NodeDataProcessorTest < ActiveSupport::TestCase extra_hash: "0x#{SecureRandom.hex(32)}", version: 0, epoch: 1, - dao: "0x01000000000000000000c16ff286230000a3a65e97fd03000057c138586f0000" + dao: "0x01000000000000000000c16ff286230000a3a65e97fd03000057c138586f0000", ) inputs = [ CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx1.tx_hash, index: 0)), # nervos_dao_withdrawing cell CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx2.tx_hash, index: 1)), # nervos_dao_withdrawing cell - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx3.tx_hash, index: 2)) # udt cell + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx3.tx_hash, index: 2)), # udt cell ] inputs1 = [ CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx4.tx_hash, index: 0)), # nervos_dao_withdrawing cell - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx5.tx_hash, index: 0)) # udt cell + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx5.tx_hash, index: 0)), # udt cell ] lock1 = CKB::Types::Script.new( code_hash: Settings.secp_cell_type_hash, hash_type: "type", - args: "0x#{SecureRandom.hex(20)}" + args: "0x#{SecureRandom.hex(20)}", ) lock2 = CKB::Types::Script.new( code_hash: Settings.secp_cell_type_hash, hash_type: "type", - args: "0x#{SecureRandom.hex(20)}" + args: "0x#{SecureRandom.hex(20)}", ) lock3 = CKB::Types::Script.new( code_hash: Settings.secp_cell_type_hash, hash_type: "type", - args: "0x#{SecureRandom.hex(20)}" + args: "0x#{SecureRandom.hex(20)}", ) outputs = [ CKB::Types::Output.new(capacity: 50000 * 10**8, lock: lock1), CKB::Types::Output.new(capacity: 60000 * 10**8, lock: lock2), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] outputs1 = [ CKB::Types::Output.new(capacity: 50000 * 10**8, lock: lock1), CKB::Types::Output.new(capacity: 60000 * 10**8, lock: lock2), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] miner_lock = CKB::Types::Script.new( code_hash: Settings.secp_cell_type_hash, hash_type: "type", - args: "0x#{SecureRandom.hex(20)}" + args: "0x#{SecureRandom.hex(20)}", ) cellbase_inputs = [ CKB::Types::Input.new( previous_output: CKB::Types::OutPoint.new( - tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295 + tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295, ), since: 3000 - ) + ), ] cellbase_outputs = [ - CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock) + CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock), ] transactions = [ CKB::Types::Transaction.new( @@ -2872,19 +3176,19 @@ class NodeDataProcessorTest < ActiveSupport::TestCase outputs: cellbase_outputs, outputs_data: %w[0x], witnesses: [ - "0x590000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd800000000" - ] + "0x590000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd800000000", + ], ), CKB::Types::Transaction.new( hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [block1.block_hash], - inputs: inputs, - outputs: outputs, + inputs:, + outputs:, outputs_data: %w[0x 0x 0x], witnesses: [ - "0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000" - ] + "0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000", + ], ), CKB::Types::Transaction.new( hash: "0x#{SecureRandom.hex(32)}", @@ -2894,15 +3198,15 @@ class NodeDataProcessorTest < ActiveSupport::TestCase outputs: outputs1, outputs_data: %w[0x 0x 0x], witnesses: [ - "0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000" - ] - ) + "0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000", + ], + ), ] node_block = CKB::Types::Block.new( uncles: [], proposals: [], - transactions: transactions, - header: header + transactions:, + header:, ) block = node_data_processor.process_block(node_block) @@ -2939,9 +3243,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase end test "#process_block should update tx's contained_udt_ids when there are udt cells in outputs" do - block1 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 2) + block1 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 2) tx1 = create(:ckb_transaction, block: block1) - block2 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 1) + block2 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 1) tx2 = create(:ckb_transaction, block: block2) tx3 = create(:ckb_transaction, block: block2) tx4 = create(:ckb_transaction, block: block2) @@ -2965,13 +3271,23 @@ class NodeDataProcessorTest < ActiveSupport::TestCase header = CKB::Types::BlockHeader.new(compact_target: "0x1000", hash: "0x#{SecureRandom.hex(32)}", number: DEFAULT_NODE_BLOCK_NUMBER, parent_hash: "0x#{SecureRandom.hex(32)}", nonce: 1757392074788233522, timestamp: CkbUtils.time_in_milliseconds(Time.current), transactions_root: "0x#{SecureRandom.hex(32)}", proposals_hash: "0x#{SecureRandom.hex(32)}", extra_hash: "0x#{SecureRandom.hex(32)}", version: 0, epoch: 1, dao: "0x01000000000000000000c16ff286230000a3a65e97fd03000057c138586f0000") inputs = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx1.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx2.tx_hash, index: 1)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx3.tx_hash, index: 2)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx1.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx2.tx_hash, index: 1, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx3.tx_hash, index: 2, + )), ] inputs1 = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx4.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx5.tx_hash, index: 0)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx4.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx5.tx_hash, index: 0, + )), ] lock1 = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") @@ -2983,40 +3299,48 @@ class NodeDataProcessorTest < ActiveSupport::TestCase args: "0x#{SecureRandom.hex(32)}") udt_script2 = CKB::Types::Script.new(code_hash: Settings.sudt_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(32)}") - Address.create(lock_hash: udt_script1.args, address_hash: "0x#{SecureRandom.hex(32)}") - Address.create(lock_hash: udt_script2.args, address_hash: "0x#{SecureRandom.hex(32)}") + Address.create(lock_hash: udt_script1.args, + address_hash: "0x#{SecureRandom.hex(32)}") + Address.create(lock_hash: udt_script2.args, + address_hash: "0x#{SecureRandom.hex(32)}") outputs = [ - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, type: udt_script1), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, type: udt_script2), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, + type: udt_script1), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, + type: udt_script2), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] outputs1 = [ - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, type: udt_script1), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, type: udt_script2), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, type: udt_script2), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, + type: udt_script1), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, + type: udt_script2), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, + type: udt_script2), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] miner_lock = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") cellbase_inputs = [ CKB::Types::Input.new( previous_output: CKB::Types::OutPoint.new( - tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295 + tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295, ), since: 3000 - ) + ), ] cellbase_outputs = [ - CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock) + CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock), ] transactions = [ CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: cellbase_inputs, outputs: cellbase_outputs, outputs_data: %w[0x], witnesses: ["0x590000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd800000000"]), - CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs, - outputs: outputs, outputs_data: %W[#{CKB::Utils.generate_sudt_amount(1000)} #{CKB::Utils.generate_sudt_amount(1000)} 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), + CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs:, + outputs:, outputs_data: %W[#{CKB::Utils.generate_sudt_amount(1000)} #{CKB::Utils.generate_sudt_amount(1000)} 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs1, - outputs: outputs1, outputs_data: %W[#{CKB::Utils.generate_sudt_amount(1000)} #{CKB::Utils.generate_sudt_amount(1000)} #{CKB::Utils.generate_sudt_amount(1000)} 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]) + outputs: outputs1, outputs_data: %W[#{CKB::Utils.generate_sudt_amount(1000)} #{CKB::Utils.generate_sudt_amount(1000)} #{CKB::Utils.generate_sudt_amount(1000)} 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), ] - node_block = CKB::Types::Block.new(uncles: [], proposals: [], transactions: transactions, header: header) + node_block = CKB::Types::Block.new(uncles: [], proposals: [], + transactions:, header:) block = node_data_processor.process_block(node_block) udt1 = Udt.find_by(args: udt_script1.args) udt2 = Udt.find_by(args: udt_script2.args) @@ -3042,13 +3366,20 @@ class NodeDataProcessorTest < ActiveSupport::TestCase args: udt_script1.args, ckb_transactions_count: 3) udt2 = create(:udt, type_hash: CKB::Types::Script.new(**type_script2.to_node).compute_hash, args: udt_script2.args, ckb_transactions_count: 2) - block1 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 2) - tx1 = create(:ckb_transaction, block: block1, contained_udt_ids: [udt1.id]) - block2 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 1) - tx2 = create(:ckb_transaction, block: block2, contained_udt_ids: [udt2.id]) - tx3 = create(:ckb_transaction, block: block2, contained_udt_ids: [udt1.id]) - tx4 = create(:ckb_transaction, block: block2, contained_udt_ids: [udt1.id]) - tx5 = create(:ckb_transaction, block: block2, contained_udt_ids: [udt2.id]) + block1 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 2) + tx1 = create(:ckb_transaction, block: block1, + contained_udt_ids: [udt1.id]) + block2 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 1) + tx2 = create(:ckb_transaction, block: block2, + contained_udt_ids: [udt2.id]) + tx3 = create(:ckb_transaction, block: block2, + contained_udt_ids: [udt1.id]) + tx4 = create(:ckb_transaction, block: block2, + contained_udt_ids: [udt1.id]) + tx5 = create(:ckb_transaction, block: block2, + contained_udt_ids: [udt2.id]) input_address1 = create(:address) input_address2 = create(:address) input_address3 = create(:address) @@ -3086,19 +3417,31 @@ class NodeDataProcessorTest < ActiveSupport::TestCase output3.update(type_hash: CKB::Types::Script.new(**output3.type_script.to_node).compute_hash) output4.update(type_hash: CKB::Types::Script.new(**output4.type_script.to_node).compute_hash) output5.update(type_hash: CKB::Types::Script.new(**output5.type_script.to_node).compute_hash) - Address.create(lock_hash: udt_script1.args, address_hash: "0x#{SecureRandom.hex(32)}") - Address.create(lock_hash: udt_script2.args, address_hash: "0x#{SecureRandom.hex(32)}") + Address.create(lock_hash: udt_script1.args, + address_hash: "0x#{SecureRandom.hex(32)}") + Address.create(lock_hash: udt_script2.args, + address_hash: "0x#{SecureRandom.hex(32)}") header = CKB::Types::BlockHeader.new(compact_target: "0x1000", hash: "0x#{SecureRandom.hex(32)}", number: DEFAULT_NODE_BLOCK_NUMBER, parent_hash: "0x#{SecureRandom.hex(32)}", nonce: 1757392074788233522, timestamp: CkbUtils.time_in_milliseconds(Time.current), transactions_root: "0x#{SecureRandom.hex(32)}", proposals_hash: "0x#{SecureRandom.hex(32)}", extra_hash: "0x#{SecureRandom.hex(32)}", version: 0, epoch: 1, dao: "0x01000000000000000000c16ff286230000a3a65e97fd03000057c138586f0000") inputs = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx1.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx2.tx_hash, index: 1)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx3.tx_hash, index: 2)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx1.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx2.tx_hash, index: 1, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx3.tx_hash, index: 2, + )), ] inputs1 = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx4.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx5.tx_hash, index: 0)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx4.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx5.tx_hash, index: 0, + )), ] lock1 = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") @@ -3110,29 +3453,30 @@ class NodeDataProcessorTest < ActiveSupport::TestCase outputs = [ CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1), CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] miner_lock = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") cellbase_inputs = [ CKB::Types::Input.new( previous_output: CKB::Types::OutPoint.new( - tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295 + tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295, ), since: 3000 - ) + ), ] cellbase_outputs = [ - CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock) + CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock), ] transactions = [ CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: cellbase_inputs, outputs: cellbase_outputs, outputs_data: %w[0x], witnesses: ["0x590000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd800000000"]), - CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs, - outputs: outputs, outputs_data: %w[0x 0x 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), + CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs:, + outputs:, outputs_data: %w[0x 0x 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs1, - outputs: outputs, outputs_data: %w[0x 0x 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]) + outputs:, outputs_data: %w[0x 0x 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), ] - node_block = CKB::Types::Block.new(uncles: [], proposals: [], transactions: transactions, header: header) + node_block = CKB::Types::Block.new(uncles: [], proposals: [], + transactions:, header:) block = node_data_processor.process_block(node_block) udt1 = Udt.find_by(args: udt_script1.args) udt2 = Udt.find_by(args: udt_script2.args) @@ -3147,9 +3491,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase end test "should recalculate udts ckb transactions count when block is invalid and outputs has udt cell" do - block1 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 2) + block1 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 2) tx1 = create(:ckb_transaction, block: block1) - block2 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 1) + block2 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 1) tx2 = create(:ckb_transaction, block: block2) tx3 = create(:ckb_transaction, block: block2) tx4 = create(:ckb_transaction, block: block2) @@ -3172,13 +3518,23 @@ class NodeDataProcessorTest < ActiveSupport::TestCase header = CKB::Types::BlockHeader.new(compact_target: "0x1000", hash: "0x#{SecureRandom.hex(32)}", number: DEFAULT_NODE_BLOCK_NUMBER, parent_hash: "0x#{SecureRandom.hex(32)}", nonce: 1757392074788233522, timestamp: CkbUtils.time_in_milliseconds(Time.current), transactions_root: "0x#{SecureRandom.hex(32)}", proposals_hash: "0x#{SecureRandom.hex(32)}", extra_hash: "0x#{SecureRandom.hex(32)}", version: 0, epoch: 1, dao: "0x01000000000000000000c16ff286230000a3a65e97fd03000057c138586f0000") inputs = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx1.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx2.tx_hash, index: 1)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx3.tx_hash, index: 2)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx1.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx2.tx_hash, index: 1, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx3.tx_hash, index: 2, + )), ] inputs1 = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx4.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx5.tx_hash, index: 0)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx4.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx5.tx_hash, index: 0, + )), ] lock1 = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") @@ -3190,43 +3546,52 @@ class NodeDataProcessorTest < ActiveSupport::TestCase args: "0x#{SecureRandom.hex(32)}") udt_script2 = CKB::Types::Script.new(code_hash: Settings.sudt_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(32)}") - Address.create(lock_hash: udt_script1.args, address_hash: "0x#{SecureRandom.hex(32)}") - Address.create(lock_hash: udt_script2.args, address_hash: "0x#{SecureRandom.hex(32)}") + Address.create(lock_hash: udt_script1.args, + address_hash: "0x#{SecureRandom.hex(32)}") + Address.create(lock_hash: udt_script2.args, + address_hash: "0x#{SecureRandom.hex(32)}") outputs = [ - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, type: udt_script1), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, type: udt_script2), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, + type: udt_script1), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, + type: udt_script2), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] outputs1 = [ - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, type: udt_script1), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, type: udt_script2), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, type: udt_script2), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, + type: udt_script1), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, + type: udt_script2), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, + type: udt_script2), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] miner_lock = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") cellbase_inputs = [ CKB::Types::Input.new( previous_output: CKB::Types::OutPoint.new( - tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295 + tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295, ), since: 3000 - ) + ), ] cellbase_outputs = [ - CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock) + CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock), ] transactions = [ CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: cellbase_inputs, outputs: cellbase_outputs, outputs_data: %w[0x], witnesses: ["0x590000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd800000000"]), - CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs, - outputs: outputs, outputs_data: %W[#{CKB::Utils.generate_sudt_amount(1000)} #{CKB::Utils.generate_sudt_amount(1000)} 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), + CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs:, + outputs:, outputs_data: %W[#{CKB::Utils.generate_sudt_amount(1000)} #{CKB::Utils.generate_sudt_amount(1000)} 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs1, - outputs: outputs1, outputs_data: %W[#{CKB::Utils.generate_sudt_amount(1000)} #{CKB::Utils.generate_sudt_amount(1000)} #{CKB::Utils.generate_sudt_amount(1000)} 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]) + outputs: outputs1, outputs_data: %W[#{CKB::Utils.generate_sudt_amount(1000)} #{CKB::Utils.generate_sudt_amount(1000)} #{CKB::Utils.generate_sudt_amount(1000)} 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), ] - node_block = CKB::Types::Block.new(uncles: [], proposals: [], transactions: transactions, header: header) + node_block = CKB::Types::Block.new(uncles: [], proposals: [], + transactions:, header:) block = node_data_processor.process_block(node_block) CkbSync::Api.any_instance.stubs(:get_tip_block_number).returns(block.number + 1) - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do node_data_processor.call end @@ -3256,13 +3621,20 @@ class NodeDataProcessorTest < ActiveSupport::TestCase args: udt_script1.args, ckb_transactions_count: 3) udt2 = create(:udt, type_hash: CKB::Types::Script.new(**type_script2.to_node).compute_hash, args: udt_script2.args, ckb_transactions_count: 2) - block1 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 2) - tx1 = create(:ckb_transaction, block: block1, contained_udt_ids: [udt1.id]) - block2 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 1) - tx2 = create(:ckb_transaction, block: block2, contained_udt_ids: [udt2.id]) - tx3 = create(:ckb_transaction, block: block2, contained_udt_ids: [udt1.id]) - tx4 = create(:ckb_transaction, block: block2, contained_udt_ids: [udt1.id]) - tx5 = create(:ckb_transaction, block: block2, contained_udt_ids: [udt2.id]) + block1 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 2) + tx1 = create(:ckb_transaction, block: block1, + contained_udt_ids: [udt1.id]) + block2 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 1) + tx2 = create(:ckb_transaction, block: block2, + contained_udt_ids: [udt2.id]) + tx3 = create(:ckb_transaction, block: block2, + contained_udt_ids: [udt1.id]) + tx4 = create(:ckb_transaction, block: block2, + contained_udt_ids: [udt1.id]) + tx5 = create(:ckb_transaction, block: block2, + contained_udt_ids: [udt2.id]) input_address1 = create(:address, balance: 50000 * 10**8) input_address2 = create(:address, balance: 60000 * 10**8) input_address3 = create(:address, balance: 70000 * 10**8) @@ -3294,19 +3666,31 @@ class NodeDataProcessorTest < ActiveSupport::TestCase output3.update(type_hash: CKB::Types::Script.new(**output3.type_script.to_node).compute_hash) output4.update(type_hash: CKB::Types::Script.new(**output4.type_script.to_node).compute_hash) output5.update(type_hash: CKB::Types::Script.new(**output5.type_script.to_node).compute_hash) - Address.create(lock_hash: udt_script1.args, address_hash: "0x#{SecureRandom.hex(32)}") - Address.create(lock_hash: udt_script2.args, address_hash: "0x#{SecureRandom.hex(32)}") + Address.create(lock_hash: udt_script1.args, + address_hash: "0x#{SecureRandom.hex(32)}") + Address.create(lock_hash: udt_script2.args, + address_hash: "0x#{SecureRandom.hex(32)}") header = CKB::Types::BlockHeader.new(compact_target: "0x1000", hash: "0x#{SecureRandom.hex(32)}", number: DEFAULT_NODE_BLOCK_NUMBER, parent_hash: "0x#{SecureRandom.hex(32)}", nonce: 1757392074788233522, timestamp: CkbUtils.time_in_milliseconds(Time.current), transactions_root: "0x#{SecureRandom.hex(32)}", proposals_hash: "0x#{SecureRandom.hex(32)}", extra_hash: "0x#{SecureRandom.hex(32)}", version: 0, epoch: 1, dao: "0x01000000000000000000c16ff286230000a3a65e97fd03000057c138586f0000") inputs = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx1.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx2.tx_hash, index: 1)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx3.tx_hash, index: 2)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx1.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx2.tx_hash, index: 1, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx3.tx_hash, index: 2, + )), ] inputs1 = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx4.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx5.tx_hash, index: 0)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx4.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx5.tx_hash, index: 0, + )), ] lock1 = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") @@ -3318,34 +3702,36 @@ class NodeDataProcessorTest < ActiveSupport::TestCase outputs = [ CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1), CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] miner_lock = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") cellbase_inputs = [ CKB::Types::Input.new( previous_output: CKB::Types::OutPoint.new( - tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295 + tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295, ), since: 3000 - ) + ), ] cellbase_outputs = [ - CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock) + CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock), ] transactions = [ CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: cellbase_inputs, outputs: cellbase_outputs, outputs_data: %w[0x], witnesses: ["0x590000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd800000000"]), - CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs, - outputs: outputs, outputs_data: %w[0x 0x 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), + CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs:, + outputs:, outputs_data: %w[0x 0x 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs1, - outputs: outputs, outputs_data: %w[0x 0x 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]) + outputs:, outputs_data: %w[0x 0x 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), ] - node_block = CKB::Types::Block.new(uncles: [], proposals: [], transactions: transactions, header: header) + node_block = CKB::Types::Block.new(uncles: [], proposals: [], + transactions:, header:) block = node_data_processor.process_block(node_block) udt1 = Udt.find_by(args: udt_script1.args) udt2 = Udt.find_by(args: udt_script2.args) CkbSync::Api.any_instance.stubs(:get_tip_block_number).returns(block.number + 1) - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do node_data_processor.call end assert_equal 3, udt1.reload.ckb_transactions_count @@ -3353,9 +3739,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase end test "should remove block's contained address's tx cache when block is invalid" do - block1 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 2) + block1 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 2) tx1 = create(:ckb_transaction, block: block1) - block2 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 1) + block2 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 1) tx2 = create(:ckb_transaction, block: block2) tx3 = create(:ckb_transaction, block: block2) tx4 = create(:ckb_transaction, block: block2) @@ -3379,13 +3767,23 @@ class NodeDataProcessorTest < ActiveSupport::TestCase header = CKB::Types::BlockHeader.new(compact_target: "0x1000", hash: "0x#{SecureRandom.hex(32)}", number: DEFAULT_NODE_BLOCK_NUMBER, parent_hash: "0x#{SecureRandom.hex(32)}", nonce: 1757392074788233522, timestamp: CkbUtils.time_in_milliseconds(Time.current), transactions_root: "0x#{SecureRandom.hex(32)}", proposals_hash: "0x#{SecureRandom.hex(32)}", extra_hash: "0x#{SecureRandom.hex(32)}", version: 0, epoch: 1, dao: "0x01000000000000000000c16ff286230000a3a65e97fd03000057c138586f0000") inputs = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx1.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx2.tx_hash, index: 1)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx3.tx_hash, index: 2)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx1.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx2.tx_hash, index: 1, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx3.tx_hash, index: 2, + )), ] inputs1 = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx4.tx_hash, index: 0)), - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx5.tx_hash, index: 0)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx4.tx_hash, index: 0, + )), + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx5.tx_hash, index: 0, + )), ] lock1 = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") @@ -3393,43 +3791,50 @@ class NodeDataProcessorTest < ActiveSupport::TestCase args: "0x#{SecureRandom.hex(20)}") lock3 = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") - dao_type = CKB::Types::Script.new(code_hash: Settings.dao_type_hash, hash_type: "type", args: "0x") + dao_type = CKB::Types::Script.new(code_hash: Settings.dao_type_hash, + hash_type: "type", args: "0x") outputs = [ - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] outputs1 = [ - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, type: dao_type), - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock2, + type: dao_type), + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock3), ] miner_lock = CKB::Types::Script.new(code_hash: Settings.secp_cell_type_hash, hash_type: "type", args: "0x#{SecureRandom.hex(20)}") cellbase_inputs = [ CKB::Types::Input.new( previous_output: CKB::Types::OutPoint.new( - tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295 + tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295, ), since: 3000 - ) + ), ] cellbase_outputs = [ - CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock) + CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock), ] transactions = [ CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: cellbase_inputs, outputs: cellbase_outputs, outputs_data: %w[0x], witnesses: ["0x590000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd800000000"]), - CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs, - outputs: outputs, outputs_data: %w[0x0000000000000000 0x0000000000000000 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), + CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs:, + outputs:, outputs_data: %w[0x0000000000000000 0x0000000000000000 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs1, - outputs: outputs1, outputs_data: %w[0x0000000000000000 0x0000000000000000 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]) + outputs: outputs1, outputs_data: %w[0x0000000000000000 0x0000000000000000 0x], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), ] - node_block = CKB::Types::Block.new(uncles: [], proposals: [], transactions: transactions, header: header) + node_block = CKB::Types::Block.new(uncles: [], proposals: [], + transactions:, header:) Sidekiq::Testing.inline! block = node_data_processor.process_block(node_block) CkbSync::Api.any_instance.stubs(:get_tip_block_number).returns(block.number + 1) - VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do + VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", + record: :new_episodes) do node_data_processor.call AccountBook.where(ckb_transaction_id: block.ckb_transactions.pluck(:id)).pluck(:address_id).uniq.each do |id| assert_equal 0, $redis.zcard("Address/txs/#{id}") @@ -3446,23 +3851,23 @@ class NodeDataProcessorTest < ActiveSupport::TestCase address = create(:address) block = create(:block, :with_block_hash) ckb_transaction1 = create(:ckb_transaction, - tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) ckb_transaction2 = create(:ckb_transaction, - tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) lock = create(:lock_script) create(:cell_output, ckb_transaction: ckb_transaction1, cell_index: 1, tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", - block: block, + block:, capacity: 10**8 * 1000, - address: address, + address:, lock_script_id: lock.id) create(:cell_output, ckb_transaction: ckb_transaction2, cell_index: 2, tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", - block: block, + block:, capacity: 10**8 * 1000, - address: address, + address:, lock_script_id: lock.id) tx1 = node_block.transactions.first output1 = tx1.outputs.first @@ -3483,31 +3888,31 @@ class NodeDataProcessorTest < ActiveSupport::TestCase block = create(:block, :with_block_hash) ckb_transaction1 = create(:ckb_transaction, tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", - block: block) + block:) ckb_transaction2 = create(:ckb_transaction, tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", - block: block) + block:) lock = create(:lock_script) create(:cell_output, ckb_transaction: ckb_transaction1, cell_index: 1, tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", - block: block, + block:, capacity: 10**8 * 1000, - address: address, + address:, lock_script_id: lock.id) create(:cell_output, ckb_transaction: ckb_transaction2, cell_index: 2, tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", - block: block, + block:, capacity: 10**8 * 1000, - address: address, + address:, lock_script_id: lock.id) tx1 = node_block.transactions.first output1 = tx1.outputs.first output1.type = CKB::Types::Script.new( args: "0xb2e61ff569acf041b3c2c17724e2379c581eeac3", hash_type: "type", - code_hash: Settings.dao_type_hash + code_hash: Settings.dao_type_hash, ) output1.capacity = 10**8 * 1000 tx1.outputs << output1 @@ -3519,12 +3924,13 @@ class NodeDataProcessorTest < ActiveSupport::TestCase factory_cell_script = CKB::Types::Script.new( code_hash: old_factory_cell.code_hash, hash_type: "type", - args: old_factory_cell.args + args: old_factory_cell.args, ) type_script1 = create(:type_script, args: factory_cell_script.args, code_hash: factory_cell_script.code_hash, hash_type: "type") - block1 = create(:block, :with_block_hash, number: DEFAULT_NODE_BLOCK_NUMBER - 1) + block1 = create(:block, :with_block_hash, + number: DEFAULT_NODE_BLOCK_NUMBER - 1) tx1 = create(:ckb_transaction, block: block1) input_address1 = create(:address) address1_lock = create(:lock_script, address_id: input_address1.id, @@ -3543,7 +3949,7 @@ class NodeDataProcessorTest < ActiveSupport::TestCase lock1 = CKB::Types::Script.new( code_hash: Settings.secp_cell_type_hash, hash_type: "type", - args: address1_lock.args + args: address1_lock.args, ) header = CKB::Types::BlockHeader.new( @@ -3558,36 +3964,40 @@ class NodeDataProcessorTest < ActiveSupport::TestCase extra_hash: "0x#{SecureRandom.hex(32)}", version: 0, epoch: 1, - dao: "0x01000000000000000000c16ff286230000a3a65e97fd03000057c138586f0000" + dao: "0x01000000000000000000c16ff286230000a3a65e97fd03000057c138586f0000", ) inputs = [ - CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new(tx_hash: tx1.tx_hash, index: 0)) + CKB::Types::Input.new(previous_output: CKB::Types::OutPoint.new( + tx_hash: tx1.tx_hash, index: 0, + )), ] outputs = [ - CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, type: factory_cell_script) + CKB::Types::Output.new(capacity: 40000 * 10**8, lock: lock1, + type: factory_cell_script), ] miner_lock = CKB::Types::Script.new( code_hash: Settings.secp_cell_type_hash, hash_type: "type", - args: "0x#{SecureRandom.hex(20)}" + args: "0x#{SecureRandom.hex(20)}", ) cellbase_inputs = [ CKB::Types::Input.new( previous_output: CKB::Types::OutPoint.new( - tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295 + tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000", index: 4294967295, ), since: 3000 - ) + ), ] cellbase_outputs = [ - CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock) + CKB::Types::Output.new(capacity: 200986682127, lock: miner_lock), ] transactions = [ CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: cellbase_inputs, outputs: cellbase_outputs, outputs_data: %w[0x], witnesses: ["0x590000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd800000000"]), - CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs: inputs, - outputs: outputs, outputs_data: %w[0x24ff5a9ab8c38d195ce2b4ea75ca89870009522b4b205631204e310009522b4b205631204e3100156465762e6b6f6c6c6563742e6d652f746f6b656e73000000030000000100000000], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]) + CKB::Types::Transaction.new(hash: "0x#{SecureRandom.hex(32)}", cell_deps: [], header_deps: [], inputs:, + outputs:, outputs_data: %w[0x24ff5a9ab8c38d195ce2b4ea75ca89870009522b4b205631204e310009522b4b205631204e3100156465762e6b6f6c6c6563742e6d652f746f6b656e73000000030000000100000000], witnesses: ["0x5d0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce801140000003954acece65096bfa81258983ddb83915fc56bd804000000123456780000000000000000"]), ] - node_block = CKB::Types::Block.new(uncles: [], proposals: [], transactions: transactions, header: header) + node_block = CKB::Types::Block.new(uncles: [], proposals: [], + transactions:, header:) block = node_data_processor.process_block(node_block) assert_equal "R+K V1 N1", old_factory_cell.reload.symbol end @@ -3597,31 +4007,37 @@ class NodeDataProcessorTest < ActiveSupport::TestCase CkbSync::Api.any_instance.stubs(:omiga_inscription_info_code_hash).returns("0x50fdea2d0030a8d0b3d69f883b471cab2a29cae6f01923f19cecac0f27fdaaa6") VCR.use_cassette("blocks/31") do node_block = CkbSync::Api.instance.get_block_by_number(31) - block1 = create(:block, :with_block_hash, number: node_block.header.number - 1) - tx1 = create(:ckb_transaction, block: block1, tx_hash: "0x3e89753ebca825e1504498eb18b56576d5b7eff59fe033346a10ab9e8ca359a4") + block1 = create(:block, :with_block_hash, + number: node_block.header.number - 1) + tx1 = create(:ckb_transaction, block: block1, + tx_hash: "0x3e89753ebca825e1504498eb18b56576d5b7eff59fe033346a10ab9e8ca359a4") input_address1 = create(:address) address1_lock = create(:lock_script, address_id: input_address1.id, - args: "0x#{SecureRandom.hex(20)}", - code_hash: Settings.secp_cell_type_hash, - hash_type: "type") + args: "0x#{SecureRandom.hex(20)}", + code_hash: Settings.secp_cell_type_hash, + hash_type: "type") output1 = create(:cell_output, ckb_transaction: tx1, - block: block1, capacity: 50000000 * 10**8, - tx_hash: tx1.tx_hash, - cell_index: 1, - address: input_address1, - cell_type: "normal", - lock_script_id: address1_lock.id, - type_script_id: nil) + block: block1, capacity: 50000000 * 10**8, + tx_hash: tx1.tx_hash, + cell_index: 1, + address: input_address1, + cell_type: "normal", + lock_script_id: address1_lock.id, + type_script_id: nil) node_data_processor.process_block(node_block) - assert_equal CellOutput.find_by(tx_hash: "0xb865e4d50a72f08acf45389fcd1f76eefe6eb3377733ffc3c1b934a57a86b5dc", cell_index: 0).cell_type, "omiga_inscription_info" + assert_equal CellOutput.find_by(tx_hash: "0xb865e4d50a72f08acf45389fcd1f76eefe6eb3377733ffc3c1b934a57a86b5dc", cell_index: 0).cell_type, + "omiga_inscription_info" info = OmigaInscriptionInfo.first - assert_equal info.code_hash, "0x50fdea2d0030a8d0b3d69f883b471cab2a29cae6f01923f19cecac0f27fdaaa6" + assert_equal info.code_hash, + "0x50fdea2d0030a8d0b3d69f883b471cab2a29cae6f01923f19cecac0f27fdaaa6" assert_equal info.hash_type, "type" - assert_equal info.args, "0xcd89d8f36593a9a82501c024c5cdc4877ca11c5b3d5831b3e78334aecb978f0d" + assert_equal info.args, + "0xcd89d8f36593a9a82501c024c5cdc4877ca11c5b3d5831b3e78334aecb978f0d" assert_equal info.decimal, 0.8e1 assert_equal info.name, "CKB Fist Inscription" assert_equal info.symbol, "CKBI" - assert_equal info.udt_hash, "0x5fa66c8d5f43914f85d3083e0529931883a5b0a14282f891201069f1b5067908" + assert_equal info.udt_hash, + "0x5fa66c8d5f43914f85d3083e0529931883a5b0a14282f891201069f1b5067908" assert_equal info.expected_supply, 0.21e16 assert_equal info.mint_limit, 0.1e12 assert_equal info.mint_status, "minting" @@ -3635,40 +4051,45 @@ class NodeDataProcessorTest < ActiveSupport::TestCase VCR.use_cassette("blocks/32") do node_block = CkbSync::Api.instance.get_block_by_number(32) - block1 = create(:block, :with_block_hash, number: node_block.header.number - 1) - tx1 = create(:ckb_transaction, block: block1, tx_hash: "0x3e89753ebca825e1504498eb18b56576d5b7eff59fe033346a10ab9e8ca359a4") + block1 = create(:block, :with_block_hash, + number: node_block.header.number - 1) + tx1 = create(:ckb_transaction, block: block1, + tx_hash: "0x3e89753ebca825e1504498eb18b56576d5b7eff59fe033346a10ab9e8ca359a4") input_address1 = create(:address) address1_lock = create(:lock_script, address_id: input_address1.id, - args: "0x#{SecureRandom.hex(20)}", - code_hash: Settings.secp_cell_type_hash, - hash_type: "type") + args: "0x#{SecureRandom.hex(20)}", + code_hash: Settings.secp_cell_type_hash, + hash_type: "type") output1 = create(:cell_output, ckb_transaction: tx1, - block: block1, capacity: 50000000 * 10**8, - tx_hash: tx1.tx_hash, - cell_index: 1, - address: input_address1, - cell_type: "normal", - lock_script_id: address1_lock.id, - type_script_id: nil) - create(:omiga_inscription_info, - code_hash: "0x50fdea2d0030a8d0b3d69f883b471cab2a29cae6f01923f19cecac0f27fdaaa6", - hash_type: "type", - args: "0xcd89d8f36593a9a82501c024c5cdc4877ca11c5b3d5831b3e78334aecb978f0d", - decimal: 0.8e1, - name: "CKB Fist Inscription", - symbol: "CKBI", - udt_hash: "0x5fa66c8d5f43914f85d3083e0529931883a5b0a14282f891201069f1b5067908", - expected_supply: 0.21e16, - mint_limit: 0.1e12, - mint_status: "minting", - udt_id: nil - ) + block: block1, capacity: 50000000 * 10**8, + tx_hash: tx1.tx_hash, + cell_index: 1, + address: input_address1, + cell_type: "normal", + lock_script_id: address1_lock.id, + type_script_id: nil) + info = create(:omiga_inscription_info, + code_hash: "0x50fdea2d0030a8d0b3d69f883b471cab2a29cae6f01923f19cecac0f27fdaaa6", + hash_type: "type", + args: "0xcd89d8f36593a9a82501c024c5cdc4877ca11c5b3d5831b3e78334aecb978f0d", + decimal: 0.8e1, + name: "CKB Fist Inscription", + symbol: "CKBI", + udt_hash: "0x5fa66c8d5f43914f85d3083e0529931883a5b0a14282f891201069f1b5067908", + expected_supply: 0.21e16, + mint_limit: 0.1e12, + mint_status: "minting", + udt_id: nil) node_data_processor.process_block(node_block) + assert_equal CellOutput.find_by(type_hash: info.udt_hash).udt_amount, + 0.1e12 assert_equal 1, UdtAccount.count + assert_equal 0.1e12, UdtAccount.first.amount assert_equal 1, UdtTransaction.count omiga_inscription = Udt.first assert_equal OmigaInscriptionInfo.first.udt_id, omiga_inscription.id - assert_equal omiga_inscription.type_hash, "0x5fa66c8d5f43914f85d3083e0529931883a5b0a14282f891201069f1b5067908" + assert_equal omiga_inscription.type_hash, + "0x5fa66c8d5f43914f85d3083e0529931883a5b0a14282f891201069f1b5067908" end end @@ -3681,16 +4102,16 @@ def node_data_processor def fake_dao_withdraw_transaction(node_block) block = create(:block, :with_block_hash, timestamp: 1557382351075) ckb_transaction1 = create(:ckb_transaction, - tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) ckb_transaction2 = create(:ckb_transaction, - tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) lock = create(:lock_script) cell_output1 = create(:cell_output, ckb_transaction: ckb_transaction1, cell_index: 1, - tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block, cell_type: "nervos_dao_withdrawing", capacity: 10**8 * 1000, data: CKB::Utils.bin_to_hex("\x02" * 8), lock_script_id: lock.id) + tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:, cell_type: "nervos_dao_withdrawing", capacity: 10**8 * 1000, data: CKB::Utils.bin_to_hex("\x02" * 8), lock_script_id: lock.id) cell_output2 = create(:cell_output, ckb_transaction: ckb_transaction2, cell_index: 1, - tx_hash: "0x398315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e2", block: block, consumed_by: ckb_transaction2, cell_type: "nervos_dao_deposit", capacity: 10**8 * 1000, data: CKB::Utils.bin_to_hex("\x00" * 8), lock_script_id: lock.id) + tx_hash: "0x398315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e2", block:, consumed_by: ckb_transaction2, cell_type: "nervos_dao_deposit", capacity: 10**8 * 1000, data: CKB::Utils.bin_to_hex("\x00" * 8), lock_script_id: lock.id) cell_output3 = create(:cell_output, ckb_transaction: ckb_transaction2, cell_index: 2, - tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block, lock_script_id: lock.id) + tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:, lock_script_id: lock.id) cell_output1.address.update(balance: 10**8 * 1000) cell_output2.address.update(balance: 10**8 * 1000) cell_output3.address.update(balance: 10**8 * 1000) @@ -3716,13 +4137,13 @@ def fake_dao_deposit_transaction(node_block) block = create(:block, :with_block_hash, timestamp: 1557382351075) lock = create(:lock_script) ckb_transaction1 = create(:ckb_transaction, - tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) ckb_transaction2 = create(:ckb_transaction, - tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block) + tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:) cell_output1 = create(:cell_output, ckb_transaction: ckb_transaction1, cell_index: 1, - tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block, capacity: 10**8 * 1000, lock_script_id: lock.id) + tx_hash: "0x498315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:, capacity: 10**8 * 1000, lock_script_id: lock.id) cell_output2 = create(:cell_output, ckb_transaction: ckb_transaction2, cell_index: 2, - tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block: block, capacity: 10**8 * 1000, lock_script_id: lock.id) + tx_hash: "0x598315db9c7ba144cca74d2e9122ac9b3a3da1641b2975ae321d91ec34f1c0e3", block:, capacity: 10**8 * 1000, lock_script_id: lock.id) cell_output1.address.update(balance: 10**8 * 1000) cell_output2.address.update(balance: 10**8 * 1000) tx = node_block.transactions.first diff --git a/test/utils/ckb_utils_test.rb b/test/utils/ckb_utils_test.rb index 5a8168ea6..d0c56573d 100644 --- a/test/utils/ckb_utils_test.rb +++ b/test/utils/ckb_utils_test.rb @@ -467,6 +467,12 @@ class CkbUtilsTest < ActiveSupport::TestCase assert_equal info[:name], nil end + test "parse omiga inscrpition data" do + data = "0x00e87648170000000000000000000000" + info = CkbUtils.parse_omiga_inscription_data(data) + assert_equal info[:mint_limit], 100000000000 + end + private def node_data_processor