From 6aefb49f22845949d1e884813505600a20b393a8 Mon Sep 17 00:00:00 2001 From: Yin Guanhao Date: Wed, 11 Oct 2023 14:12:10 +0800 Subject: [PATCH] Fix clippy warnings --- crates/block-producer/src/cleaner.rs | 8 +++-- crates/block-producer/src/runner.rs | 2 +- crates/block-producer/src/withdrawal.rs | 14 ++++---- .../src/account_lock_manage/always_success.rs | 2 +- .../src/account_lock_manage/eip712/types.rs | 12 ++----- .../src/account_lock_manage/secp256k1.rs | 16 ++++----- crates/generator/src/utils.rs | 8 ++--- crates/mem-pool/src/block_sync_server.rs | 2 +- crates/mem-pool/src/restore_manager.rs | 4 +-- crates/mem-pool/src/withdrawal.rs | 8 ++--- .../src/recover/eth_sender.rs | 2 +- crates/replay-chain/src/setup.rs | 2 +- crates/rpc-client/src/withdrawal.rs | 8 ++--- crates/store/src/state/overlay/mem_store.rs | 2 +- .../src/script_tests/l2_scripts/examples.rs | 14 +++----- .../script_tests/l2_scripts/meta_contract.rs | 2 +- .../cancel_challenge/tx_signature.rs | 2 +- .../state_validator/submit_block.rs | 4 +-- crates/tests/src/testing_tool/chain.rs | 34 +++++++------------ crates/tests/src/tests/export_import_block.rs | 24 +++++-------- .../src/tests/unlock_withdrawal_to_owner.rs | 4 +-- crates/tools/src/deploy_genesis.rs | 4 +-- crates/tools/src/prepare_scripts.rs | 3 ++ crates/tools/src/setup.rs | 5 +++ crates/utils/src/genesis_info.rs | 2 +- gwos-evm/polyjuice-tests/src/ctx.rs | 12 +++---- gwos-evm/polyjuice-tests/src/helper.rs | 14 ++++---- .../src/test_cases/address_collision.rs | 2 +- .../src/test_cases/call_multiple_times.rs | 2 +- .../src/test_cases/contract_call_contract.rs | 2 +- .../test_cases/contract_create_contract.rs | 2 +- .../polyjuice-tests/src/test_cases/create2.rs | 8 ++--- .../src/test_cases/delegatecall.rs | 2 +- .../src/test_cases/eth_addr_reg.rs | 8 ++--- .../src/test_cases/gas_price.rs | 2 +- .../src/test_cases/get_block_info.rs | 2 +- .../src/test_cases/get_chain_id.rs | 2 +- .../src/test_cases/heap_memory.rs | 2 +- .../test_cases/invalid_sudt_erc20_proxy.rs | 6 ++-- .../src/test_cases/multicall3.rs | 2 +- .../src/test_cases/parse_log_event.rs | 6 ++-- .../src/test_cases/recover_account.rs | 16 ++++----- .../src/test_cases/recursion_contract.rs | 2 +- .../polyjuice-tests/src/test_cases/revert.rs | 10 +++--- .../src/test_cases/selfdestruct.rs | 4 +-- .../src/test_cases/simple_storage.rs | 2 +- .../src/test_cases/simple_transfer.rs | 8 ++--- .../src/test_cases/sudt_erc20_proxy.rs | 4 +-- .../sudt_erc20_proxy_attack_allowance.rs | 4 +-- .../polyjuice-tests/tests/ethereum_test.rs | 26 +++++++------- gwos/contracts/eth-account-lock/src/entry.rs | 2 +- 51 files changed, 162 insertions(+), 178 deletions(-) diff --git a/crates/block-producer/src/cleaner.rs b/crates/block-producer/src/cleaner.rs index 7888d5cfc..0de959705 100644 --- a/crates/block-producer/src/cleaner.rs +++ b/crates/block-producer/src/cleaner.rs @@ -152,9 +152,11 @@ impl Cleaner { let rpc_client = &self.rpc_client; for (idx, tx_hash) in consumed_txs { let consumed = match tx_hash { - Some(tx_hash) => { - !matches!(rpc_client.ckb.get_transaction_status(tx_hash).await?, None) - } + Some(tx_hash) => rpc_client + .ckb + .get_transaction_status(tx_hash) + .await? + .is_some(), None => false, }; if consumed { diff --git a/crates/block-producer/src/runner.rs b/crates/block-producer/src/runner.rs index 8a2962725..650f808de 100644 --- a/crates/block-producer/src/runner.rs +++ b/crates/block-producer/src/runner.rs @@ -374,7 +374,7 @@ impl BaseInitComponents { .ok_or_else(|| anyhow!("Eth: No allowed EoA type hashes in the rollup config"))?; account_lock_manage.register_lock_algorithm( eth_lock_script_type_hash.hash().unpack(), - Arc::new(Secp256k1Eth::default()), + Arc::new(Secp256k1Eth), ); let mut gen = Generator::new( backend_manage, diff --git a/crates/block-producer/src/withdrawal.rs b/crates/block-producer/src/withdrawal.rs index 6ebb3a450..255044374 100644 --- a/crates/block-producer/src/withdrawal.rs +++ b/crates/block-producer/src/withdrawal.rs @@ -347,7 +347,7 @@ mod test { let sudt_script = Script::new_builder() .code_hash(H256::from_u32(2).pack()) .hash_type(ScriptHashType::Type.into()) - .args(vec![3u8; 32].pack()) + .args([3u8; 32][..].pack()) .build(); let finalized_custodians = CollectedCustodianCells { @@ -358,7 +358,7 @@ mod test { let owner_lock = Script::new_builder() .code_hash(H256::from_u32(4).pack()) - .args(vec![5; 32].pack()) + .args([5; 32][..].pack()) .build(); let withdrawal = { @@ -374,7 +374,7 @@ mod test { .build(); WithdrawalRequest::new_builder() .raw(raw) - .signature(vec![6u8; 65].pack()) + .signature([6u8; 65][..].pack()) .build() }; @@ -460,7 +460,7 @@ mod test { let sudt_script = Script::new_builder() .code_hash(H256::from_u32(3).pack()) .hash_type(ScriptHashType::Type.into()) - .args(vec![4u8; 32].pack()) + .args([4u8; 32][..].pack()) .build(); let rollup_context = RollupContext { @@ -497,7 +497,7 @@ mod test { let owner_lock = Script::new_builder() .code_hash(H256::from_u32(8).pack()) .hash_type(ScriptHashType::Type.into()) - .args(vec![9u8; 32].pack()) + .args([9u8; 32][..].pack()) .build(); let withdrawal_without_owner_lock = { @@ -722,7 +722,7 @@ mod test { let sudt_script = Script::new_builder() .code_hash(H256::from_u32(3).pack()) .hash_type(ScriptHashType::Type.into()) - .args(vec![4u8; 32].pack()) + .args([4u8; 32][..].pack()) .build(); let rollup_config = RollupConfig::new_builder() .l1_sudt_script_type_hash(sudt_script.code_hash()) @@ -793,7 +793,7 @@ mod test { let owner_lock_script = Script::new_builder() .code_hash(H256::from_u32(8).pack()) .hash_type(ScriptHashType::Type.into()) - .args(vec![9u8; 32].pack()) + .args([9u8; 32][..].pack()) .build(); let withdrawal_lock_args = WithdrawalLockArgs::new_builder() .owner_lock_hash(owner_lock_script.hash().pack()) diff --git a/crates/generator/src/account_lock_manage/always_success.rs b/crates/generator/src/account_lock_manage/always_success.rs index a232f4e9b..57496b491 100644 --- a/crates/generator/src/account_lock_manage/always_success.rs +++ b/crates/generator/src/account_lock_manage/always_success.rs @@ -16,7 +16,7 @@ pub struct AlwaysSuccess; /// Usage /// register AlwaysSuccess to AccountLockManage /// -/// manage.register_lock_algorithm(code_hash, Box::new(AlwaysSuccess::default())); +/// manage.register_lock_algorithm(code_hash, Box::new(AlwaysSuccess)); impl LockAlgorithm for AlwaysSuccess { fn recover(&self, _message: H256, _signature: &[u8]) -> Result { Ok(Default::default()) diff --git a/crates/generator/src/account_lock_manage/eip712/types.rs b/crates/generator/src/account_lock_manage/eip712/types.rs index c50e0ef07..0b618ef1d 100644 --- a/crates/generator/src/account_lock_manage/eip712/types.rs +++ b/crates/generator/src/account_lock_manage/eip712/types.rs @@ -466,9 +466,7 @@ mod tests { buf[64] = v; buf }; - let pubkey_hash = Secp256k1Eth::default() - .recover(message, &signature) - .unwrap(); + let pubkey_hash = Secp256k1Eth.recover(message, &signature).unwrap(); assert_eq!(hex::encode(mail.from.wallet), hex::encode(pubkey_hash)); } @@ -517,9 +515,7 @@ mod tests { }; let message = withdrawal.eip712_message(domain_seperator.hash_struct()); let signature: [u8; 65] = hex::decode("22cae59f1bfaf58f423d1a414cbcaefd45a89dd54c9142fccbb2473c74f4741b45f77f1f3680b8c0b6362957c8d79f96a683a859ccbf22a6cfc1ebc311b936d301").unwrap().try_into().unwrap(); - let pubkey_hash = Secp256k1Eth::default() - .recover(message, &signature) - .unwrap(); + let pubkey_hash = Secp256k1Eth.recover(message, &signature).unwrap(); assert_eq!( "cc3e7fb0176a0e22a7f675306ceeb61d26eb0dc4".to_string(), hex::encode(pubkey_hash) @@ -555,9 +551,7 @@ mod tests { }; let message = tx.eip712_message(domain_seperator.hash_struct()); let signature: [u8; 65] = hex::decode("64b164f5303000c283119974d7ba8f050cc7429984af904134d5cda6d3ce045934cc6b6f513ec939c2ae4cfb9cbee249ba8ae86f6274e4035c150f9c8e634a3a1b").unwrap().try_into().unwrap(); - let pubkey_hash = Secp256k1Eth::default() - .recover(message, &signature) - .unwrap(); + let pubkey_hash = Secp256k1Eth.recover(message, &signature).unwrap(); assert_eq!( "e8ae579256c3b84efb76bbb69cb6bcbef1375f00".to_string(), hex::encode(pubkey_hash) diff --git a/crates/generator/src/account_lock_manage/secp256k1.rs b/crates/generator/src/account_lock_manage/secp256k1.rs index 61a6dfcf0..95a39e154 100644 --- a/crates/generator/src/account_lock_manage/secp256k1.rs +++ b/crates/generator/src/account_lock_manage/secp256k1.rs @@ -107,7 +107,7 @@ impl Secp256k1Eth { /// Usage /// register AlwaysSuccess to AccountLockManage /// -/// manage.register_lock_algorithm(code_hash, Box::new(AlwaysSuccess::default())); +/// manage.register_lock_algorithm(code_hash, Box::new(AlwaysSuccess)); impl LockAlgorithm for Secp256k1Eth { fn recover(&self, message: H256, signature: &[u8]) -> Result { // extract rec_id @@ -319,7 +319,7 @@ mod tests { .raw(raw_tx) .signature(signature.to_vec().pack()) .build(); - let eth = Secp256k1Eth::default(); + let eth = Secp256k1Eth; let rollup_type_hash = vec![0u8; 32]; @@ -354,7 +354,7 @@ mod tests { #[test] fn test_secp256k1_eth_polyjuice_native_token_transfer() { let chain_id = 42; - let mut polyjuice_args = vec![0u8; 72]; + let mut polyjuice_args = [0u8; 72]; polyjuice_args[0..7].copy_from_slice(b"\xFF\xFF\xFFPOLY"); polyjuice_args[7] = 0; let gas_limit: u64 = 21000; @@ -410,7 +410,7 @@ mod tests { .build(), ..Default::default() }; - let eth = Secp256k1Eth::default(); + let eth = Secp256k1Eth; eth.verify_tx(&ctx, sender_reg_addr, sender_script, receive_script, tx) .expect("verify signature"); } @@ -442,7 +442,7 @@ mod tests { .raw(raw_tx) .signature(signature.to_vec().pack()) .build(); - let eth = Secp256k1Eth::default(); + let eth = Secp256k1Eth; // This rollup type hash is used, so the receiver script hash is: // 00002b003de527c1d67f2a2a348683ecc9598647c30884c89c5dcf6da1afbddd, @@ -510,7 +510,7 @@ mod tests { .raw(raw_tx) .signature(signature.to_vec().pack()) .build(); - let eth = Secp256k1Eth::default(); + let eth = Secp256k1Eth; let rollup_type_hash = vec![0u8; 32]; @@ -555,7 +555,7 @@ mod tests { .raw(raw_tx) .signature(signature.to_vec().pack()) .build(); - let eth = Secp256k1Eth::default(); + let eth = Secp256k1Eth; let rollup_type_hash = vec![0u8; 32]; @@ -644,7 +644,7 @@ mod tests { rollup_config: RollupConfig::new_builder().chain_id(0.pack()).build(), ..Default::default() }; - let eth = Secp256k1Eth::default(); + let eth = Secp256k1Eth; eth.verify_tx(&ctx, sender_address, sender_script, receiver_script, tx) .expect("verify signature"); } diff --git a/crates/generator/src/utils.rs b/crates/generator/src/utils.rs index 41b4ed0f8..9a904c43f 100644 --- a/crates/generator/src/utils.rs +++ b/crates/generator/src/utils.rs @@ -166,11 +166,11 @@ mod test { }; let sudt_script = Script::new_builder() .code_hash(H256::from_u32(1).pack()) - .args(vec![3; 32].pack()) + .args([3; 32][..].pack()) .build(); let owner_lock = Script::new_builder() .code_hash(H256::from_u32(4).pack()) - .args(vec![5; 32].pack()) + .args([5; 32][..].pack()) .build(); // ## Fulfill withdrawal request @@ -187,7 +187,7 @@ mod test { .build(); WithdrawalRequest::new_builder() .raw(raw) - .signature(vec![6u8; 65].pack()) + .signature([6u8; 65][..].pack()) .build() }; let withdrawal = WithdrawalRequestExtra::new_builder() @@ -291,7 +291,7 @@ mod test { let err_owner_lock = Script::new_builder() .code_hash([100u8; 32].pack()) .hash_type(ScriptHashType::Data.into()) - .args(vec![99u8; 32].pack()) + .args([99u8; 32][..].pack()) .build(); let err = build_withdrawal_cell_output( &rollup_context, diff --git a/crates/mem-pool/src/block_sync_server.rs b/crates/mem-pool/src/block_sync_server.rs index eeb1e0e61..5be37c897 100644 --- a/crates/mem-pool/src/block_sync_server.rs +++ b/crates/mem-pool/src/block_sync_server.rs @@ -106,7 +106,7 @@ impl BlockSyncServerState { .transaction(tx) .build(); let msg = BlockSync::new_builder().set(msg).build(); - if let Some((_, messages)) = self.buffer.iter_mut().rev().next() { + if let Some((_, messages)) = self.buffer.iter_mut().next_back() { // The first message is either a LocalBlock or a NextMemBlock. We // only need to buffer it for NextMemBlock. if matches!( diff --git a/crates/mem-pool/src/restore_manager.rs b/crates/mem-pool/src/restore_manager.rs index 8c60a63d8..77c521455 100644 --- a/crates/mem-pool/src/restore_manager.rs +++ b/crates/mem-pool/src/restore_manager.rs @@ -265,10 +265,10 @@ mod tests { // Should able to restore from deprecated compact mem block let deprecated = DeprecatedCompactMemBlock::new_builder() - .txs(vec![[1u8; 32]].pack()) + .txs([[1u8; 32]][..].pack()) .build(); let expected = CompactMemBlock::new_builder() - .txs(vec![[1u8; 32]].pack()) + .txs([[1u8; 32]][..].pack()) .build(); let latest_timestamp = SystemTime::now() diff --git a/crates/mem-pool/src/withdrawal.rs b/crates/mem-pool/src/withdrawal.rs index 87bdabe76..472166d21 100644 --- a/crates/mem-pool/src/withdrawal.rs +++ b/crates/mem-pool/src/withdrawal.rs @@ -341,7 +341,7 @@ mod test { let sudt_script = Script::new_builder() .code_hash(H256::from_u32(2).pack()) - .args(vec![3u8; 32].pack()) + .args([3u8; 32][..].pack()) .build(); let available_custodians = FinalizedCustodianCapacity { @@ -353,7 +353,7 @@ mod test { let owner_lock = Script::new_builder() .code_hash(H256::from_u32(4).pack()) - .args(vec![5; 32].pack()) + .args([5; 32][..].pack()) .build(); let req = { @@ -369,7 +369,7 @@ mod test { .build(); WithdrawalRequest::new_builder() .raw(raw) - .signature(vec![6u8; 65].pack()) + .signature([6u8; 65][..].pack()) .build() }; @@ -415,7 +415,7 @@ mod test { let err_req_extra = { let err_owner_lock = Script::new_builder() .code_hash([100u8; 32].pack()) - .args(vec![99u8; 32].pack()) + .args([99u8; 32][..].pack()) .build(); req_extra .clone() diff --git a/crates/polyjuice-sender-recover/src/recover/eth_sender.rs b/crates/polyjuice-sender-recover/src/recover/eth_sender.rs index 1cd8530b8..59f64201c 100644 --- a/crates/polyjuice-sender-recover/src/recover/eth_sender.rs +++ b/crates/polyjuice-sender-recover/src/recover/eth_sender.rs @@ -107,7 +107,7 @@ fn recover_registry_address( let message = Secp256k1Eth::polyjuice_tx_signing_message(ctx.chain_id, raw_tx, &to_script) .map_err(PolyjuiceTxSenderRecoverError::InvalidSignature)?; - let eth_address = Secp256k1Eth::default() + let eth_address = Secp256k1Eth .recover(message, signature) .map_err(|err| PolyjuiceTxSenderRecoverError::InvalidSignature(err.into()))?; let registry_address = RegistryAddress::new(ETH_REGISTRY_ACCOUNT_ID, eth_address.to_vec()); diff --git a/crates/replay-chain/src/setup.rs b/crates/replay-chain/src/setup.rs index fb2a59dbc..3e7f4b4b9 100644 --- a/crates/replay-chain/src/setup.rs +++ b/crates/replay-chain/src/setup.rs @@ -108,7 +108,7 @@ pub async fn setup(args: SetupArgs) -> Result { .ok_or_else(|| anyhow!("Eth: No allowed EoA type hashes in the rollup config"))?; account_lock_manage.register_lock_algorithm( eth_lock_script_type_hash.hash().unpack(), - Arc::new(Secp256k1Eth::default()), + Arc::new(Secp256k1Eth), ); Arc::new(Generator::new( backend_manage, diff --git a/crates/rpc-client/src/withdrawal.rs b/crates/rpc-client/src/withdrawal.rs index 11b9a6b2f..218ca8d70 100644 --- a/crates/rpc-client/src/withdrawal.rs +++ b/crates/rpc-client/src/withdrawal.rs @@ -92,7 +92,7 @@ mod test { let owner_lock = Script::new_builder() .code_hash(H256::from_u32(1).pack()) .hash_type(ScriptHashType::Type.into()) - .args(vec![2u8; 32].pack()) + .args([2u8; 32][..].pack()) .build(); let rollup_type_hash = [3u8; 32]; @@ -186,7 +186,7 @@ mod test { // # owner lock not match let err_owner_lock = Script::new_builder() .code_hash(H256::from_u32(5).pack()) - .args(vec![7u8; 32].pack()) + .args([7u8; 32][..].pack()) .build(); let mut args = rollup_type_hash.to_vec(); args.extend_from_slice(&lock_args.as_bytes()); @@ -209,13 +209,13 @@ mod test { let owner_lock = Script::new_builder() .code_hash(H256::from_u32(1).pack()) .hash_type(ScriptHashType::Type.into()) - .args(vec![2u8; 32].pack()) + .args([2u8; 32][..].pack()) .build(); let l1_sudt = Script::new_builder() .code_hash(H256::from_u32(3).pack()) .hash_type(ScriptHashType::Type.into()) - .args(vec![4u8; 32].pack()) + .args([4u8; 32][..].pack()) .build(); let last_finalized_timepoint = Timepoint::from_block_number(100); diff --git a/crates/store/src/state/overlay/mem_store.rs b/crates/store/src/state/overlay/mem_store.rs index dd171cbe9..28e3e6600 100644 --- a/crates/store/src/state/overlay/mem_store.rs +++ b/crates/store/src/state/overlay/mem_store.rs @@ -105,7 +105,7 @@ impl HistoryStateStore for MemStore { .collect(), None => HashSet::new(), }; - list.extend(self.inner.iter_block_state_record(block_number).into_iter()); + list.extend(self.inner.iter_block_state_record(block_number)); list } diff --git a/crates/tests/src/script_tests/l2_scripts/examples.rs b/crates/tests/src/script_tests/l2_scripts/examples.rs index 25841de82..af80c084b 100644 --- a/crates/tests/src/script_tests/l2_scripts/examples.rs +++ b/crates/tests/src/script_tests/l2_scripts/examples.rs @@ -98,8 +98,7 @@ fn test_example_sum() { }]) .unwrap(); let mut account_lock_manage = AccountLockManage::default(); - account_lock_manage - .register_lock_algorithm(H256::zero(), Arc::new(AlwaysSuccess::default())); + account_lock_manage.register_lock_algorithm(H256::zero(), Arc::new(AlwaysSuccess)); let rollup_context = RollupContext { rollup_config: Default::default(), rollup_script_hash: [42u8; 32], @@ -238,7 +237,7 @@ fn test_example_account_operation() { }]) .unwrap(); let mut account_lock_manage = AccountLockManage::default(); - account_lock_manage.register_lock_algorithm(H256::zero(), Arc::new(AlwaysSuccess::default())); + account_lock_manage.register_lock_algorithm(H256::zero(), Arc::new(AlwaysSuccess)); let rollup_context = RollupContext { rollup_config: RollupConfig::new_builder() .allowed_contract_type_hashes( @@ -478,8 +477,7 @@ fn test_example_recover_account() { .unwrap(); let mut account_lock_manage = AccountLockManage::default(); let secp256k1_code_hash = H256::from_u32(11); - account_lock_manage - .register_lock_algorithm(secp256k1_code_hash, Arc::new(Secp256k1Eth::default())); + account_lock_manage.register_lock_algorithm(secp256k1_code_hash, Arc::new(Secp256k1Eth)); let rollup_script_hash: H256 = [42u8; 32]; let rollup_context = RollupContext { rollup_config: RollupConfig::new_builder() @@ -661,10 +659,8 @@ fn test_sudt_total_supply() { }]) .unwrap(); let mut account_lock_manage = AccountLockManage::default(); - account_lock_manage.register_lock_algorithm( - *ALWAYS_SUCCESS_CODE_HASH, - Arc::new(AlwaysSuccess::default()), - ); + account_lock_manage + .register_lock_algorithm(*ALWAYS_SUCCESS_CODE_HASH, Arc::new(AlwaysSuccess)); let rollup_context = RollupContext { rollup_config, rollup_script_hash: [42u8; 32], diff --git a/crates/tests/src/script_tests/l2_scripts/meta_contract.rs b/crates/tests/src/script_tests/l2_scripts/meta_contract.rs index d0e123650..39e069a63 100644 --- a/crates/tests/src/script_tests/l2_scripts/meta_contract.rs +++ b/crates/tests/src/script_tests/l2_scripts/meta_contract.rs @@ -116,7 +116,7 @@ fn test_duplicated_script_hash() { // create contract let contract_script = Script::new_builder() .code_hash([0u8; 32].pack()) - .args(vec![42].pack()) + .args([42][..].pack()) .hash_type(ScriptHashType::Type.into()) .build(); diff --git a/crates/tests/src/script_tests/state_validator/cancel_challenge/tx_signature.rs b/crates/tests/src/script_tests/state_validator/cancel_challenge/tx_signature.rs index 03e09743b..425600605 100644 --- a/crates/tests/src/script_tests/state_validator/cancel_challenge/tx_signature.rs +++ b/crates/tests/src/script_tests/state_validator/cancel_challenge/tx_signature.rs @@ -371,7 +371,7 @@ async fn test_cancel_tx_signature() { .lock(sender_script) .capacity(CKBPack::pack(&42u64)) .build(); - let owner_lock_hash = vec![42u8; 32]; + let owner_lock_hash = [42u8; 32]; let message = { let typed_tx = eip712::types::L2Transaction::from_raw( &tx.raw(), diff --git a/crates/tests/src/script_tests/state_validator/submit_block.rs b/crates/tests/src/script_tests/state_validator/submit_block.rs index 727afb104..b8b212f76 100644 --- a/crates/tests/src/script_tests/state_validator/submit_block.rs +++ b/crates/tests/src/script_tests/state_validator/submit_block.rs @@ -1281,7 +1281,7 @@ async fn test_withdrawal_cell_lock_args_with_owner_lock_in_submit_block() { construct_block_with_timestamp( &chain, &mut mem_pool, - vec![deposit.clone()].pack(), + [deposit.clone()].pack(), timestamp_now(), true, ) @@ -1291,7 +1291,7 @@ async fn test_withdrawal_cell_lock_args_with_owner_lock_in_submit_block() { let apply_deposits = L1Action { context: L1ActionContext::SubmitBlock { l2block: block_result.block.clone(), - deposit_info_vec: vec![deposit].pack(), + deposit_info_vec: [deposit].pack(), deposit_asset_scripts: Default::default(), withdrawals: Default::default(), }, diff --git a/crates/tests/src/testing_tool/chain.rs b/crates/tests/src/testing_tool/chain.rs index 8014812a7..0fb774610 100644 --- a/crates/tests/src/testing_tool/chain.rs +++ b/crates/tests/src/testing_tool/chain.rs @@ -222,10 +222,8 @@ impl TestChain { let mut account_lock_manage = AccountLockManage::default(); account_lock_manage .register_lock_algorithm(*ALWAYS_SUCCESS_CODE_HASH, Arc::new(AlwaysSuccess)); - account_lock_manage.register_lock_algorithm( - *ETH_ACCOUNT_LOCK_CODE_HASH, - Arc::new(Secp256k1Eth::default()), - ); + account_lock_manage + .register_lock_algorithm(*ETH_ACCOUNT_LOCK_CODE_HASH, Arc::new(Secp256k1Eth)); let restore_path = { let mem_pool = chain.mem_pool().as_ref().unwrap(); @@ -392,10 +390,8 @@ pub async fn setup_chain(rollup_type_script: Script) -> Chain { .chain_id(TEST_CHAIN_ID.pack()) .build(); account_lock_manage.register_lock_algorithm(*ALWAYS_SUCCESS_CODE_HASH, Arc::new(AlwaysSuccess)); - account_lock_manage.register_lock_algorithm( - *ETH_ACCOUNT_LOCK_CODE_HASH, - Arc::new(Secp256k1Eth::default()), - ); + account_lock_manage + .register_lock_algorithm(*ETH_ACCOUNT_LOCK_CODE_HASH, Arc::new(Secp256k1Eth)); let chain = setup_chain_with_account_lock_manage( rollup_type_script, rollup_config, @@ -415,10 +411,8 @@ pub async fn setup_chain_with_config( ) -> Chain { let mut account_lock_manage = AccountLockManage::default(); account_lock_manage.register_lock_algorithm(*ALWAYS_SUCCESS_CODE_HASH, Arc::new(AlwaysSuccess)); - account_lock_manage.register_lock_algorithm( - *ETH_ACCOUNT_LOCK_CODE_HASH, - Arc::new(Secp256k1Eth::default()), - ); + account_lock_manage + .register_lock_algorithm(*ETH_ACCOUNT_LOCK_CODE_HASH, Arc::new(Secp256k1Eth)); setup_chain_with_account_lock_manage( rollup_type_script, rollup_config, @@ -439,10 +433,8 @@ pub async fn restart_chain( let mut account_lock_manage = AccountLockManage::default(); let rollup_config = chain.generator().rollup_context().rollup_config.to_owned(); account_lock_manage.register_lock_algorithm(*ALWAYS_SUCCESS_CODE_HASH, Arc::new(AlwaysSuccess)); - account_lock_manage.register_lock_algorithm( - *ETH_ACCOUNT_LOCK_CODE_HASH, - Arc::new(Secp256k1Eth::default()), - ); + account_lock_manage + .register_lock_algorithm(*ETH_ACCOUNT_LOCK_CODE_HASH, Arc::new(Secp256k1Eth)); let restore_path = { let mem_pool = chain.mem_pool().as_ref().unwrap(); let mem_pool = mem_pool.lock().await; @@ -467,10 +459,8 @@ pub fn chain_generator(chain: &Chain, rollup_type_script: Script) -> Arc(), 32].pack()) + .args([rand::random::(), 32][..].pack()) .build(); let withdrawal_lock_type = random_always_success_script(None); @@ -76,7 +76,7 @@ async fn test_export_import_block() { let rollup_type_script = Script::new_builder() .code_hash(state_validator_type.hash().pack()) .hash_type(ScriptHashType::Type.into()) - .args(vec![1u8; 32].pack()) + .args([1u8; 32][..].pack()) .build(); let rollup_script_hash: H256 = rollup_type_script.hash(); @@ -102,10 +102,8 @@ async fn test_export_import_block() { let mut account_lock_manage = AccountLockManage::default(); account_lock_manage .register_lock_algorithm(*ALWAYS_SUCCESS_CODE_HASH, Arc::new(AlwaysSuccess)); - account_lock_manage.register_lock_algorithm( - *ETH_ACCOUNT_LOCK_CODE_HASH, - Arc::new(Secp256k1Eth::default()), - ); + account_lock_manage + .register_lock_algorithm(*ETH_ACCOUNT_LOCK_CODE_HASH, Arc::new(Secp256k1Eth)); setup_chain_with_account_lock_manage( rollup_type_script.clone(), rollup_config.clone(), @@ -154,7 +152,7 @@ async fn test_export_import_block() { context: L1ActionContext::SubmitBlock { l2block: deposit_block_result.block.clone(), deposit_info_vec, - deposit_asset_scripts: HashSet::from_iter(vec![sudt_script.clone()].into_iter()), + deposit_asset_scripts: HashSet::from_iter([sudt_script.clone()]), withdrawals: Default::default(), }, transaction: build_sync_tx(rollup_cell.output.clone(), deposit_block_result.clone()), @@ -202,10 +200,8 @@ async fn test_export_import_block() { let mut account_lock_manage = AccountLockManage::default(); account_lock_manage .register_lock_algorithm(*ALWAYS_SUCCESS_CODE_HASH, Arc::new(AlwaysSuccess)); - account_lock_manage.register_lock_algorithm( - *ETH_ACCOUNT_LOCK_CODE_HASH, - Arc::new(Secp256k1Eth::default()), - ); + account_lock_manage + .register_lock_algorithm(*ETH_ACCOUNT_LOCK_CODE_HASH, Arc::new(Secp256k1Eth)); setup_chain_with_account_lock_manage( rollup_type_script.clone(), rollup_config.clone(), @@ -282,10 +278,8 @@ async fn test_export_import_block() { let mut account_lock_manage = AccountLockManage::default(); account_lock_manage .register_lock_algorithm(*ALWAYS_SUCCESS_CODE_HASH, Arc::new(AlwaysSuccess)); - account_lock_manage.register_lock_algorithm( - *ETH_ACCOUNT_LOCK_CODE_HASH, - Arc::new(Secp256k1Eth::default()), - ); + account_lock_manage + .register_lock_algorithm(*ETH_ACCOUNT_LOCK_CODE_HASH, Arc::new(Secp256k1Eth)); setup_chain_with_account_lock_manage( rollup_type_script.clone(), rollup_config.clone(), diff --git a/crates/tests/src/tests/unlock_withdrawal_to_owner.rs b/crates/tests/src/tests/unlock_withdrawal_to_owner.rs index e60b09459..40a2eff83 100644 --- a/crates/tests/src/tests/unlock_withdrawal_to_owner.rs +++ b/crates/tests/src/tests/unlock_withdrawal_to_owner.rs @@ -63,7 +63,7 @@ async fn test_build_unlock_to_owner_tx() { let sudt_script = Script::new_builder() .code_hash(always_type.hash().pack()) .hash_type(ScriptHashType::Type.into()) - .args(vec![rand::random::(), 32].pack()) + .args([rand::random::(), 32][..].pack()) .build(); let withdrawal_lock_type = random_always_success_script(None); @@ -161,7 +161,7 @@ async fn test_build_unlock_to_owner_tx() { let rollup_type_script = Script::new_builder() .code_hash(state_validator_type.hash().pack()) .hash_type(ScriptHashType::Type.into()) - .args(vec![1u8; 32].pack()) + .args([1u8; 32][..].pack()) .build(); let rollup_script_hash: H256 = rollup_type_script.hash(); let rollup_cell = CellInfo { diff --git a/crates/tools/src/deploy_genesis.rs b/crates/tools/src/deploy_genesis.rs index 5aee75ebb..c6ac3e856 100644 --- a/crates/tools/src/deploy_genesis.rs +++ b/crates/tools/src/deploy_genesis.rs @@ -97,7 +97,7 @@ pub async fn deploy_rollup_cell(args: DeployRollupCellArgs<'_>) -> Result) -> Result = HashSet::from_iter(&user_rollup_config.allowed_eoa_type_hashes); diff --git a/crates/tools/src/prepare_scripts.rs b/crates/tools/src/prepare_scripts.rs index 16ae3f77f..11d04de5e 100644 --- a/crates/tools/src/prepare_scripts.rs +++ b/crates/tools/src/prepare_scripts.rs @@ -1,3 +1,6 @@ +// Useless vec is from the arg_enum macro. +#![allow(clippy::useless_vec)] + use std::{ collections::HashMap, fs, diff --git a/crates/tools/src/setup.rs b/crates/tools/src/setup.rs index 9d38557e7..9f0c9428f 100644 --- a/crates/tools/src/setup.rs +++ b/crates/tools/src/setup.rs @@ -1,3 +1,6 @@ +// Useless vec is from the arg_enum macro. +#![allow(clippy::useless_vec)] + use std::{ fs, path::{Path, PathBuf}, @@ -104,6 +107,7 @@ pub async fn setup(args: SetupArgs<'_>) { let scripts_deploy_result = output_dir.join("scripts-result.json"); let deploy_result = deploy_scripts( // TODO. + #[allow(clippy::unnecessary_literal_unwrap)] None.unwrap(), &build_scripts_result, ) @@ -170,6 +174,7 @@ pub async fn setup(args: SetupArgs<'_>) { NodeMode::ReadOnly }; // TODO. + #[allow(clippy::unnecessary_literal_unwrap)] let args = None.unwrap(); generate_node_config(args).await.expect("generate_config"); } diff --git a/crates/utils/src/genesis_info.rs b/crates/utils/src/genesis_info.rs index 6c8354cc9..610ac53f9 100644 --- a/crates/utils/src/genesis_info.rs +++ b/crates/utils/src/genesis_info.rs @@ -59,7 +59,7 @@ impl CKBGenesisInfo { raw_tx .outputs() .into_iter() - .zip(raw_tx.outputs_data().into_iter()) + .zip(raw_tx.outputs_data()) .enumerate() .map(|(index, (output, data))| { let data_hash: H256 = { diff --git a/gwos-evm/polyjuice-tests/src/ctx.rs b/gwos-evm/polyjuice-tests/src/ctx.rs index 1c673787b..4c3a18e3e 100644 --- a/gwos-evm/polyjuice-tests/src/ctx.rs +++ b/gwos-evm/polyjuice-tests/src/ctx.rs @@ -80,7 +80,7 @@ fn load_code_hash(path: &Path) -> [u8; 32] { fn set_mapping(state: &mut DummyState, eth_address: &[u8; 20], script_hash: &[u8; 32]) { let address = RegistryAddress::new(ETH_REGISTRY_ACCOUNT_ID, eth_address.to_vec()); state - .mapping_registry_address_to_script_hash(address, (*script_hash).into()) + .mapping_registry_address_to_script_hash(address, *script_hash) .expect("map reg addr to script hash"); } @@ -159,7 +159,7 @@ impl MockChain { code: &[u8], storage: HashMap, ) -> anyhow::Result { - let mut new_script_args = vec![0u8; 32 + 4 + 20]; + let mut new_script_args = [0u8; 32 + 4 + 20]; new_script_args[0..32].copy_from_slice(&ROLLUP_SCRIPT_HASH); new_script_args[32..36].copy_from_slice(&CREATOR_ACCOUNT_ID.to_le_bytes()[..]); new_script_args[36..36 + 20].copy_from_slice(eth_address); @@ -400,7 +400,7 @@ impl Context { .expect("create creator_account"); assert_eq!(creator_account_id, CREATOR_ACCOUNT_ID); - state.insert_data(config.secp_data_hash.into(), config.secp_data.clone()); + state.insert_data(config.secp_data_hash, config.secp_data.clone()); state .update_raw( build_data_hash_key(config.secp_data_hash.as_slice()), @@ -413,11 +413,11 @@ impl Context { // NOTICE in this test we won't need SUM validator let mut account_lock_manage = AccountLockManage::default(); account_lock_manage.register_lock_algorithm( - SECP_LOCK_CODE_HASH.into(), - Arc::new(Secp256k1Eth::default()), + SECP_LOCK_CODE_HASH, + Arc::new(Secp256k1Eth), ); let rollup_context = RollupContext { - rollup_script_hash: ROLLUP_SCRIPT_HASH.into(), + rollup_script_hash: ROLLUP_SCRIPT_HASH, rollup_config: config.rollup, fork_config: Default::default(), }; diff --git a/gwos-evm/polyjuice-tests/src/helper.rs b/gwos-evm/polyjuice-tests/src/helper.rs index daf3bdebb..b1e9d7d64 100644 --- a/gwos-evm/polyjuice-tests/src/helper.rs +++ b/gwos-evm/polyjuice-tests/src/helper.rs @@ -92,7 +92,7 @@ lazy_static::lazy_static! { let mut hasher = new_blake2b(); hasher.update(SECP_DATA); hasher.finalize(&mut buf); - buf.into() + buf }; pub static ref POLYJUICE_GENERATOR_PROGRAM: Bytes @@ -292,7 +292,7 @@ pub fn new_contract_account_script_with_nonce(from_addr: &[u8; 20], from_nonce: // ); let data_hash = tiny_keccak::keccak256(stream.as_raw()); - let mut new_script_args = vec![0u8; 32 + 4 + 20]; + let mut new_script_args = [0u8; 32 + 4 + 20]; new_script_args[0..32].copy_from_slice(&ROLLUP_SCRIPT_HASH); new_script_args[32..36].copy_from_slice(&CREATOR_ACCOUNT_ID.to_le_bytes()[..]); new_script_args[36..36 + 20].copy_from_slice(&data_hash[12..]); @@ -480,8 +480,8 @@ pub fn setup() -> (Store, DummyState, Generator) { // NOTICE in this test we won't need SUM validator let mut account_lock_manage = AccountLockManage::default(); account_lock_manage.register_lock_algorithm( - SECP_LOCK_CODE_HASH.into(), - Arc::new(Secp256k1Eth::default()), + SECP_LOCK_CODE_HASH, + Arc::new(Secp256k1Eth), ); let rollup_config = RollupConfig::new_builder() .chain_id(CHAIN_ID.pack()) @@ -513,7 +513,7 @@ pub fn setup() -> (Store, DummyState, Generator) { ..Default::default() }; let rollup_context = RollupContext { - rollup_script_hash: ROLLUP_SCRIPT_HASH.into(), + rollup_script_hash: ROLLUP_SCRIPT_HASH, rollup_config, fork_config, }; @@ -605,7 +605,7 @@ pub fn compute_create2_script( data[1 + 20 + 32..1 + 20 + 32 + 32].copy_from_slice(&init_code_hash[..]); let data_hash = tiny_keccak::keccak256(&data); - let mut script_args = vec![0u8; 32 + 4 + 20]; + let mut script_args = [0u8; 32 + 4 + 20]; script_args[0..32].copy_from_slice(&ROLLUP_SCRIPT_HASH[..]); script_args[32..32 + 4].copy_from_slice(&CREATOR_ACCOUNT_ID.to_le_bytes()[..]); script_args[32 + 4..32 + 4 + 20].copy_from_slice(&data_hash[12..]); @@ -794,7 +794,7 @@ pub(crate) fn register_eoa_account( ) { let address = RegistryAddress::new(ETH_REGISTRY_ACCOUNT_ID, eth_address.to_vec()); state - .mapping_registry_address_to_script_hash(address, (*script_hash).into()) + .mapping_registry_address_to_script_hash(address, *script_hash) .expect("map reg addr to script hash"); } diff --git a/gwos-evm/polyjuice-tests/src/test_cases/address_collision.rs b/gwos-evm/polyjuice-tests/src/test_cases/address_collision.rs index 2e2d4a66c..8a9490979 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/address_collision.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/address_collision.rs @@ -210,7 +210,7 @@ fn create2_address_collision_overwrite() -> Result<()> { let script_hash = state.get_script_hash_by_registry_address(&create2_eth_reg_addr)?; assert!(script_hash.is_some()); - let create_account_id = state.get_account_id_by_script_hash(&create2_script_hash.into())?; + let create_account_id = state.get_account_id_by_script_hash(&create2_script_hash)?; assert_eq!(create_account_id, Some(8)); Ok(()) } diff --git a/gwos-evm/polyjuice-tests/src/test_cases/call_multiple_times.rs b/gwos-evm/polyjuice-tests/src/test_cases/call_multiple_times.rs index a20a74401..887aa8049 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/call_multiple_times.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/call_multiple_times.rs @@ -120,7 +120,7 @@ fn test_call_multiple_times() { // let ss2_contract_ethabi_addr = contract_script_to_eth_addr(&ss2_account_script, true); let input = hex::decode(format!( "bca0b9c2{}{}", - hex::encode(&ss2_contract_eth_abi_addr), + hex::encode(ss2_contract_eth_abi_addr), "0000000000000000000000000000000000000000000000000000000000000014", )) .unwrap(); diff --git a/gwos-evm/polyjuice-tests/src/test_cases/contract_call_contract.rs b/gwos-evm/polyjuice-tests/src/test_cases/contract_call_contract.rs index 616c6ae13..03d41d1c9 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/contract_call_contract.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/contract_call_contract.rs @@ -49,7 +49,7 @@ fn test_contract_call_contract() { // Deploy CallContract block_number += 1; - let input = format!("{}{}", INIT_CODE, hex::encode(&ss_eth_abi_addr)); + let input = format!("{}{}", INIT_CODE, hex::encode(ss_eth_abi_addr)); let run_result = deploy( &generator, &store, diff --git a/gwos-evm/polyjuice-tests/src/test_cases/contract_create_contract.rs b/gwos-evm/polyjuice-tests/src/test_cases/contract_create_contract.rs index d03498954..30403096c 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/contract_create_contract.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/contract_create_contract.rs @@ -49,7 +49,7 @@ fn test_contract_create_contract() { new_contract_account_script(&state, from_id, &from_eth_address, false); let mom_contract_script_hash = mom_contract_script.hash(); let mom_contract_id = state - .get_account_id_by_script_hash(&mom_contract_script_hash.into()) + .get_account_id_by_script_hash(&mom_contract_script_hash) .unwrap() .unwrap(); // mom_contract_id = 6 let mom_contract_nonce = state.get_nonce(mom_contract_id).unwrap(); diff --git a/gwos-evm/polyjuice-tests/src/test_cases/create2.rs b/gwos-evm/polyjuice-tests/src/test_cases/create2.rs index 55838ae38..e275f5302 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/create2.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/create2.rs @@ -126,11 +126,11 @@ fn test_create2() { ); assert_eq!(run_result.return_data, create2_ethabi_addr); let create2_account_id = state - .get_account_id_by_script_hash(&create2_script_hash.into()) + .get_account_id_by_script_hash(&create2_script_hash) .unwrap() .unwrap(); let address = state - .get_registry_address_by_script_hash(ETH_REGISTRY_ACCOUNT_ID, &create2_script_hash.into()) + .get_registry_address_by_script_hash(ETH_REGISTRY_ACCOUNT_ID, &create2_script_hash) .unwrap() .unwrap(); let create2_account_balance = state @@ -148,8 +148,8 @@ fn test_create2() { } => { println!( "transfer from: {}, to: {}, amount: {}", - hex::encode(&from_addr.address), - hex::encode(&to_addr.address), + hex::encode(from_addr.address), + hex::encode(to_addr.address), amount ); Some(amount) diff --git a/gwos-evm/polyjuice-tests/src/test_cases/delegatecall.rs b/gwos-evm/polyjuice-tests/src/test_cases/delegatecall.rs index 6df4bc107..18bd7709d 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/delegatecall.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/delegatecall.rs @@ -39,7 +39,7 @@ fn test_delegatecall() { ); let ss_account_script = new_contract_account_script_with_nonce(&from_eth_address, 0); let ss_account_id = state - .get_account_id_by_script_hash(&ss_account_script.hash().into()) + .get_account_id_by_script_hash(&ss_account_script.hash()) .unwrap() .unwrap(); diff --git a/gwos-evm/polyjuice-tests/src/test_cases/eth_addr_reg.rs b/gwos-evm/polyjuice-tests/src/test_cases/eth_addr_reg.rs index 3f2aae7ae..83bd7905b 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/eth_addr_reg.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/eth_addr_reg.rs @@ -94,7 +94,7 @@ fn test_update_eth_addr_reg_by_contract() { &generator, eth_eoa_account_id, new_block_info(block_producer_id.clone(), 1, 1), - crate::helper::SetMappingArgs::One(eth_eoa_account_script_hash.into()), + crate::helper::SetMappingArgs::One(eth_eoa_account_script_hash), ) .expect("execute the MSG_SET_MAPPING method of `ETH Address Registry` layer2 contract"); assert_eq!(run_result.exit_code, crate::constant::EVMC_SUCCESS); @@ -116,7 +116,7 @@ fn test_update_eth_addr_reg_by_contract() { &generator, eth_eoa_account_id, new_block_info(block_producer_id.clone(), 2, 2), - crate::helper::SetMappingArgs::One(eth_eoa_account_script_hash.into()), + crate::helper::SetMappingArgs::One(eth_eoa_account_script_hash), ) .unwrap(); assert_eq!( @@ -206,7 +206,7 @@ fn test_batch_set_mapping_by_contract() { for address in eth_eoa_addresses.iter() { let account_script = build_eth_l2_script(address); let account_script_hash = account_script.hash(); - eth_eoa_script_hashes.push(account_script_hash.into()); + eth_eoa_script_hashes.push(account_script_hash); state.create_account_from_script(account_script).unwrap(); let address = RegistryAddress::new(ETH_REGISTRY_ACCOUNT_ID, address.to_vec()); @@ -243,7 +243,7 @@ fn test_batch_set_mapping_by_contract() { for (eth_eoa_address, eth_eoa_account_script_hash) in eth_eoa_addresses.into_iter().zip(eth_eoa_script_hashes) { - let eth_eoa_account_script_hash: [u8; 32] = eth_eoa_account_script_hash.into(); + let eth_eoa_account_script_hash: [u8; 32] = eth_eoa_account_script_hash; // check result: eth_address -> gw_script_hash let args = EthToGwArgsBuilder::default() diff --git a/gwos-evm/polyjuice-tests/src/test_cases/gas_price.rs b/gwos-evm/polyjuice-tests/src/test_cases/gas_price.rs index 4b94955d0..be7fa5550 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/gas_price.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/gas_price.rs @@ -70,6 +70,6 @@ fn gas_price_test() -> anyhow::Result<()> { let mut arr = [0u8; 16]; arr.copy_from_slice(&run_result.return_data[16..]); let tx_gas_price = u128::from_be_bytes(arr); - assert_eq!(tx_gas_price as u128, gas_price); + assert_eq!({ tx_gas_price }, gas_price); Ok(()) } diff --git a/gwos-evm/polyjuice-tests/src/test_cases/get_block_info.rs b/gwos-evm/polyjuice-tests/src/test_cases/get_block_info.rs index 1c8bf8f03..f05bcc0e7 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/get_block_info.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/get_block_info.rs @@ -81,7 +81,7 @@ fn test_get_block_info() { let contract_account_script = new_contract_account_script(&state, from_id, &from_eth_address, false); let new_account_id = state - .get_account_id_by_script_hash(&contract_account_script.hash().into()) + .get_account_id_by_script_hash(&contract_account_script.hash()) .unwrap() .unwrap(); diff --git a/gwos-evm/polyjuice-tests/src/test_cases/get_chain_id.rs b/gwos-evm/polyjuice-tests/src/test_cases/get_chain_id.rs index 29be94bb2..be416a0db 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/get_chain_id.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/get_chain_id.rs @@ -21,7 +21,7 @@ fn test_get_chain_id() { let (from_id, from_script_hash) = crate::helper::create_eth_eoa_account(&mut state, &from_eth_address, 200000u64.into()); let address = state - .get_registry_address_by_script_hash(ETH_REGISTRY_ACCOUNT_ID, &from_script_hash.into()) + .get_registry_address_by_script_hash(ETH_REGISTRY_ACCOUNT_ID, &from_script_hash) .unwrap() .unwrap(); diff --git a/gwos-evm/polyjuice-tests/src/test_cases/heap_memory.rs b/gwos-evm/polyjuice-tests/src/test_cases/heap_memory.rs index a831f2d3a..847449a32 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/heap_memory.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/heap_memory.rs @@ -39,7 +39,7 @@ fn test_heap_momory() { ); let account_script = new_contract_account_script(&state, from_id, &from_eth_address, false); let contract_account_id = state - .get_account_id_by_script_hash(&account_script.hash().into()) + .get_account_id_by_script_hash(&account_script.hash()) .unwrap() .unwrap(); diff --git a/gwos-evm/polyjuice-tests/src/test_cases/invalid_sudt_erc20_proxy.rs b/gwos-evm/polyjuice-tests/src/test_cases/invalid_sudt_erc20_proxy.rs index 0559849a6..2110162cb 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/invalid_sudt_erc20_proxy.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/invalid_sudt_erc20_proxy.rs @@ -26,7 +26,7 @@ fn test_invalid_sudt_erc20_proxy() { let (from_id1, from_script_hash1) = helper::create_eth_eoa_account(&mut state, &from_eth_address1, 2000000u64.into()); let address1 = state - .get_registry_address_by_script_hash(ETH_REGISTRY_ACCOUNT_ID, &from_script_hash1.into()) + .get_registry_address_by_script_hash(ETH_REGISTRY_ACCOUNT_ID, &from_script_hash1) .unwrap() .unwrap(); @@ -34,7 +34,7 @@ fn test_invalid_sudt_erc20_proxy() { let (_from_id2, from_script_hash2) = helper::create_eth_eoa_account(&mut state, &from_eth_address2, 2000000u64.into()); let address2 = state - .get_registry_address_by_script_hash(ETH_REGISTRY_ACCOUNT_ID, &from_script_hash2.into()) + .get_registry_address_by_script_hash(ETH_REGISTRY_ACCOUNT_ID, &from_script_hash2) .unwrap() .unwrap(); @@ -65,7 +65,7 @@ fn test_invalid_sudt_erc20_proxy() { let contract_account_script = new_contract_account_script(&state, from_id1, &from_eth_address1, false); let invalid_proxy_account_id = state - .get_account_id_by_script_hash(&contract_account_script.hash().into()) + .get_account_id_by_script_hash(&contract_account_script.hash()) .unwrap() .unwrap(); diff --git a/gwos-evm/polyjuice-tests/src/test_cases/multicall3.rs b/gwos-evm/polyjuice-tests/src/test_cases/multicall3.rs index d4b8b73d1..115739f88 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/multicall3.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/multicall3.rs @@ -19,7 +19,7 @@ fn multicall3_test() -> anyhow::Result<()> { .get_account_id_by_eth_address(&contract_eth_addr)? .expect("contract account id"); - let eth_addr = hex::encode(&contract_eth_addr); + let eth_addr = hex::encode(contract_eth_addr); const OLD_ADDR: &str = "ca11bde05977b3631167028862be2a173976ca11"; let input = MULTICALL3_INPUT.trim_end_matches('\n'); let input = input.replace(OLD_ADDR, ð_addr); diff --git a/gwos-evm/polyjuice-tests/src/test_cases/parse_log_event.rs b/gwos-evm/polyjuice-tests/src/test_cases/parse_log_event.rs index 2440dc541..40f2c9b9e 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/parse_log_event.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/parse_log_event.rs @@ -21,7 +21,7 @@ fn test_parse_log_event() { let (from_id, from_script_hash) = crate::helper::create_eth_eoa_account(&mut state, &from_eth_addr, 200000u64.into()); let address = state - .get_registry_address_by_script_hash(ETH_REGISTRY_ACCOUNT_ID, &from_script_hash.into()) + .get_registry_address_by_script_hash(ETH_REGISTRY_ACCOUNT_ID, &from_script_hash) .unwrap() .unwrap(); @@ -48,12 +48,12 @@ fn test_parse_log_event() { let contract_addr = state .get_registry_address_by_script_hash( ETH_REGISTRY_ACCOUNT_ID, - &contract_script.hash().into(), + &contract_script.hash(), ) .unwrap() .unwrap(); let contract_id = state - .get_account_id_by_script_hash(&contract_script.hash().into()) + .get_account_id_by_script_hash(&contract_script.hash()) .unwrap() .unwrap(); assert_eq!(run_result.logs.len(), 4); diff --git a/gwos-evm/polyjuice-tests/src/test_cases/recover_account.rs b/gwos-evm/polyjuice-tests/src/test_cases/recover_account.rs index ebc2aa158..722be52ee 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/recover_account.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/recover_account.rs @@ -48,7 +48,7 @@ fn test_recover_account() { let contract_account_script = new_contract_account_script(&state, from_id, &from_eth_address, false); let new_account_id = state - .get_account_id_by_script_hash(&contract_account_script.hash().into()) + .get_account_id_by_script_hash(&contract_account_script.hash()) .unwrap() .unwrap(); @@ -58,13 +58,13 @@ fn test_recover_account() { let message_hex = "1cdeae55a5768fe14b628001c6247ae84c70310a7ddcfdc73ac68494251e46ec"; let signature_hex = "28aa0c394487edf2211f445c47fb5f4fb5e3023920f62124d309f5bdf70d95045a934f278cec717300a5417313d1cdc390e761e37c0964b940c0a6f07b7361ed01"; - let secp256k1 = Secp256k1Eth::default(); - let message = hex::decode(&message_hex).unwrap(); + let secp256k1 = Secp256k1Eth; + let message = hex::decode(message_hex).unwrap(); let msg: [u8; 32] = message.try_into().unwrap(); - let signature = hex::decode(&signature_hex).unwrap(); + let signature = hex::decode(signature_hex).unwrap(); let lock_args = secp256k1 - .recover(msg.into(), &signature) + .recover(msg, &signature) .expect("get lock args"); let lock_args_hex = hex::encode(&lock_args); println!("lock args: {}", &lock_args_hex); @@ -75,7 +75,7 @@ fn test_recover_account() { let input = hex::decode(format!( "7d7b0255{}0000000000000000000000000000000000000000000000000000000000000060{}0000000000000000000000000000000000000000000000000000000000000041{}00000000000000000000000000000000000000000000000000000000000000", message_hex, - hex::encode(&SECP_LOCK_CODE_HASH), + hex::encode(SECP_LOCK_CODE_HASH), signature_hex, )) .unwrap(); @@ -130,7 +130,7 @@ fn test_recover_account() { let input = hex::decode(format!( "7d7b0255{}0000000000000000000000000000000000000000000000000000000000000060{}0000000000000000000000000000000000000000000000000000000000000041{}00000000000000000000000000000000000000000000000000000000000000", message_hex, - hex::encode(&SECP_LOCK_CODE_HASH), + hex::encode(SECP_LOCK_CODE_HASH), signature_hex, )) .unwrap(); @@ -170,7 +170,7 @@ fn test_recover_account() { let input = hex::decode(format!( "7d7b0255{}0000000000000000000000000000000000000000000000000000000000000060{}0000000000000000000000000000000000000000000000000000000000000041{}00000000000000000000000000000000000000000000000000000000000000", message_hex, - hex::encode(&[1u8; 32]), + hex::encode([1u8; 32]), signature_hex, )) .unwrap(); diff --git a/gwos-evm/polyjuice-tests/src/test_cases/recursion_contract.rs b/gwos-evm/polyjuice-tests/src/test_cases/recursion_contract.rs index 4fdf25e2f..1762aa4f0 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/recursion_contract.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/recursion_contract.rs @@ -39,7 +39,7 @@ fn test_recursion_contract_call() { let recur_account_script = new_contract_account_script(&state, from_id, &from_eth_address, false); let recur_account_id = state - .get_account_id_by_script_hash(&recur_account_script.hash().into()) + .get_account_id_by_script_hash(&recur_account_script.hash()) .unwrap() .unwrap(); diff --git a/gwos-evm/polyjuice-tests/src/test_cases/revert.rs b/gwos-evm/polyjuice-tests/src/test_cases/revert.rs index 6ef0825e5..96cf8e91f 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/revert.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/revert.rs @@ -41,7 +41,7 @@ fn revert_in_try_test() -> anyhow::Result<()> { //call CallRevertWithTryCatch.test(Revert) let args_str = format!( "bb29998e000000000000000000000000{}", - hex::encode(&revert_eth_addr) + hex::encode(revert_eth_addr) ); let code = hex::decode(args_str)?; let run_result = chain.execute(from_id, call_revert_id, &code, gas_limit, gas_price, value)?; @@ -102,8 +102,8 @@ fn revert_in_deep_try_test() -> anyhow::Result<()> { //CallRevertWithTryCatchInDepth.test(CallRevertWithTryCatch, Revert) let args_str = format!( "2b6d0ceb000000000000000000000000{}000000000000000000000000{}", - hex::encode(&call_revert_eth_addr), - hex::encode(&revert_eth_addr) + hex::encode(call_revert_eth_addr), + hex::encode(revert_eth_addr) ); let code = hex::decode(args_str)?; let run_result = chain.execute( @@ -165,7 +165,7 @@ fn revert_contructor_try_test() -> anyhow::Result<()> { .expect("to id"); assert_eq!(run_result.exit_code, 0); - let deploy_args = format!("000000000000000000000000{}", hex::encode(&revert_eth_addr)); + let deploy_args = format!("000000000000000000000000{}", hex::encode(revert_eth_addr)); let code = format!("{}{}", CONSTRUCTOR_REVERT_CODE, deploy_args); let code = hex::decode(code).expect("decode code"); let run_result = chain.deploy(from_id, &code, gas_limit, gas_price, value)?; @@ -233,7 +233,7 @@ fn revert_test() -> anyhow::Result<()> { //call CallRevertWithoutTryCatch.test(Revert) let args_str = format!( "bb29998e000000000000000000000000{}", - hex::encode(&revert_eth_addr) + hex::encode(revert_eth_addr) ); let code = hex::decode(args_str)?; let run_result = chain.execute(from_id, call_revert_id, &code, gas_limit, gas_price, value)?; diff --git a/gwos-evm/polyjuice-tests/src/test_cases/selfdestruct.rs b/gwos-evm/polyjuice-tests/src/test_cases/selfdestruct.rs index 8878455ba..5179dcbfb 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/selfdestruct.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/selfdestruct.rs @@ -75,11 +75,11 @@ fn test_selfdestruct() { new_contract_account_script(&state, from_id, &from_eth_address, false); let new_script_hash = contract_account_script.hash(); let contract_reg_addr = state - .get_registry_address_by_script_hash(ETH_REGISTRY_ACCOUNT_ID, &new_script_hash.into()) + .get_registry_address_by_script_hash(ETH_REGISTRY_ACCOUNT_ID, &new_script_hash) .unwrap() .unwrap(); let new_account_id = state - .get_account_id_by_script_hash(&contract_account_script.hash().into()) + .get_account_id_by_script_hash(&contract_account_script.hash()) .unwrap() .unwrap(); assert_eq!( diff --git a/gwos-evm/polyjuice-tests/src/test_cases/simple_storage.rs b/gwos-evm/polyjuice-tests/src/test_cases/simple_storage.rs index 2a713f378..b7aa5e27a 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/simple_storage.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/simple_storage.rs @@ -63,7 +63,7 @@ fn test_simple_storage() { let contract_account_script = new_contract_account_script(&state, from_id, &from_eth_address, false); let new_account_id = state - .get_account_id_by_script_hash(&contract_account_script.hash().into()) + .get_account_id_by_script_hash(&contract_account_script.hash()) .unwrap() .unwrap(); let from_balance2 = state diff --git a/gwos-evm/polyjuice-tests/src/test_cases/simple_transfer.rs b/gwos-evm/polyjuice-tests/src/test_cases/simple_transfer.rs index a4f021c06..36a56f9cc 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/simple_transfer.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/simple_transfer.rs @@ -68,11 +68,11 @@ fn test_simple_transfer() { .try_into() .unwrap(); let ss_reg_addr = state - .get_registry_address_by_script_hash(ETH_REGISTRY_ACCOUNT_ID, &ss_script_hash.into()) + .get_registry_address_by_script_hash(ETH_REGISTRY_ACCOUNT_ID, &ss_script_hash) .unwrap() .unwrap(); let ss_account_id = state - .get_account_id_by_script_hash(&ss_account_script.hash().into()) + .get_account_id_by_script_hash(&ss_account_script.hash()) .unwrap() .unwrap(); let ss_balance = state @@ -116,12 +116,12 @@ fn test_simple_transfer() { let st_contract_reg_addr = state .get_registry_address_by_script_hash( ETH_REGISTRY_ACCOUNT_ID, - &st_contract_script_hash.into(), + &st_contract_script_hash, ) .unwrap() .unwrap(); let st_contract_id = state - .get_account_id_by_script_hash(&st_contract_account_script.hash().into()) + .get_account_id_by_script_hash(&st_contract_account_script.hash()) .unwrap() .unwrap(); let st_contract_balance = state diff --git a/gwos-evm/polyjuice-tests/src/test_cases/sudt_erc20_proxy.rs b/gwos-evm/polyjuice-tests/src/test_cases/sudt_erc20_proxy.rs index d2d19340f..b23f5f211 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/sudt_erc20_proxy.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/sudt_erc20_proxy.rs @@ -70,7 +70,7 @@ fn test_sudt_erc20_proxy_inner( let contract_account_script = new_contract_account_script(state, from_id1, &from_eth_address1, false); - let script_hash = contract_account_script.hash().into(); + let script_hash = contract_account_script.hash(); let new_account_id = state .get_account_id_by_script_hash(&script_hash) .unwrap() @@ -128,7 +128,7 @@ fn test_sudt_erc20_proxy_inner( let mut buf = [0u8; 32]; let total_supply = state.get_sudt_total_supply(new_sudt_id).unwrap(); total_supply.to_big_endian(&mut buf); - hex::encode(&buf) + hex::encode(buf) }; for (idx, (action, from_id, args_str, return_data_str)) in [ // balanceOf(eoa1) diff --git a/gwos-evm/polyjuice-tests/src/test_cases/sudt_erc20_proxy_attack_allowance.rs b/gwos-evm/polyjuice-tests/src/test_cases/sudt_erc20_proxy_attack_allowance.rs index d5513ff8e..32727b58a 100644 --- a/gwos-evm/polyjuice-tests/src/test_cases/sudt_erc20_proxy_attack_allowance.rs +++ b/gwos-evm/polyjuice-tests/src/test_cases/sudt_erc20_proxy_attack_allowance.rs @@ -69,7 +69,7 @@ fn test_attack_allowance() { let proxy_eth_addr = { let contract_account_script = new_contract_account_script(&state, from_id, &from_eth_addr, false); - let script_hash = contract_account_script.hash().into(); + let script_hash = contract_account_script.hash(); let reg_addr = state .get_registry_address_by_script_hash(ETH_REGISTRY_ACCOUNT_ID, &script_hash) .unwrap() @@ -105,7 +105,7 @@ fn test_attack_allowance() { let attack_account_id = { let contract_account_script = new_contract_account_script(&state, from_id, &from_eth_addr, false); - let script_hash = contract_account_script.hash().into(); + let script_hash = contract_account_script.hash(); state .get_account_id_by_script_hash(&script_hash) .unwrap() diff --git a/gwos-evm/polyjuice-tests/tests/ethereum_test.rs b/gwos-evm/polyjuice-tests/tests/ethereum_test.rs index f87a2b2b3..14184a7ee 100644 --- a/gwos-evm/polyjuice-tests/tests/ethereum_test.rs +++ b/gwos-evm/polyjuice-tests/tests/ethereum_test.rs @@ -177,7 +177,7 @@ impl Filler { let label = format!("{} {}", LABEL_PREFIX, label); self.expect.iter().find(|ex| match &ex.indexes.data { LabelIndex::Single(l) => l == &label, - LabelIndex::Sequence(l) => l.iter().find(|data| **data == label).is_some(), + LabelIndex::Sequence(l) => l.iter().any(|data| *data == label), _ => false, }) } @@ -212,7 +212,7 @@ impl TestRunner { let eth_addr: [u8; 20] = eth_addr.try_into().unwrap(); if account.code != "0x" { - let code = hex::decode(&account.code.trim_start_matches("0x"))?; + let code = hex::decode(account.code.trim_start_matches("0x"))?; let mut storage = HashMap::with_capacity(account.storage.len()); for (k, v) in &account.storage { let k = hex_to_h256(k)?; @@ -235,7 +235,7 @@ impl TestRunner { for hardfork in HARD_FORKS { if let Some(posts) = self.testcase.post.get(&hardfork.to_string()) { println!("Prepare tx, hardfork: {}", hardfork); - for (_idx, post) in posts.into_iter().enumerate() { + for (_idx, post) in posts.iter().enumerate() { // init ctx for each `post` let mut chain = self.init()?; let label = self @@ -274,7 +274,7 @@ impl TestRunner { Some(gas_price) => U256::from_str_radix(gas_price, 16)?, None => U256::zero(), }; - let from_eth_addr = hex_to_eth_address(&transaction.sender.as_ref().expect("sender"))?; + let from_eth_addr = hex_to_eth_address(transaction.sender.as_ref().expect("sender"))?; let to_eth_addr = hex_to_eth_address(&transaction.to)?; let from_id = chain .get_account_id_by_eth_address(&from_eth_addr)? @@ -295,7 +295,7 @@ impl TestRunner { let run_result = sub_test_case.run()?; let logs_hash = rlp_log_hash(&run_result); let expect_logs_hash = hex::decode(post.logs.trim_start_matches("0x"))?; - if logs_hash.as_slice() != &expect_logs_hash { + if logs_hash.as_slice() != expect_logs_hash { return Err(anyhow::anyhow!( "Compare logs hash failed: expect: {}, actual: {}", hex::encode(&expect_logs_hash), @@ -330,15 +330,15 @@ impl TestRunner { let mut buf = [0u8; 32]; buf[24..].copy_from_slice(&k.to_be_bytes()); let actual = chain - .get_storage(account_id, &buf.into()) + .get_storage(account_id, &buf) .expect("get value"); - let expect = decode_storage_value(&v).expect("decode value"); + let expect = decode_storage_value(v).expect("decode value"); if expect.as_slice() != actual.as_slice() { return Err(anyhow::anyhow!( "State validate failed for key: {:x}, expect value: {}, actual value: {}", k, - &hex::encode(&expect.as_slice()), - &hex::encode(&actual.as_slice()), + &hex::encode(expect.as_slice()), + &hex::encode(actual.as_slice()), )); } } @@ -404,8 +404,7 @@ fn rlp_log_hash(run_result: &RunResult) -> H256 { } }); stream.finalize_unbounded_list(); - let log_hash = tiny_keccak::keccak256(&stream.out().freeze()); - log_hash.into() + tiny_keccak::keccak256(&stream.out().freeze()) } fn hex_to_h256(hex_str: &str) -> anyhow::Result { @@ -470,6 +469,7 @@ fn decode_storage_value(v: &str) -> anyhow::Result { #[test] fn ethereum_test() -> anyhow::Result<()> { + #[allow(clippy::manual_flatten)] for dir in fs::read_dir(TEST_CASE_DIR)? { if let Ok(dir) = dir { let subdir = dir.path(); @@ -565,10 +565,10 @@ fn ethereum_vmtest_test() -> anyhow::Result<()> { #[test] fn ethereum_single_test() -> anyhow::Result<()> { let path = "../integration-test/ethereum-tests/GeneralStateTests/VMTests/vmLogTest/log0.json"; - let content = fs::read_to_string(&path)?; + let content = fs::read_to_string(path)?; let test_cases: HashMap = serde_json::from_str(&content)?; let path = "../integration-test/ethereum-tests/src/GeneralStateTestsFiller/VMTests/vmLogTest/log0Filler.yml"; - let content = fs::read_to_string(&path)?; + let content = fs::read_to_string(path)?; let mut fillers: HashMap = serde_yaml::from_str(&content)?; for (k, test_case) in test_cases.into_iter() { let filler = fillers.remove(&k).expect("get filler"); diff --git a/gwos/contracts/eth-account-lock/src/entry.rs b/gwos/contracts/eth-account-lock/src/entry.rs index c30829f6b..4408b8645 100644 --- a/gwos/contracts/eth-account-lock/src/entry.rs +++ b/gwos/contracts/eth-account-lock/src/entry.rs @@ -78,7 +78,7 @@ fn verify_message_signature( // load signature let signature = load_signature_from_witness()?; // verify message - let secp256k1_eth = Secp256k1Eth::default(); + let secp256k1_eth = Secp256k1Eth; let valid = match signing_type { SigningType::WithPrefix => secp256k1_eth.verify_message(eth_address, signature, message)?, SigningType::Raw => secp256k1_eth.verify_alone(eth_address, signature, message)?,