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

Add gas_used to Reply #1954

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 4 additions & 3 deletions SEMANTICS.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,12 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr

pub struct Reply {
pub id: u64,
/// ContractResult is just a nicely serializable version of `Result<SubcallResponse, String>`
pub result: ContractResult<SubcallResponse>,
pub gas_used: u64,
/// SubMsgResult is just a nicely serializable version of `Result<SubMsgResponse, String>`
pub result: SubMsgResult,
}

pub struct SubcallResponse {
pub struct SubMsgResponse {
pub events: Vec<Event>,
pub data: Option<Binary>,
}
Expand Down
2 changes: 2 additions & 0 deletions contracts/ibc-reflect/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ mod tests {
// fake a reply and ensure this works
let response = Reply {
id,
gas_used: 1234567,
result: SubMsgResult::Ok(SubMsgResponse {
events: fake_events(&account),
data: None,
Expand Down Expand Up @@ -481,6 +482,7 @@ mod tests {
// fake a reply and ensure this works
let response = Reply {
id,
gas_used: 1234567,
result: SubMsgResult::Ok(SubMsgResponse {
events: fake_events(REFLECT_ADDR),
data: None,
Expand Down
2 changes: 2 additions & 0 deletions contracts/ibc-reflect/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ fn connect(
// fake a reply and ensure this works
let response = Reply {
id,
gas_used: 1234567,
result: SubMsgResult::Ok(SubMsgResponse {
events: fake_events(&account),
data: None,
Expand Down Expand Up @@ -173,6 +174,7 @@ fn proper_handshake_flow() {
// we get the callback from reflect
let response = Reply {
id,
gas_used: 1234567,
result: SubMsgResult::Ok(SubMsgResponse {
events: fake_events(REFLECT_ADDR),
data: None,
Expand Down
7 changes: 7 additions & 0 deletions contracts/reflect/schema/raw/response_to_sub_msg_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
"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).",
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"id": {
"description": "The ID that the contract set when emitting the `SubMsg`. Use this to identify which submessage triggered the `reply`.",
"type": "integer",
Expand Down
7 changes: 7 additions & 0 deletions contracts/reflect/schema/reflect.json
Original file line number Diff line number Diff line change
Expand Up @@ -1885,10 +1885,17 @@
"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).",
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"id": {
"description": "The ID that the contract set when emitting the `SubMsg`. Use this to identify which submessage triggered the `reply`.",
"type": "integer",
Expand Down
7 changes: 6 additions & 1 deletion contracts/reflect/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,16 @@ mod tests {
let id = 123u64;
let data = Binary::from(b"foobar");
let events = vec![Event::new("message").add_attribute("signer", "caller-addr")];
let gas_used = 1234567u64;
let result = SubMsgResult::Ok(SubMsgResponse {
events: events.clone(),
data: Some(data.clone()),
});
let subcall = Reply { id, result };
let subcall = Reply {
id,
gas_used,
result,
};
let res = reply(deps.as_mut(), mock_env(), subcall).unwrap();
assert_eq!(0, res.messages.len());

Expand Down
7 changes: 6 additions & 1 deletion contracts/reflect/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,16 @@ fn reply_and_query() {
let id = 123u64;
let data = Binary::from(b"foobar");
let events = vec![Event::new("message").add_attribute("signer", "caller-addr")];
let gas_used = 1234567u64;
let result = SubMsgResult::Ok(SubMsgResponse {
events: events.clone(),
data: Some(data.clone()),
});
let subcall = Reply { id, result };
let subcall = Reply {
id,
gas_used,
result,
};
let res: Response = reply(&mut deps, mock_env(), subcall).unwrap();
assert_eq!(0, res.messages.len());

Expand Down
2 changes: 1 addition & 1 deletion packages/go-gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
mod utils;

fn main() -> Result<()> {
let root = cosmwasm_schema::schema_for!(cosmwasm_std::BankQuery);
let root = cosmwasm_schema::schema_for!(cosmwasm_std::Reply);

Check warning on line 14 in packages/go-gen/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/go-gen/src/main.rs#L14

Added line #L14 was not covered by tests

let code = generate_go(root)?;
println!("{}", code);
Expand Down
3 changes: 3 additions & 0 deletions packages/std/src/results/submessages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ pub struct Reply {
/// The ID that the contract set when emitting the `SubMsg`.
/// Use this to identify which submessage triggered the `reply`.
pub id: u64,
/// The amount of gas used by the submessage,
/// measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).
pub gas_used: u64,
pub result: SubMsgResult,
}

Expand Down
1 change: 1 addition & 0 deletions packages/vm/src/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,7 @@ mod tests {
// which creates a reflect account. here we get the callback
let response = Reply {
id,
gas_used: 1234567,
result: SubMsgResult::Ok(SubMsgResponse {
events: vec![event],
data: None,
Expand Down
Loading