remove clippy_vec_init_and_push and dup code
MODIFY
chain/src/verifier/mod.rs
chain/src/verifier/mod.rs
@@ -171,15 +171,6 @@ impl BlockVerifier for BasicVerifier {
new_block_header.number()
);
- verify_block!(
- VerifyBlockField::Header,
- current_id == new_block_parent,
- "Invalid block: Parent id mismatch, expect:{}, got: {}, number:{}.",
- current_id,
- new_block_parent,
- new_block_header.number()
- );
-
verify_block!(
VerifyBlockField::Header,
new_block_header.timestamp() > current.timestamp(),

MODIFY
chain/tests/test_block_chain.rs
chain/tests/test_block_chain.rs
@@ -202,13 +202,11 @@ fn product_a_block(branch: &BlockChain, miner: &AccountInfo, uncles: Vec<BlockHe
}
#[stest::test(timeout = 120)]
-#[allow(clippy::vec_init_then_push)]
fn test_uncle() {
let (mut mock_chain, _, uncle_block_header) = gen_uncle();
let miner = mock_chain.miner();
// 3. mock chain apply
- let mut uncles = Vec::new();
- uncles.push(uncle_block_header.clone());
+ let uncles = vec![uncle_block_header.clone()];
let block = product_a_block(mock_chain.head(), miner, uncles);
mock_chain.apply(block).unwrap();
assert!(mock_chain.head().head_block().block.uncles().is_some());
@@ -223,13 +221,11 @@ fn test_uncle() {
}
#[stest::test(timeout = 120)]
-#[allow(clippy::vec_init_then_push)]
fn test_uncle_exist() {
let (mut mock_chain, _, uncle_block_header) = gen_uncle();
let miner = mock_chain.miner().clone();
// 3. mock chain apply
- let mut uncles = Vec::new();
- uncles.push(uncle_block_header.clone());
+ let uncles = vec![uncle_block_header.clone()];
let block = product_a_block(mock_chain.head(), &miner, uncles);
mock_chain.apply(block).unwrap();
assert!(mock_chain.head().head_block().block.uncles().is_some());
@@ -243,14 +239,12 @@ fn test_uncle_exist() {
assert_eq!(mock_chain.head().current_epoch_uncles_size(), 1);
// 4. uncle exist
- let mut uncles = Vec::new();
- uncles.push(uncle_block_header);
+ let uncles = vec![uncle_block_header];
let block = product_a_block(mock_chain.head(), &miner, uncles);
assert!(mock_chain.apply(block).is_err());
}
#[stest::test(timeout = 120)]
-#[allow(clippy::vec_init_then_push)]
fn test_uncle_son() {
let (mut mock_chain, mut fork_block_chain, _) = gen_uncle();
let miner = mock_chain.miner();
@@ -260,36 +254,31 @@ fn test_uncle_son() {
fork_block_chain.apply(uncle_son).unwrap();
// 4. mock chain apply
- let mut uncles = Vec::new();
- uncles.push(uncle_son_block_header);
+ let uncles = vec![uncle_son_block_header];
let block = product_a_block(mock_chain.head(), miner, uncles);
assert!(mock_chain.apply(block).is_err());
assert_eq!(mock_chain.head().current_epoch_uncles_size(), 0);
}
#[stest::test(timeout = 120)]
-#[allow(clippy::vec_init_then_push)]
fn test_random_uncle() {
let (mut mock_chain, _, _) = gen_uncle();
let miner = mock_chain.miner();
// 3. random BlockHeader and apply
- let mut uncles = Vec::new();
- uncles.push(BlockHeader::random());
+ let uncles = vec![BlockHeader::random()];
let block = product_a_block(mock_chain.head(), miner, uncles);
assert!(mock_chain.apply(block).is_err());
assert_eq!(mock_chain.head().current_epoch_uncles_size(), 0);
}
#[stest::test(timeout = 480)]
-#[allow(clippy::vec_init_then_push)]
fn test_switch_epoch() {
let (mut mock_chain, _, uncle_block_header) = gen_uncle();
let miner = mock_chain.miner().clone();
// 3. mock chain apply
- let mut uncles = Vec::new();
- uncles.push(uncle_block_header.clone());
+ let uncles = vec![uncle_block_header.clone()];
let block = product_a_block(mock_chain.head(), &miner, uncles);
mock_chain.apply(block).unwrap();
assert!(mock_chain.head().head_block().block.uncles().is_some());
@@ -322,7 +311,6 @@ fn test_switch_epoch() {
}
#[stest::test(timeout = 480)]
-#[allow(clippy::vec_init_then_push)]
fn test_uncle_in_diff_epoch() {
let (mut mock_chain, _, uncle_block_header) = gen_uncle();
let miner = mock_chain.miner().clone();
@@ -347,8 +335,7 @@ fn test_uncle_in_diff_epoch() {
assert_eq!(mock_chain.head().current_epoch_uncles_size(), 0);
// 5. mock chain apply
- let mut uncles = Vec::new();
- uncles.push(uncle_block_header);
+ let uncles = vec![uncle_block_header];
let block = product_a_block(mock_chain.head(), &miner, uncles);
assert!(mock_chain.apply(block).is_err());
}

MODIFY
commons/forkable-jellyfish-merkle/src/node_type/node_type_test.rs
commons/forkable-jellyfish-merkle/src/node_type/node_type_test.rs
@@ -722,7 +722,6 @@ impl NaiveInternalNode {
BinaryTreeNode::new_internal(begin, width, left, right)
}
- #[allow(clippy::vec_init_then_push)]
fn get_child_with_siblings(&self, n: u8) -> (Option<NodeKey>, Vec<HashValue>) {
let mut current_node = Rc::clone(&self.root);
let mut siblings = Vec::new();

MODIFY
executor/src/account.rs
executor/src/account.rs
@@ -18,7 +18,6 @@ pub use starcoin_types::account::*;
/// Returns a transaction to transfer coin from one account to another (possibly new) one, with the
/// given arguments.
-#[allow(clippy::vec_init_then_push)]
pub fn peer_to_peer_txn(
sender: &Account,
receiver: &Account,
@@ -27,9 +26,10 @@ pub fn peer_to_peer_txn(
expiration_timestamp_secs: u64,
chain_id: ChainId,
) -> SignedUserTransaction {
- let mut args: Vec<Vec<u8>> = Vec::new();
- args.push(bcs_ext::to_bytes(receiver.address()).unwrap());
- args.push(bcs_ext::to_bytes(&transfer_amount).unwrap());
+ let args = vec![
+ bcs_ext::to_bytes(receiver.address()).unwrap(),
+ bcs_ext::to_bytes(&transfer_amount).unwrap(),
+ ];
// get a SignedTransaction
sender.create_signed_txn_with_args(
@@ -51,7 +51,6 @@ pub fn peer_to_peer_txn(
}
/// Returns a transaction to create a new account with the given arguments.
-#[allow(clippy::vec_init_then_push)]
pub fn create_account_txn_sent_as_association(
new_account: &Account,
seq_num: u64,
@@ -59,10 +58,11 @@ pub fn create_account_txn_sent_as_association(
expiration_timstamp_secs: u64,
net: &ChainNetwork,
) -> SignedUserTransaction {
- let mut args: Vec<Vec<u8>> = Vec::new();
- args.push(bcs_ext::to_bytes(new_account.address()).unwrap());
- args.push(bcs_ext::to_bytes(&new_account.auth_key().to_vec()).unwrap());
- args.push(bcs_ext::to_bytes(&initial_amount).unwrap());
+ let args = vec![
+ bcs_ext::to_bytes(new_account.address()).unwrap(),
+ bcs_ext::to_bytes(&new_account.auth_key().to_vec()).unwrap(),
+ bcs_ext::to_bytes(&initial_amount).unwrap(),
+ ];
create_signed_txn_with_association_account(
TransactionPayload::ScriptFunction(ScriptFunction::new(

MODIFY
sync/src/block_connector/test_illegal_block.rs
sync/src/block_connector/test_illegal_block.rs
@@ -310,7 +310,6 @@ async fn test_verify_new_epoch_block_uncle_should_none_failed() {
}
#[stest::test]
-#[allow(clippy::vec_init_then_push)]
async fn test_verify_can_not_be_uncle_is_member_failed() {
let times = 5;
let (mut writeable_block_chain_service, node_config, storage) =
@@ -327,8 +326,7 @@ async fn test_verify_can_not_be_uncle_is_member_failed() {
.get_header_by_number(times - 2)
.unwrap()
.unwrap();
- let mut uncles = Vec::new();
- uncles.push(uncle_header);
+ let uncles = vec![uncle_header];
let apply_failed = apply_with_illegal_uncle(
node_config.net(),
uncles,
@@ -342,7 +340,6 @@ async fn test_verify_can_not_be_uncle_is_member_failed() {
}
#[stest::test]
-#[allow(clippy::vec_init_then_push)]
async fn test_verify_can_not_be_uncle_check_ancestor_failed() {
// 1. chain
let times = 7;
@@ -379,8 +376,7 @@ async fn test_verify_can_not_be_uncle_check_ancestor_failed() {
// 3. new block
let uncle_header = new_branch.current_header();
- let mut uncles = Vec::new();
- uncles.push(uncle_header);
+ let uncles = vec![uncle_header];
let apply_failed = apply_with_illegal_uncle(
node_config.net(),
uncles,
@@ -393,7 +389,6 @@ async fn test_verify_can_not_be_uncle_check_ancestor_failed() {
}
}
-#[allow(clippy::vec_init_then_push)]
async fn test_verify_illegal_uncle_future_timestamp(succ: bool) -> Result<Block> {
let count = 5;
let (mut uncle_header, mut writeable_block_chain_service, node_config, storage) =
@@ -404,8 +399,7 @@ async fn test_verify_illegal_uncle_future_timestamp(succ: bool) -> Result<Block>
.with_timestamp((duration_since_epoch().as_millis() + 1000) as u64)
.build();
}
- let mut uncles = Vec::new();
- uncles.push(uncle_header);
+ let uncles = vec![uncle_header];
apply_with_illegal_uncle(
node_config.net(),
uncles,
@@ -426,7 +420,6 @@ async fn test_verify_illegal_uncle_future_timestamp_failed() {
}
}
-#[allow(clippy::vec_init_then_push)]
async fn test_verify_illegal_uncle_consensus(succ: bool) -> Result<()> {
let mut genesis_config = BuiltinNetworkID::Test.genesis_config().clone();
genesis_config.genesis_block_parameter =
@@ -465,8 +458,7 @@ async fn test_verify_illegal_uncle_consensus(succ: bool) -> Result<()> {
}
// 3. main and create a new block with uncle block
- let mut uncles = Vec::new();
- uncles.push(uncle_block_header);
+ let uncles = vec![uncle_block_header];
let mut main_block_chain = mock_chain.fork_new_branch(None).unwrap();
let (block_template, _) = main_block_chain
.create_block_template(*miner.address(), None, Vec::new(), uncles, None)
@@ -533,12 +525,10 @@ async fn test_verify_block_used_gas_failed() {
}
#[stest::test]
-#[allow(clippy::vec_init_then_push)]
async fn test_verify_txn_count_failed() {
// TODO: fix me
let (mut new_block, mut main) = new_block_and_main().await;
- let mut txns = Vec::new();
- txns.push(SignedUserTransaction::mock());
+ let txns = vec![SignedUserTransaction::mock()];
let mut body = new_block.body.clone();
body.transactions = txns;
new_block.body = body;
@@ -659,7 +649,6 @@ async fn test_verify_uncles_count_failed() {
debug!("expect apply failed : {:?}", apply_failed.err().unwrap());
}
-#[allow(clippy::vec_init_then_push)]
async fn test_verify_uncles_number(succ: bool) -> Result<Block> {
let count = 5;
let (mut uncle_header, mut writeable_block_chain_service, node_config, storage) =
@@ -676,8 +665,7 @@ async fn test_verify_uncles_number(succ: bool) -> Result<Block> {
)
.build();
}
- let mut uncles = Vec::new();
- uncles.push(uncle_header);
+ let uncles = vec![uncle_header];
apply_with_illegal_uncle(
node_config.net(),
uncles,
@@ -696,7 +684,6 @@ async fn test_verify_uncles_number_failed() {
}
}
-#[allow(clippy::vec_init_then_push)]
async fn test_verify_uncles_in_old_epoch(begin_epoch: bool) -> Result<Block> {
let count = 5;
let (uncle_header, mut writeable_block_chain_service, node_config, storage) =
@@ -731,8 +718,7 @@ async fn test_verify_uncles_in_old_epoch(begin_epoch: bool) -> Result<Block> {
}
}
- let mut uncles = Vec::new();
- uncles.push(uncle_header);
+ let uncles = vec![uncle_header];
apply_with_illegal_uncle(
node_config.net(),
uncles,
@@ -751,14 +737,12 @@ async fn test_verify_uncles_in_old_epoch_failed() {
}
#[stest::test]
-#[allow(clippy::vec_init_then_push)]
async fn test_verify_uncles_uncle_exist_failed() {
let count = 5;
let (uncle_header, mut writeable_block_chain_service, node_config, storage) =
uncle_block_and_writeable_block_chain(count, count - 2).await;
let net = node_config.net();
- let mut uncles = Vec::new();
- uncles.push(uncle_header);
+ let uncles = vec![uncle_header];
info!(
"number 1 : {}",
writeable_block_chain_service
@@ -828,7 +812,6 @@ async fn test_some_uncles_in_block_failed() {
}
#[stest::test]
-#[allow(clippy::vec_init_then_push)]
async fn test_verify_uncle_and_parent_number_failed() {
let count = 5;
let (mut uncle_header, mut writeable_block_chain_service, node_config, storage) =
@@ -863,8 +846,7 @@ async fn test_verify_uncle_and_parent_number_failed() {
.number();
assert_eq!(old_number + 1, new_number);
- let mut uncles = Vec::new();
- uncles.push(uncle_header);
+ let uncles = vec![uncle_header];
let apply_failed = apply_with_illegal_uncle(
node_config.net(),
@@ -879,7 +861,6 @@ async fn test_verify_uncle_and_parent_number_failed() {
}
#[stest::test]
-#[allow(clippy::vec_init_then_push)]
async fn test_verify_uncle_which_parent_is_end_block_in_last_epoch() {
let count = TEST_CONFIG.consensus_config.epoch_block_count;
let (uncle_header, mut writeable_block_chain_service, node_config, storage) =
@@ -905,8 +886,7 @@ async fn test_verify_uncle_which_parent_is_end_block_in_last_epoch() {
(uncle_parent_header.number() + 1)
);
- let mut uncles = Vec::new();
- uncles.push(uncle_header);
+ let uncles = vec![uncle_header];
let apply_failed = apply_with_illegal_uncle(
node_config.net(),
uncles,

MODIFY
vm/types/src/on_chain_config/mod.rs
vm/types/src/on_chain_config/mod.rs
@@ -60,13 +60,12 @@ impl ConfigID {
}
}
-#[allow(clippy::vec_init_then_push)]
pub static ON_CHAIN_CONFIG_REGISTRY: Lazy<Vec<ConfigID>> = Lazy::new(|| {
- let mut configs: Vec<ConfigID> = Vec::new();
- configs.push(Version::config_id());
- configs.push(ConsensusConfig::config_id());
- configs.push(DaoConfig::config_id());
- configs
+ vec![
+ Version::config_id(),
+ ConsensusConfig::config_id(),
+ DaoConfig::config_id(),
+ ]
});
#[derive(Clone, Debug, PartialEq)]

remove clippy_vec_init_and_push and dup code (#3311)