Repository: CosmWasm/cosmwasm
Pull request #795 (2021-02-24 11:56:20)

Run linter on tests in dev contracts


Patch:
diff --git a/.circleci/config.yml b/.circleci/config.yml
index c176a6eb2..1df57e62e 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -759,35 +759,59 @@ jobs:
       - run:
           name: Clippy linting on burner
           working_directory: ~/project/contracts/burner
-          command: cargo clippy -- -D warnings
+          command: |
+            mkdir -p target/wasm32-unknown-unknown/release
+            touch target/wasm32-unknown-unknown/release/burner.wasm
+            cargo clippy --tests -- -D warnings
       - run:
           name: Clippy linting on crypto-verify
           working_directory: ~/project/contracts/crypto-verify
-          command: cargo clippy -- -D warnings
+          command: |
+            mkdir -p target/wasm32-unknown-unknown/release
+            touch target/wasm32-unknown-unknown/release/crypto_verify.wasm
+            cargo clippy --tests -- -D warnings
       - run:
           name: Clippy linting on hackatom
           working_directory: ~/project/contracts/hackatom
-          command: cargo clippy -- -D warnings
+          command: |
+            mkdir -p target/wasm32-unknown-unknown/release
+            touch target/wasm32-unknown-unknown/release/hackatom.wasm
+            cargo clippy --tests -- -D warnings
       - run:
           name: Clippy linting on ibc-reflect
           working_directory: ~/project/contracts/ibc-reflect
-          command: cargo clippy -- -D warnings
+          command: |
+            mkdir -p target/wasm32-unknown-unknown/release
+            touch target/wasm32-unknown-unknown/release/ibc_reflect.wasm
+            cargo clippy --tests -- -D warnings
       - run:
           name: Clippy linting on ibc-reflect-send
           working_directory: ~/project/contracts/ibc-reflect-send
-          command: cargo clippy -- -D warnings
+          command: |
+            mkdir -p target/wasm32-unknown-unknown/release
+            touch target/wasm32-unknown-unknown/release/ibc_reflect_send.wasm
+            cargo clippy --tests -- -D warnings
       - run:
           name: Clippy linting on queue
           working_directory: ~/project/contracts/queue
-          command: cargo clippy -- -D warnings
+          command: |
+            mkdir -p target/wasm32-unknown-unknown/release
+            touch target/wasm32-unknown-unknown/release/queue.wasm
+            cargo clippy --tests -- -D warnings
       - run:
           name: Clippy linting on reflect
           working_directory: ~/project/contracts/reflect
-          command: cargo clippy -- -D warnings
+          command: |
+            mkdir -p target/wasm32-unknown-unknown/release
+            touch target/wasm32-unknown-unknown/release/reflect.wasm
+            cargo clippy --tests -- -D warnings
       - run:
           name: Clippy linting on staking
           working_directory: ~/project/contracts/staking
-          command: cargo clippy -- -D warnings
+          command: |
+            mkdir -p target/wasm32-unknown-unknown/release
+            touch target/wasm32-unknown-unknown/release/staking.wasm
+            cargo clippy --tests -- -D warnings
       - save_cache:
           paths:
             - /usr/local/cargo/registry
