Skip to content

Commit

Permalink
Merge pull request #2159 from CosmWasm/mergify/bp/main/pr-2158
Browse files Browse the repository at this point in the history
Fix `gas_used` deserialization (backport #2158)
  • Loading branch information
chipshort committed May 30, 2024
2 parents b96aa96 + fc0148c commit 9cd3350
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to
### Fixed

- cosmwasm-std: Fix CWA-2024-002
- cosmwasm-std: Fix `Reply` deserialization on CosmWasm 1.x chains ([#2159])

[#2159]: https://github.com/CosmWasm/cosmwasm/pull/2159

### Added

Expand Down
4 changes: 2 additions & 2 deletions contracts/reflect/schema/raw/response_to_sub_msg_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions contracts/reflect/schema/reflect.json
Original file line number Diff line number Diff line change
Expand Up @@ -2006,13 +2006,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
Expand Down
29 changes: 29 additions & 0 deletions packages/std/src/results/submessages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,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,
}
Expand Down Expand Up @@ -612,4 +616,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);
}
}

0 comments on commit 9cd3350

Please sign in to comment.