Skip to content

Commit 4c9d104

Browse files
committed
Fix all contract tests
1 parent f5c7fdb commit 4c9d104

File tree

18 files changed

+91
-72
lines changed

18 files changed

+91
-72
lines changed

contracts/burner/src/contract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ mod tests {
9898
use cosmwasm_std::testing::{
9999
message_info, mock_dependencies, mock_dependencies_with_balance, mock_env,
100100
};
101-
use cosmwasm_std::{coin, coins, Attribute, StdError, Storage, SubMsg};
101+
use cosmwasm_std::{coin, coins, Attribute, Storage, SubMsg};
102102

103103
/// Gets the value of the first attribute with the given key
104104
fn first_attr(data: impl AsRef<[Attribute]>, search_key: &str) -> Option<String> {

contracts/crypto-verify/src/contract.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ mod tests {
326326
use cosmwasm_std::testing::{
327327
message_info, mock_dependencies, mock_env, MockApi, MockQuerier, MockStorage,
328328
};
329-
use cosmwasm_std::{from_json, OwnedDeps, RecoverPubkeyError, VerificationError};
329+
use cosmwasm_std::{from_json, OwnedDeps, StdErrorKind};
330330
use hex_literal::hex;
331331

332332
const CREATOR: &str = "creator";
@@ -426,11 +426,8 @@ mod tests {
426426
let res = query(deps.as_ref(), mock_env(), verify_msg);
427427
assert!(res.is_err());
428428
assert!(matches!(
429-
res.unwrap_err(),
430-
StdError::VerificationErr {
431-
source: VerificationError::InvalidPubkeyFormat,
432-
..
433-
}
429+
res.unwrap_err().kind(),
430+
StdErrorKind::Cryptography,
434431
))
435432
}
436433

@@ -500,11 +497,8 @@ mod tests {
500497
signer_address: signer_address.into(),
501498
};
502499
let result = query(deps.as_ref(), mock_env(), verify_msg);
503-
match result.unwrap_err() {
504-
StdError::RecoverPubkeyErr {
505-
source: RecoverPubkeyError::UnknownErr { .. },
506-
..
507-
} => {}
500+
match result.unwrap_err().kind() {
501+
StdErrorKind::Cryptography => {}
508502
err => panic!("Unexpected error: {err:?}"),
509503
}
510504
}
@@ -715,11 +709,8 @@ mod tests {
715709
let res = query(deps.as_ref(), mock_env(), verify_msg);
716710
assert!(res.is_err());
717711
assert!(matches!(
718-
res.unwrap_err(),
719-
StdError::VerificationErr {
720-
source: VerificationError::InvalidPubkeyFormat,
721-
..
722-
}
712+
res.unwrap_err().kind(),
713+
StdErrorKind::Cryptography
723714
))
724715
}
725716

@@ -781,11 +772,8 @@ mod tests {
781772
let res = query(deps.as_ref(), mock_env(), verify_msg);
782773
assert!(res.is_err());
783774
assert!(matches!(
784-
res.unwrap_err(),
785-
StdError::VerificationErr {
786-
source: VerificationError::InvalidPubkeyFormat,
787-
..
788-
}
775+
res.unwrap_err().kind(),
776+
StdErrorKind::Cryptography,
789777
))
790778
}
791779

contracts/cyberpunk/src/contract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn execute_argon2(mem_cost: u32, time_cost: u32) -> Result<Response, ContractErr
5656
ad: &[],
5757
hash_length: 32,
5858
};
59-
let hash = argon2::hash_encoded(password, salt, &config)?;
59+
let hash = argon2::hash_encoded(password, salt, &config).map_err(StdError::from)?;
6060
// let matches = argon2::verify_encoded(&hash, password).unwrap();
6161
// assert!(matches);
6262
Ok(Response::new().set_data(hash.into_bytes()))

contracts/cyberpunk/src/errors.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
use cosmwasm_std::StdError;
22
use thiserror::Error;
33

4-
#[derive(Error, Debug, PartialEq)]
4+
#[derive(Error, Debug)]
55
pub enum ContractError {
66
#[error("{0}")]
77
/// this is needed so we can use `bucket.load(...)?` and have it auto-converted to the custom error
8-
Std(#[from] StdError),
8+
Std(StdError),
9+
}
10+
11+
impl From<StdError> for ContractError {
12+
fn from(err: StdError) -> Self {
13+
Self::Std(err)
14+
}
915
}

contracts/hackatom/src/contract.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn migrate(
5353
let data = deps
5454
.storage
5555
.get(CONFIG_KEY)
56-
.ok_or_else(|| StdError::not_found("State"))?;
56+
.ok_or_else(|| StdError::msg("State"))?;
5757
let mut config: State = from_json(data)?;
5858
config.verifier = deps.api.addr_validate(&msg.verifier)?;
5959
deps.storage.set(CONFIG_KEY, &to_json_vec(&config)?);
@@ -102,7 +102,7 @@ fn do_release(
102102
let data = deps
103103
.storage
104104
.get(CONFIG_KEY)
105-
.ok_or_else(|| StdError::not_found("State"))?;
105+
.ok_or_else(|| StdError::msg("State"))?;
106106
let state: State = from_json(data)?;
107107

108108
if info.sender == state.verifier {
@@ -265,7 +265,7 @@ fn query_verifier(deps: Deps) -> StdResult<VerifierResponse> {
265265
let data = deps
266266
.storage
267267
.get(CONFIG_KEY)
268-
.ok_or_else(|| StdError::not_found("State"))?;
268+
.ok_or_else(|| StdError::msg("State"))?;
269269
let state: State = from_json(data)?;
270270
Ok(VerifierResponse {
271271
verifier: state.verifier.into(),
@@ -582,7 +582,7 @@ mod tests {
582582
denom: "earth".to_string(),
583583
},
584584
);
585-
assert_eq!(execute_res.unwrap_err(), HackError::Unauthorized {});
585+
assert_eq!(execute_res.unwrap_err().to_string(), "Unauthorized");
586586

587587
// state should not change
588588
let data = deps.storage.get(CONFIG_KEY).expect("no data stored");

contracts/hackatom/src/errors.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
use cosmwasm_std::StdError;
22
use thiserror::Error;
33

4-
#[derive(Error, Debug, PartialEq)]
4+
#[derive(Error, Debug)]
55
pub enum HackError {
66
#[error("{0}")]
77
/// this is needed so we can use `bucket.load(...)?` and have it auto-converted to the custom error
8-
Std(#[from] StdError),
8+
Std(StdError),
99
// this is whatever we want
1010
#[error("Unauthorized")]
1111
Unauthorized {},
1212
// this is whatever we want
1313
#[error("Downgrade is not supported")]
1414
Downgrade,
1515
}
16+
17+
impl From<StdError> for HackError {
18+
fn from(err: StdError) -> Self {
19+
Self::Std(err)
20+
}
21+
}

contracts/ibc-callbacks/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn save_stats(storage: &mut dyn Storage, counts: &CallbackStats) -> StdResul
2929
fn load_item<T: DeserializeOwned>(storage: &dyn Storage, key: &[u8]) -> StdResult<T> {
3030
storage
3131
.get(&to_length_prefixed(key))
32-
.ok_or_else(|| StdError::not_found(type_name::<T>()))
32+
.ok_or_else(|| StdError::msg(type_name::<T>()))
3333
.and_then(from_json)
3434
}
3535

contracts/ibc-reflect-send/src/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn may_load_account(storage: &dyn Storage, id: &str) -> StdResult<Option<Acc
3838
}
3939

4040
pub fn load_account(storage: &dyn Storage, id: &str) -> StdResult<AccountData> {
41-
may_load_account(storage, id)?.ok_or_else(|| StdError::not_found(format!("account {id}")))
41+
may_load_account(storage, id)?.ok_or_else(|| StdError::msg(format!("account {id}")))
4242
}
4343

4444
pub fn save_account(storage: &mut dyn Storage, id: &str, account: &AccountData) -> StdResult<()> {
@@ -71,7 +71,7 @@ pub fn range_accounts(
7171
pub fn load_config(storage: &dyn Storage) -> StdResult<Config> {
7272
storage
7373
.get(&to_length_prefixed(KEY_CONFIG))
74-
.ok_or_else(|| StdError::not_found("config"))
74+
.ok_or_else(|| StdError::msg("config"))
7575
.and_then(from_json)
7676
}
7777

contracts/ibc-reflect/src/contract.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ mod tests {
560560
from_json(res.acknowledgement.unwrap()).unwrap();
561561
assert_eq!(
562562
ack.unwrap_err(),
563-
"invalid packet: account channel-123 not found"
563+
"invalid packet: kind: Other, error: account channel-123"
564564
);
565565

566566
// register the channel
@@ -610,7 +610,7 @@ mod tests {
610610
// acknowledgement is an error
611611
let ack: AcknowledgementMsg<DispatchResponse> =
612612
from_json(res.acknowledgement.unwrap()).unwrap();
613-
assert_eq!(ack.unwrap_err(), "invalid packet: Error parsing into type ibc_reflect::msg::PacketMsg: unknown variant `reflect_code_id`, expected one of `dispatch`, `who_am_i`, `balance`, `panic`, `return_err`, `return_msgs`, `no_ack` at line 1 column 18");
613+
assert_eq!(ack.unwrap_err(), "invalid packet: kind: Serialization, error: unknown variant `reflect_code_id`, expected one of `dispatch`, `who_am_i`, `balance`, `panic`, `return_err`, `return_msgs`, `no_ack` at line 1 column 18");
614614
}
615615

616616
#[test]

contracts/ibc-reflect/src/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn may_load_account(storage: &dyn Storage, id: &str) -> StdResult<Option<Add
2727
}
2828

2929
pub fn load_account(storage: &dyn Storage, id: &str) -> StdResult<Addr> {
30-
may_load_account(storage, id)?.ok_or_else(|| StdError::not_found(format!("account {id}")))
30+
may_load_account(storage, id)?.ok_or_else(|| StdError::msg(format!("account {id}")))
3131
}
3232

3333
pub fn save_account(storage: &mut dyn Storage, id: &str, account: &Addr) -> StdResult<()> {
@@ -60,7 +60,7 @@ pub fn range_accounts(
6060
pub fn load_item<T: DeserializeOwned>(storage: &dyn Storage, key: &[u8]) -> StdResult<T> {
6161
storage
6262
.get(&to_length_prefixed(key))
63-
.ok_or_else(|| StdError::not_found(type_name::<T>()))
63+
.ok_or_else(|| StdError::msg(type_name::<T>()))
6464
.and_then(from_json)
6565
}
6666

0 commit comments

Comments
 (0)