Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bunch of warnings across the workspace #2066

Merged
merged 3 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ commands:
# After wasm build to ensure target/wasm32-unknown-unknown/release/<contract>.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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions packages/crypto/src/secp256r1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/addresses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ fn hash(ty: &str, key: &[u8]) -> Vec<u8> {
#[cfg(test)]
mod tests {
use super::*;
use crate::{assert_hash_works, HexBinary};
use crate::assert_hash_works;
use hex_literal::hex;

#[test]
Expand Down
1 change: 0 additions & 1 deletion packages/std/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/hex_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/ibc.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
1 change: 0 additions & 1 deletion packages/std/src/math/decimal256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions packages/std/src/math/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ mod tests {
{
}

#[allow(dead_code)] // This is used to statically ensure all the integers have a shared set of traits
trait SignedImpl<'a>: IntImpl<'a> + Neg<Output = Self> {}

impl AllImpl<'_> for Uint64 {}
Expand Down
1 change: 1 addition & 0 deletions packages/std/src/query/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
17 changes: 7 additions & 10 deletions packages/std/src/testing/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,16 +521,16 @@
}
}

pub fn update_wasm<WH: 'static>(&mut self, handler: WH)
pub fn update_wasm<WH>(&mut self, handler: WH)
where
WH: Fn(&WasmQuery) -> QuerierResult,
WH: Fn(&WasmQuery) -> QuerierResult + 'static,
{
self.wasm.update_handler(handler)
}

pub fn with_custom_handler<CH: 'static>(mut self, handler: CH) -> Self
pub fn with_custom_handler<CH>(mut self, handler: CH) -> Self

Check warning on line 531 in packages/std/src/testing/mock.rs

View check run for this annotation

Codecov / codecov/patch

packages/std/src/testing/mock.rs#L531

Added line #L531 was not covered by tests
where
CH: Fn(&C) -> MockQuerierCustomHandlerResult,
CH: Fn(&C) -> MockQuerierCustomHandlerResult + 'static,

Check warning on line 533 in packages/std/src/testing/mock.rs

View check run for this annotation

Codecov / codecov/patch

packages/std/src/testing/mock.rs#L533

Added line #L533 was not covered by tests
{
self.custom_handler = Box::from(handler);
self
Expand Down Expand Up @@ -598,9 +598,9 @@
Self { handler }
}

fn update_handler<WH: 'static>(&mut self, handler: WH)
fn update_handler<WH>(&mut self, handler: WH)
where
WH: Fn(&WasmQuery) -> QuerierResult,
WH: Fn(&WasmQuery) -> QuerierResult + 'static,
{
self.handler = Box::from(handler)
}
Expand Down Expand Up @@ -1116,10 +1116,7 @@
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;
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions packages/vm/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions packages/vm/src/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/src/compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 0 additions & 1 deletion packages/vm/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub fn to_i32<T: TryInto<i32> + ToString + Copy>(input: T) -> VmResult<i32> {
#[cfg(test)]
mod tests {
use super::*;
use crate::errors::VmError;

#[test]
fn to_u32_works_for_usize() {
Expand Down
2 changes: 0 additions & 2 deletions packages/vm/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,7 @@ pub fn process_gas_info<A: BackendApi, S: Storage, Q: Querier>(
#[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};
Expand Down
1 change: 0 additions & 1 deletion packages/vm/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
4 changes: 1 addition & 3 deletions packages/vm/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions packages/vm/src/modules/file_system_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions packages/vm/src/modules/in_memory_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/vm/src/testing/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 5 additions & 5 deletions packages/vm/src/testing/querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ impl<C: CustomQuery + DeserializeOwned> MockQuerier<C> {
self.querier.staking.update(denom, validators, delegations);
}

pub fn update_wasm<WH: 'static>(&mut self, handler: WH)
pub fn update_wasm<WH>(&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<CH: 'static>(mut self, handler: CH) -> Self
pub fn with_custom_handler<CH>(mut self, handler: CH) -> Self
where
CH: Fn(&C) -> MockQuerierCustomHandlerResult,
CH: Fn(&C) -> MockQuerierCustomHandlerResult + 'static,
{
self.querier = self.querier.with_custom_handler(handler);
self
Expand Down Expand Up @@ -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;

Expand Down
Loading