Skip to content

Commit

Permalink
style!: enforcing clippy::pedantic and clippy::nursery (#24)
Browse files Browse the repository at this point in the history
* style: comply with clippy::pedantic

* style!: added clippy::nursery and deny warnings

* imp(e2e): bumped wasmd to 0.45.0

* ci: trying to add dependency caching

* deps: bump crate version to 0.3.0

* deps: Cargo.lock updated

* imp: fixed test

* fix(testing/owner): fix linter issues after breaking api changes

* style: ran 'cargo fmt'

* fix: fixed incorrect reversion
  • Loading branch information
srdtrk authored Nov 22, 2023
1 parent 4c56599 commit bc58a99
Show file tree
Hide file tree
Showing 23 changed files with 232 additions and 130 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: "1.20"
check-latest: true
cache-dependency-path: |
e2e/interchaintest/go.sum
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.6.0
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-ica-controller"
version = "0.2.0"
version = "0.3.0"
authors = ["srdtrk <srdtrk@hotmail.com>"]
edition = "2021"
description = "This is a cosmwasm implementation of an interchain accounts controller."
Expand Down
2 changes: 1 addition & 1 deletion e2e/interchaintest/chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var chainSpecs = []*interchaintest.ChainSpec{
Images: []ibc.DockerImage{
{
Repository: "cosmwasm/wasmd", // FOR LOCAL IMAGE USE: Docker Image Name
Version: "v0.41.0", // FOR LOCAL IMAGE USE: Docker Image Tag
Version: "v0.45.0", // FOR LOCAL IMAGE USE: Docker Image Tag
},
},
Bin: "wasmd",
Expand Down
13 changes: 9 additions & 4 deletions src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! This module handles the execution logic of the contract.
// Clippy pedantic is disabled for `entry_point` functions since they require a certain signature.
#![allow(clippy::pedantic)]

use cosmwasm_std::entry_point;
use cosmwasm_std::{to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};

Expand Down Expand Up @@ -308,8 +311,7 @@ mod tests {
};
let res = execute(deps.as_mut(), env.clone(), info, msg).unwrap();

let expected_packet =
IcaPacketData::from_json_strings(vec![custom_msg_str.to_string()], None);
let expected_packet = IcaPacketData::from_json_strings(&[custom_msg_str.to_string()], None);
let expected_msg = expected_packet.to_ibc_msg(&env, "channel-0", None).unwrap();

assert_eq!(1, res.messages.len());
Expand Down Expand Up @@ -426,7 +428,7 @@ mod tests {
let _res = instantiate(
deps.as_mut(),
mock_env(),
info.clone(),
info,
InstantiateMsg {
admin: None,
channel_open_init_options: None,
Expand Down Expand Up @@ -456,7 +458,10 @@ mod tests {
let res = migrate(deps.as_mut(), mock_env(), MigrateMsg {});
assert_eq!(
res.unwrap_err().to_string(),
"invalid migration version: expected > 100.0.0, got 0.2.0".to_string()
format!(
"invalid migration version: expected > 100.0.0, got {}",
CONTRACT_VERSION
)
);
}
}
77 changes: 55 additions & 22 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,34 @@ use cosmwasm_std::{to_json_binary, Addr, Binary, CosmosMsg, QuerierWrapper, StdR

use crate::types::{msg, state};

/// CwIcaControllerContract is a wrapper around Addr that provides helpers
/// `CwIcaControllerContract` is a wrapper around Addr that provides helpers
/// for working with this contract.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct CwIcaControllerContract(pub Addr);

/// CwIcaControllerCodeId is a wrapper around u64 that provides helpers for
/// `CwIcaControllerCodeId` is a wrapper around u64 that provides helpers for
/// initializing this contract.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct CwIcaControllerCode(pub u64);

impl CwIcaControllerContract {
/// new creates a new [`CwIcaControllerContract`]
pub fn new(addr: Addr) -> Self {
#[must_use]
pub const fn new(addr: Addr) -> Self {
Self(addr)
}

/// addr returns the address of the contract
#[must_use]
pub fn addr(&self) -> Addr {
self.0.clone()
}

/// call creates a [`WasmMsg::Execute`] message targeting this contract,
///
/// # Errors
///
/// This function returns an error if the given message cannot be serialized
pub fn call(&self, msg: impl Into<msg::ExecuteMsg>) -> StdResult<CosmosMsg> {
let msg = to_json_binary(&msg.into())?;
Ok(WasmMsg::Execute {
Expand All @@ -40,42 +46,59 @@ impl CwIcaControllerContract {
.into())
}

/// query_channel queries the [`state::ChannelState`] of this contract
/// `query_channel` queries the [`state::ChannelState`] of this contract
///
/// # Errors
///
/// This function returns an error if the query fails
pub fn query_channel(&self, querier: QuerierWrapper) -> StdResult<state::ChannelState> {
querier.query_wasm_smart(self.addr(), &msg::QueryMsg::GetChannel {})
}

/// query_state queries the [`state::ContractState`] of this contract
/// `query_state` queries the [`state::ContractState`] of this contract
///
/// # Errors
///
/// This function returns an error if the query fails
pub fn query_state(&self, querier: QuerierWrapper) -> StdResult<state::ContractState> {
querier.query_wasm_smart(self.addr(), &msg::QueryMsg::GetContractState {})
}

/// query_callback_counter queries the [`state::CallbackCounter`] of this contract
/// `query_callback_counter` queries the [`state::CallbackCounter`] of this contract
///
/// # Errors
///
/// This function returns an error if the query fails
pub fn query_callback_counter(
&self,
querier: QuerierWrapper,
) -> StdResult<state::CallbackCounter> {
querier.query_wasm_smart(self.addr(), &msg::QueryMsg::GetCallbackCounter {})
}

/// update_admin creates a [`WasmMsg::UpdateAdmin`] message targeting this contract
pub fn update_admin(&self, admin: impl Into<String>) -> StdResult<CosmosMsg> {
Ok(WasmMsg::UpdateAdmin {
/// `update_admin` creates a [`WasmMsg::UpdateAdmin`] message targeting this contract
pub fn update_admin(&self, admin: impl Into<String>) -> CosmosMsg {
WasmMsg::UpdateAdmin {
contract_addr: self.addr().into(),
admin: admin.into(),
}
.into())
.into()
}

/// clear_admin creates a [`WasmMsg::ClearAdmin`] message targeting this contract
pub fn clear_admin(&self) -> StdResult<CosmosMsg> {
Ok(WasmMsg::ClearAdmin {
/// `clear_admin` creates a [`WasmMsg::ClearAdmin`] message targeting this contract
#[must_use]
pub fn clear_admin(&self) -> CosmosMsg {
WasmMsg::ClearAdmin {
contract_addr: self.addr().into(),
}
.into())
.into()
}

/// migrate creates a [`WasmMsg::Migrate`] message targeting this contract
/// `migrate` creates a [`WasmMsg::Migrate`] message targeting this contract
///
/// # Errors
///
/// This function returns an error if the given message cannot be serialized
pub fn migrate(
&self,
msg: impl Into<msg::MigrateMsg>,
Expand All @@ -93,16 +116,22 @@ impl CwIcaControllerContract {

impl CwIcaControllerCode {
/// new creates a new [`CwIcaControllerCode`]
pub fn new(code_id: u64) -> Self {
#[must_use]
pub const fn new(code_id: u64) -> Self {
Self(code_id)
}

/// code_id returns the code id of this code
pub fn code_id(&self) -> u64 {
/// `code_id` returns the code id of this code
#[must_use]
pub const fn code_id(&self) -> u64 {
self.0
}

/// instantiate creates a [`WasmMsg::Instantiate`] message targeting this code
/// `instantiate` creates a [`WasmMsg::Instantiate`] message targeting this code
///
/// # Errors
///
/// This function returns an error if the given message cannot be serialized
pub fn instantiate(
&self,
msg: impl Into<msg::InstantiateMsg>,
Expand All @@ -115,12 +144,16 @@ impl CwIcaControllerCode {
msg,
funds: vec![],
label: label.into(),
admin: admin.map(|s| s.into()),
admin: admin.map(Into::into),
}
.into())
}

/// instantiate2 creates a [`WasmMsg::Instantiate2`] message targeting this code
/// `instantiate2` creates a [`WasmMsg::Instantiate2`] message targeting this code
///
/// # Errors
///
/// This function returns an error if the given message cannot be serialized
pub fn instantiate2(
&self,
msg: impl Into<msg::InstantiateMsg>,
Expand All @@ -134,7 +167,7 @@ impl CwIcaControllerCode {
msg,
funds: vec![],
label: label.into(),
admin: admin.map(|s| s.into()),
admin: admin.map(Into::into),
salt: salt.into(),
}
.into())
Expand Down
3 changes: 3 additions & 0 deletions src/ibc/handshake.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! This module contains the entry points for the IBC handshake.
// Clippy pedantic is disabled for `entry_point` functions since they require a certain signature.
#![allow(clippy::pedantic)]

use cosmwasm_std::entry_point;
use cosmwasm_std::{
DepsMut, Env, Ibc3ChannelOpenResponse, IbcBasicResponse, IbcChannel, IbcChannelCloseMsg,
Expand Down
5 changes: 4 additions & 1 deletion src/ibc/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
//! - The IBC packet timeout.
//! - The IBC packet receive.
// Clippy pedantic is disabled for `entry_point` functions since they require a certain signature.
#![allow(clippy::pedantic)]

use cosmwasm_std::entry_point;
use cosmwasm_std::{
from_json, DepsMut, Env, IbcBasicResponse, IbcPacketAckMsg, IbcPacketReceiveMsg,
Expand All @@ -14,7 +17,7 @@ use crate::types::{
ContractError,
};

use super::types::{events, packet::acknowledgement::AcknowledgementData};
use super::types::{events, packet::acknowledgement::Data as AcknowledgementData};

/// Implements the IBC module's `OnAcknowledgementPacket` handler.
#[entry_point]
Expand Down
6 changes: 4 additions & 2 deletions src/ibc/types/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ use cosmwasm_std::{Event, IbcPacket};
pub mod packet_ack {
use cosmwasm_std::Binary;

use super::*;
use super::{attributes, Event, IbcPacket};

const EVENT_TYPE: &str = "acknowledge_packet";

/// returns an event for a successful packet acknowledgement.
#[must_use]
pub fn success(packet: &IbcPacket, resp: &Binary) -> Event {
Event::new(EVENT_TYPE)
.add_attributes(attributes::from_packet(packet))
.add_attribute(attributes::ACK_BASE64, resp.to_base64())
}

/// returns an event for an unsuccessful packet acknowledgement.
#[must_use]
pub fn error(packet: &IbcPacket, err: &str) -> Event {
Event::new(EVENT_TYPE)
.add_attributes(attributes::from_packet(packet))
Expand All @@ -40,7 +42,7 @@ pub mod packet_ack {
}

mod attributes {
use super::*;
use super::IbcPacket;
use cosmwasm_std::Attribute;

pub const ACK_BASE64: &str = "packet_ack_base64";
Expand Down
4 changes: 2 additions & 2 deletions src/ibc/types/keys.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Contains the key constants' definitions for the ibc module.
/// Version defines the current version for interchain accounts module
/// `ICA_VERSION` defines the current version for interchain accounts module
pub const ICA_VERSION: &str = "ics27-1";

/// HOST_PORT_ID is the default port id that the interchain accounts host submodule binds to
/// `HOST_PORT_ID` is the default port id that the interchain accounts host submodule binds to
pub const HOST_PORT_ID: &str = "icahost";
Loading

0 comments on commit bc58a99

Please sign in to comment.