Skip to content

Commit 9cd3350

Browse files
authored
Merge pull request #2159 from CosmWasm/mergify/bp/main/pr-2158
Fix `gas_used` deserialization (backport #2158)
2 parents b96aa96 + fc0148c commit 9cd3350

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ and this project adheres to
1111
### Fixed
1212

1313
- cosmwasm-std: Fix CWA-2024-002
14+
- cosmwasm-std: Fix `Reply` deserialization on CosmWasm 1.x chains ([#2159])
15+
16+
[#2159]: https://github.com/CosmWasm/cosmwasm/pull/2159
1417

1518
### Added
1619

contracts/reflect/schema/raw/response_to_sub_msg_result.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"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.",
55
"type": "object",
66
"required": [
7-
"gas_used",
87
"id",
98
"result"
109
],
1110
"properties": {
1211
"gas_used": {
13-
"description": "The amount of gas used by the submessage, measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).",
12+
"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.",
13+
"default": 0,
1414
"type": "integer",
1515
"format": "uint64",
1616
"minimum": 0.0

contracts/reflect/schema/reflect.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,13 +2006,13 @@
20062006
"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.",
20072007
"type": "object",
20082008
"required": [
2009-
"gas_used",
20102009
"id",
20112010
"result"
20122011
],
20132012
"properties": {
20142013
"gas_used": {
2015-
"description": "The amount of gas used by the submessage, measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).",
2014+
"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.",
2015+
"default": 0,
20162016
"type": "integer",
20172017
"format": "uint64",
20182018
"minimum": 0.0

packages/std/src/results/submessages.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ pub struct Reply {
181181
pub payload: Binary,
182182
/// The amount of gas used by the submessage,
183183
/// measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).
184+
///
185+
/// This only contains a useful value on chains running CosmWasm 2.0 or higher.
186+
/// On older chains, this field is always 0.
187+
#[serde(default)]
184188
pub gas_used: u64,
185189
pub result: SubMsgResult,
186190
}
@@ -612,4 +616,29 @@ mod tests {
612616
}
613617
);
614618
}
619+
620+
#[test]
621+
fn reply_serialization_cosmwasm_1() {
622+
// json coming from wasmvm 1.5.0
623+
let json = r#"{"id":1234,"result":{"ok":{"events":[{"type":"message","attributes":[{"key":"signer","value":"caller-addr"}]}],"data":"Zm9vYmFy"}}}"#;
624+
625+
let reply: Reply = from_json(json).unwrap();
626+
assert_eq!(reply.id, 1234);
627+
assert_eq!(reply.payload, Binary::default());
628+
assert_eq!(
629+
reply.result,
630+
SubMsgResult::Ok(SubMsgResponse {
631+
data: Some(Binary::from_base64("Zm9vYmFy").unwrap()),
632+
events: vec![Event {
633+
ty: "message".to_string(),
634+
attributes: vec![Attribute {
635+
key: "signer".to_string(),
636+
value: "caller-addr".to_string()
637+
}]
638+
}],
639+
msg_responses: vec![]
640+
})
641+
);
642+
assert_eq!(reply.gas_used, 0);
643+
}
615644
}

0 commit comments

Comments
 (0)