Skip to content

Commit

Permalink
Adapt contracts to new new payload field in Reply
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Jan 29, 2024
1 parent 6b430ba commit 7bdc344
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 4 deletions.
4 changes: 4 additions & 0 deletions contracts/ibc-reflect/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,13 @@ mod tests {
res.events[0]
);
let id = res.messages[0].id;
let payload = res.messages[0].payload.clone();

// fake a reply and ensure this works
#[allow(deprecated)]
let response = Reply {
id,
payload,
gas_used: 1234567,
result: SubMsgResult::Ok(SubMsgResponse {
events: fake_events(&account),
Expand Down Expand Up @@ -461,6 +463,7 @@ mod tests {
// and set up a reflect account
assert_eq!(1, res.messages.len());
let id = res.messages[0].id;
let payload = res.messages[0].payload.clone();
if let CosmosMsg::Wasm(WasmMsg::Instantiate {
admin,
code_id,
Expand All @@ -486,6 +489,7 @@ mod tests {
#[allow(deprecated)]
let response = Reply {
id,
payload,
gas_used: 1234567,
result: SubMsgResult::Ok(SubMsgResponse {
events: fake_events(reflect_addr.as_str()),
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 @@ -91,11 +91,13 @@ fn connect(
res.events[0]
);
let id = res.messages[0].id;
let payload = res.messages[0].payload.clone();

// fake a reply and ensure this works
#[allow(deprecated)]
let response = Reply {
id,
payload,
gas_used: 1234567,
result: SubMsgResult::Ok(SubMsgResponse {
events: fake_events(&account),
Expand Down Expand Up @@ -153,6 +155,7 @@ fn proper_handshake_flow() {
// and set up a reflect account
assert_eq!(1, res.messages.len());
let id = res.messages[0].id;
let payload = res.messages[0].payload.clone();
if let CosmosMsg::Wasm(WasmMsg::Instantiate {
admin,
code_id,
Expand All @@ -178,6 +181,7 @@ fn proper_handshake_flow() {
#[allow(deprecated)]
let response = Reply {
id,
payload,
gas_used: 1234567,
result: SubMsgResult::Ok(SubMsgResponse {
events: fake_events(reflect_addr.as_str()),
Expand Down
9 changes: 9 additions & 0 deletions contracts/reflect/schema/raw/execute.json
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,15 @@
"msg": {
"$ref": "#/definitions/CosmosMsg_for_CustomMsg"
},
"payload": {
"description": "Some arbirary data that the contract can set in an application specific way. This is just passed into the `reply` entry point and is not stored to state. Any encoding can be used. If `id` is used to identify a particular action, the encoding can also be different for each of those actions since you can match `id` first and then start processing the `payload`.\n\nThe environment restricts the length of this field in order to avoid abuse. The limit is environment specific and can change over time. The initial default is 128 KiB.\n\nUnset/nil/null cannot be differentiated from empty data.\n\nOn chains running CosmWasm 1.x this field will be ignored.",
"default": "",
"allOf": [
{
"$ref": "#/definitions/Binary"
}
]
},
"reply_on": {
"$ref": "#/definitions/ReplyOn"
}
Expand Down
9 changes: 9 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 @@ -21,6 +21,15 @@
"format": "uint64",
"minimum": 0.0
},
"payload": {
"description": "Some arbirary data that the contract set when emitting the `SubMsg`. This is just passed into the `reply` entry point and is not stored to state.\n\nUnset/nil/null cannot be differentiated from empty data.\n\nOn chains running CosmWasm 1.x this field is never filled.",
"default": "",
"allOf": [
{
"$ref": "#/definitions/Binary"
}
]
},
"result": {
"$ref": "#/definitions/SubMsgResult"
}
Expand Down
18 changes: 18 additions & 0 deletions contracts/reflect/schema/reflect.json
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,15 @@
"msg": {
"$ref": "#/definitions/CosmosMsg_for_CustomMsg"
},
"payload": {
"description": "Some arbirary data that the contract can set in an application specific way. This is just passed into the `reply` entry point and is not stored to state. Any encoding can be used. If `id` is used to identify a particular action, the encoding can also be different for each of those actions since you can match `id` first and then start processing the `payload`.\n\nThe environment restricts the length of this field in order to avoid abuse. The limit is environment specific and can change over time. The initial default is 128 KiB.\n\nUnset/nil/null cannot be differentiated from empty data.\n\nOn chains running CosmWasm 1.x this field will be ignored.",
"default": "",
"allOf": [
{
"$ref": "#/definitions/Binary"
}
]
},
"reply_on": {
"$ref": "#/definitions/ReplyOn"
}
Expand Down Expand Up @@ -1875,6 +1884,15 @@
"format": "uint64",
"minimum": 0.0
},
"payload": {
"description": "Some arbirary data that the contract set when emitting the `SubMsg`. This is just passed into the `reply` entry point and is not stored to state.\n\nUnset/nil/null cannot be differentiated from empty data.\n\nOn chains running CosmWasm 1.x this field is never filled.",
"default": "",
"allOf": [
{
"$ref": "#/definitions/Binary"
}
]
},
"result": {
"$ref": "#/definitions/SubMsgResult"
}
Expand Down
6 changes: 4 additions & 2 deletions contracts/reflect/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ mod tests {
let _res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();

let id = 123u64;
let payload = Binary::from(b"my dear");
let data = Binary::from(b"foobar");
let events = vec![Event::new("message").add_attribute("signer", "caller-addr")];
let gas_used = 1234567u64;
Expand All @@ -443,12 +444,13 @@ mod tests {
data: Some(data.clone()),
msg_responses: vec![],
});
let subcall = Reply {
let the_reply = Reply {
id,
payload,
gas_used,
result,
};
let res = reply(deps.as_mut(), mock_env(), subcall).unwrap();
let res = reply(deps.as_mut(), mock_env(), the_reply).unwrap();
assert_eq!(0, res.messages.len());

// query for a non-existant id
Expand Down
6 changes: 4 additions & 2 deletions contracts/reflect/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ fn reply_and_query() {
let _res: Response = instantiate(&mut deps, mock_env(), info, msg).unwrap();

let id = 123u64;
let payload = Binary::from(b"my dear");
let data = Binary::from(b"foobar");
let events = vec![Event::new("message").add_attribute("signer", "caller-addr")];
let gas_used = 1234567u64;
Expand All @@ -277,12 +278,13 @@ fn reply_and_query() {
data: Some(data.clone()),
msg_responses: vec![],
});
let subcall = Reply {
let the_reply = Reply {
id,
payload,
gas_used,
result,
};
let res: Response = reply(&mut deps, mock_env(), subcall).unwrap();
let res: Response = reply(&mut deps, mock_env(), the_reply).unwrap();
assert_eq!(0, res.messages.len());

// query for a non-existant id
Expand Down

0 comments on commit 7bdc344

Please sign in to comment.