Skip to content

Commit 9022e4f

Browse files
committed
Add cosmwasm_3_0 capability
1 parent 82444e7 commit 9022e4f

File tree

7 files changed

+29
-14
lines changed

7 files changed

+29
-14
lines changed

docs/CAPABILITIES-BUILT-IN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ might define others.
3333
`migrate` entrypoint, as well as IBC Fees support with `IbcMsg::PayPacketFee`,
3434
`IbcMsg::PayPacketFeeAsync` and `IbcQuery::FeeEnabledChannel`. Only chains
3535
running CosmWasm `2.2.0` or higher support this.
36+
- `cosmwasm_3_0` enables `WasmQuery::RawRange`. Only chains running CosmWasm
37+
`3.0.0` or higher support this.

packages/std/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ license = "Apache-2.0"
99
readme = "README.md"
1010

1111
[package.metadata.docs.rs]
12-
features = ["cosmwasm_2_2", "staking", "stargate", "ibc2"]
12+
features = ["cosmwasm_3_0", "staking", "stargate", "ibc2"]
1313

1414
[features]
1515
default = ["exports", "iterator", "std"]
@@ -55,6 +55,9 @@ cosmwasm_2_1 = ["cosmwasm_2_0"]
5555
# This enables functionality that is only available on 2.2 chains.
5656
# It adds `IbcMsg::PayPacketFee` and `IbcMsg::PayPacketFeeAsync`.
5757
cosmwasm_2_2 = ["cosmwasm_2_1"]
58+
# This enables functionality that is only available on 3.0 chains.
59+
# It adds `WasmQuery::RawRange`.
60+
cosmwasm_3_0 = ["cosmwasm_2_2"]
5861

5962
[dependencies]
6063
base64 = "0.22.0"

packages/std/src/exports/exports.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ extern "C" fn requires_cosmwasm_2_1() {}
8282
#[no_mangle]
8383
extern "C" fn requires_cosmwasm_2_2() {}
8484

85+
#[cfg(feature = "cosmwasm_3_0")]
86+
#[no_mangle]
87+
extern "C" fn requires_cosmwasm_3_0() {}
88+
8589
/// interface_version_* exports mark which Wasm VM interface level this contract is compiled for.
8690
/// They can be checked by cosmwasm_vm.
8791
/// Update this whenever the Wasm VM interface breaks.

packages/std/src/query/wasm.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
use core::ops::RangeBounds;
2-
31
use schemars::JsonSchema;
42
use serde::{Deserialize, Serialize};
53

4+
use crate::prelude::*;
5+
#[cfg(all(feature = "cosmwasm_3_0", feature = "iterator"))]
66
use crate::storage_keys::{range_to_bounds, ToByteVec};
7-
use crate::{prelude::*, Order};
87
use crate::{Addr, Binary, Checksum};
8+
#[cfg(all(feature = "cosmwasm_3_0", feature = "iterator"))]
9+
use core::ops::RangeBounds;
910

1011
use super::query_response::QueryResponseType;
1112

