diff --git a/CHANGELOG.md b/CHANGELOG.md index d78371aa53..8fdcb8761c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ and this project adheres to ## [Unreleased] +### Fixed + +- cosmwasm-std: Fix `Reply` deserialization on CosmWasm 1.x chains ([#2158]) + +[#2158]: https://github.com/CosmWasm/cosmwasm/pull/2158 + ## [2.0.3] - 2024-05-10 ### Changed diff --git a/contracts/reflect/schema/raw/response_to_sub_msg_result.json b/contracts/reflect/schema/raw/response_to_sub_msg_result.json index 8b9a44cd09..f7cc42888d 100644 --- a/contracts/reflect/schema/raw/response_to_sub_msg_result.json +++ b/contracts/reflect/schema/raw/response_to_sub_msg_result.json @@ -4,13 +4,13 @@ "description": "The result object returned to `reply`. We always get the ID from the submessage back and then must handle success and error cases ourselves.", "type": "object", "required": [ - "gas_used", "id", "result" ], "properties": { "gas_used": { - "description": "The amount of gas used by the submessage, measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).", + "description": "The amount of gas used by the submessage, measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).\n\nThis only contains a useful value on chains running CosmWasm 2.0 or higher. On older chains, this field is always 0.", + "default": 0, "type": "integer", "format": "uint64", "minimum": 0.0 diff --git a/contracts/reflect/schema/reflect.json b/contracts/reflect/schema/reflect.json index 19f39681c1..449e9bef79 100644 --- a/contracts/reflect/schema/reflect.json +++ b/contracts/reflect/schema/reflect.json @@ -1956,13 +1956,13 @@ "description": "The result object returned to `reply`. We always get the ID from the submessage back and then must handle success and error cases ourselves.", "type": "object", "required": [ - "gas_used", "id", "result" ], "properties": { "gas_used": { - "description": "The amount of gas used by the submessage, measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).", + "description": "The amount of gas used by the submessage, measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).\n\nThis only contains a useful value on chains running CosmWasm 2.0 or higher. On older chains, this field is always 0.", + "default": 0, "type": "integer", "format": "uint64", "minimum": 0.0 diff --git a/packages/std/src/results/submessages.rs b/packages/std/src/results/submessages.rs index a4c3d31da2..5b29bd1908 100644 --- a/packages/std/src/results/submessages.rs +++ b/packages/std/src/results/submessages.rs @@ -167,6 +167,10 @@ pub struct Reply { pub payload: Binary, /// The amount of gas used by the submessage, /// measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md). + /// + /// This only contains a useful value on chains running CosmWasm 2.0 or higher. + /// On older chains, this field is always 0. + #[serde(default)] pub gas_used: u64, pub result: SubMsgResult, } @@ -591,4 +595,29 @@ mod tests { } ); } + + #[test] + fn reply_serialization_cosmwasm_1() { + // json coming from wasmvm 1.5.0 + let json = r#"{"id":1234,"result":{"ok":{"events":[{"type":"message","attributes":[{"key":"signer","value":"caller-addr"}]}],"data":"Zm9vYmFy"}}}"#; + + let reply: Reply = from_json(json).unwrap(); + assert_eq!(reply.id, 1234); + assert_eq!(reply.payload, Binary::default()); + assert_eq!( + reply.result, + SubMsgResult::Ok(SubMsgResponse { + data: Some(Binary::from_base64("Zm9vYmFy").unwrap()), + events: vec![Event { + ty: "message".to_string(), + attributes: vec![Attribute { + key: "signer".to_string(), + value: "caller-addr".to_string() + }] + }], + msg_responses: vec![] + }) + ); + assert_eq!(reply.gas_used, 0); + } }