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

Better error message with missing sudo (no parse error) #279

Merged
merged 1 commit into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions packages/multi-test/src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use cosmwasm_std::{
};
use cw_storage_plus::Item;

use crate::wasm::{Contract, ContractWrapper};
use crate::wasm::{Any, Contract, ContractWrapper};

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct EmptyMsg {}
Expand Down Expand Up @@ -37,7 +37,7 @@ fn query_error(_deps: Deps, _env: Env, _msg: EmptyMsg) -> Result<Binary, StdErro
}

pub fn contract_error() -> Box<dyn Contract<Empty>> {
let contract: ContractWrapper<_, _, _, _, _, _, _, String, String> =
let contract: ContractWrapper<_, _, _, _, _, _, _, Any, Any> =
ContractWrapper::new(handle_error, init_error, query_error);
Box::new(contract)
}
Expand All @@ -47,7 +47,7 @@ pub fn contract_error_custom<C>() -> Box<dyn Contract<C>>
where
C: Clone + fmt::Debug + PartialEq + JsonSchema + 'static,
{
let contract: ContractWrapper<_, _, _, _, _, _, _, String, String> =
let contract: ContractWrapper<_, _, _, _, _, _, _, Any, Any> =
ContractWrapper::new_with_empty(handle_error, init_error, query_error);
Box::new(contract)
}
Expand Down
16 changes: 14 additions & 2 deletions packages/multi-test/src/wasm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use schemars::JsonSchema;
use serde::de::DeserializeOwned;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::collections::HashMap;
use std::fmt;
use std::ops::Deref;
Expand All @@ -10,6 +10,18 @@ use cosmwasm_std::{
};

use crate::transactions::{RepLog, StorageTransaction};
use std::fmt::Formatter;

/// This is used as a placeholder type that can be anything
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct Any {}

// We couldn't use Empty as it didn't implement Display. Shall we upstream this?
maurolacy marked this conversation as resolved.
Show resolved Hide resolved
impl fmt::Display for Any {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("{Any}")
}
}

/// Interface to call into a Contract
pub trait Contract<T>
Expand Down Expand Up @@ -48,7 +60,7 @@ type QueryClosure<T, E> = Box<dyn Fn(Deps, Env, T) -> Result<Binary, E>>;

/// Wraps the exported functions from a contract and provides the normalized format
/// Place T4 and E4 at the end, as we just want default placeholders for most contracts that don't have sudo
pub struct ContractWrapper<T1, T2, T3, E1, E2, E3, C = Empty, T4 = String, E4 = String>
pub struct ContractWrapper<T1, T2, T3, E1, E2, E3, C = Empty, T4 = Any, E4 = Any>
Copy link
Member

@webmaster128 webmaster128 Apr 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you use T4 = Empty and E4 = String?

String is a great default error type. The only restrictions those types have is ToString. So requiring Display is more than necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm.. that might work and be a simpler solution.
Will try

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just approved your PR to that end

where
T1: DeserializeOwned,
T2: DeserializeOwned,
Expand Down