From 7235b480cbf2828aa4f42ca959e5ef996481210d Mon Sep 17 00:00:00 2001 From: Aumetra Weisman Date: Thu, 21 Mar 2024 18:46:06 +0100 Subject: [PATCH 1/3] Fix a bunch of warning across the workspace --- packages/crypto/src/secp256r1.rs | 3 --- packages/std/src/addresses.rs | 2 +- packages/std/src/binary.rs | 1 - packages/std/src/hex_binary.rs | 2 +- packages/std/src/ibc.rs | 2 +- packages/std/src/math/decimal256.rs | 1 - packages/std/src/math/mod.rs | 1 + packages/std/src/testing/mock.rs | 17 +++++++---------- packages/std/src/traits.rs | 2 +- packages/vm/src/cache.rs | 4 +--- packages/vm/src/calls.rs | 8 ++------ packages/vm/src/compatibility.rs | 2 +- packages/vm/src/conversion.rs | 1 - packages/vm/src/environment.rs | 2 -- packages/vm/src/imports.rs | 1 - packages/vm/src/instance.rs | 4 +--- packages/vm/src/lib.rs | 2 +- packages/vm/src/modules/file_system_cache.rs | 7 +------ packages/vm/src/modules/in_memory_cache.rs | 5 +---- packages/vm/src/testing/mock.rs | 1 - packages/vm/src/testing/querier.rs | 10 +++++----- 21 files changed, 25 insertions(+), 53 deletions(-) diff --git a/packages/crypto/src/secp256r1.rs b/packages/crypto/src/secp256r1.rs index 0a0256d697..eacb74fa33 100644 --- a/packages/crypto/src/secp256r1.rs +++ b/packages/crypto/src/secp256r1.rs @@ -4,7 +4,6 @@ use p256::{ ecdsa::signature::DigestVerifier, // traits ecdsa::{Signature, VerifyingKey}, // type aliases }; -use std::convert::TryInto; use crate::ecdsa::{ECDSA_COMPRESSED_PUBKEY_LEN, ECDSA_UNCOMPRESSED_PUBKEY_LEN}; use crate::errors::{CryptoError, CryptoResult}; @@ -145,8 +144,6 @@ mod tests { use std::fs::File; use std::io::BufReader; - use crate::secp256r1_recover_pubkey; - use ecdsa::RecoveryId; use p256::{ ecdsa::signature::DigestSigner, ecdsa::SigningKey, elliptic_curve::rand_core::OsRng, }; diff --git a/packages/std/src/addresses.rs b/packages/std/src/addresses.rs index 659fe86534..66b07c4267 100644 --- a/packages/std/src/addresses.rs +++ b/packages/std/src/addresses.rs @@ -360,7 +360,7 @@ fn hash(ty: &str, key: &[u8]) -> Vec { #[cfg(test)] mod tests { use super::*; - use crate::{assert_hash_works, HexBinary}; + use crate::assert_hash_works; use hex_literal::hex; #[test] diff --git a/packages/std/src/binary.rs b/packages/std/src/binary.rs index 8237980666..8ee6d9661c 100644 --- a/packages/std/src/binary.rs +++ b/packages/std/src/binary.rs @@ -258,7 +258,6 @@ impl<'de> de::Visitor<'de> for Base64Visitor { mod tests { use super::*; use crate::assert_hash_works; - use crate::errors::StdError; use crate::serde::{from_json, to_json_vec}; #[test] diff --git a/packages/std/src/hex_binary.rs b/packages/std/src/hex_binary.rs index 1b704e2261..91ceca1a3a 100644 --- a/packages/std/src/hex_binary.rs +++ b/packages/std/src/hex_binary.rs @@ -248,7 +248,7 @@ impl<'de> de::Visitor<'de> for HexVisitor { mod tests { use super::*; - use crate::{assert_hash_works, from_json, to_json_vec, StdError}; + use crate::{assert_hash_works, from_json, to_json_vec}; #[test] fn from_hex_works() { diff --git a/packages/std/src/ibc.rs b/packages/std/src/ibc.rs index 8662531e68..a7c6f8b2ba 100644 --- a/packages/std/src/ibc.rs +++ b/packages/std/src/ibc.rs @@ -1,7 +1,7 @@ // The CosmosMsg variants are defined in results/cosmos_msg.rs // The rest of the IBC related functionality is defined here -use core::cmp::{Ord, Ordering, PartialOrd}; +use core::cmp::Ordering; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; diff --git a/packages/std/src/math/decimal256.rs b/packages/std/src/math/decimal256.rs index 4117dd8305..c2dd92932f 100644 --- a/packages/std/src/math/decimal256.rs +++ b/packages/std/src/math/decimal256.rs @@ -783,7 +783,6 @@ impl<'de> de::Visitor<'de> for Decimal256Visitor { #[cfg(test)] mod tests { use super::*; - use crate::errors::StdError; use crate::{from_json, to_json_vec}; fn dec(input: &str) -> Decimal256 { diff --git a/packages/std/src/math/mod.rs b/packages/std/src/math/mod.rs index 1e4527f214..df67652eb9 100644 --- a/packages/std/src/math/mod.rs +++ b/packages/std/src/math/mod.rs @@ -80,6 +80,7 @@ mod tests { { } + #[allow(dead_code)] trait SignedImpl<'a>: IntImpl<'a> + Neg {} impl AllImpl<'_> for Uint64 {} diff --git a/packages/std/src/testing/mock.rs b/packages/std/src/testing/mock.rs index 3a517270ff..1772e159e5 100644 --- a/packages/std/src/testing/mock.rs +++ b/packages/std/src/testing/mock.rs @@ -521,16 +521,16 @@ impl MockQuerier { } } - pub fn update_wasm(&mut self, handler: WH) + pub fn update_wasm(&mut self, handler: WH) where - WH: Fn(&WasmQuery) -> QuerierResult, + WH: Fn(&WasmQuery) -> QuerierResult + 'static, { self.wasm.update_handler(handler) } - pub fn with_custom_handler(mut self, handler: CH) -> Self + pub fn with_custom_handler(mut self, handler: CH) -> Self where - CH: Fn(&C) -> MockQuerierCustomHandlerResult, + CH: Fn(&C) -> MockQuerierCustomHandlerResult + 'static, { self.custom_handler = Box::from(handler); self @@ -598,9 +598,9 @@ impl WasmQuerier { Self { handler } } - fn update_handler(&mut self, handler: WH) + fn update_handler(&mut self, handler: WH) where - WH: Fn(&WasmQuery) -> QuerierResult, + WH: Fn(&WasmQuery) -> QuerierResult + 'static, { self.handler = Box::from(handler) } @@ -1116,10 +1116,7 @@ mod tests { use super::*; #[cfg(feature = "cosmwasm_1_3")] use crate::DenomUnit; - use crate::{ - coin, coins, from_json, instantiate2_address, to_json_binary, ContractInfoResponse, - HexBinary, Response, - }; + use crate::{coin, coins, instantiate2_address, ContractInfoResponse, HexBinary, Response}; #[cfg(feature = "staking")] use crate::{Decimal, Delegation}; use hex_literal::hex; diff --git a/packages/std/src/traits.rs b/packages/std/src/traits.rs index 7ed3a44e70..fd974cd619 100644 --- a/packages/std/src/traits.rs +++ b/packages/std/src/traits.rs @@ -529,7 +529,7 @@ mod tests { use super::*; use crate::testing::MockQuerier; - use crate::{coins, from_json, Uint128}; + use crate::{coins, Uint128}; // this is a simple demo helper to prove we can use it fn demo_helper(_querier: &dyn Querier) -> u64 { diff --git a/packages/vm/src/cache.rs b/packages/vm/src/cache.rs index 993d8590d9..2810e83683 100644 --- a/packages/vm/src/cache.rs +++ b/packages/vm/src/cache.rs @@ -580,11 +580,9 @@ mod tests { use super::*; use crate::calls::{call_execute, call_instantiate}; use crate::capabilities::capabilities_from_csv; - use crate::errors::VmError; use crate::testing::{mock_backend, mock_env, mock_info, MockApi, MockQuerier, MockStorage}; use cosmwasm_std::{coins, Empty}; - use std::fs::{create_dir_all, remove_dir_all, OpenOptions}; - use std::io::Write; + use std::fs::{create_dir_all, remove_dir_all}; use tempfile::TempDir; const TESTING_GAS_LIMIT: u64 = 500_000_000; // ~0.5ms diff --git a/packages/vm/src/calls.rs b/packages/vm/src/calls.rs index f09e9841c4..c56d738f5b 100644 --- a/packages/vm/src/calls.rs +++ b/packages/vm/src/calls.rs @@ -859,18 +859,14 @@ mod tests { #[cfg(feature = "stargate")] mod ibc { use super::*; - use crate::calls::{call_instantiate, call_reply}; - use crate::testing::{ - mock_env, mock_info, mock_instance, MockApi, MockQuerier, MockStorage, - }; + use crate::testing::{MockApi, MockQuerier, MockStorage}; use cosmwasm_std::testing::mock_ibc_packet_timeout; use cosmwasm_std::testing::{ mock_ibc_channel_close_init, mock_ibc_channel_connect_ack, mock_ibc_channel_open_init, mock_ibc_packet_ack, mock_ibc_packet_recv, mock_wasmd_attr, }; use cosmwasm_std::{ - Empty, Event, IbcAcknowledgement, IbcOrder, Reply, ReplyOn, SubMsgResponse, - SubMsgResult, + Event, IbcAcknowledgement, IbcOrder, ReplyOn, SubMsgResponse, SubMsgResult, }; static CONTRACT: &[u8] = include_bytes!("../testdata/ibc_reflect.wasm"); const IBC_VERSION: &str = "ibc-reflect-v1"; diff --git a/packages/vm/src/compatibility.rs b/packages/vm/src/compatibility.rs index 2cb3fcd28d..de5259e677 100644 --- a/packages/vm/src/compatibility.rs +++ b/packages/vm/src/compatibility.rs @@ -268,7 +268,7 @@ fn check_wasm_functions(module: &ParsedWasm) -> VmResult<()> { #[cfg(test)] mod tests { use super::*; - use crate::{capabilities_from_csv, errors::VmError}; + use crate::capabilities_from_csv; static CONTRACT_0_7: &[u8] = include_bytes!("../testdata/hackatom_0.7.wasm"); static CONTRACT_0_12: &[u8] = include_bytes!("../testdata/hackatom_0.12.wasm"); diff --git a/packages/vm/src/conversion.rs b/packages/vm/src/conversion.rs index 409abd6fa4..83ef6f867a 100644 --- a/packages/vm/src/conversion.rs +++ b/packages/vm/src/conversion.rs @@ -32,7 +32,6 @@ pub fn to_i32 + ToString + Copy>(input: T) -> VmResult { #[cfg(test)] mod tests { use super::*; - use crate::errors::VmError; #[test] fn to_u32_works_for_usize() { diff --git a/packages/vm/src/environment.rs b/packages/vm/src/environment.rs index f62b1952f7..dbf10e436b 100644 --- a/packages/vm/src/environment.rs +++ b/packages/vm/src/environment.rs @@ -455,9 +455,7 @@ pub fn process_gas_info( #[cfg(test)] mod tests { use super::*; - use crate::backend::Storage; use crate::conversion::ref_to_u32; - use crate::errors::VmError; use crate::size::Size; use crate::testing::{MockApi, MockQuerier, MockStorage}; use crate::wasm_backend::{compile, make_compiling_engine}; diff --git a/packages/vm/src/imports.rs b/packages/vm/src/imports.rs index 4dfaeea6a6..4be82c6744 100644 --- a/packages/vm/src/imports.rs +++ b/packages/vm/src/imports.rs @@ -691,7 +691,6 @@ mod tests { use std::ptr::NonNull; use wasmer::{imports, Function, FunctionEnv, Instance as WasmerInstance, Store}; - use crate::backend::{BackendError, Storage}; use crate::size::Size; use crate::testing::{MockApi, MockQuerier, MockStorage}; use crate::wasm_backend::{compile, make_compiling_engine}; diff --git a/packages/vm/src/instance.rs b/packages/vm/src/instance.rs index 8baf998350..eb6c3a9283 100644 --- a/packages/vm/src/instance.rs +++ b/packages/vm/src/instance.rs @@ -491,9 +491,7 @@ mod tests { use std::time::SystemTime; use super::*; - use crate::backend::Storage; use crate::calls::{call_execute, call_instantiate, call_query}; - use crate::errors::VmError; use crate::testing::{ mock_backend, mock_env, mock_info, mock_instance, mock_instance_options, mock_instance_with_balances, mock_instance_with_failing_api, mock_instance_with_gas_limit, @@ -502,7 +500,7 @@ mod tests { use cosmwasm_std::{ coin, coins, from_json, AllBalanceResponse, BalanceResponse, BankQuery, Empty, QueryRequest, }; - use wasmer::{FunctionEnv, FunctionEnvMut}; + use wasmer::FunctionEnvMut; const KIB: usize = 1024; const MIB: usize = 1024 * 1024; diff --git a/packages/vm/src/lib.rs b/packages/vm/src/lib.rs index 4b87b7638b..7fe798e7ec 100644 --- a/packages/vm/src/lib.rs +++ b/packages/vm/src/lib.rs @@ -47,8 +47,8 @@ pub use crate::instance::{DebugInfo, GasReport, Instance, InstanceOptions}; pub use crate::serde::{from_slice, to_vec}; pub use crate::size::Size; -#[doc(hidden)] pub mod internals { + #![doc(hidden)] //! We use the internals module for exporting types that are only //! intended to be used in internal crates / utils. //! Please don't use any of these types directly, as diff --git a/packages/vm/src/modules/file_system_cache.rs b/packages/vm/src/modules/file_system_cache.rs index 8303c9ca35..7ad6f72f5b 100644 --- a/packages/vm/src/modules/file_system_cache.rs +++ b/packages/vm/src/modules/file_system_cache.rs @@ -237,13 +237,8 @@ fn modules_path(base_path: &Path, wasmer_module_version: u32, target: &Target) - #[cfg(test)] mod tests { - use std::fs; - use super::*; - use crate::{ - size::Size, - wasm_backend::{compile, make_compiling_engine}, - }; + use crate::wasm_backend::{compile, make_compiling_engine}; use tempfile::TempDir; use wasmer::{imports, Instance as WasmerInstance, Store}; use wasmer_middlewares::metering::set_remaining_points; diff --git a/packages/vm/src/modules/in_memory_cache.rs b/packages/vm/src/modules/in_memory_cache.rs index 69a74106f3..be5257ec7c 100644 --- a/packages/vm/src/modules/in_memory_cache.rs +++ b/packages/vm/src/modules/in_memory_cache.rs @@ -94,10 +94,7 @@ impl InMemoryCache { #[cfg(test)] mod tests { use super::*; - use crate::{ - size::Size, - wasm_backend::{compile, make_compiling_engine, make_runtime_engine}, - }; + use crate::wasm_backend::{compile, make_compiling_engine, make_runtime_engine}; use std::mem; use wasmer::{imports, Instance as WasmerInstance, Module, Store}; use wasmer_middlewares::metering::set_remaining_points; diff --git a/packages/vm/src/testing/mock.rs b/packages/vm/src/testing/mock.rs index c9f88cc815..6bc458a9d4 100644 --- a/packages/vm/src/testing/mock.rs +++ b/packages/vm/src/testing/mock.rs @@ -241,7 +241,6 @@ pub fn mock_info(sender: &str, funds: &[Coin]) -> MessageInfo { #[cfg(test)] mod tests { use super::*; - use crate::BackendError; use cosmwasm_std::coins; #[test] diff --git a/packages/vm/src/testing/querier.rs b/packages/vm/src/testing/querier.rs index 046526ed9f..682ad757b6 100644 --- a/packages/vm/src/testing/querier.rs +++ b/packages/vm/src/testing/querier.rs @@ -45,16 +45,16 @@ impl MockQuerier { self.querier.staking.update(denom, validators, delegations); } - pub fn update_wasm(&mut self, handler: WH) + pub fn update_wasm(&mut self, handler: WH) where - WH: Fn(&cosmwasm_std::WasmQuery) -> cosmwasm_std::QuerierResult, + WH: Fn(&cosmwasm_std::WasmQuery) -> cosmwasm_std::QuerierResult + 'static, { self.querier.update_wasm(handler) } - pub fn with_custom_handler(mut self, handler: CH) -> Self + pub fn with_custom_handler(mut self, handler: CH) -> Self where - CH: Fn(&C) -> MockQuerierCustomHandlerResult, + CH: Fn(&C) -> MockQuerierCustomHandlerResult + 'static, { self.querier = self.querier.with_custom_handler(handler); self @@ -113,7 +113,7 @@ impl MockQuerier { #[cfg(test)] mod tests { use super::*; - use cosmwasm_std::{coin, from_json, AllBalanceResponse, BalanceResponse, BankQuery, Empty}; + use cosmwasm_std::{coin, from_json, AllBalanceResponse, BalanceResponse, BankQuery}; const DEFAULT_QUERY_GAS_LIMIT: u64 = 300_000; From dd9aa5b72f6fa1577c760cf6e950143cb40dc85a Mon Sep 17 00:00:00 2001 From: Aumetra Weisman Date: Thu, 21 Mar 2024 18:51:06 +0100 Subject: [PATCH 2/3] Add docs to allow attributes --- packages/std/src/math/mod.rs | 2 +- packages/std/src/query/query_response.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/std/src/math/mod.rs b/packages/std/src/math/mod.rs index df67652eb9..68b02525d4 100644 --- a/packages/std/src/math/mod.rs +++ b/packages/std/src/math/mod.rs @@ -80,7 +80,7 @@ mod tests { { } - #[allow(dead_code)] + #[allow(dead_code)] // This is used to statically ensure all the integers have a shared set of traits trait SignedImpl<'a>: IntImpl<'a> + Neg {} impl AllImpl<'_> for Uint64 {} diff --git a/packages/std/src/query/query_response.rs b/packages/std/src/query/query_response.rs index 00dae078c0..c8385f2fab 100644 --- a/packages/std/src/query/query_response.rs +++ b/packages/std/src/query/query_response.rs @@ -15,4 +15,5 @@ use serde::de::DeserializeOwned; /// - multi-test/cw-sdk: create a default instance and mutate the fields /// /// This trait is crate-internal and can change any time. +#[allow(dead_code)] // This is used to statically ensure all the types have a shared set of traits pub(crate) trait QueryResponseType: DeserializeOwned + Debug + PartialEq + Clone {} From ad959c84300d4402b295fd7745a87383c07bcf9b Mon Sep 17 00:00:00 2001 From: Aumetra Weisman Date: Mon, 25 Mar 2024 10:23:31 +0100 Subject: [PATCH 3/3] Pass `--tests` to the clippy invocation --- .circleci/config.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index dfc0187e4d..a4e6c7ff51 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,7 +25,7 @@ commands: # After wasm build to ensure target/wasm32-unknown-unknown/release/.wasm exists - run: name: Clippy - command: cargo clippy --all-targets -- -D warnings + command: cargo clippy --all-targets --tests -- -D warnings - run: name: Integration tests (singlepass backend) command: cargo integration-test --locked --no-default-features @@ -882,35 +882,35 @@ jobs: - run: name: Clippy linting on crypto working_directory: ~/project/packages/crypto - command: cargo clippy --all-targets -- -D warnings + command: cargo clippy --all-targets --tests -- -D warnings - run: name: Clippy linting on derive working_directory: ~/project/packages/derive - command: cargo clippy --all-targets -- -D warnings + command: cargo clippy --all-targets --tests -- -D warnings - run: name: Clippy linting on schema working_directory: ~/project/packages/schema - command: cargo clippy --all-targets -- -D warnings + command: cargo clippy --all-targets --tests -- -D warnings - run: name: Clippy linting on schema-derive working_directory: ~/project/packages/schema-derive - command: cargo clippy --all-targets -- -D warnings + command: cargo clippy --all-targets --tests -- -D warnings - run: name: Clippy linting on std (no feature flags) working_directory: ~/project/packages/std - command: cargo clippy --all-targets -- -D warnings + command: cargo clippy --all-targets --tests -- -D warnings - run: name: Clippy linting on std (all feature flags) working_directory: ~/project/packages/std - command: cargo clippy --all-targets --features abort,iterator,staking,stargate,cosmwasm_2_0 -- -D warnings + command: cargo clippy --all-targets --tests --features abort,iterator,staking,stargate,cosmwasm_2_0 -- -D warnings - run: name: Clippy linting on vm (no feature flags) working_directory: ~/project/packages/vm - command: cargo clippy --all-targets --no-default-features -- -D warnings + command: cargo clippy --all-targets --tests --no-default-features -- -D warnings - run: name: Clippy linting on vm (all feature flags) working_directory: ~/project/packages/vm - command: cargo clippy --all-targets --features iterator,staking,stargate -- -D warnings + command: cargo clippy --all-targets --tests --features iterator,staking,stargate -- -D warnings - save_cache: paths: - /usr/local/cargo/registry