Skip to content

Commit

Permalink
fix(test): apply linter new rules
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Feb 9, 2023
1 parent 78f9152 commit 43129c0
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 22 deletions.
11 changes: 5 additions & 6 deletions contracts/cw-logic-sample/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut<LogicCustomQuery>,
deps: DepsMut<'_, LogicCustomQuery>,
_env: Env,
info: MessageInfo,
msg: InstantiateMsg,
Expand All @@ -31,7 +31,7 @@ pub fn instantiate(
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps<LogicCustomQuery>, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
pub fn query(deps: Deps<'_, LogicCustomQuery>, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Ask { query } => to_binary(&query::ask(deps, query)?),
}
Expand All @@ -40,7 +40,7 @@ pub fn query(deps: Deps<LogicCustomQuery>, _env: Env, msg: QueryMsg) -> StdResul
pub mod query {
use super::*;

pub fn ask(deps: Deps<LogicCustomQuery>, query: String) -> StdResult<AskResponse> {
pub fn ask(deps: Deps<'_, LogicCustomQuery>, query: String) -> StdResult<AskResponse> {
let state = STATE.load(deps.storage)?;

let req = LogicCustomQuery::Ask {
Expand All @@ -55,10 +55,9 @@ pub mod query {

#[cfg(test)]
mod tests {
use std::marker::PhantomData;
use super::*;
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info, MockApi, MockQuerier, MockStorage};
use cosmwasm_std::{Coin, coins, from_binary, OwnedDeps};
use cosmwasm_std::testing::{mock_env, mock_info};
use cosmwasm_std::{Coin, coins, from_binary};
use logic_bindings::testing::mock::mock_dependencies_with_logic_and_balance;


Expand Down
1 change: 1 addition & 0 deletions contracts/cw-logic-sample/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
#[allow(unused_imports)]
use logic_bindings::AskResponse;

/// Instantiate messages
Expand Down
2 changes: 1 addition & 1 deletion contracts/cw-logic-sample/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ pub struct State {
pub program: String,
}

pub const STATE: Item<State> = Item::new("state");
pub const STATE: Item<'_, State> = Item::new("state");
12 changes: 6 additions & 6 deletions contracts/cw-template/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
deps: DepsMut<'_>,
_env: Env,
info: MessageInfo,
msg: InstantiateMsg,
Expand All @@ -33,7 +33,7 @@ pub fn instantiate(

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
deps: DepsMut,
deps: DepsMut<'_>,
_env: Env,
info: MessageInfo,
msg: ExecuteMsg,
Expand All @@ -47,7 +47,7 @@ pub fn execute(
pub mod execute {
use super::*;

pub fn increment(deps: DepsMut) -> Result<Response, ContractError> {
pub fn increment(deps: DepsMut<'_>) -> Result<Response, ContractError> {
STATE.update(deps.storage, |mut state| -> Result<_, ContractError> {
state.count += 1;
Ok(state)
Expand All @@ -56,7 +56,7 @@ pub mod execute {
Ok(Response::new().add_attribute("action", "increment"))
}

pub fn reset(deps: DepsMut, info: MessageInfo, count: i32) -> Result<Response, ContractError> {
pub fn reset(deps: DepsMut<'_>, info: MessageInfo, count: i32) -> Result<Response, ContractError> {
STATE.update(deps.storage, |mut state| -> Result<_, ContractError> {
if info.sender != state.owner {
return Err(ContractError::Unauthorized {});
Expand All @@ -69,7 +69,7 @@ pub mod execute {
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
pub fn query(deps: Deps<'_>, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::GetCount {} => to_binary(&query::count(deps)?),
}
Expand All @@ -78,7 +78,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
pub mod query {
use super::*;

pub fn count(deps: Deps) -> StdResult<GetCountResponse> {
pub fn count(deps: Deps<'_>) -> StdResult<GetCountResponse> {
let state = STATE.load(deps.storage)?;
Ok(GetCountResponse { count: state.count })
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/cw-template/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ pub struct State {
pub owner: Addr,
}

pub const STATE: Item<State> = Item::new("state");
pub const STATE: Item<'_, State> = Item::new("state");
12 changes: 4 additions & 8 deletions packages/logic-bindings/src/testing/mock.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::marker::PhantomData;
use cosmwasm_std::{Coin, OwnedDeps, QuerierResult, SystemError, SystemResult, to_binary, Uint128};
use cosmwasm_std::testing::{BankQuerier, MOCK_CONTRACT_ADDR, MockApi, MockQuerier, MockStorage};
use serde::de::DeserializeOwned;
use cosmwasm_std::{Coin, OwnedDeps, QuerierResult, SystemResult, to_binary};
use cosmwasm_std::testing::{MOCK_CONTRACT_ADDR, MockApi, MockQuerier, MockStorage};
use crate::{Answer, AskResponse, LogicCustomQuery, Substitution, Term};

/// Creates all external requirements that can be injected for unit tests.
Expand Down Expand Up @@ -50,23 +49,20 @@ impl LogicQuerier {
Self { handler }
}

#[allow(dead_code)]
fn update_handler<LH: 'static>(&mut self, handler: LH)
where
LH: Fn(&LogicCustomQuery) -> QuerierResult,
{
self.handler = Box::from(handler)
}

fn query(&self, request: &LogicCustomQuery) -> QuerierResult {
(*self.handler)(request)
}
}

impl Default for LogicQuerier {
fn default() -> Self {
let handler = Box::from(|request: &LogicCustomQuery| -> QuerierResult {
let result = match request {
LogicCustomQuery::Ask { program, query} => to_binary(&AskResponse {
LogicCustomQuery::Ask { .. } => to_binary(&AskResponse {
height: 1,
gas_used: 1000,
answer: Some(Answer {
Expand Down

0 comments on commit 43129c0

Please sign in to comment.