From 4b369bbd5e52b525a6c2e3129d77620803b7b2de Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Mon, 6 May 2024 09:41:18 +0800 Subject: [PATCH] Fix cargo clippy for integration test Signed-off-by: Eval EXEC --- Cargo.lock | 1 + chain/Cargo.toml | 1 + chain/src/tests/block_assembler.rs | 4 + .../relayer/tests/compact_block_process.rs | 2 + sync/src/tests/sync_shared.rs | 83 +++++++------------ sync/src/tests/synchronizer/basic_sync.rs | 3 +- sync/src/tests/synchronizer/functions.rs | 1 + test/src/node.rs | 2 +- 8 files changed, 40 insertions(+), 57 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 04b53f658a1..d1788d68420 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -726,6 +726,7 @@ dependencies = [ "ckb-error", "ckb-jsonrpc-types", "ckb-logger", + "ckb-logger-service", "ckb-merkle-mountain-range", "ckb-metrics", "ckb-network", diff --git a/chain/Cargo.toml b/chain/Cargo.toml index a39f1faad1d..95b145c2d5a 100644 --- a/chain/Cargo.toml +++ b/chain/Cargo.toml @@ -47,6 +47,7 @@ ckb-network = { path = "../network", version = "= 0.116.0-pre" } lazy_static = "1.4" tempfile.workspace = true ckb-systemtime = { path = "../util/systemtime", version = "= 0.116.0-pre", features = ["enable_faketime"] } +ckb-logger-service = { path = "../util/logger-service", version = "= 0.116.0-pre" } [features] default = [] diff --git a/chain/src/tests/block_assembler.rs b/chain/src/tests/block_assembler.rs index 33f561e2a15..3e0638d2e39 100644 --- a/chain/src/tests/block_assembler.rs +++ b/chain/src/tests/block_assembler.rs @@ -283,6 +283,8 @@ fn test_prepare_uncles() { #[test] fn test_candidate_uncles_retain() { + let _log_guard = ckb_logger_service::init_for_test("debug").expect("init log"); + let mut consensus = Consensus::default(); consensus.genesis_epoch_ext.set_length(5); let epoch = consensus.genesis_epoch_ext().clone(); @@ -622,6 +624,8 @@ fn test_package_multi_best_scores() { #[test] fn test_package_low_fee_descendants() { + let _log_guard = ckb_logger_service::init_for_test("debug").expect("init log"); + let mut consensus = Consensus::default(); consensus.genesis_epoch_ext.set_length(5); let epoch = consensus.genesis_epoch_ext().clone(); diff --git a/sync/src/relayer/tests/compact_block_process.rs b/sync/src/relayer/tests/compact_block_process.rs index cb2316a22cc..df4e7491d41 100644 --- a/sync/src/relayer/tests/compact_block_process.rs +++ b/sync/src/relayer/tests/compact_block_process.rs @@ -334,6 +334,8 @@ fn test_send_missing_indexes() { #[test] fn test_accept_block() { + let _log_guard = ckb_logger_service::init_for_test("info,ckb-chain=debug").expect("init log"); + let (relayer, _) = build_chain(5); let parent = { let active_chain = relayer.shared.active_chain(); diff --git a/sync/src/tests/sync_shared.rs b/sync/src/tests/sync_shared.rs index 8e6de22e417..16499c86e95 100644 --- a/sync/src/tests/sync_shared.rs +++ b/sync/src/tests/sync_shared.rs @@ -5,7 +5,6 @@ use crate::tests::util::{build_chain, inherit_block}; use crate::SyncShared; use ckb_chain::{start_chain_services, RemoteBlock, VerifyResult}; use ckb_logger::info; -use ckb_logger_service::LoggerInitGuard; use ckb_shared::block_status::BlockStatus; use ckb_shared::{Shared, SharedBuilder}; use ckb_store::{self, ChainStore}; @@ -240,47 +239,29 @@ fn test_insert_child_block_with_stored_but_unverified_parent() { #[test] fn test_switch_valid_fork() { - let _log_guard: LoggerInitGuard = - ckb_logger_service::init_for_test("info,ckb_chain=debug").expect("init log"); - let (shared, chain) = build_chain(4); - let make_valid_block = |shared, parent_hash| -> BlockView { - let header = inherit_block(shared, &parent_hash).build().header(); - let timestamp = header.timestamp() + 3; - let cellbase = inherit_block(shared, &parent_hash).build().transactions()[0].clone(); - BlockBuilder::default() - .header(header) - .timestamp(timestamp.pack()) - .transaction(cellbase) - .build() - }; - + let (shared, chain) = build_chain(5); // Insert the valid fork. The fork blocks would not been verified until the fork switches as // the main chain. And `block_status_map` would mark the fork blocks as `BLOCK_STORED` - let block_number = 1; - let mut parent_hash = shared.store().get_block_hash(block_number).unwrap(); - for number in 0..=block_number { - let block_hash = shared.store().get_block_hash(number).unwrap(); - shared.store().get_block(&block_hash).unwrap(); - } - - info!( - "chain tip is {}={}", - shared.active_chain().tip_number(), - shared.active_chain().tip_hash() - ); + let fork_tip = 2; + let (fork_shared, fork_chain) = build_chain(fork_tip); + let fork_tip_hash = fork_shared.store().get_block_hash(fork_tip).unwrap(); let mut valid_fork = Vec::new(); - for _ in 2..shared.active_chain().tip_number() { - let block = make_valid_block(shared.shared(), parent_hash.clone()); - info!( - "blocking insert valid fork: {}-{}", - block.number(), - block.hash() - ); + let mut parent_header = fork_shared + .store() + .get_block_header(&fork_tip_hash) + .unwrap(); + for _ in 3..shared.active_chain().tip_number() { + let block = inherit_block(fork_shared.shared(), &parent_header.hash()) + .timestamp((parent_header.timestamp() + 3).pack()) + .build(); + let arc_block = Arc::new(block.clone()); + assert!(fork_shared + .blocking_insert_new_block(&fork_chain, Arc::clone(&arc_block)) + .expect("insert fork"),); assert!(shared - .blocking_insert_new_block(&chain, Arc::new(block.clone())) - .expect("insert fork")); - - parent_hash = block.header().hash(); + .blocking_insert_new_block(&chain, arc_block) + .expect("insert fork"),); + parent_header = block.header().clone(); valid_fork.push(block); } for block in valid_fork.iter() { @@ -289,26 +270,23 @@ fn test_switch_valid_fork() { .active_chain() .get_block_status(&block.header().hash()), BlockStatus::BLOCK_STORED, - "block {}-{} should be BLOCK_STORED", - block.number(), - block.hash() ); } let tip_number = shared.active_chain().tip_number(); // Make the fork switch as the main chain. for _ in tip_number..tip_number + 2 { - let block = inherit_block(shared.shared(), &parent_hash.clone()).build(); - info!( - "blocking insert fork block: {}-{}", - block.number(), - block.hash() - ); + let block = inherit_block(fork_shared.shared(), &parent_header.hash()) + .timestamp((parent_header.timestamp() + 3).pack()) + .build(); + let arc_block = Arc::new(block.clone()); + assert!(fork_shared + .blocking_insert_new_block(&fork_chain, Arc::clone(&arc_block)) + .expect("insert fork"),); assert!(shared - .blocking_insert_new_block(&chain, Arc::new(block.clone())) - .expect("insert fork")); - - parent_hash = block.header().hash(); + .blocking_insert_new_block(&chain, arc_block) + .expect("insert fork"),); + parent_header = block.header().clone(); valid_fork.push(block); } for block in valid_fork.iter() { @@ -317,9 +295,6 @@ fn test_switch_valid_fork() { .active_chain() .get_block_status(&block.header().hash()), BlockStatus::BLOCK_VALID, - "block {}-{} should be BLOCK_VALID", - block.number(), - block.hash() ); } } diff --git a/sync/src/tests/synchronizer/basic_sync.rs b/sync/src/tests/synchronizer/basic_sync.rs index 7639d1b3266..b139fdaab13 100644 --- a/sync/src/tests/synchronizer/basic_sync.rs +++ b/sync/src/tests/synchronizer/basic_sync.rs @@ -10,7 +10,6 @@ use ckb_channel::bounded; use ckb_dao::DaoCalculator; use ckb_dao_utils::genesis_dao_data; use ckb_logger::info; -use ckb_logger_service::LoggerInitGuard; use ckb_network::SupportProtocols; use ckb_reward_calculator::RewardCalculator; use ckb_shared::{Shared, SharedBuilder}; @@ -34,7 +33,7 @@ const DEFAULT_CHANNEL: usize = 128; #[test] fn basic_sync() { - let _log_guard: LoggerInitGuard = ckb_logger_service::init_for_test("debug").expect("init log"); + let _log_guard = ckb_logger_service::init_for_test("debug").expect("init log"); let _faketime_guard = ckb_systemtime::faketime(); _faketime_guard.set_faketime(0); let thread_name = "fake_time=0".to_string(); diff --git a/sync/src/tests/synchronizer/functions.rs b/sync/src/tests/synchronizer/functions.rs index 266e74dcd9c..a0c758c695a 100644 --- a/sync/src/tests/synchronizer/functions.rs +++ b/sync/src/tests/synchronizer/functions.rs @@ -179,6 +179,7 @@ fn test_locator() { #[test] fn test_locate_latest_common_block() { + let _log_guard = ckb_logger_service::init_for_test("debug").expect("init log"); let consensus = Consensus::default(); let (chain_controller1, shared1, synchronizer1) = start_chain(Some(consensus.clone())); let (chain_controller2, shared2, synchronizer2) = start_chain(Some(consensus.clone())); diff --git a/test/src/node.rs b/test/src/node.rs index a0d70a108a3..338a0f6fbfb 100644 --- a/test/src/node.rs +++ b/test/src/node.rs @@ -34,7 +34,7 @@ use std::time::{Duration, Instant}; #[cfg(target_os = "windows")] use windows_sys::Win32::System::Console::{GenerateConsoleCtrlEvent, CTRL_C_EVENT}; -struct ProcessGuard { +pub(crate) struct ProcessGuard { pub name: String, pub child: Child, pub killed: bool,