Skip to content

Commit f5c7fdb

Browse files
committed
Fix errors in contracts, fix scripts
1 parent 4c53801 commit f5c7fdb

File tree

32 files changed

+126
-131
lines changed

32 files changed

+126
-131
lines changed

contracts/burner/src/contract.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn instantiate(
1313
_info: MessageInfo,
1414
_msg: InstantiateMsg,
1515
) -> StdResult<Response> {
16-
Err(StdError::generic_err(
16+
Err(StdError::msg(
1717
"You can only use this contract for migrations",
1818
))
1919
}
@@ -23,7 +23,7 @@ pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> StdResult<Response>
2323
let denom_len = msg.denoms.len();
2424
let denoms = BTreeSet::<String>::from_iter(msg.denoms); // Ensure uniqueness
2525
if denoms.len() != denom_len {
26-
return Err(StdError::generic_err("Denoms not unique"));
26+
return Err(StdError::msg("Denoms not unique"));
2727
}
2828

2929
// get balance and send to recipient
@@ -121,12 +121,10 @@ mod tests {
121121
let info = message_info(&creator, &coins(1000, "earth"));
122122
// we can just call .unwrap() to assert this was a success
123123
let res = instantiate(deps.as_mut(), mock_env(), info, msg);
124-
match res.unwrap_err() {
125-
StdError::GenericErr { msg, .. } => {
126-
assert_eq!(msg, "You can only use this contract for migrations")
127-
}
128-
_ => panic!("expected migrate error message"),
129-
}
124+
assert!(res
125+
.unwrap_err()
126+
.to_string()
127+
.ends_with("You can only use this contract for migrations"));
130128
}
131129

132130
#[test]
@@ -142,10 +140,7 @@ mod tests {
142140
delete: 0,
143141
};
144142
let err = migrate(deps.as_mut(), mock_env(), msg).unwrap_err();
145-
match err {
146-
StdError::GenericErr { msg, .. } => assert_eq!(msg, "Denoms not unique"),
147-
err => panic!("Unexpected error: {err:?}"),
148-
}
143+
assert!(err.to_string().ends_with("Denoms not unique"));
149144

150145
// One denom
151146
let msg = MigrateMsg {

contracts/crypto-verify/src/contract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ pub fn query_verify_ethereum_text(
210210
// Decompose signature
211211
let (v, rs) = match signature.split_last() {
212212
Some(pair) => pair,
213-
None => return Err(StdError::generic_err("Signature must not be empty")),
213+
None => return Err(StdError::msg("Signature must not be empty")),
214214
};
215215
let recovery = get_recovery_param(*v)?;
216216

contracts/crypto-verify/src/ethereum.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub fn get_recovery_param(v: u8) -> StdResult<u8> {
7272
match v {
7373
27 => Ok(0),
7474
28 => Ok(1),
75-
_ => Err(StdError::generic_err("Values of v other than 27 and 28 not supported. Replay protection (EIP-155) cannot be used here."))
75+
_ => Err(StdError::msg("Values of v other than 27 and 28 not supported. Replay protection (EIP-155) cannot be used here."))
7676
}
7777
}
7878

@@ -87,7 +87,7 @@ pub fn get_recovery_param_with_chain_id(v: u64, chain_id: u64) -> StdResult<u8>
8787
let recovery = v - chain_id * 2 - 35;
8888
match recovery {
8989
0 | 1 => Ok(recovery as u8),
90-
_ => Err(StdError::generic_err(format!(
90+
_ => Err(StdError::msg(format_args!(
9191
"Calculated recovery parameter must be 0 or 1 but is {recovery}."
9292
))),
9393
}
@@ -97,13 +97,13 @@ pub fn get_recovery_param_with_chain_id(v: u64, chain_id: u64) -> StdResult<u8>
9797
pub fn ethereum_address_raw(pubkey: &[u8]) -> StdResult<[u8; 20]> {
9898
let (tag, data) = match pubkey.split_first() {
9999
Some(pair) => pair,
100-
None => return Err(StdError::generic_err("Public key must not be empty")),
100+
None => return Err(StdError::msg("Public key must not be empty")),
101101
};
102102
if *tag != 0x04 {
103-
return Err(StdError::generic_err("Public key must start with 0x04"));
103+
return Err(StdError::msg("Public key must start with 0x04"));
104104
}
105105
if data.len() != 64 {
106-
return Err(StdError::generic_err("Public key must be 65 bytes long"));
106+
return Err(StdError::msg("Public key must be 65 bytes long"));
107107
}
108108

109109
let hash = Keccak256::digest(data);
@@ -112,14 +112,12 @@ pub fn ethereum_address_raw(pubkey: &[u8]) -> StdResult<[u8; 20]> {
112112

113113
pub fn decode_address(input: &str) -> StdResult<[u8; 20]> {
114114
if input.len() != 42 {
115-
return Err(StdError::generic_err(
116-
"Ethereum address must be 42 characters long",
117-
));
115+
return Err(StdError::msg("Ethereum address must be 42 characters long"));
118116
}
119117
if !input.starts_with("0x") {
120-
return Err(StdError::generic_err("Ethereum address must start with 0x"));
118+
return Err(StdError::msg("Ethereum address must start with 0x"));
121119
}
122-
let data = hex::decode(&input[2..]).map_err(|_| StdError::generic_err("hex decoding error"))?;
120+
let data = hex::decode(&input[2..])?;
123121
Ok(data.try_into().unwrap())
124122
}
125123

contracts/cyberpunk/src/contract.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +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)
60-
.map_err(|e| StdError::generic_err(format!("hash_encoded errored: {e}")))?;
59+
let hash = argon2::hash_encoded(password, salt, &config)?;
6160
// let matches = argon2::verify_encoded(&hash, password).unwrap();
6261
// assert!(matches);
6362
Ok(Response::new().set_data(hash.into_bytes()))
@@ -106,13 +105,13 @@ fn execute_allocate_large_memory(pages: u32) -> Result<Response, ContractError>
106105
use core::arch::wasm32;
107106
let old_size = wasm32::memory_grow(0, pages as usize);
108107
if old_size == usize::max_value() {
109-
return Err(StdError::generic_err("memory.grow failed").into());
108+
return Err(StdError::msg("memory.grow failed").into());
110109
}
111110
Ok(Response::new().set_data((old_size as u32).to_be_bytes()))
112111
}
113112

114113
#[cfg(not(target_arch = "wasm32"))]
115-
Err(StdError::generic_err("Unsupported architecture").into())
114+
Err(StdError::msg("Unsupported architecture").into())
116115
}
117116

118117
fn execute_panic() -> Result<Response, ContractError> {
@@ -139,7 +138,7 @@ fn execute_unreachable() -> Result<Response, ContractError> {
139138
core::arch::wasm32::unreachable();
140139

141140
#[cfg(not(target_arch = "wasm32"))]
142-
Err(StdError::generic_err("Unsupported architecture").into())
141+
Err(StdError::msg("Unsupported architecture").into())
143142
}
144143

145144
fn execute_mirror_env(env: Env) -> Result<Response, ContractError> {

contracts/hackatom/src/contract.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use sha2::{Digest, Sha256};
33
use cosmwasm_std::{
44
entry_point, from_json, to_json_binary, to_json_vec, Addr, Api, BankMsg, CanonicalAddr, Deps,
55
DepsMut, Env, Event, MessageInfo, MigrateInfo, QueryRequest, QueryResponse, Response, StdError,
6-
StdResult, WasmMsg, WasmQuery,
6+
StdErrorKind, StdResult, WasmMsg, WasmQuery,
77
};
88

99
use crate::errors::HackError;
@@ -171,13 +171,13 @@ fn do_allocate_large_memory(pages: u32) -> Result<Response, HackError> {
171171
use core::arch::wasm32;
172172
let old_size = wasm32::memory_grow(0, pages as usize);
173173
if old_size == usize::max_value() {
174-
return Err(StdError::generic_err("memory.grow failed").into());
174+
return Err(StdError::msg("memory.grow failed").into());
175175
}
176176
Ok(Response::new().set_data((old_size as u32).to_be_bytes()))
177177
}
178178

179179
#[cfg(not(target_arch = "wasm32"))]
180-
Err(StdError::generic_err("Unsupported architecture").into())
180+
Err(StdError::msg("Unsupported architecture").into())
181181
}
182182

183183
fn do_panic() -> Result<Response, HackError> {
@@ -203,32 +203,32 @@ fn do_user_errors_in_api_calls(api: &dyn Api) -> Result<Response, HackError> {
203203
// Canonicalize
204204

205205
let empty = "";
206-
match api.addr_canonicalize(empty).unwrap_err() {
207-
StdError::GenericErr { .. } => {}
206+
match api.addr_canonicalize(empty).unwrap_err().kind() {
207+
StdErrorKind::Other => {}
208208
err => {
209-
return Err(StdError::generic_err(format!(
209+
return Err(StdError::msg(format_args!(
210210
"Unexpected error in do_user_errors_in_api_calls: {err:?}"
211211
))
212212
.into())
213213
}
214214
}
215215

216216
let invalid = "bn9hhssomeltvhzgvuqkwjkpwxoj";
217-
match api.addr_canonicalize(invalid).unwrap_err() {
218-
StdError::GenericErr { .. } => {}
217+
match api.addr_canonicalize(invalid).unwrap_err().kind() {
218+
StdErrorKind::Other => {}
219219
err => {
220-
return Err(StdError::generic_err(format!(
220+
return Err(StdError::msg(format_args!(
221221
"Unexpected error in do_user_errors_in_api_calls: {err:?}"
222222
))
223223
.into())
224224
}
225225
}
226226

227227
let too_long = "cosmwasm1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqehqqkz";
228-
match api.addr_canonicalize(too_long).unwrap_err() {
229-
StdError::GenericErr { .. } => {}
228+
match api.addr_canonicalize(too_long).unwrap_err().kind() {
229+
StdErrorKind::Other => {}
230230
err => {
231-
return Err(StdError::generic_err(format!(
231+
return Err(StdError::msg(format_args!(
232232
"Unexpected error in do_user_errors_in_api_calls: {err:?}"
233233
))
234234
.into())
@@ -237,10 +237,10 @@ fn do_user_errors_in_api_calls(api: &dyn Api) -> Result<Response, HackError> {
237237

238238
// Humanize
239239
let empty: CanonicalAddr = vec![].into();
240-
match api.addr_humanize(&empty).unwrap_err() {
241-
StdError::GenericErr { .. } => {}
240+
match api.addr_humanize(&empty).unwrap_err().kind() {
241+
StdErrorKind::Other => {}
242242
err => {
243-
return Err(StdError::generic_err(format!(
243+
return Err(StdError::msg(format_args!(
244244
"Unexpected error in do_user_errors_in_api_calls: {err:?}"
245245
))
246246
.into())

contracts/ibc-callbacks/src/contract.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn execute_transfer(
6565
let coin = match &*info.funds {
6666
[coin] if !coin.amount.is_zero() => coin,
6767
_ => {
68-
return Err(StdError::generic_err(
68+
return Err(StdError::msg(
6969
"Must send exactly one denom to trigger ics-20 transfer",
7070
))
7171
}
@@ -142,7 +142,7 @@ pub fn ibc_destination_callback(
142142
.query_balance(&transfer.receiver, &coin.denom)?;
143143
ensure!(
144144
balance.amount >= coin.amount,
145-
StdError::generic_err(format!(
145+
StdError::msg(format_args!(
146146
"Didn't receive expected funds. expected: {coin}, have: {balance}"
147147
))
148148
);

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn handle_update_admin(
5050
// auth check
5151
let mut cfg = load_config(deps.storage)?;
5252
if info.sender != cfg.admin {
53-
return Err(StdError::generic_err("Only admin may set new admin"));
53+
return Err(StdError::msg("Only admin may set new admin"));
5454
}
5555
cfg.admin = deps.api.addr_validate(&new_admin)?;
5656
save_config(deps.storage, &cfg)?;
@@ -70,7 +70,7 @@ pub fn handle_send_msgs(
7070
// auth check
7171
let cfg = load_config(deps.storage)?;
7272
if info.sender != cfg.admin {
73-
return Err(StdError::generic_err("Only admin may send messages"));
73+
return Err(StdError::msg("Only admin may send messages"));
7474
}
7575
// ensure the channel exists (not found if not registered)
7676
load_account(deps.storage, &channel_id)?;
@@ -98,7 +98,7 @@ pub fn handle_check_remote_balance(
9898
// auth check
9999
let cfg = load_config(deps.storage)?;
100100
if info.sender != cfg.admin {
101-
return Err(StdError::generic_err("Only admin may send messages"));
101+
return Err(StdError::msg("Only admin may send messages"));
102102
}
103103
// ensure the channel exists (not found if not registered)
104104
load_account(deps.storage, &channel_id)?;
@@ -130,22 +130,22 @@ pub fn handle_send_funds(
130130
let amount = match info.funds.pop() {
131131
Some(coin) => coin,
132132
None => {
133-
return Err(StdError::generic_err(
133+
return Err(StdError::msg(
134134
"you must send the coins you wish to ibc transfer",
135135
))
136136
}
137137
};
138138
// if there are any more coins, reject the message
139139
if !info.funds.is_empty() {
140-
return Err(StdError::generic_err("you can only ibc transfer one coin"));
140+
return Err(StdError::msg("you can only ibc transfer one coin"));
141141
}
142142

143143
// load remote account
144144
let data = load_account(deps.storage, &reflect_channel_id)?;
145145
let remote_addr = match data.remote_addr {
146146
Some(addr) => addr,
147147
None => {
148-
return Err(StdError::generic_err(
148+
return Err(StdError::msg(
149149
"We don't have the remote address for this channel",
150150
))
151151
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ pub fn ibc_channel_open(
2626
let channel = msg.channel();
2727

2828
if channel.order != IbcOrder::Ordered {
29-
return Err(StdError::generic_err("Only supports ordered channels"));
29+
return Err(StdError::msg("Only supports ordered channels"));
3030
}
3131
if channel.version.as_str() != IBC_APP_VERSION {
32-
return Err(StdError::generic_err(format!(
32+
return Err(StdError::msg(format_args!(
3333
"Must set version to `{IBC_APP_VERSION}`"
3434
)));
3535
}
3636

3737
if let Some(counter_version) = msg.counterparty_version() {
3838
if counter_version != IBC_APP_VERSION {
39-
return Err(StdError::generic_err(format!(
39+
return Err(StdError::msg(format_args!(
4040
"Counterparty version must be `{IBC_APP_VERSION}`"
4141
)));
4242
}
@@ -165,7 +165,7 @@ fn acknowledge_who_am_i(
165165
}
166166
save_account(deps.storage, &caller, &acct)?;
167167
}
168-
None => return Err(StdError::generic_err("no account to update")),
168+
None => return Err(StdError::msg("no account to update")),
169169
}
170170

171171
Ok(IbcBasicResponse::new().add_attribute("action", "acknowledge_who_am_i"))
@@ -192,7 +192,7 @@ fn acknowledge_balances(
192192
Some(acct) => {
193193
if let Some(old_addr) = acct.remote_addr {
194194
if old_addr != account {
195-
return Err(StdError::generic_err(format!(
195+
return Err(StdError::msg(format_args!(
196196
"remote account changed from {old_addr} to {account}"
197197
)));
198198
}
@@ -207,7 +207,7 @@ fn acknowledge_balances(
207207
},
208208
)?;
209209
}
210-
None => return Err(StdError::generic_err("no account to update")),
210+
None => return Err(StdError::msg("no account to update")),
211211
}
212212

213213
Ok(IbcBasicResponse::new().add_attribute("action", "acknowledge_balances"))

0 commit comments

Comments
 (0)