Skip to content

Commit

Permalink
Enable ibcv3 feature for cw-proposal-single contract (#318)
Browse files Browse the repository at this point in the history
* Enable ibcv3 feature (which includes stargate) for cw-proposal-single contract

* fix clippy

* update schema

* Add stargate test to cw-core

* Add stargate feature flag for cw-multi-test

* Use main branch of cw-plus, add TODOs

* Add cw-core schemas

* Update Cargo.lock

* Fix clippy
  • Loading branch information
de-husk authored Jun 7, 2022
1 parent 3a65522 commit b5f2b08
Show file tree
Hide file tree
Showing 12 changed files with 1,469 additions and 77 deletions.
187 changes: 113 additions & 74 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions contracts/cw-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ optimize = """docker run --rm -v "$(pwd)":/code \
"""

[dependencies]
cosmwasm-std = { version = "1.0.0" }
cosmwasm-std = { version = "1.0.0", features = ["ibc3"] }
cosmwasm-storage = { version = "1.0.0" }
cw-storage-plus = "0.13"
cw2 = "0.13"
Expand All @@ -45,7 +45,8 @@ cw-paginate = { version = "0.1.0", path = "../../packages/cw-paginate" }

[dev-dependencies]
cosmwasm-schema = { version = "1.0.0" }
cw-multi-test = "0.13"
# TODO: We are using the main branch of cw-multi-test until the next release, because we need recent stargate parsing fixes
cw-multi-test = { git = "https://github.com/CosmWasm/cw-plus", branch = "main", features = ["stargate"] }
cw20-base = "0.13"
cw721-base = "0.13"
cw-proposal-sudo = { version = "0.1.0", path = "../../debug/cw-proposal-sudo"}
Expand Down
254 changes: 254 additions & 0 deletions contracts/cw-core/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,43 @@
},
"additionalProperties": false
},
{
"description": "A Stargate message encoded the same way as a protobuf [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto). This is the same structure as messages in `TxBody` from [ADR-020](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-020-protobuf-transaction-encoding.md)",
"type": "object",
"required": [
"stargate"
],
"properties": {
"stargate": {
"type": "object",
"required": [
"type_url",
"value"
],
"properties": {
"type_url": {
"type": "string"
},
"value": {
"$ref": "#/definitions/Binary"
}
}
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"ibc"
],
"properties": {
"ibc": {
"$ref": "#/definitions/IbcMsg"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
Expand All @@ -532,6 +569,18 @@
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"gov"
],
"properties": {
"gov": {
"$ref": "#/definitions/GovMsg"
}
},
"additionalProperties": false
}
]
},
Expand Down Expand Up @@ -662,6 +711,190 @@
"description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)",
"type": "object"
},
"GovMsg": {
"oneOf": [
{
"description": "This maps directly to [MsgVote](https://github.com/cosmos/cosmos-sdk/blob/v0.42.5/proto/cosmos/gov/v1beta1/tx.proto#L46-L56) in the Cosmos SDK with voter set to the contract address.",
"type": "object",
"required": [
"vote"
],
"properties": {
"vote": {
"type": "object",
"required": [
"proposal_id",
"vote"
],
"properties": {
"proposal_id": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"vote": {
"$ref": "#/definitions/VoteOption"
}
}
}
},
"additionalProperties": false
}
]
},
"IbcMsg": {
"description": "These are messages in the IBC lifecycle. Only usable by IBC-enabled contracts (contracts that directly speak the IBC protocol via 6 entry points)",
"oneOf": [
{
"description": "Sends bank tokens owned by the contract to the given address on another chain. The channel must already be established between the ibctransfer module on this chain and a matching module on the remote chain. We cannot select the port_id, this is whatever the local chain has bound the ibctransfer module to.",
"type": "object",
"required": [
"transfer"
],
"properties": {
"transfer": {
"type": "object",
"required": [
"amount",
"channel_id",
"timeout",
"to_address"
],
"properties": {
"amount": {
"description": "packet data only supports one coin https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20",
"allOf": [
{
"$ref": "#/definitions/Coin"
}
]
},
"channel_id": {
"description": "exisiting channel to send the tokens over",
"type": "string"
},
"timeout": {
"description": "when packet times out, measured on remote chain",
"allOf": [
{
"$ref": "#/definitions/IbcTimeout"
}
]
},
"to_address": {
"description": "address on the remote chain to receive these tokens",
"type": "string"
}
}
}
},
"additionalProperties": false
},
{
"description": "Sends an IBC packet with given data over the existing channel. Data should be encoded in a format defined by the channel version, and the module on the other side should know how to parse this.",
"type": "object",
"required": [
"send_packet"
],
"properties": {
"send_packet": {
"type": "object",
"required": [
"channel_id",
"data",
"timeout"
],
"properties": {
"channel_id": {
"type": "string"
},
"data": {
"$ref": "#/definitions/Binary"
},
"timeout": {
"description": "when packet times out, measured on remote chain",
"allOf": [
{
"$ref": "#/definitions/IbcTimeout"
}
]
}
}
}
},
"additionalProperties": false
},
{
"description": "This will close an existing channel that is owned by this contract. Port is auto-assigned to the contract's IBC port",
"type": "object",
"required": [
"close_channel"
],
"properties": {
"close_channel": {
"type": "object",
"required": [
"channel_id"
],
"properties": {
"channel_id": {
"type": "string"
}
}
}
},
"additionalProperties": false
}
]
},
"IbcTimeout": {
"description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.",
"type": "object",
"properties": {
"block": {
"anyOf": [
{
"$ref": "#/definitions/IbcTimeoutBlock"
},
{
"type": "null"
}
]
},
"timestamp": {
"anyOf": [
{
"$ref": "#/definitions/Timestamp"
},
{
"type": "null"
}
]
}
}
},
"IbcTimeoutBlock": {
"description": "IBCTimeoutHeight Height is a monotonically increasing data type that can be compared against another Height for the purposes of updating and freezing clients. Ordering is (revision_number, timeout_height)",
"type": "object",
"required": [
"height",
"revision"
],
"properties": {
"height": {
"description": "block height after which the packet times out. the height within the given revision",
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"revision": {
"description": "the version that the client is currently on (eg. after reseting the chain this could increment 1 as height drops to 0)",
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
}
},
"ModuleInstantiateInfo": {
"description": "Information needed to instantiate a proposal or voting module.",
"type": "object",
Expand Down Expand Up @@ -784,10 +1017,31 @@
}
]
},
"Timestamp": {
"description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```",
"allOf": [
{
"$ref": "#/definitions/Uint64"
}
]
},
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
},
"Uint64": {
"description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```",
"type": "string"
},
"VoteOption": {
"type": "string",
"enum": [
"yes",
"no",
"abstain",
"no_with_veto"
]
},
"WasmMsg": {
"description": "The message types of the wasm module.\n\nSee https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto",
"oneOf": [
Expand Down
5 changes: 5 additions & 0 deletions contracts/cw-core/schema/migrate_msg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "MigrateMsg",
"type": "object"
}
32 changes: 32 additions & 0 deletions contracts/cw-core/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1911,3 +1911,35 @@ fn test_migrate() {

assert_eq!(new_state, state);
}

#[test]
fn test_execute_stargate_msg() {
let (core_addr, mut app) = do_standard_instantiate(true, None);
let proposal_modules: Vec<Addr> = app
.wrap()
.query_wasm_smart(
core_addr.clone(),
&QueryMsg::ProposalModules {
start_at: None,
limit: None,
},
)
.unwrap();

assert_eq!(proposal_modules.len(), 1);
let proposal_module = proposal_modules.into_iter().next().unwrap();

let res = app.execute_contract(
proposal_module,
core_addr,
&ExecuteMsg::ExecuteProposalHook {
msgs: vec![CosmosMsg::Stargate {
type_url: "foo_type".to_string(),
value: to_binary("foo_bin").unwrap(),
}],
},
&[],
);
// TODO: Once cw-multi-test supports executing stargate/ibc messages we can change this test assert
assert!(res.is_err());
}
2 changes: 1 addition & 1 deletion contracts/cw-proposal-single/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ optimize = """docker run --rm -v "$(pwd)":/code \
"""

[dependencies]
cosmwasm-std = { version = "1.0.0" }
cosmwasm-std = { version = "1.0.0", features = ["ibc3"] }
cosmwasm-storage = { version = "1.0.0" }
cw-storage-plus = "0.13"
cw-utils = "0.13"
Expand Down
Loading

0 comments on commit b5f2b08

Please sign in to comment.