Skip to content

Commit

Permalink
Add cosmwasm_2_0 capability and feature
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Dec 20, 2023
1 parent 4c673f4 commit 4ffac28
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 10 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,15 @@ jobs:
- run:
name: Build library for native target (all features)
working_directory: ~/project/packages/std
command: cargo build --locked --features abort,iterator,staking,stargate,cosmwasm_1_4
command: cargo build --locked --features abort,iterator,staking,stargate,cosmwasm_2_0
- run:
name: Build library for wasm target (all features)
working_directory: ~/project/packages/std
command: cargo wasm --locked --features abort,iterator,staking,stargate,cosmwasm_1_4
command: cargo wasm --locked --features abort,iterator,staking,stargate,cosmwasm_2_0
- run:
name: Run unit tests (all features)
working_directory: ~/project/packages/std
command: cargo test --locked --features abort,iterator,staking,stargate,cosmwasm_1_4
command: cargo test --locked --features abort,iterator,staking,stargate,cosmwasm_2_0
- save_cache:
paths:
- /usr/local/cargo/registry
Expand Down Expand Up @@ -903,7 +903,7 @@ jobs:
- run:
name: Clippy linting on std (all feature flags)
working_directory: ~/project/packages/std
command: cargo clippy --all-targets --features abort,iterator,staking,stargate,cosmwasm_1_4 -- -D warnings
command: cargo clippy --all-targets --features abort,iterator,staking,stargate,cosmwasm_2_0 -- -D warnings
- run:
name: Clippy linting on vm (no feature flags)
working_directory: ~/project/packages/vm
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"abort",
"stargate",
"staking",
"cosmwasm_1_4"
"cosmwasm_2_0"
]
}
11 changes: 11 additions & 0 deletions MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ major releases of `cosmwasm`. Note that you can also view the
+cosmwasm-std = { version = "2.0.0", default-features = false, features = ["std", ...] }
```

- If you want to use a feature that is only available on CosmWasm 2.0+ chains,
use this feature:

```diff
-cosmwasm-std = { version = "1.4.0", features = ["stargate"] }
+cosmwasm-std = { version = "1.4.0", features = ["stargate", "cosmwasm_2_0"] }
```

Please note that `cosmwasm_2_0` implies `cosmwasm_1_4`, `cosmwasm_1_3` and so
on, so there is no need to set multiple.

- `ContractInfoResponse::new` now takes all fields of the response as
parameters:

Expand Down
2 changes: 2 additions & 0 deletions docs/CAPABILITIES-BUILT-IN.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ might define others.
`DistributionQuery::DelegationTotalRewards` and
`DistributionQuery::DelegatorValidators` queries. Only chains running CosmWasm
`1.4.0` or higher support this.
- `cosmwasm_2_0` enables `CosmosMsg::Any`. Only chains running CosmWasm `2.0.0`
or higher support this.
2 changes: 1 addition & 1 deletion packages/go-gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ publish = false

[dependencies]
schemars = "0.8.3"
cosmwasm-std = { path = "../std", version = "1.5.0", features = ["cosmwasm_1_4", "staking", "stargate"] }
cosmwasm-std = { path = "../std", version = "1.5.0", features = ["cosmwasm_2_0", "staking", "stargate"] }
cosmwasm-schema = { path = "../schema", version = "1.5.0" }
anyhow = "1"
Inflector = "0.11.4"
Expand Down
5 changes: 4 additions & 1 deletion packages/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "Apache-2.0"
readme = "README.md"

[package.metadata.docs.rs]
features = ["abort", "stargate", "staking", "cosmwasm_1_4"]
features = ["abort", "stargate", "staking", "cosmwasm_2_0"]

[features]
default = ["iterator", "abort", "std"]
Expand Down Expand Up @@ -46,6 +46,9 @@ cosmwasm_1_3 = ["cosmwasm_1_2"]
# available for the contract to call.
# It requires the host blockchain to run CosmWasm `1.4.0` or higher.
cosmwasm_1_4 = ["cosmwasm_1_3"]
# This enables functionality that is only available on 2.0 chains.
# It adds `CosmosMsg::Any`, replacing `CosmosMsg::Stargate`.
cosmwasm_2_0 = ["cosmwasm_1_4"]

[dependencies]
base64 = "0.21.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/std/src/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ extern "C" fn requires_cosmwasm_1_3() -> () {}
#[no_mangle]
extern "C" fn requires_cosmwasm_1_4() -> () {}

#[cfg(feature = "cosmwasm_2_0")]
#[no_mangle]
extern "C" fn requires_cosmwasm_2_0() -> () {}

/// interface_version_* exports mark which Wasm VM interface level this contract is compiled for.
/// They can be checked by cosmwasm_vm.
/// Update this whenever the Wasm VM interface breaks.
Expand Down
8 changes: 6 additions & 2 deletions packages/std/src/results/cosmos_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub enum CosmosMsg<T = Empty> {
Staking(StakingMsg),
#[cfg(feature = "staking")]
Distribution(DistributionMsg),
#[cfg(feature = "cosmwasm_2_0")]
Any(AnyMsg),
#[cfg(feature = "stargate")]
Ibc(IbcMsg),
Expand Down Expand Up @@ -385,6 +386,7 @@ impl<T> From<DistributionMsg> for CosmosMsg<T> {

// By implementing `From<MyType> for cosmwasm_std::AnyMsg`,
// you automatically get a MyType -> CosmosMsg conversion.
#[cfg(feature = "cosmwasm_2_0")]
impl<S: Into<AnyMsg>, T> From<S> for CosmosMsg<T> {
fn from(source: S) -> Self {
CosmosMsg::<T>::Any(source.into())
Expand Down Expand Up @@ -414,7 +416,7 @@ impl<T> From<GovMsg> for CosmosMsg<T> {
#[cfg(test)]
mod tests {
use super::*;
use crate::{coin, coins, to_json_string};
use crate::{coin, coins};

#[test]
fn from_bank_msg_works() {
Expand All @@ -429,6 +431,7 @@ mod tests {
}

#[test]
#[cfg(feature = "cosmwasm_2_0")]
fn from_any_msg_works() {
// should work with AnyMsg
let any = AnyMsg {
Expand Down Expand Up @@ -519,13 +522,14 @@ mod tests {
}

#[test]
#[cfg(feature = "cosmwasm_2_0")]
fn any_msg_serializes_to_correct_json() {
// Same serialization as CosmosMsg::Stargate (see above), except the top level key
let msg: CosmosMsg = CosmosMsg::Any(AnyMsg {
type_url: "/cosmos.foo.v1beta.MsgBar".to_string(),
value: Binary::from_base64("5yu/rQ+HrMcxH1zdga7P5hpGMLE=").unwrap(),
});
let json = to_json_string(&msg).unwrap();
let json = crate::to_json_string(&msg).unwrap();
assert_eq!(
json,
r#"{"any":{"type_url":"/cosmos.foo.v1beta.MsgBar","value":"5yu/rQ+HrMcxH1zdga7P5hpGMLE="}}"#,
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/src/testing/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl MockInstanceOptions<'_> {
fn default_capabilities() -> HashSet<String> {
#[allow(unused_mut)]
let mut out = capabilities_from_csv(
"iterator,staking,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4",
"iterator,staking,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4,cosmwasm_2_0",
);
#[cfg(feature = "stargate")]
out.insert("stargate".to_string());
Expand Down

0 comments on commit 4ffac28

Please sign in to comment.