Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gas_used deserialization #2158

Merged
merged 4 commits into from
May 30, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/std/src/results/submessages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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);
}
}
Loading