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

Migrate to v0.11 #104

Merged
merged 20 commits into from
Oct 5, 2020
Merged
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion contracts/cw1-whitelist/Cargo.toml
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ cosmwasm-std = { version = "0.11.0-alpha3", features = ["iterator"] }
cosmwasm-storage = { version = "0.11.0-alpha3", features = ["iterator"] }
schemars = "0.7"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
snafu = { version = "0.6.3" }
thiserror = { version = "1.0.20" }

[dev-dependencies]
cosmwasm-schema = { version = "0.11.0-alpha3" }
27 changes: 14 additions & 13 deletions contracts/cw1-whitelist/src/contract.rs
Original file line number Diff line number Diff line change
@@ -3,11 +3,12 @@ use std::fmt;

use cosmwasm_std::{
attr, to_binary, Api, Binary, CanonicalAddr, CosmosMsg, Empty, Env, Extern, HandleResponse,
HumanAddr, InitResponse, Querier, StdError, StdResult, Storage,
HumanAddr, InitResponse, Querier, StdResult, Storage,
};
use cw1::CanSendResponse;
use cw2::set_contract_version;

use crate::error::ContractError;
use crate::msg::{AdminListResponse, HandleMsg, InitMsg, QueryMsg};
use crate::state::{admin_list, admin_list_read, AdminList};

@@ -46,7 +47,7 @@ pub fn handle<S: Storage, A: Api, Q: Querier>(
// Note: implement this function with different type to add support for custom messages
// and then import the rest of this contract code.
msg: HandleMsg<Empty>,
) -> StdResult<HandleResponse<Empty>> {
) -> Result<HandleResponse<Empty>, ContractError> {
match msg {
HandleMsg::Execute { msgs } => handle_execute(deps, env, msgs),
HandleMsg::Freeze {} => handle_freeze(deps, env),
@@ -58,12 +59,12 @@ pub fn handle_execute<S: Storage, A: Api, Q: Querier, T>(
deps: &mut Extern<S, A, Q>,
env: Env,
msgs: Vec<CosmosMsg<T>>,
) -> StdResult<HandleResponse<T>>
) -> Result<HandleResponse<T>, ContractError>
where
T: Clone + fmt::Debug + PartialEq + JsonSchema,
{
if !can_send(&deps, &env.message.sender)? {
Err(StdError::unauthorized())
Err(ContractError::Unauthorized {})
} else {
let mut res = HandleResponse::default();
res.messages = msgs;
@@ -75,10 +76,10 @@ where
pub fn handle_freeze<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
env: Env,
) -> StdResult<HandleResponse> {
) -> Result<HandleResponse, ContractError> {
let mut cfg = admin_list_read(&deps.storage).load()?;
if !cfg.can_modify(&deps.api.canonical_address(&env.message.sender)?) {
Err(StdError::unauthorized())
Err(ContractError::Unauthorized {})
} else {
cfg.mutable = false;
admin_list(&mut deps.storage).save(&cfg)?;
@@ -93,10 +94,10 @@ pub fn handle_update_admins<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
env: Env,
admins: Vec<HumanAddr>,
) -> StdResult<HandleResponse> {
) -> Result<HandleResponse, ContractError> {
let mut cfg = admin_list_read(&deps.storage).load()?;
if !cfg.can_modify(&deps.api.canonical_address(&env.message.sender)?) {
Err(StdError::unauthorized())
Err(ContractError::Unauthorized {})
} else {
cfg.admins = map_canonical(&deps.api, &admins)?;
admin_list(&mut deps.storage).save(&cfg)?;
@@ -150,7 +151,7 @@ pub fn query_can_send<S: Storage, A: Api, Q: Querier>(
mod tests {
use super::*;
use cosmwasm_std::testing::{mock_dependencies, mock_env, MOCK_CONTRACT_ADDR};
use cosmwasm_std::{coin, coins, BankMsg, StakingMsg, StdError, WasmMsg};
use cosmwasm_std::{coin, coins, BankMsg, StakingMsg, WasmMsg};

const CANONICAL_LENGTH: usize = 20;

@@ -186,7 +187,7 @@ mod tests {
let env = mock_env(&anyone, &[]);
let res = handle(&mut deps, env, msg);
match res.unwrap_err() {
StdError::Unauthorized { .. } => {}
ContractError::Unauthorized { .. } => {}
e => panic!("unexpected error: {}", e),
}

@@ -208,7 +209,7 @@ mod tests {
let env = mock_env(&carl, &[]);
let res = handle(&mut deps, env, HandleMsg::Freeze {});
match res.unwrap_err() {
StdError::Unauthorized { .. } => {}
ContractError::Unauthorized { .. } => {}
e => panic!("unexpected error: {}", e),
}

@@ -228,7 +229,7 @@ mod tests {
let env = mock_env(&alice, &[]);
let res = handle(&mut deps, env, msg);
match res.unwrap_err() {
StdError::Unauthorized { .. } => {}
ContractError::Unauthorized { .. } => {}
e => panic!("unexpected error: {}", e),
}
}
@@ -272,7 +273,7 @@ mod tests {
let env = mock_env(&bob, &[]);
let res = handle(&mut deps, env, handle_msg.clone());
match res.unwrap_err() {
StdError::Unauthorized { .. } => {}
ContractError::Unauthorized { .. } => {}
e => panic!("unexpected error: {}", e),
}

11 changes: 11 additions & 0 deletions contracts/cw1-whitelist/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use cosmwasm_std::StdError;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum ContractError {
maurolacy marked this conversation as resolved.
Show resolved Hide resolved
#[error("{0}")]
Std(#[from] StdError),

#[error("Unauthorized")]
Unauthorized {},
}
1 change: 1 addition & 0 deletions contracts/cw1-whitelist/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod contract;
mod error;
pub mod msg;
pub mod state;