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

[2.0] Add msg_responses to SubMsgResponse #1903

Merged
merged 11 commits into from
Nov 23, 2023
4 changes: 4 additions & 0 deletions contracts/ibc-reflect/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,13 @@ mod tests {
let id = res.messages[0].id;

// fake a reply and ensure this works
#[allow(deprecated)]
let response = Reply {
id,
gas_used: 1234567,
result: SubMsgResult::Ok(SubMsgResponse {
events: fake_events(&account),
msg_responses: vec![],
data: None,
}),
};
Expand Down Expand Up @@ -480,11 +482,13 @@ mod tests {
assert_eq!(0, res.accounts.len());

// fake a reply and ensure this works
#[allow(deprecated)]
let response = Reply {
id,
gas_used: 1234567,
result: SubMsgResult::Ok(SubMsgResponse {
events: fake_events(REFLECT_ADDR),
msg_responses: vec![],
data: None,
}),
};
Expand Down
4 changes: 4 additions & 0 deletions contracts/ibc-reflect/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ fn connect(
let id = res.messages[0].id;

// fake a reply and ensure this works
#[allow(deprecated)]
let response = Reply {
id,
gas_used: 1234567,
result: SubMsgResult::Ok(SubMsgResponse {
events: fake_events(&account),
msg_responses: vec![],
data: None,
}),
};
Expand Down Expand Up @@ -172,11 +174,13 @@ fn proper_handshake_flow() {
assert_eq!(0, res.accounts.len());

// we get the callback from reflect
#[allow(deprecated)]
let response = Reply {
id,
gas_used: 1234567,
result: SubMsgResult::Ok(SubMsgResponse {
events: fake_events(REFLECT_ADDR),
msg_responses: vec![],
data: None,
}),
};
Expand Down
25 changes: 24 additions & 1 deletion contracts/reflect/schema/raw/response_to_sub_msg_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@
}
}
},
"MsgResponse": {
"type": "object",
"required": [
"type_url",
"value"
],
"properties": {
"type_url": {
"type": "string"
},
"value": {
"$ref": "#/definitions/Binary"
}
}
},
"SubMsgResponse": {
"description": "The information we get back from a successful sub message execution, with full Cosmos SDK events.",
"type": "object",
Expand All @@ -75,6 +90,7 @@
],
"properties": {
"data": {
"deprecated": true,
"anyOf": [
{
"$ref": "#/definitions/Binary"
Expand All @@ -89,11 +105,18 @@
"items": {
"$ref": "#/definitions/Event"
}
},
"msg_responses": {
"default": [],
"type": "array",
"items": {
"$ref": "#/definitions/MsgResponse"
}
}
}
},
"SubMsgResult": {
"description": "This is the result type that is returned from a sub message execution.\n\nWe use a custom type here instead of Rust's Result because we want to be able to define the serialization, which is a public interface. Every language that compiles to Wasm and runs in the ComsWasm VM needs to create the same JSON representation.\n\nUntil version 1.0.0-beta5, `ContractResult<SubMsgResponse>` was used instead of this type. Once serialized, the two types are the same. However, in the Rust type system we want different types for clarity and documenation reasons.\n\n# Examples\n\nSuccess:\n\n``` # use cosmwasm_std::{to_vec, Binary, Event, SubMsgResponse, SubMsgResult}; let response = SubMsgResponse { data: Some(Binary::from_base64(\"MTIzCg==\").unwrap()), events: vec![Event::new(\"wasm\").add_attribute(\"fo\", \"ba\")], }; let result: SubMsgResult = SubMsgResult::Ok(response); assert_eq!(to_vec(&result).unwrap(), br#\"{\"ok\":{\"events\":[{\"type\":\"wasm\",\"attributes\":[{\"key\":\"fo\",\"value\":\"ba\"}]}],\"data\":\"MTIzCg==\"}}\"#); ```\n\nFailure:\n\n``` # use cosmwasm_std::{to_vec, SubMsgResult, Response}; let error_msg = String::from(\"Something went wrong\"); let result = SubMsgResult::Err(error_msg); assert_eq!(to_vec(&result).unwrap(), br#\"{\"error\":\"Something went wrong\"}\"#); ```",
"description": "This is the result type that is returned from a sub message execution.\n\nWe use a custom type here instead of Rust's Result because we want to be able to define the serialization, which is a public interface. Every language that compiles to Wasm and runs in the ComsWasm VM needs to create the same JSON representation.\n\nUntil version 1.0.0-beta5, `ContractResult<SubMsgResponse>` was used instead of this type. Once serialized, the two types are the same. However, in the Rust type system we want different types for clarity and documenation reasons.\n\n# Examples\n\nSuccess:\n\n``` # use cosmwasm_std::{to_json_string, Binary, Event, SubMsgResponse, SubMsgResult}; #[allow(deprecated)] let response = SubMsgResponse { data: Some(Binary::from_base64(\"MTIzCg==\").unwrap()), events: vec![Event::new(\"wasm\").add_attribute(\"fo\", \"ba\")], msg_responses: vec![], }; let result: SubMsgResult = SubMsgResult::Ok(response); assert_eq!( to_json_string(&result).unwrap(), r#\"{\"ok\":{\"events\":[{\"type\":\"wasm\",\"attributes\":[{\"key\":\"fo\",\"value\":\"ba\"}]}],\"data\":\"MTIzCg==\",\"msg_responses\":[]}}\"#, ); ```\n\nFailure:\n\n``` # use cosmwasm_std::{to_json_string, SubMsgResult, Response}; let error_msg = String::from(\"Something went wrong\"); let result = SubMsgResult::Err(error_msg); assert_eq!(to_json_string(&result).unwrap(), r#\"{\"error\":\"Something went wrong\"}\"#); ```",
"oneOf": [
{
"type": "object",
Expand Down
25 changes: 24 additions & 1 deletion contracts/reflect/schema/reflect.json
Original file line number Diff line number Diff line change
Expand Up @@ -1948,6 +1948,21 @@
}
}
},
"MsgResponse": {
"type": "object",
"required": [
"type_url",
"value"
],
"properties": {
"type_url": {
"type": "string"
},
"value": {
"$ref": "#/definitions/Binary"
}
}
},
"SubMsgResponse": {
"description": "The information we get back from a successful sub message execution, with full Cosmos SDK events.",
"type": "object",
Expand All @@ -1956,6 +1971,7 @@
],
"properties": {
"data": {
"deprecated": true,
"anyOf": [
{
"$ref": "#/definitions/Binary"
Expand All @@ -1970,11 +1986,18 @@
"items": {
"$ref": "#/definitions/Event"
}
},
"msg_responses": {
"default": [],
"type": "array",
"items": {
"$ref": "#/definitions/MsgResponse"
}
}
}
},
"SubMsgResult": {
"description": "This is the result type that is returned from a sub message execution.\n\nWe use a custom type here instead of Rust's Result because we want to be able to define the serialization, which is a public interface. Every language that compiles to Wasm and runs in the ComsWasm VM needs to create the same JSON representation.\n\nUntil version 1.0.0-beta5, `ContractResult<SubMsgResponse>` was used instead of this type. Once serialized, the two types are the same. However, in the Rust type system we want different types for clarity and documenation reasons.\n\n# Examples\n\nSuccess:\n\n``` # use cosmwasm_std::{to_vec, Binary, Event, SubMsgResponse, SubMsgResult}; let response = SubMsgResponse { data: Some(Binary::from_base64(\"MTIzCg==\").unwrap()), events: vec![Event::new(\"wasm\").add_attribute(\"fo\", \"ba\")], }; let result: SubMsgResult = SubMsgResult::Ok(response); assert_eq!(to_vec(&result).unwrap(), br#\"{\"ok\":{\"events\":[{\"type\":\"wasm\",\"attributes\":[{\"key\":\"fo\",\"value\":\"ba\"}]}],\"data\":\"MTIzCg==\"}}\"#); ```\n\nFailure:\n\n``` # use cosmwasm_std::{to_vec, SubMsgResult, Response}; let error_msg = String::from(\"Something went wrong\"); let result = SubMsgResult::Err(error_msg); assert_eq!(to_vec(&result).unwrap(), br#\"{\"error\":\"Something went wrong\"}\"#); ```",
"description": "This is the result type that is returned from a sub message execution.\n\nWe use a custom type here instead of Rust's Result because we want to be able to define the serialization, which is a public interface. Every language that compiles to Wasm and runs in the ComsWasm VM needs to create the same JSON representation.\n\nUntil version 1.0.0-beta5, `ContractResult<SubMsgResponse>` was used instead of this type. Once serialized, the two types are the same. However, in the Rust type system we want different types for clarity and documenation reasons.\n\n# Examples\n\nSuccess:\n\n``` # use cosmwasm_std::{to_json_string, Binary, Event, SubMsgResponse, SubMsgResult}; #[allow(deprecated)] let response = SubMsgResponse { data: Some(Binary::from_base64(\"MTIzCg==\").unwrap()), events: vec![Event::new(\"wasm\").add_attribute(\"fo\", \"ba\")], msg_responses: vec![], }; let result: SubMsgResult = SubMsgResult::Ok(response); assert_eq!( to_json_string(&result).unwrap(), r#\"{\"ok\":{\"events\":[{\"type\":\"wasm\",\"attributes\":[{\"key\":\"fo\",\"value\":\"ba\"}]}],\"data\":\"MTIzCg==\",\"msg_responses\":[]}}\"#, ); ```\n\nFailure:\n\n``` # use cosmwasm_std::{to_json_string, SubMsgResult, Response}; let error_msg = String::from(\"Something went wrong\"); let result = SubMsgResult::Err(error_msg); assert_eq!(to_json_string(&result).unwrap(), r#\"{\"error\":\"Something went wrong\"}\"#); ```",
"oneOf": [
{
"type": "object",
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 @@ -435,9 +435,11 @@ mod tests {
let data = Binary::from(b"foobar");
let events = vec![Event::new("message").add_attribute("signer", "caller-addr")];
let gas_used = 1234567u64;
#[allow(deprecated)]
let result = SubMsgResult::Ok(SubMsgResponse {
events: events.clone(),
data: Some(data.clone()),
msg_responses: vec![],
});
let subcall = Reply {
id,
Expand All @@ -460,7 +462,10 @@ mod tests {
let qres: Reply = from_json(raw).unwrap();
assert_eq!(qres.id, id);
let result = qres.result.unwrap();
assert_eq!(result.data, Some(data));
#[allow(deprecated)]
{
assert_eq!(result.data, Some(data));
}
chipshort marked this conversation as resolved.
Show resolved Hide resolved
assert_eq!(result.events, events);
}
}
7 changes: 6 additions & 1 deletion contracts/reflect/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,11 @@ fn reply_and_query() {
let data = Binary::from(b"foobar");
let events = vec![Event::new("message").add_attribute("signer", "caller-addr")];
let gas_used = 1234567u64;
#[allow(deprecated)]
let result = SubMsgResult::Ok(SubMsgResponse {
events: events.clone(),
data: Some(data.clone()),
msg_responses: vec![],
});
let subcall = Reply {
id,
Expand All @@ -290,6 +292,9 @@ fn reply_and_query() {
let qres: Reply = from_json(raw).unwrap();
assert_eq!(qres.id, id);
let result = qres.result.unwrap();
assert_eq!(result.data, Some(data));
#[allow(deprecated)]
{
assert_eq!(result.data, Some(data));
}
assert_eq!(result.events, events);
}
2 changes: 1 addition & 1 deletion packages/std/src/results/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ pub use empty::Empty;
pub use events::{attr, Attribute, Event};
pub use query::QueryResponse;
pub use response::Response;
pub use submessages::{Reply, ReplyOn, SubMsg, SubMsgResponse, SubMsgResult};
pub use submessages::{MsgResponse, Reply, ReplyOn, SubMsg, SubMsgResponse, SubMsgResult};
pub use system_result::SystemResult;
Loading