Skip to content

Commit 90d0432

Browse files
committed
Remove update_* functions from MockQuerier
1 parent d7d03a6 commit 90d0432

File tree

5 files changed

+35
-25
lines changed

5 files changed

+35
-25
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ and this project adheres to
7575
- cosmwasm-std: Add `QueryRequest::Grpc` and deprecate `QueryRequest::Stargate`.
7676
([#1973])
7777
- cosmwasm-std: Remove `update_balance`, `set_denom_metadata`,
78-
`set_withdraw_address`, `set_withdraw_addresses`, `clear_withdraw_addresses`
79-
from `MockQuerier` and expose the underlying queriers directly. ([#1977])
78+
`set_withdraw_address`, `set_withdraw_addresses`, `clear_withdraw_addresses`,
79+
`update_ibc` and `update_staking` from `MockQuerier` and expose the underlying
80+
queriers directly. ([#1977])
8081

8182
[#1874]: https://github.com/CosmWasm/cosmwasm/pull/1874
8283
[#1876]: https://github.com/CosmWasm/cosmwasm/pull/1876

MIGRATING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ major releases of `cosmwasm`. Note that you can also view the
198198
+querier.bank.update_balance("addr", coins(1000, "ATOM"));
199199
-querier.set_withdraw_address("delegator", "withdrawer");
200200
+querier.distribution.set_withdraw_address("delegator", "withdrawer");
201+
-querier.update_staking(denom, &[], &[]);
202+
+querier.staking.update(denom, &[], &[]);
203+
-querier.update_ibc(port_id, &[]);
204+
+querier.ibc.update(port_id, &[]);
201205
```
202206

203207
- If you were using `QueryRequest::Stargate`, you might want to enable the

contracts/staking/src/contract.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ pub fn query_investment(deps: Deps) -> StdResult<InvestmentResponse> {
406406
mod tests {
407407
use super::*;
408408
use cosmwasm_std::testing::{
409-
mock_dependencies, mock_env, mock_info, MockQuerier, MOCK_CONTRACT_ADDR,
409+
mock_dependencies, mock_env, mock_info, MockQuerier, StakingQuerier, MOCK_CONTRACT_ADDR,
410410
};
411411
use cosmwasm_std::{coins, Addr, Coin, CosmosMsg, Decimal, FullDelegation, Validator};
412412
use std::str::FromStr;
@@ -431,11 +431,12 @@ mod tests {
431431
}
432432

433433
fn set_validator(querier: &mut MockQuerier) {
434-
querier.update_staking("ustake", &[sample_validator(DEFAULT_VALIDATOR)], &[]);
434+
querier.staking =
435+
StakingQuerier::new("ustake", &[sample_validator(DEFAULT_VALIDATOR)], &[]);
435436
}
436437

437438
fn set_delegation(querier: &mut MockQuerier, amount: u128, denom: &str) {
438-
querier.update_staking(
439+
querier.staking.update(
439440
"ustake",
440441
&[sample_validator(DEFAULT_VALIDATOR)],
441442
&[sample_delegation(DEFAULT_VALIDATOR, coin(amount, denom))],
@@ -467,7 +468,8 @@ mod tests {
467468
fn initialization_with_missing_validator() {
468469
let mut deps = mock_dependencies();
469470
deps.querier
470-
.update_staking("ustake", &[sample_validator("john")], &[]);
471+
.staking
472+
.update("ustake", &[sample_validator("john")], &[]);
471473

472474
let creator = deps.api.addr_make("creator").to_string();
473475
let msg = InstantiateMsg {
@@ -493,7 +495,7 @@ mod tests {
493495
#[test]
494496
fn proper_initialization() {
495497
let mut deps = mock_dependencies();
496-
deps.querier.update_staking(
498+
deps.querier.staking.update(
497499
"ustake",
498500
&[
499501
sample_validator("john"),

packages/std/src/testing/mock.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,12 @@ pub type MockQuerierCustomHandlerResult = SystemResult<ContractResult<Binary>>;
464464
pub struct MockQuerier<C: DeserializeOwned = Empty> {
465465
pub bank: BankQuerier,
466466
#[cfg(feature = "staking")]
467-
staking: StakingQuerier,
467+
pub staking: StakingQuerier,
468468
#[cfg(feature = "cosmwasm_1_3")]
469469
pub distribution: DistributionQuerier,
470470
wasm: WasmQuerier,
471471
#[cfg(feature = "stargate")]
472-
ibc: IbcQuerier,
472+
pub ibc: IbcQuerier,
473473
/// A handler to handle custom queries. This is set to a dummy handler that
474474
/// always errors by default. Update it via `with_custom_handler`.
475475
///
@@ -497,21 +497,6 @@ impl<C: DeserializeOwned> MockQuerier<C> {
497497
}
498498
}
499499

500-
#[cfg(feature = "staking")]
501-
pub fn update_staking(
502-
&mut self,
503-
denom: &str,
504-
validators: &[crate::query::Validator],
505-
delegations: &[crate::query::FullDelegation],
506-
) {
507-
self.staking = StakingQuerier::new(denom, validators, delegations);
508-
}
509-
510-
#[cfg(feature = "stargate")]
511-
pub fn update_ibc(&mut self, port_id: &str, channels: &[IbcChannel]) {
512-
self.ibc = IbcQuerier::new(port_id, channels);
513-
}
514-
515500
pub fn update_wasm<WH: 'static>(&mut self, handler: WH)
516501
where
517502
WH: Fn(&WasmQuery) -> QuerierResult,
@@ -800,6 +785,12 @@ impl IbcQuerier {
800785
}
801786
}
802787

788+
/// Update the querier's configuration
789+
pub fn update(&mut self, port_id: impl Into<String>, channels: &[IbcChannel]) {
790+
self.port_id = port_id.into();
791+
self.channels = channels.to_vec();
792+
}
793+
803794
pub fn query(&self, request: &IbcQuery) -> QuerierResult {
804795
let contract_result: ContractResult<Binary> = match request {
805796
IbcQuery::Channel {
@@ -863,6 +854,18 @@ impl StakingQuerier {
863854
}
864855
}
865856

857+
/// Update the querier's configuration
858+
pub fn update(
859+
&mut self,
860+
denom: impl Into<String>,
861+
validators: &[Validator],
862+
delegations: &[FullDelegation],
863+
) {
864+
self.denom = denom.into();
865+
self.validators = validators.to_vec();
866+
self.delegations = delegations.to_vec();
867+
}
868+
866869
pub fn query(&self, request: &StakingQuery) -> QuerierResult {
867870
let contract_result: ContractResult<Binary> = match request {
868871
StakingQuery::BondedDenom {} => {

packages/vm/src/testing/querier.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl<C: CustomQuery + DeserializeOwned> MockQuerier<C> {
4242
validators: &[cosmwasm_std::Validator],
4343
delegations: &[cosmwasm_std::FullDelegation],
4444
) {
45-
self.querier.update_staking(denom, validators, delegations);
45+
self.querier.staking.update(denom, validators, delegations);
4646
}
4747

4848
pub fn update_wasm<WH: 'static>(&mut self, handler: WH)

0 commit comments

Comments
 (0)