From 7bdc3440036b45c71b85b406c18fafbce00a2d2a Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 29 Jan 2024 16:51:47 +0100 Subject: [PATCH] Adapt contracts to new new payload field in Reply --- contracts/ibc-reflect/src/contract.rs | 4 ++++ contracts/ibc-reflect/tests/integration.rs | 4 ++++ contracts/reflect/schema/raw/execute.json | 9 +++++++++ .../schema/raw/response_to_sub_msg_result.json | 9 +++++++++ contracts/reflect/schema/reflect.json | 18 ++++++++++++++++++ contracts/reflect/src/contract.rs | 6 ++++-- contracts/reflect/tests/integration.rs | 6 ++++-- 7 files changed, 52 insertions(+), 4 deletions(-) diff --git a/contracts/ibc-reflect/src/contract.rs b/contracts/ibc-reflect/src/contract.rs index 900ed8f242..d66dd49af0 100644 --- a/contracts/ibc-reflect/src/contract.rs +++ b/contracts/ibc-reflect/src/contract.rs @@ -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), @@ -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, @@ -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()), diff --git a/contracts/ibc-reflect/tests/integration.rs b/contracts/ibc-reflect/tests/integration.rs index 7c69621065..ecbb60cb86 100644 --- a/contracts/ibc-reflect/tests/integration.rs +++ b/contracts/ibc-reflect/tests/integration.rs @@ -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), @@ -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, @@ -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()), diff --git a/contracts/reflect/schema/raw/execute.json b/contracts/reflect/schema/raw/execute.json index 65a3e108d7..55c55e28b1 100644 --- a/contracts/reflect/schema/raw/execute.json +++ b/contracts/reflect/schema/raw/execute.json @@ -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" } diff --git a/contracts/reflect/schema/raw/response_to_sub_msg_result.json b/contracts/reflect/schema/raw/response_to_sub_msg_result.json index e11c7ad73e..8b9a44cd09 100644 --- a/contracts/reflect/schema/raw/response_to_sub_msg_result.json +++ b/contracts/reflect/schema/raw/response_to_sub_msg_result.json @@ -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" } diff --git a/contracts/reflect/schema/reflect.json b/contracts/reflect/schema/reflect.json index 0eb4351c4a..b510a0572b 100644 --- a/contracts/reflect/schema/reflect.json +++ b/contracts/reflect/schema/reflect.json @@ -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" } @@ -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" } diff --git a/contracts/reflect/src/contract.rs b/contracts/reflect/src/contract.rs index 0aa15d3459..3b4149fcd7 100644 --- a/contracts/reflect/src/contract.rs +++ b/contracts/reflect/src/contract.rs @@ -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; @@ -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 diff --git a/contracts/reflect/tests/integration.rs b/contracts/reflect/tests/integration.rs index b3cfda30c8..675b4786ad 100644 --- a/contracts/reflect/tests/integration.rs +++ b/contracts/reflect/tests/integration.rs @@ -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; @@ -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