Skip to content

Commit

Permalink
Merge pull request #795 from CosmWasm/lint-contract-tests
Browse files Browse the repository at this point in the history
Run linter on tests in dev contracts
  • Loading branch information
webmaster128 authored Feb 24, 2021
2 parents ee76be0 + 0196dac commit 5cb1418
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 76 deletions.
40 changes: 32 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions contracts/burner/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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,
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion contracts/crypto-verify/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Expand Down
4 changes: 2 additions & 2 deletions contracts/crypto-verify/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions contracts/hackatom/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,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(), &[]);
Expand Down Expand Up @@ -604,7 +604,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"));
Expand Down
8 changes: 4 additions & 4 deletions contracts/hackatom/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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"));
Expand All @@ -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(), &[]);
Expand Down
2 changes: 1 addition & 1 deletion contracts/ibc-reflect-send/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions contracts/ibc-reflect-send/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions contracts/ibc-reflect/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions contracts/ibc-reflect/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down
12 changes: 3 additions & 9 deletions contracts/queue/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ mod tests {
handle(
deps.as_mut(),
mock_env(),
info.clone(),
info,
HandleMsg::Enqueue { value: 45 },
)
.unwrap();
Expand All @@ -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();
Expand Down Expand Up @@ -339,7 +333,7 @@ mod tests {
handle(
deps.as_mut(),
mock_env(),
info.clone(),
info,
HandleMsg::Enqueue { value: -10 },
)
.unwrap();
Expand Down
14 changes: 7 additions & 7 deletions contracts/queue/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down Expand Up @@ -68,7 +68,7 @@ fn push_and_query() {
let _: Response = handle(
&mut deps,
mock_env(),
info.clone(),
info,
HandleMsg::Enqueue { value: 25 },
)
.unwrap();
Expand Down Expand Up @@ -96,7 +96,7 @@ fn multiple_push() {
let _: Response = handle(
&mut deps,
mock_env(),
info.clone(),
info,
HandleMsg::Enqueue { value: 45 },
)
.unwrap();
Expand All @@ -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();
Expand Down Expand Up @@ -159,7 +159,7 @@ fn push_and_reduce() {
let _: Response = handle(
&mut deps,
mock_env(),
info.clone(),
info,
HandleMsg::Enqueue { value: -10 },
)
.unwrap();
Expand All @@ -184,7 +184,7 @@ fn migrate_works() {
let _: Response = handle(
&mut deps,
mock_env(),
info.clone(),
info,
HandleMsg::Enqueue { value: 17 },
)
.unwrap();
Expand Down
Loading

0 comments on commit 5cb1418

Please sign in to comment.