diff --git a/CHANGELOG.md b/CHANGELOG.md index b4e3cea2fe..f13690e319 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,8 +75,9 @@ and this project adheres to - cosmwasm-std: Add `QueryRequest::Grpc` and deprecate `QueryRequest::Stargate`. ([#1973]) - cosmwasm-std: Remove `update_balance`, `set_denom_metadata`, - `set_withdraw_address`, `set_withdraw_addresses`, `clear_withdraw_addresses` - from `MockQuerier` and expose the underlying queriers directly. ([#1977]) + `set_withdraw_address`, `set_withdraw_addresses`, `clear_withdraw_addresses`, + `update_ibc` and `update_staking` from `MockQuerier` and expose the underlying + queriers directly. ([#1977]) [#1874]: https://github.com/CosmWasm/cosmwasm/pull/1874 [#1876]: https://github.com/CosmWasm/cosmwasm/pull/1876 diff --git a/MIGRATING.md b/MIGRATING.md index 097a7cd9d5..624fd74975 100644 --- a/MIGRATING.md +++ b/MIGRATING.md @@ -198,6 +198,10 @@ major releases of `cosmwasm`. Note that you can also view the +querier.bank.update_balance("addr", coins(1000, "ATOM")); -querier.set_withdraw_address("delegator", "withdrawer"); +querier.distribution.set_withdraw_address("delegator", "withdrawer"); + -querier.update_staking(denom, &[], &[]); + +querier.staking = StakingQuerier::new(denom, &[], &[]); + -querier.update_ibc(port_id, &[]); + +querier.ibc = IbcQuerier::new(port_id, &[]); ``` - If you were using `QueryRequest::Stargate`, you might want to enable the diff --git a/contracts/staking/src/contract.rs b/contracts/staking/src/contract.rs index 949c4bccf1..496d42e8a0 100644 --- a/contracts/staking/src/contract.rs +++ b/contracts/staking/src/contract.rs @@ -406,7 +406,7 @@ pub fn query_investment(deps: Deps) -> StdResult { mod tests { use super::*; use cosmwasm_std::testing::{ - mock_dependencies, mock_env, mock_info, MockQuerier, MOCK_CONTRACT_ADDR, + mock_dependencies, mock_env, mock_info, MockQuerier, StakingQuerier, MOCK_CONTRACT_ADDR, }; use cosmwasm_std::{coins, Addr, Coin, CosmosMsg, Decimal, FullDelegation, Validator}; use std::str::FromStr; @@ -431,11 +431,12 @@ mod tests { } fn set_validator(querier: &mut MockQuerier) { - querier.update_staking("ustake", &[sample_validator(DEFAULT_VALIDATOR)], &[]); + querier.staking = + StakingQuerier::new("ustake", &[sample_validator(DEFAULT_VALIDATOR)], &[]); } fn set_delegation(querier: &mut MockQuerier, amount: u128, denom: &str) { - querier.update_staking( + querier.staking = StakingQuerier::new( "ustake", &[sample_validator(DEFAULT_VALIDATOR)], &[sample_delegation(DEFAULT_VALIDATOR, coin(amount, denom))], @@ -466,8 +467,7 @@ mod tests { #[test] fn initialization_with_missing_validator() { let mut deps = mock_dependencies(); - deps.querier - .update_staking("ustake", &[sample_validator("john")], &[]); + deps.querier.staking = StakingQuerier::new("ustake", &[sample_validator("john")], &[]); let creator = deps.api.addr_make("creator").to_string(); let msg = InstantiateMsg { @@ -493,7 +493,7 @@ mod tests { #[test] fn proper_initialization() { let mut deps = mock_dependencies(); - deps.querier.update_staking( + deps.querier.staking = StakingQuerier::new( "ustake", &[ sample_validator("john"), diff --git a/packages/std/src/testing/mock.rs b/packages/std/src/testing/mock.rs index b9de939b35..aa9887a1b7 100644 --- a/packages/std/src/testing/mock.rs +++ b/packages/std/src/testing/mock.rs @@ -464,12 +464,12 @@ pub type MockQuerierCustomHandlerResult = SystemResult>; pub struct MockQuerier { pub bank: BankQuerier, #[cfg(feature = "staking")] - staking: StakingQuerier, + pub staking: StakingQuerier, #[cfg(feature = "cosmwasm_1_3")] pub distribution: DistributionQuerier, wasm: WasmQuerier, #[cfg(feature = "stargate")] - ibc: IbcQuerier, + pub ibc: IbcQuerier, /// A handler to handle custom queries. This is set to a dummy handler that /// always errors by default. Update it via `with_custom_handler`. /// @@ -497,21 +497,6 @@ impl MockQuerier { } } - #[cfg(feature = "staking")] - pub fn update_staking( - &mut self, - denom: &str, - validators: &[crate::query::Validator], - delegations: &[crate::query::FullDelegation], - ) { - self.staking = StakingQuerier::new(denom, validators, delegations); - } - - #[cfg(feature = "stargate")] - pub fn update_ibc(&mut self, port_id: &str, channels: &[IbcChannel]) { - self.ibc = IbcQuerier::new(port_id, channels); - } - pub fn update_wasm(&mut self, handler: WH) where WH: Fn(&WasmQuery) -> QuerierResult, diff --git a/packages/vm/src/testing/querier.rs b/packages/vm/src/testing/querier.rs index b0993c72bc..d3d9d04efc 100644 --- a/packages/vm/src/testing/querier.rs +++ b/packages/vm/src/testing/querier.rs @@ -42,7 +42,9 @@ impl MockQuerier { validators: &[cosmwasm_std::Validator], delegations: &[cosmwasm_std::FullDelegation], ) { - self.querier.update_staking(denom, validators, delegations); + use cosmwasm_std::testing::StakingQuerier; + + self.querier.staking = StakingQuerier::new(denom, validators, delegations); } pub fn update_wasm(&mut self, handler: WH)