@@ -42,6 +43,7 @@ pub enum WasmQuery {
4243
/// Please keep in mind that the contract you are querying might change its storage layout using
4344
/// migrations, which could break your queries, so it is recommended to only use this for
4445
/// contracts you control.
46+
#[cfg(all(feature = "cosmwasm_3_0", feature = "iterator"))]
4547
RawRange {
4648
/// The address of the contract to query
4749
contract_addr: String,
@@ -59,19 +61,20 @@ pub enum WasmQuery {
5961
/// on the full JSON size of the response type.
6062
limit: u16,
6163
/// The order in which you want to receive the key-value pairs.
62-
order: Order,
64+
order: crate::Order,
6365
},
6466
}
6567

6668
impl WasmQuery {
6769
/// Creates a new [`WasmQuery::RawRange`] from the given parameters.
6870
///
6971
/// This takes a [`RangeBounds`] to allow for specifying the range in a more idiomatic way.
72+
#[cfg(all(feature = "cosmwasm_3_0", feature = "iterator"))]
7073
pub fn raw_range<'a, R, B>(
7174
contract_addr: impl Into<String>,
7275
range: R,
7376
limit: u16,
74-
order: Order,
77+
order: crate::Order,
7578
) -> Self
7679
where
7780
R: RangeBounds<&'a B>,
@@ -224,7 +227,10 @@ mod tests {
224227
}
225228

226229
#[test]
230+
#[cfg(all(feature = "cosmwasm_3_0", feature = "iterator"))]
227231
fn raw_range_constructor_works() {
232+
use crate::Order;
233+
228234
let query = WasmQuery::raw_range(
229235
"contract_addr",
230236
&b"asdf"[..]..&b"asdz"[..],

packages/std/src/storage_keys/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
mod length_prefixed;
2+
#[cfg(all(feature = "cosmwasm_3_0", feature = "iterator"))]
23
mod range;
34

45
// Please note that the entire storage_keys module is public. So be careful
56
// when adding elements here.
67
pub use length_prefixed::{namespace_with_key, to_length_prefixed, to_length_prefixed_nested};
8+
#[cfg(all(feature = "cosmwasm_3_0", feature = "iterator"))]
79
pub(crate) use range::{range_to_bounds, ToByteVec};

packages/std/src/testing/mock.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ impl Default for WasmQuerier {
946946
WasmQuery::CodeInfo { code_id, .. } => {
947947
SystemError::NoSuchCode { code_id: *code_id }
948948
}
949-
// #[cfg(feature = "cosmwasm_3_0")]
949+
#[cfg(all(feature = "cosmwasm_3_0", feature = "iterator"))]
950950
WasmQuery::RawRange { contract_addr, .. } => SystemError::NoSuchContract {
951951
addr: contract_addr.clone(),
952952
},
@@ -1422,10 +1422,7 @@ mod tests {
14221422
use crate::coins;
14231423
#[cfg(feature = "cosmwasm_1_3")]
14241424
use crate::DenomUnit;
1425-
use crate::{
1426-
coin, instantiate2_address, query::RawRangeResponse, ContractInfoResponse, HexBinary,
1427-
Response, Storage,
1428-
};
1425+
use crate::{coin, instantiate2_address, ContractInfoResponse, HexBinary, Response, Storage};
14291426
#[cfg(feature = "staking")]
14301427
use crate::{Decimal, Delegation};
14311428
use base64::{engine::general_purpose, Engine};
@@ -2823,6 +2820,7 @@ mod tests {
28232820
SystemResult::Err(SystemError::NoSuchCode { code_id })
28242821
}
28252822
}
2823+
#[cfg(all(feature = "cosmwasm_3_0", feature = "iterator"))]
28262824
WasmQuery::RawRange {
28272825
contract_addr,
28282826
start,
@@ -2852,7 +2850,7 @@ mod tests {
28522850
} else {
28532851
None
28542852
};
2855-
let raw_range_response = RawRangeResponse { data, next_key };
2853+
let raw_range_response = crate::RawRangeResponse { data, next_key };
28562854

28572855
SystemResult::Ok(ContractResult::Ok(
28582856
to_json_binary(&raw_range_response).unwrap(),
@@ -2936,7 +2934,7 @@ mod tests {
29362934
}
29372935
}
29382936

2939-
// #[cfg(feature = "cosmwasm_3_0")]
2937+
#[cfg(all(feature = "cosmwasm_3_0", feature = "iterator"))]
29402938
{
29412939
let result = querier.query(&WasmQuery::RawRange {
29422940
contract_addr: contract_addr.clone().into(),

packages/vm/src/testing/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl MockInstanceOptions<'_> {
9898
fn default_capabilities() -> HashSet<String> {
9999
#[allow(unused_mut)]
100100
let mut out = capabilities_from_csv(
101-
"ibc2,iterator,staking,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4,cosmwasm_2_0,cosmwasm_2_1,cosmwasm_2_2",
101+
"ibc2,iterator,staking,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4,cosmwasm_2_0,cosmwasm_2_1,cosmwasm_2_2,cosmwasm_3_0",
102102
);
103103
#[cfg(feature = "stargate")]
104104
out.insert("stargate".to_string());

0 commit comments

Comments
 (0)