Skip to content

Commit

Permalink
Fix cargo clippy for integration test
Browse files Browse the repository at this point in the history
Signed-off-by: Eval EXEC <[email protected]>
  • Loading branch information
eval-exec committed May 13, 2024
1 parent a0532cb commit 95c26d9
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 57 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
4 changes: 4 additions & 0 deletions chain/src/tests/block_assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions sync/src/relayer/tests/compact_block_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
83 changes: 29 additions & 54 deletions sync/src/tests/sync_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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()
);
}
}
3 changes: 1 addition & 2 deletions sync/src/tests/synchronizer/basic_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions sync/src/tests/synchronizer/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
2 changes: 1 addition & 1 deletion test/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 95c26d9

Please sign in to comment.