diff --git a/contracts/crypto-verify/src/contract.rs b/contracts/crypto-verify/src/contract.rs
index 20fea1d20..1114d1c1e 100644
--- a/contracts/crypto-verify/src/contract.rs
+++ b/contracts/crypto-verify/src/contract.rs
@@ -297,7 +297,7 @@ mod tests {
         let signer_address = ETHEREUM_SIGNER_ADDRESS;
 
         let verify_msg = QueryMsg::VerifyEthereumText {
-            message: message.into(),
+            message,
             signature: signature.into(),
             signer_address: signer_address.into(),
         };
diff --git a/contracts/hackatom/src/contract.rs b/contracts/hackatom/src/contract.rs
index b44eda5a8..0180e9b42 100644
--- a/contracts/hackatom/src/contract.rs
+++ b/contracts/hackatom/src/contract.rs
@@ -409,7 +409,7 @@ mod tests {
         let beneficiary = HumanAddr::from("benefits");
         let creator = HumanAddr::from("creator");
         let msg = InitMsg {
-            verifier: verifier.clone(),
+            verifier,
             beneficiary,
         };
         let info = mock_info(creator.as_str(), &[]);
@@ -550,7 +550,7 @@ mod tests {
         let creator = HumanAddr(String::from("creator"));
 
         let init_msg = InitMsg {
-            verifier: verifier.clone(),
+            verifier,
             beneficiary: beneficiary.clone(),
         };
         let init_info = mock_info(creator.as_str(), &coins(1000, "earth"));
diff --git a/contracts/ibc-reflect-send/src/ibc.rs b/contracts/ibc-reflect-send/src/ibc.rs
index c434ca0ef..94140453c 100644
--- a/contracts/ibc-reflect-send/src/ibc.rs
+++ b/contracts/ibc-reflect-send/src/ibc.rs
@@ -369,7 +369,7 @@ mod tests {
         .into()];
         let handle_msg = HandleMsg::SendMsgs {
             channel_id: channel_id.into(),
-            msgs: msgs_to_dispatch.clone(),
+            msgs: msgs_to_dispatch,
         };
         let info = mock_info(CREATOR, &[]);
         let mut res = handle(deps.as_mut(), mock_env(), info, handle_msg).unwrap();
diff --git a/contracts/ibc-reflect/src/contract.rs b/contracts/ibc-reflect/src/contract.rs
index 9379e4274..389129aa7 100644
--- a/contracts/ibc-reflect/src/contract.rs
+++ b/contracts/ibc-reflect/src/contract.rs
@@ -465,7 +465,7 @@ mod tests {
             msgs: msgs_to_dispatch.clone(),
         };
         let packet = mock_ibc_packet_recv(channel_id, &ibc_msg).unwrap();
-        let res = ibc_packet_receive(deps.as_mut(), mock_env(), packet.clone()).unwrap();
+        let res = ibc_packet_receive(deps.as_mut(), mock_env(), packet).unwrap();
         // we didn't dispatch anything
         assert_eq!(0, res.messages.len());
         // acknowledgement is an error
@@ -480,7 +480,7 @@ mod tests {
 
         // receive a packet for an unregistered channel returns app-level error (not Result::Err)
         let packet = mock_ibc_packet_recv(channel_id, &ibc_msg).unwrap();
-        let res = ibc_packet_receive(deps.as_mut(), mock_env(), packet.clone()).unwrap();
+        let res = ibc_packet_receive(deps.as_mut(), mock_env(), packet).unwrap();
 
         // assert app-level success
         let ack: AcknowledgementMsg<()> = from_slice(&res.acknowledgement).unwrap();
@@ -514,7 +514,7 @@ mod tests {
             reflect_code_id: 12345,
         };
         let packet = mock_ibc_packet_recv(channel_id, &bad_data).unwrap();
-        let res = ibc_packet_receive(deps.as_mut(), mock_env(), packet.clone()).unwrap();
+        let res = ibc_packet_receive(deps.as_mut(), mock_env(), packet).unwrap();
         // we didn't dispatch anything
         assert_eq!(0, res.messages.len());
         // acknowledgement is an error
diff --git a/contracts/queue/src/contract.rs b/contracts/queue/src/contract.rs
index 3ae914277..9ca35ab2d 100644
--- a/contracts/queue/src/contract.rs
+++ b/contracts/queue/src/contract.rs
@@ -270,7 +270,7 @@ mod tests {
         handle(
             deps.as_mut(),
             mock_env(),
-            info.clone(),
+            info,
             HandleMsg::Enqueue { value: 45 },
         )
         .unwrap();
@@ -295,13 +295,7 @@ mod tests {
             HandleMsg::Enqueue { value: 17 },
         )
         .unwrap();
-        let res = handle(
-            deps.as_mut(),
-            mock_env(),
-            info.clone(),
-            HandleMsg::Dequeue {},
-        )
-        .unwrap();
+        let res = handle(deps.as_mut(), mock_env(), info, HandleMsg::Dequeue {}).unwrap();
         // ensure we popped properly
         assert!(res.data.is_some());
         let data = res.data.unwrap();
@@ -339,7 +333,7 @@ mod tests {
         handle(
             deps.as_mut(),
             mock_env(),
-            info.clone(),
+            info,
             HandleMsg::Enqueue { value: -10 },
         )
         .unwrap();
diff --git a/contracts/reflect/src/contract.rs b/contracts/reflect/src/contract.rs
index 0f18087cc..365ce6f3a 100644
--- a/contracts/reflect/src/contract.rs
+++ b/contracts/reflect/src/contract.rs
@@ -248,9 +248,7 @@ mod tests {
             amount: coins(1, "token"),
         }
         .into()];
-        let msg = HandleMsg::ReflectMsg {
-            msgs: payload.clone(),
-        };
+        let msg = HandleMsg::ReflectMsg { msgs: payload };
 
         let info = mock_info("random", &[]);
         let res = handle(deps.as_mut(), mock_env(), info, msg);
@@ -271,9 +269,7 @@ mod tests {
         let info = mock_info("creator", &[]);
         let payload = vec![];
 
-        let msg = HandleMsg::ReflectMsg {
-            msgs: payload.clone(),
-        };
+        let msg = HandleMsg::ReflectMsg { msgs: payload };
         let err = handle(deps.as_mut(), mock_env(), info, msg).unwrap_err();
         assert_eq!(err, ReflectError::MessagesEmpty);
     }
@@ -320,9 +316,7 @@ mod tests {
 
         let info = mock_info("creator", &[]);
         let new_owner = HumanAddr::from("friend");
-        let msg = HandleMsg::ChangeOwner {
-            owner: new_owner.clone(),
-        };
+        let msg = HandleMsg::ChangeOwner { owner: new_owner };
         let res = handle(deps.as_mut(), mock_env(), info, msg).unwrap();
 
         // should change state
@@ -343,9 +337,7 @@ mod tests {
         let random = HumanAddr::from("random");
         let info = mock_info(&random, &[]);
         let new_owner = HumanAddr::from("friend");
-        let msg = HandleMsg::ChangeOwner {
-            owner: new_owner.clone(),
-        };
+        let msg = HandleMsg::ChangeOwner { owner: new_owner };
 
         let err = handle(deps.as_mut(), mock_env(), info, msg).unwrap_err();
         let expected = deps.api.canonical_address(&creator).unwrap();
diff --git a/contracts/staking/src/contract.rs b/contracts/staking/src/contract.rs
index 07061865b..e892e82e2 100644
--- a/contracts/staking/src/contract.rs
+++ b/contracts/staking/src/contract.rs
@@ -498,7 +498,7 @@ mod tests {
         let info = mock_info(&creator, &[]);
 
         // make sure we can init with this
-        let res = init(deps.as_mut(), mock_env(), info, msg.clone());
+        let res = init(deps.as_mut(), mock_env(), info, msg);
         match res.unwrap_err() {
             StdError::GenericErr { msg, .. } => {
                 assert_eq!(msg, "my-validator is not in the current validator set")


Test patch:
diff --git a/contracts/burner/tests/integration.rs b/contracts/burner/tests/integration.rs
index 312b5633f..dc540d23b 100644
--- a/contracts/burner/tests/integration.rs
+++ b/contracts/burner/tests/integration.rs
@@ -17,9 +17,7 @@
 //!      });
 //! 4. Anywhere you see query(&deps, ...) you must replace it with query(&mut deps, ...)
 
-use cosmwasm_std::{
-    coins, BankMsg, ContractResult, HumanAddr, InitResponse, MigrateResponse, Order,
-};
+use cosmwasm_std::{coins, BankMsg, ContractResult, HumanAddr, Order, Response};
 use cosmwasm_vm::testing::{init, migrate, mock_env, mock_info, mock_instance};
 
 use burner::msg::{InitMsg, MigrateMsg};
@@ -37,7 +35,7 @@ fn init_fails() {
     let msg = InitMsg {};
     let info = mock_info("creator", &coins(1000, "earth"));
     // we can just call .unwrap() to assert this was a success
-    let res: ContractResult<InitResponse> = init(&mut deps, mock_env(), info, msg);
+    let res: ContractResult<Response> = init(&mut deps, mock_env(), info, msg);
     let msg = res.unwrap_err();
     assert_eq!(
         msg,
@@ -66,7 +64,7 @@ fn migrate_cleans_up_data() {
     let msg = MigrateMsg {
         payout: payout.clone(),
     };
-    let res: MigrateResponse = migrate(&mut deps, mock_env(), msg).unwrap();
+    let res: Response = migrate(&mut deps, mock_env(), msg).unwrap();
     // check payout
     assert_eq!(1, res.messages.len());
     let msg = res.messages.get(0).expect("no message");
diff --git a/contracts/crypto-verify/tests/integration.rs b/contracts/crypto-verify/tests/integration.rs
index 4871e3b46..29c984959 100644
--- a/contracts/crypto-verify/tests/integration.rs
+++ b/contracts/crypto-verify/tests/integration.rs
@@ -149,7 +149,7 @@ fn ethereum_signature_verify_fails_for_corrupted_message() {
     let signer_address = ETHEREUM_SIGNER_ADDRESS;
 
     let verify_msg = QueryMsg::VerifyEthereumText {
-        message: message.into(),
+        message,
         signature: signature.into(),
         signer_address: signer_address.into(),
     };
@@ -172,7 +172,7 @@ fn ethereum_signature_verify_fails_for_corrupted_signature() {
     let verify_msg = QueryMsg::VerifyEthereumText {
         message: message.into(),
         signature: signature.into(),
-        signer_address: signer_address.clone().into(),
+        signer_address: signer_address.into(),
     };
     let raw = query(&mut deps, mock_env(), verify_msg).unwrap();
     let res: VerifyResponse = from_slice(&raw).unwrap();
diff --git a/contracts/hackatom/tests/integration.rs b/contracts/hackatom/tests/integration.rs
index b9c044fe0..c60be6431 100644
--- a/contracts/hackatom/tests/integration.rs
+++ b/contracts/hackatom/tests/integration.rs
@@ -40,8 +40,8 @@ fn make_init_msg() -> (InitMsg, HumanAddr) {
     let creator = HumanAddr::from("creator");
     (
         InitMsg {
-            verifier: verifier.clone(),
-            beneficiary: beneficiary.clone(),
+            verifier,
+            beneficiary,
         },
         creator,
     )
@@ -94,7 +94,7 @@ fn init_and_query() {
     let beneficiary = HumanAddr(String::from("benefits"));
     let creator = HumanAddr(String::from("creator"));
     let msg = InitMsg {
-        verifier: verifier.clone(),
+        verifier,
         beneficiary,
     };
     let info = mock_info(creator.as_str(), &coins(1000, "earth"));
@@ -119,7 +119,7 @@ fn migrate_verifier() {
     let beneficiary = HumanAddr::from("benefits");
     let creator = HumanAddr::from("creator");
     let msg = InitMsg {
-        verifier: verifier.clone(),
+        verifier,
         beneficiary,
     };
     let info = mock_info(creator.as_str(), &[]);
diff --git a/contracts/ibc-reflect-send/tests/integration.rs b/contracts/ibc-reflect-send/tests/integration.rs
index f7685d71c..ee4dce844 100644
--- a/contracts/ibc-reflect-send/tests/integration.rs
+++ b/contracts/ibc-reflect-send/tests/integration.rs
@@ -129,7 +129,7 @@ fn proper_handshake_flow() {
     connect(&mut deps, channel_id);
 
     // check for empty account
-    let acct = get_account(&mut deps, channel_id.into());
+    let acct = get_account(&mut deps, channel_id);
     assert!(acct.remote_addr.is_none());
     assert!(acct.remote_balance.is_empty());
     assert_eq!(0, acct.last_update_time);
@@ -139,7 +139,7 @@ fn proper_handshake_flow() {
     who_am_i_response(&mut deps, channel_id, remote_addr);
 
     // account should be set up
-    let acct = get_account(&mut deps, channel_id.into());
+    let acct = get_account(&mut deps, channel_id);
     assert_eq!(acct.remote_addr.unwrap(), HumanAddr::from(remote_addr));
     assert!(acct.remote_balance.is_empty());
     assert_eq!(0, acct.last_update_time);
@@ -165,7 +165,7 @@ fn dispatch_message_send_and_ack() {
     .into()];
     let handle_msg = HandleMsg::SendMsgs {
         channel_id: channel_id.into(),
-        msgs: msgs_to_dispatch.clone(),
+        msgs: msgs_to_dispatch,
     };
     let info = mock_info(CREATOR, &[]);
     let mut res: Response = handle(&mut deps, mock_env(), info, handle_msg).unwrap();
diff --git a/contracts/ibc-reflect/tests/integration.rs b/contracts/ibc-reflect/tests/integration.rs
index 950a3b539..c41cae908 100644
--- a/contracts/ibc-reflect/tests/integration.rs
+++ b/contracts/ibc-reflect/tests/integration.rs
@@ -196,8 +196,7 @@ fn handle_dispatch_packet() {
         msgs: msgs_to_dispatch.clone(),
     };
     let packet = mock_ibc_packet_recv(channel_id, &ibc_msg).unwrap();
-    let res: IbcReceiveResponse =
-        ibc_packet_receive(&mut deps, mock_env(), packet.clone()).unwrap();
+    let res: IbcReceiveResponse = ibc_packet_receive(&mut deps, mock_env(), packet).unwrap();
     // we didn't dispatch anything
     assert_eq!(0, res.messages.len());
     // acknowledgement is an error
@@ -212,8 +211,7 @@ fn handle_dispatch_packet() {
 
     // receive a packet for an unregistered channel returns app-level error (not Result::Err)
     let packet = mock_ibc_packet_recv(channel_id, &ibc_msg).unwrap();
-    let res: IbcReceiveResponse =
-        ibc_packet_receive(&mut deps, mock_env(), packet.clone()).unwrap();
+    let res: IbcReceiveResponse = ibc_packet_receive(&mut deps, mock_env(), packet).unwrap();
     println!(
         "{}",
         String::from_utf8(res.acknowledgement.0.clone()).unwrap()
@@ -251,8 +249,7 @@ fn handle_dispatch_packet() {
         reflect_code_id: 12345,
     };
     let packet = mock_ibc_packet_recv(channel_id, &bad_data).unwrap();
-    let res: IbcReceiveResponse =
-        ibc_packet_receive(&mut deps, mock_env(), packet.clone()).unwrap();
+    let res: IbcReceiveResponse = ibc_packet_receive(&mut deps, mock_env(), packet).unwrap();
     // we didn't dispatch anything
     assert_eq!(0, res.messages.len());
     // acknowledgement is an error
diff --git a/contracts/queue/tests/integration.rs b/contracts/queue/tests/integration.rs
index 38ab3ed45..09893811a 100644
--- a/contracts/queue/tests/integration.rs
+++ b/contracts/queue/tests/integration.rs
@@ -17,7 +17,7 @@
 //!      });
 //! 4. Anywhere you see query(&deps, ...) you must replace it with query(&mut deps, ...)
 
-use cosmwasm_std::{from_binary, from_slice, HumanAddr, InitResponse, MessageInfo, Response};
+use cosmwasm_std::{from_binary, from_slice, HumanAddr, MessageInfo, Response};
 use cosmwasm_vm::{
     testing::{
         handle, init, migrate, mock_env, mock_info, mock_instance_with_gas_limit, query, MockApi,
@@ -38,7 +38,7 @@ fn create_contract() -> (Instance<MockApi, MockStorage, MockQuerier>, MessageInf
     let mut deps = mock_instance_with_gas_limit(WASM, gas_limit);
     let creator = HumanAddr(String::from("creator"));
     let info = mock_info(creator.as_str(), &[]);
-    let res: InitResponse = init(&mut deps, mock_env(), info.clone(), InitMsg {}).unwrap();
+    let res: Response = init(&mut deps, mock_env(), info.clone(), InitMsg {}).unwrap();
     assert_eq!(0, res.messages.len());
     (deps, info)
 }
@@ -68,7 +68,7 @@ fn push_and_query() {
     let _: Response = handle(
         &mut deps,
         mock_env(),
-        info.clone(),
+        info,
         HandleMsg::Enqueue { value: 25 },
     )
     .unwrap();
@@ -96,7 +96,7 @@ fn multiple_push() {
     let _: Response = handle(
         &mut deps,
         mock_env(),
-        info.clone(),
+        info,
         HandleMsg::Enqueue { value: 45 },
     )
     .unwrap();
@@ -121,7 +121,7 @@ fn push_and_pop() {
         HandleMsg::Enqueue { value: 17 },
     )
     .unwrap();
-    let res: Response = handle(&mut deps, mock_env(), info.clone(), HandleMsg::Dequeue {}).unwrap();
+    let res: Response = handle(&mut deps, mock_env(), info, HandleMsg::Dequeue {}).unwrap();
     // ensure we popped properly
     assert!(res.data.is_some());
     let data = res.data.unwrap();
@@ -159,7 +159,7 @@ fn push_and_reduce() {
     let _: Response = handle(
         &mut deps,
         mock_env(),
-        info.clone(),
+        info,
         HandleMsg::Enqueue { value: -10 },
     )
     .unwrap();
@@ -184,7 +184,7 @@ fn migrate_works() {
     let _: Response = handle(
         &mut deps,
         mock_env(),
-        info.clone(),
+        info,
         HandleMsg::Enqueue { value: 17 },
     )
     .unwrap();
diff --git a/contracts/reflect/tests/integration.rs b/contracts/reflect/tests/integration.rs
index f69130e17..cd0ba6a52 100644
--- a/contracts/reflect/tests/integration.rs
+++ b/contracts/reflect/tests/integration.rs
@@ -120,9 +120,7 @@ fn reflect_requires_owner() {
         amount: coins(1, "token"),
     }
     .into()];
-    let msg = HandleMsg::ReflectMsg {
-        msgs: payload.clone(),
-    };
+    let msg = HandleMsg::ReflectMsg { msgs: payload };
 
     let info = mock_info("someone", &[]);
     let res: ContractResult<Response<CustomMsg>> = handle(&mut deps, mock_env(), info, msg);
@@ -140,9 +138,7 @@ fn transfer() {
 
     let info = mock_info("creator", &[]);
     let new_owner = HumanAddr::from("friend");
-    let msg = HandleMsg::ChangeOwner {
-        owner: new_owner.clone(),
-    };
+    let msg = HandleMsg::ChangeOwner { owner: new_owner };
     let res: Response<CustomMsg> = handle(&mut deps, mock_env(), info, msg).unwrap();
 
     // should change state
@@ -162,9 +158,7 @@ fn transfer_requires_owner() {
 
     let info = mock_info("random", &[]);
     let new_owner = HumanAddr::from("friend");
-    let msg = HandleMsg::ChangeOwner {
-        owner: new_owner.clone(),
-    };
+    let msg = HandleMsg::ChangeOwner { owner: new_owner };
 
     let res: ContractResult<Response> = handle(&mut deps, mock_env(), info, msg);
     let msg = res.unwrap_err();
diff --git a/contracts/staking/tests/integration.rs b/contracts/staking/tests/integration.rs
index bf54d9cd4..96d870f4c 100644
--- a/contracts/staking/tests/integration.rs
+++ b/contracts/staking/tests/integration.rs
@@ -18,7 +18,7 @@
 //! 4. Anywhere you see query(&deps, ...) you must replace it with query(&mut deps, ...)
 
 use cosmwasm_std::{
-    coin, from_binary, ContractResult, Decimal, HumanAddr, InitResponse, Uint128, Validator,
+    coin, from_binary, ContractResult, Decimal, HumanAddr, Response, Uint128, Validator,
 };
 use cosmwasm_vm::testing::{init, mock_backend, mock_env, mock_info, mock_instance_options, query};
 use cosmwasm_vm::Instance;
@@ -62,7 +62,7 @@ fn initialization_with_missing_validator() {
     let info = mock_info(&creator, &[]);
 
     // make sure we can init with this
-    let res: ContractResult<InitResponse> = init(&mut deps, mock_env(), info, msg.clone());
+    let res: ContractResult<Response> = init(&mut deps, mock_env(), info, msg);
     let msg = res.unwrap_err();
     assert_eq!(
         msg,
@@ -100,7 +100,7 @@ fn proper_initialization() {
     let info = mock_info(&creator, &[]);
 
     // make sure we can init with this
-    let res: InitResponse = init(&mut deps, mock_env(), info, msg.clone()).unwrap();
+    let res: Response = init(&mut deps, mock_env(), info, msg.clone()).unwrap();
     assert_eq!(0, res.messages.len());
 
     // token info is proper