From f07b2e86285eead16955dc34bea5d672f42c7997 Mon Sep 17 00:00:00 2001 From: Rabbit Date: Mon, 22 Jan 2024 08:20:39 +0800 Subject: [PATCH] refactor: add cell dependencies sync worker (#1599) * refactor: add cell dependencies sync worker * chore: adjust tests --- .rubocop.yml | 4 +- Gemfile | 1 - Gemfile.lock | 2 - .../ckb_sync/new_node_data_processor.rb | 197 +++++------------- .../generate_cell_dependencies_worker.rb | 21 ++ test/models/address_test.rb | 1 + test/models/block_test.rb | 1 + test/models/ckb_sync/dao_events_test.rb | 1 + .../ckb_sync/node_data_processor_test.rb | 1 + test/models/ckb_transaction_test.rb | 1 + test/models/lock_script_test.rb | 1 + test/models/type_script_test.rb | 1 + test/models/uncle_block_test.rb | 1 + test/test_helper.rb | 1 + test/utils/ckb_utils_test.rb | 1 + 15 files changed, 89 insertions(+), 146 deletions(-) create mode 100644 app/workers/generate_cell_dependencies_worker.rb diff --git a/.rubocop.yml b/.rubocop.yml index 94304388b..87fa66de2 100755 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -449,9 +449,9 @@ Layout/InitialIndentation: Enabled: false Layout/LineLength: - Description: 'Limit lines to 80 characters.' + Description: 'Limit lines to 200 characters.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits' - Max: 80 + Max: 200 # Lint diff --git a/Gemfile b/Gemfile index b03462596..ff1ef8e1d 100644 --- a/Gemfile +++ b/Gemfile @@ -66,7 +66,6 @@ gem "with_advisory_lock" gem "nokogiri", ">= 1.11.0.rc4" -gem "benchmark_methods", require: false gem "sentry-ruby" gem "sentry-rails" gem "sentry-sidekiq" diff --git a/Gemfile.lock b/Gemfile.lock index 2f9df335a..a865302b5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -111,7 +111,6 @@ GEM awesome_print (1.9.2) backport (1.2.0) benchmark (0.2.1) - benchmark_methods (0.7) bigdecimal (3.1.4) bootsnap (1.13.0) msgpack (~> 1.2) @@ -479,7 +478,6 @@ DEPENDENCIES annotate async-websocket (~> 0.22.1) awesome_print - benchmark_methods bigdecimal bootsnap ckb-sdk-ruby! diff --git a/app/models/ckb_sync/new_node_data_processor.rb b/app/models/ckb_sync/new_node_data_processor.rb index de86b42fa..c6c180db3 100644 --- a/app/models/ckb_sync/new_node_data_processor.rb +++ b/app/models/ckb_sync/new_node_data_processor.rb @@ -1,4 +1,3 @@ -require "benchmark_methods" require "newrelic_rpm" require "new_relic/agent/method_tracer" @@ -6,25 +5,18 @@ module CkbSync class NewNodeDataProcessor include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation include NewRelic::Agent::MethodTracer - # include BenchmarkMethods include Redis::Objects + value :reorg_started_at, global: true - attr_accessor :enable_cota - # benchmark :call, :process_block, :build_block!, :build_uncle_blocks!, :build_ckb_transactions!, :build_udts!, :process_ckb_txs, :build_cells_and_locks!, - # :update_ckb_txs_rel_and_fee, :update_block_info!, :update_block_reward_info!, :update_mining_info, :update_table_records_count, - # :update_or_create_udt_accounts!, :update_udt_info, :process_dao_events!, :update_addresses_info, - # :cache_address_txs, :flush_inputs_outputs_caches, :generate_statistics_data attr_accessor :local_tip_block, :pending_raw_block, :ckb_txs, :target_block, :addrs_changes, - :outputs, :inputs, :outputs_data, - :udt_address_ids, :contained_address_ids, :dao_address_ids, :contained_udt_ids, - :tx_cell_deps, :cell_datas, :cell_data_hashes + :outputs, :inputs, :outputs_data, :udt_address_ids, :contained_address_ids, + :dao_address_ids, :contained_udt_ids, :cell_datas, :enable_cota def initialize(enable_cota = ENV["COTA_AGGREGATOR_URL"].present?) @enable_cota = enable_cota @local_cache = LocalCache.new @offset = ENV["BLOCK_OFFSET"].to_i @cell_datas = {} # data_hash => data - @cell_data_hashes = {} # cell_id => data_hash end # returns the remaining block numbers to process @@ -67,7 +59,6 @@ def process_block(node_block, refresh_balance: true) inputs = @inputs = {} outputs = @outputs = {} outputs_data = @outputs_data = {} - @tx_cell_deps = {} @ckb_txs = build_ckb_transactions!(node_block, local_block, inputs, outputs, outputs_data).to_a benchmark :build_udts!, local_block, outputs, outputs_data @@ -96,18 +87,15 @@ def process_block(node_block, refresh_balance: true) # maybe can be changed to asynchronous update benchmark :update_udt_info, local_block benchmark :process_dao_events!, local_block - if refresh_balance - benchmark :update_addresses_info, addrs_changes, local_block - end + benchmark :update_addresses_info, addrs_changes, local_block, refresh_balance end - benchmark :flush_inputs_outputs_caches, local_block - benchmark :generate_statistics_data, local_block - # benchmark :generate_deployed_cells_and_referring_cells, local_block + flush_inputs_outputs_caches(local_block) + generate_statistics_data(local_block) + generate_deployed_cells_and_referring_cells(local_block) + detect_cota_infos(local_block) - FetchCotaWorker.perform_async(local_block.number) if enable_cota local_block.update_counter_for_ckb_node_version - local_block end @@ -132,17 +120,17 @@ def check_invalid_address(address) private 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] - ReferringCell.create_initial_data_for_ckb_transaction ckb_transaction - end + GenerateCellDependenciesWorker.perform_async(local_block.id) end def generate_statistics_data(local_block) GenerateStatisticsDataWorker.perform_async(local_block.id) end + def detect_cota_infos(local_block) + FetchCotaWorker.perform_async(local_block.number) if enable_cota + end + def process_ckb_txs( node_block, ckb_txs, contained_address_ids, contained_udt_ids, dao_address_ids, tags, udt_address_ids @@ -183,11 +171,9 @@ 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, @@ -196,21 +182,21 @@ def process_dao_events!(local_tip_block = @local_tip_block) ).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:, 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 + value: 1, status: "processed", contract_id: dao_contract.id, block_timestamp: local_block.timestamp, + created_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| @@ -253,8 +239,7 @@ def process_withdraw_dao_events!(local_block, _new_dao_depositors, } end if addrs_withdraw_info[address.id][:dao_deposit] < 0 - 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, @@ -339,7 +324,6 @@ def process_interest_dao_events!(local_block, dao_contract) created_at: Time.current, updated_at: Time.current, } - address_dao_deposit = Address.where(id: previous_cell_output.address_id).pick(:dao_deposit) claimed_compensation += interest end DaoEvent.insert_all!(dao_events_attributes) if dao_events_attributes.present? @@ -351,8 +335,7 @@ def process_interest_dao_events!(local_block, dao_contract) 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 = {} @@ -421,13 +404,11 @@ def update_udt_info(local_block) local_block.cell_outputs.udt.select(:id, :type_hash).each do |udt_output| type_hashes << udt_output.type_hash end - local_block.cell_outputs.omiga_inscription.select(:id, - :type_hash).each do |udt_output| + local_block.cell_outputs.omiga_inscription.select(:id, :type_hash).each do |udt_output| 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 @@ -587,34 +568,8 @@ def update_mining_info(local_block) CkbUtils.update_current_block_mining_info(local_block) end - def update_addresses_info(addrs_change, local_block) - ### Backup the old upsert code - # addrs = [] - # attributes = - # addrs_change.map do |addr_id, values| - # addr = Address.where(id: addr_id).select(:id, :address_hash, :lock_hash, :balance, :ckb_transactions_count, :dao_transactions_count, :live_cells_count, :created_at, :balance_occupied).take! - # balance_diff = values[:balance_diff] - # balance_occupied_diff = values[:balance_occupied_diff].presence || 0 - # live_cells_diff = values[:cells_diff] - # dao_txs_count = values[:dao_txs].present? ? values[:dao_txs].size : 0 - # ckb_txs_count = values[:ckb_txs].present? ? values[:ckb_txs].size : 0 - # addrs << addr - # { - # id: addr.id, - # balance: addr.balance + balance_diff, - # 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, - # created_at: addr.created_at, - # updated_at: Time.current - # } - # end - # if attributes.present? - # Address.upsert_all(attributes) - # addrs.each(&:touch) - # end - + def update_addresses_info(addrs_change, local_block, refresh_balance) + return unless refresh_balance ### because `upsert` don't validate record, so it may pass invalid data into database. ### here we use one by one update (maybe slower) addrs_change.each do |addr_id, values| @@ -656,10 +611,12 @@ def save_address_block_snapshot!(addr, local_block) end def update_block_info!(local_block) - local_block.update!(total_transaction_fee: local_block.ckb_transactions.sum(:transaction_fee), - ckb_transactions_count: local_block.ckb_transactions.count, - live_cell_changes: local_block.ckb_transactions.sum(&:live_cell_changes), - address_ids: local_block.ckb_transactions.map(&:contained_address_ids).flatten.uniq) + local_block.update!( + total_transaction_fee: local_block.ckb_transactions.sum(:transaction_fee), + ckb_transactions_count: local_block.ckb_transactions.count, + live_cell_changes: local_block.ckb_transactions.sum(&:live_cell_changes), + address_ids: local_block.ckb_transactions.map(&:contained_address_ids).flatten.uniq, + ) end def build_udts!(local_block, outputs, outputs_data) @@ -879,14 +836,10 @@ def build_cells_and_locks!( 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 @@ -903,15 +856,13 @@ def build_cells_and_locks!( 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 @@ -945,7 +896,6 @@ def build_cells_and_locks!( end end - # prev_outputs = prepare_previous_outputs(inputs) prev_outputs = nil build_cell_inputs(inputs, ckb_txs, local_block.id, cell_inputs_attributes, prev_cell_outputs_attributes, input_capacities, tags, udt_address_ids, dao_address_ids, contained_udt_ids, contained_addr_ids, @@ -964,50 +914,19 @@ def build_cells_and_locks!( [input_capacities, output_capacities] end - # def prepare_previous_outputs(inputs) - # previous_outputs = {} - # outpoints = [] - # sql = "select id, tx_hash, cell_index, cell_type, capacity, address_id, type_hash, created_at, data from cell_outputs where " - # inputs.each_value do |items| - # items.each do |item| - # if !from_cell_base?(item) - # outpoints << "(tx_hash = '\\#{item.previous_output.tx_hash.delete_prefix('0')}' and cell_index = #{item.previous_output.index}) or " - # end - # end - # end - # block_number = local_cache.read("BlockNumber") - # # not just cellbase in inputs - # if inputs.size > 1 - # outpoints.each_slice(100) do |ops| - # inner_sql = sql.dup - # ops.each do |op| - # inner_sql << op - # end - # inner_sql.delete_suffix!("or ") - # CellOutput.find_by_sql(inner_sql).each do |item| - # previous_outputs["#{item.tx_hash}-#{item.cell_index}"] = item - # local_cache.push("NodeData/#{block_number}/ContainedAddresses", Address.where(id: item.address_id).select(:id, :created_at).first!) - # end - # end - # end - # previous_outputs - # end - def build_addresses!(outputs, local_block) block_number = local_cache.read("BlockNumber") outputs.each_value do |items| items.each do |item| address = local_cache.fetch("NodeData/Address/#{item.lock.code_hash}-#{item.lock.hash_type}-#{item.lock.args}") do - # 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) + 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) end - local_cache.push("NodeData/#{block_number}/ContainedAddresses", - Address.new(id: address.id, - created_at: address.created_at)) + local_cache.push( + "NodeData/#{block_number}/ContainedAddresses", + Address.new(id: address.id, created_at: address.created_at) + ) end end end @@ -1037,26 +956,23 @@ def build_scripts(outputs) block_number = local_cache.read("BlockNumber") outputs.each_value do |items| items.each do |output| - unless local_cache.read("NodeData/#{block_number}/Lock/#{output.lock.code_hash}-#{output.lock.hash_type}-#{output.lock.args}") + lock_cache_key = "NodeData/#{block_number}/Lock/#{output.lock.code_hash}-#{output.lock.hash_type}-#{output.lock.args}" + unless local_cache.read(lock_cache_key) script_hash = output.lock.compute_hash - # TODO use LockScript.where(script_hash: script_hash).exists? replace search by code_hash, hash_type and args query after script_hash has been filled - unless LockScript.where(code_hash: output.lock.code_hash, hash_type: output.lock.hash_type, - args: output.lock.args).exists? + unless LockScript.where(code_hash: output.lock.code_hash, hash_type: output.lock.hash_type, args: output.lock.args).exists? locks_attributes << script_attributes(output.lock, script_hash) - local_cache.write( - "NodeData/#{block_number}/Lock/#{output.lock.code_hash}-#{output.lock.hash_type}-#{output.lock.args}", true - ) + local_cache.write(lock_cache_key, true) end end - if output.type.present? && !local_cache.read("NodeData/#{block_number}/Type/#{output.type.code_hash}-#{output.type.hash_type}-#{output.type.args}") - script_hash = output.type.compute_hash - # TODO use TypeScript.where(script_hash: script_hash).exists? replace search by code_hash, hash_type and args query after script_hash has been filled - unless TypeScript.where(code_hash: output.type.code_hash, hash_type: output.type.hash_type, - args: output.type.args).exists? - types_attributes << script_attributes(output.type, script_hash) - local_cache.write( - "NodeData/#{block_number}/Type/#{output.type.code_hash}-#{output.type.hash_type}-#{output.type.args}", true - ) + + if output.type.present? + type_cache_key = "NodeData/#{block_number}/Type/#{output.type.code_hash}-#{output.type.hash_type}-#{output.type.args}" + if !local_cache.read(type_cache_key) + script_hash = output.type.compute_hash + unless TypeScript.where(code_hash: output.type.code_hash, hash_type: output.type.hash_type, args: output.type.args).exists? + types_attributes << script_attributes(output.type, script_hash) + local_cache.write(type_cache_key, true) + end end end end @@ -1344,7 +1260,6 @@ def build_ckb_transactions!(node_block, local_block, inputs, outputs, end header_deps[tx.hash] = tx.header_deps witnesses[tx.hash] = tx.witnesses - tx_cell_deps[tx.hash] = tx.cell_deps ckb_transactions_attributes << attrs hashes << tx.hash diff --git a/app/workers/generate_cell_dependencies_worker.rb b/app/workers/generate_cell_dependencies_worker.rb new file mode 100644 index 000000000..fdd191131 --- /dev/null +++ b/app/workers/generate_cell_dependencies_worker.rb @@ -0,0 +1,21 @@ +class GenerateCellDependenciesWorker + include Sidekiq::Worker + + def perform(block_id) + block = Block.find_by(id: block_id) + return unless block + + tx_cell_deps = build_cell_deps(block.number) + block.ckb_transactions.each do |txs| + DeployedCell.create_initial_data_for_ckb_transaction(txs, tx_cell_deps[txs.tx_hash]) + ReferringCell.create_initial_data_for_ckb_transaction(txs) + end + end + + def build_cell_deps(number) + node_block = CkbSync::Api.instance.get_block_by_number(number) + node_block.transactions.each_with_object({}) do |tx, deps| + deps[tx.hash] = tx.cell_deps + end + end +end diff --git a/test/models/address_test.rb b/test/models/address_test.rb index a0a20be90..dbbf49074 100644 --- a/test/models/address_test.rb +++ b/test/models/address_test.rb @@ -11,6 +11,7 @@ class AddressTest < ActiveSupport::TestCase ], ) GenerateStatisticsDataWorker.any_instance.stubs(:perform).returns(true) + GenerateCellDependenciesWorker.any_instance.stubs(:perform).returns(true) end context "associations" do diff --git a/test/models/block_test.rb b/test/models/block_test.rb index 82355a38d..15058b3d6 100644 --- a/test/models/block_test.rb +++ b/test/models/block_test.rb @@ -6,6 +6,7 @@ class BlockTest < ActiveSupport::TestCase create(:table_record_count, :ckb_transactions_counter) CkbSync::Api.any_instance.stubs(:get_blockchain_info).returns(OpenStruct.new(chain: "ckb_testnet")) GenerateStatisticsDataWorker.any_instance.stubs(:perform).returns(true) + GenerateCellDependenciesWorker.any_instance.stubs(:perform).returns(true) CkbSync::Api.any_instance.stubs(:get_block_cycles).returns( [ "0x100", "0x200", "0x300", "0x400", "0x500", "0x600", "0x700", "0x800", "0x900" diff --git a/test/models/ckb_sync/dao_events_test.rb b/test/models/ckb_sync/dao_events_test.rb index 37f08d42e..9477b01a2 100644 --- a/test/models/ckb_sync/dao_events_test.rb +++ b/test/models/ckb_sync/dao_events_test.rb @@ -16,6 +16,7 @@ class DaoEventsTest < ActiveSupport::TestCase create(:table_record_count, :ckb_transactions_counter) CkbSync::Api.any_instance.stubs(:get_blockchain_info).returns(OpenStruct.new(chain: "ckb_testnet")) GenerateStatisticsDataWorker.any_instance.stubs(:perform).returns(true) + GenerateCellDependenciesWorker.any_instance.stubs(:perform).returns(true) CkbSync::Api.any_instance.stubs(:get_block_cycles).returns( [ "0x100", "0x200", "0x300", "0x400", "0x500", "0x600", "0x700", "0x800", "0x900" diff --git a/test/models/ckb_sync/node_data_processor_test.rb b/test/models/ckb_sync/node_data_processor_test.rb index c90feb21b..f8037850d 100644 --- a/test/models/ckb_sync/node_data_processor_test.rb +++ b/test/models/ckb_sync/node_data_processor_test.rb @@ -20,6 +20,7 @@ class NodeDataProcessorTest < ActiveSupport::TestCase create(:table_record_count, :ckb_transactions_counter) CkbSync::Api.any_instance.stubs(:get_blockchain_info).returns(OpenStruct.new(chain: "ckb_testnet")) GenerateStatisticsDataWorker.any_instance.stubs(:perform).returns(true) + GenerateCellDependenciesWorker.any_instance.stubs(:perform).returns(true) CkbSync::Api.any_instance.stubs(:get_blockchain_info).returns(OpenStruct.new(chain: "ckb_testnet")) end diff --git a/test/models/ckb_transaction_test.rb b/test/models/ckb_transaction_test.rb index 85f51f714..0bed44893 100644 --- a/test/models/ckb_transaction_test.rb +++ b/test/models/ckb_transaction_test.rb @@ -27,6 +27,7 @@ class CkbTransactionTest < ActiveSupport::TestCase test "#tx_hash should decodes packed string" do GenerateStatisticsDataWorker.any_instance.stubs(:perform).returns(true) + GenerateCellDependenciesWorker.any_instance.stubs(:perform).returns(true) VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}") do CkbSync::Api.any_instance.stubs(:get_epoch_by_number).returns( CKB::Types::Epoch.new( diff --git a/test/models/lock_script_test.rb b/test/models/lock_script_test.rb index 7159d3e8e..e599313a0 100644 --- a/test/models/lock_script_test.rb +++ b/test/models/lock_script_test.rb @@ -6,6 +6,7 @@ class LockScriptTest < ActiveSupport::TestCase create(:table_record_count, :ckb_transactions_counter) CkbSync::Api.any_instance.stubs(:get_blockchain_info).returns(OpenStruct.new(chain: "ckb_testnet")) GenerateStatisticsDataWorker.any_instance.stubs(:perform).returns(true) + GenerateCellDependenciesWorker.any_instance.stubs(:perform).returns(true) CkbSync::Api.any_instance.stubs(:get_block_cycles).returns( [ "0x100", "0x200", "0x300", "0x400", "0x500", "0x600", "0x700", "0x800", "0x900" diff --git a/test/models/type_script_test.rb b/test/models/type_script_test.rb index 4b883d1f2..ac94e4c24 100644 --- a/test/models/type_script_test.rb +++ b/test/models/type_script_test.rb @@ -17,6 +17,7 @@ class TypeScriptTest < ActiveSupport::TestCase test "#code_hash should decodes packed string" do GenerateStatisticsDataWorker.any_instance.stubs(:perform).returns(true) + GenerateCellDependenciesWorker.any_instance.stubs(:perform).returns(true) CkbSync::Api.any_instance.stubs(:get_epoch_by_number).returns( CKB::Types::Epoch.new( compact_target: "0x1000", diff --git a/test/models/uncle_block_test.rb b/test/models/uncle_block_test.rb index f6e275295..a749491ca 100644 --- a/test/models/uncle_block_test.rb +++ b/test/models/uncle_block_test.rb @@ -6,6 +6,7 @@ class UncleBlockTest < ActiveSupport::TestCase create(:table_record_count, :ckb_transactions_counter) CkbSync::Api.any_instance.stubs(:get_blockchain_info).returns(OpenStruct.new(chain: "ckb_testnet")) GenerateStatisticsDataWorker.any_instance.stubs(:perform).returns(true) + GenerateCellDependenciesWorker.any_instance.stubs(:perform).returns(true) CkbSync::Api.any_instance.stubs(:get_block_cycles).returns( [ "0x100", "0x200", "0x300", "0x400", "0x500", "0x600", "0x700", "0x800", "0x900" diff --git a/test/test_helper.rb b/test/test_helper.rb index 46a3839da..257bfa077 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -49,6 +49,7 @@ def prepare_node_data(node_tip_block_number = 30) Sidekiq::Testing.inline! GenerateStatisticsDataWorker.any_instance.stubs(:perform).returns(true) + GenerateCellDependenciesWorker.any_instance.stubs(:perform).returns(true) CkbSync::Api.any_instance.stubs(:get_tip_block_number).returns(node_tip_block_number + 1) CkbSync::Api.any_instance.stubs(:get_epoch_by_number).returns( CKB::Types::Epoch.new( diff --git a/test/utils/ckb_utils_test.rb b/test/utils/ckb_utils_test.rb index 48b3e6fbb..6a95508a3 100644 --- a/test/utils/ckb_utils_test.rb +++ b/test/utils/ckb_utils_test.rb @@ -19,6 +19,7 @@ class CkbUtilsTest < ActiveSupport::TestCase ], ) GenerateStatisticsDataWorker.any_instance.stubs(:perform).returns(true) + GenerateCellDependenciesWorker.any_instance.stubs(:perform).returns(true) end test ".generate_address should return mainnet address when mode is mainnet" do