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

Add message_info and deprecate mock_info (backport #2160) #2161

Merged
merged 9 commits into from
Jun 3, 2024
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: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ and this project adheres to

[#2158]: https://github.com/CosmWasm/cosmwasm/pull/2158

### Changed

- cosmwasm-std: Add message_info and deprecate mock_info ([#2160])

[#2160]: https://github.com/CosmWasm/cosmwasm/pull/2160

## [2.0.3] - 2024-05-10

### Changed
Expand Down
6 changes: 5 additions & 1 deletion MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This guide explains what is needed to upgrade contracts when migrating over
major releases of `cosmwasm`. Note that you can also view the
[complete CHANGELOG](./CHANGELOG.md) to understand the differences.

## 1.5.x -> 2.0.0
## 1.5.x -> 2.0.x

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

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

- In test code, replace calls to `mock_info` with `message_info`. This takes a
`&Addr` as the first argument which you get by using owned `Addr` in the test
bodies.

## 1.4.x -> 1.5.0

- Update `cosmwasm-*` dependencies in Cargo.toml (skip the ones you don't use):
Expand Down
12 changes: 8 additions & 4 deletions contracts/burner/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn cleanup(storage: &mut dyn Storage, mut limit: usize) -> usize {
mod tests {
use super::*;
use cosmwasm_std::testing::{
mock_dependencies, mock_dependencies_with_balance, mock_env, mock_info,
message_info, mock_dependencies, mock_dependencies_with_balance, mock_env,
};
use cosmwasm_std::{coins, Attribute, StdError, Storage, SubMsg};

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

let creator = deps.api.addr_make("creator");

let msg = InstantiateMsg {};
let info = mock_info("creator", &coins(1000, "earth"));
let info = message_info(&creator, &coins(1000, "earth"));
// we can just call .unwrap() to assert this was a success
let res = instantiate(deps.as_mut(), mock_env(), info, msg);
match res.unwrap_err() {
Expand Down Expand Up @@ -164,6 +166,8 @@ mod tests {
fn execute_cleans_up_data() {
let mut deps = mock_dependencies_with_balance(&coins(123456, "gold"));

let anon = deps.api.addr_make("anon");

// store some sample data
deps.storage.set(b"foo", b"bar");
deps.storage.set(b"key2", b"data2");
Expand All @@ -179,7 +183,7 @@ mod tests {
let res = execute(
deps.as_mut(),
mock_env(),
mock_info("anon", &[]),
message_info(&anon, &[]),
ExecuteMsg::Cleanup { limit: Some(2) },
)
.unwrap();
Expand All @@ -192,7 +196,7 @@ mod tests {
let res = execute(
deps.as_mut(),
mock_env(),
mock_info("anon", &[]),
message_info(&anon, &[]),
ExecuteMsg::Cleanup { limit: Some(2) },
)
.unwrap();
Expand Down
5 changes: 3 additions & 2 deletions contracts/crypto-verify/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ pub fn query_list_verifications(deps: Deps) -> StdResult<ListVerificationsRespon
mod tests {
use super::*;
use cosmwasm_std::testing::{
mock_dependencies, mock_env, mock_info, MockApi, MockQuerier, MockStorage,
message_info, mock_dependencies, mock_env, MockApi, MockQuerier, MockStorage,
};
use cosmwasm_std::{
from_json, Binary, OwnedDeps, RecoverPubkeyError, StdError, VerificationError,
Expand Down Expand Up @@ -247,8 +247,9 @@ mod tests {

fn setup() -> OwnedDeps<MockStorage, MockApi, MockQuerier> {
let mut deps = mock_dependencies();
let creator = deps.api.addr_make(CREATOR);
let msg = InstantiateMsg {};
let info = mock_info(CREATOR, &[]);
let info = message_info(&creator, &[]);
let res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
assert_eq!(0, res.messages.len());
deps
Expand Down
8 changes: 5 additions & 3 deletions contracts/cyberpunk/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,15 @@ fn query_denom(deps: Deps, denom: String) -> StdResult<DenomMetadata> {
mod tests {
use super::*;
use cosmwasm_std::testing::{
mock_dependencies, mock_env, mock_info, MockApi, MockQuerier, MockStorage,
message_info, mock_dependencies, mock_env, MockApi, MockQuerier, MockStorage,
};
use cosmwasm_std::{from_json, DenomMetadata, DenomUnit, OwnedDeps};

fn setup() -> OwnedDeps<MockStorage, MockApi, MockQuerier> {
let mut deps = mock_dependencies();
let creator = deps.api.addr_make("creator");
let msg = Empty {};
let info = mock_info("creator", &[]);
let info = message_info(&creator, &[]);
let res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
assert_eq!(0, res.messages.len());
deps
Expand All @@ -250,9 +251,10 @@ mod tests {
#[test]
fn debug_works() {
let mut deps = setup();
let caller = deps.api.addr_make("caller");

let msg = ExecuteMsg::Debug {};
execute(deps.as_mut(), mock_env(), mock_info("caller", &[]), msg).unwrap();
execute(deps.as_mut(), mock_env(), message_info(&caller, &[]), msg).unwrap();
}

#[test]
Expand Down
Loading
Loading