Skip to content

Commit

Permalink
Remove update_* functions from MockQuerier
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Dec 21, 2023
1 parent d7d03a6 commit 97b527c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 26 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions contracts/staking/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ pub fn query_investment(deps: Deps) -> StdResult<InvestmentResponse> {
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;
Expand All @@ -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))],
Expand Down Expand Up @@ -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 {
Expand All @@ -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"),
Expand Down
19 changes: 2 additions & 17 deletions packages/std/src/testing/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,12 @@ pub type MockQuerierCustomHandlerResult = SystemResult<ContractResult<Binary>>;
pub struct MockQuerier<C: DeserializeOwned = Empty> {
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`.
///
Expand Down Expand Up @@ -497,21 +497,6 @@ impl<C: DeserializeOwned> MockQuerier<C> {
}
}

#[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<WH: 'static>(&mut self, handler: WH)
where
WH: Fn(&WasmQuery) -> QuerierResult,
Expand Down
4 changes: 3 additions & 1 deletion packages/vm/src/testing/querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ impl<C: CustomQuery + DeserializeOwned> MockQuerier<C> {
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<WH: 'static>(&mut self, handler: WH)
Expand Down

0 comments on commit 97b527c

Please sign in to comment.