From f8cb29f7bb711ea7219f60d9c4ff440870812a9b Mon Sep 17 00:00:00 2001 From: Gancho Manev Date: Fri, 4 Oct 2024 17:43:51 +0300 Subject: [PATCH] refactor: workaround cw-multi-test issue #206 --- platform/packages/platform/src/reply.rs | 37 +++++++++++++++++++------ 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/platform/packages/platform/src/reply.rs b/platform/packages/platform/src/reply.rs index 54d9906a1..149616dbb 100644 --- a/platform/packages/platform/src/reply.rs +++ b/platform/packages/platform/src/reply.rs @@ -5,11 +5,14 @@ use serde::de::DeserializeOwned; use sdk::{ - cosmos_sdk_proto::cosmwasm::wasm::v1::{ - MsgExecuteContractResponse, MsgInstantiateContract2Response, MsgInstantiateContractResponse, + cosmos_sdk_proto::{ + cosmwasm::wasm::v1::{ + MsgExecuteContractResponse, MsgInstantiateContract2Response, + MsgInstantiateContractResponse, + }, + prost::Message, }, - cosmos_sdk_proto::prost::Message, - cosmwasm_std::{from_json, Addr, Api, Reply}, + cosmwasm_std::{from_json, Addr, Api, Reply, SubMsgResponse}, }; use crate::{error::Error, result::Result}; @@ -97,13 +100,31 @@ fn decode_first_response(reply: Reply) -> Result where M: Message + Default, { - let responses = reply + reply .result .into_result() - .map_err(Error::ReplyResultError)? - .msg_responses; + .map_err(Error::ReplyResultError) + .and_then(|ref resp| decode_from_responses(resp).or_else(|_| decode_from_data(resp))) +} - if let [response] = responses.as_slice() { +// TODO remove once the [PR][https://github.com/CosmWasm/cw-multi-test/issues/206] got released +fn decode_from_data(resp: &SubMsgResponse) -> Result +where + M: Message + Default, +{ + #[allow(deprecated)] + resp.data + .as_ref() + .ok_or(Error::EmptyReply()) + .map_err(Into::into) + .and_then(|ref data| decode_raw(data)) +} + +fn decode_from_responses(resp: &SubMsgResponse) -> Result +where + M: Message + Default, +{ + if let [response] = resp.msg_responses.as_slice() { decode_raw(&response.value) } else { Err(Error::EmptyReply())