Skip to content

Commit 76479b3

Browse files
authored
Merge pull request #2160 from CosmWasm/add-message_info
Add message_info and deprecate mock_info
2 parents af4b239 + b4d551e commit 76479b3

File tree

17 files changed

+323
-176
lines changed

17 files changed

+323
-176
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ and this project adheres to
8080
- cosmwasm-vm: Update wasmer to 4.3.1 ([#2147], [#2153])
8181
- cosmwasm-vm: Rebalance gas costs for cryptographic functions and wasm
8282
instructions. ([#2152])
83+
- cosmwasm-std: Add message_info and deprecate mock_info ([#2160])
8384

8485
[#2044]: https://github.com/CosmWasm/cosmwasm/pull/2044
8586
[#2051]: https://github.com/CosmWasm/cosmwasm/pull/2051
@@ -92,6 +93,7 @@ and this project adheres to
9293
[#2147]: https://github.com/CosmWasm/cosmwasm/pull/2147
9394
[#2152]: https://github.com/CosmWasm/cosmwasm/pull/2152
9495
[#2153]: https://github.com/CosmWasm/cosmwasm/pull/2153
96+
[#2160]: https://github.com/CosmWasm/cosmwasm/pull/2160
9597

9698
## [2.0.1] - 2024-04-03
9799

MIGRATING.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This guide explains what is needed to upgrade contracts when migrating over
44
major releases of `cosmwasm`. Note that you can also view the
55
[complete CHANGELOG](./CHANGELOG.md) to understand the differences.
66

7-
## 1.5.x -> 2.0.0
7+
## 1.5.x -> 2.0.x
88

99
- Update `cosmwasm-*` dependencies in Cargo.toml (skip the ones you don't use):
1010

@@ -262,6 +262,10 @@ major releases of `cosmwasm`. Note that you can also view the
262262
in 2.0. To keep the CosmWasm 1.x behaviour, just set payload to
263263
`Binary::default()`.
264264

265+
- In test code, replace calls to `mock_info` with `message_info`. This takes a
266+
`&Addr` as the first argument which you get by using owned `Addr` in the test
267+
bodies.
268+
265269
## 1.4.x -> 1.5.0
266270

267271
- Update `cosmwasm-*` dependencies in Cargo.toml (skip the ones you don't use):

contracts/burner/src/contract.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn cleanup(storage: &mut dyn Storage, mut limit: usize) -> usize {
8383
mod tests {
8484
use super::*;
8585
use cosmwasm_std::testing::{
86-
mock_dependencies, mock_dependencies_with_balance, mock_env, mock_info,
86+
message_info, mock_dependencies, mock_dependencies_with_balance, mock_env,
8787
};
8888
use cosmwasm_std::{coins, Attribute, StdError, Storage, SubMsg};
8989

@@ -102,8 +102,10 @@ mod tests {
102102
fn instantiate_fails() {
103103
let mut deps = mock_dependencies();
104104

105+
let creator = deps.api.addr_make("creator");
106+
105107
let msg = InstantiateMsg {};
106-
let info = mock_info("creator", &coins(1000, "earth"));
108+
let info = message_info(&creator, &coins(1000, "earth"));
107109
// we can just call .unwrap() to assert this was a success
108110
let res = instantiate(deps.as_mut(), mock_env(), info, msg);
109111
match res.unwrap_err() {
@@ -164,6 +166,8 @@ mod tests {
164166
fn execute_cleans_up_data() {
165167
let mut deps = mock_dependencies_with_balance(&coins(123456, "gold"));
166168

169+
let anon = deps.api.addr_make("anon");
170+
167171
// store some sample data
168172
deps.storage.set(b"foo", b"bar");
169173
deps.storage.set(b"key2", b"data2");
@@ -179,7 +183,7 @@ mod tests {
179183
let res = execute(
180184
deps.as_mut(),
181185
mock_env(),
182-
mock_info("anon", &[]),
186+
message_info(&anon, &[]),
183187
ExecuteMsg::Cleanup { limit: Some(2) },
184188
)
185189
.unwrap();
@@ -192,7 +196,7 @@ mod tests {
192196
let res = execute(
193197
deps.as_mut(),
194198
mock_env(),
195-
mock_info("anon", &[]),
199+
message_info(&anon, &[]),
196200
ExecuteMsg::Cleanup { limit: Some(2) },
197201
)
198202
.unwrap();

contracts/crypto-verify/src/contract.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ pub fn query_verify_bls12_pairing_g2(
324324
mod tests {
325325
use super::*;
326326
use cosmwasm_std::testing::{
327-
mock_dependencies, mock_env, mock_info, MockApi, MockQuerier, MockStorage,
327+
message_info, mock_dependencies, mock_env, MockApi, MockQuerier, MockStorage,
328328
};
329329
use cosmwasm_std::{from_json, OwnedDeps, RecoverPubkeyError, VerificationError};
330330
use hex_literal::hex;
@@ -354,8 +354,9 @@ mod tests {
354354

355355
fn setup() -> OwnedDeps<MockStorage, MockApi, MockQuerier> {
356356
let mut deps = mock_dependencies();
357+
let creator = deps.api.addr_make(CREATOR);
357358
let msg = InstantiateMsg {};
358-
let info = mock_info(CREATOR, &[]);
359+
let info = message_info(&creator, &[]);
359360
let res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
360361
assert_eq!(0, res.messages.len());
361362
deps

contracts/cyberpunk/src/contract.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,15 @@ fn query_denom(deps: Deps, denom: String) -> StdResult<DenomMetadata> {
227227
mod tests {
228228
use super::*;
229229
use cosmwasm_std::testing::{
230-
mock_dependencies, mock_env, mock_info, MockApi, MockQuerier, MockStorage,
230+
message_info, mock_dependencies, mock_env, MockApi, MockQuerier, MockStorage,
231231
};
232232
use cosmwasm_std::{from_json, DenomMetadata, DenomUnit, OwnedDeps};
233233

234234
fn setup() -> OwnedDeps<MockStorage, MockApi, MockQuerier> {
235235
let mut deps = mock_dependencies();
236+
let creator = deps.api.addr_make("creator");
236237
let msg = Empty {};
237-
let info = mock_info("creator", &[]);
238+
let info = message_info(&creator, &[]);
238239
let res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
239240
assert_eq!(0, res.messages.len());
240241
deps
@@ -248,9 +249,10 @@ mod tests {
248249
#[test]
249250
fn debug_works() {
250251
let mut deps = setup();
252+
let caller = deps.api.addr_make("caller");
251253

252254
let msg = ExecuteMsg::Debug {};
253-
execute(deps.as_mut(), mock_env(), mock_info("caller", &[]), msg).unwrap();
255+
execute(deps.as_mut(), mock_env(), message_info(&caller, &[]), msg).unwrap();
254256
}
255257

256258
#[test]

0 commit comments

Comments
 (0)