From e71fe0542dd5a5abd32a4bb52f21b678696e7dc0 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Thu, 15 Feb 2024 13:18:52 +0100 Subject: [PATCH 1/3] Omit Reply.Payload from json if empty --- types/submessages.go | 2 +- types/submessages_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/types/submessages.go b/types/submessages.go index 4965027d..6e6abbb0 100644 --- a/types/submessages.go +++ b/types/submessages.go @@ -93,7 +93,7 @@ type Reply struct { // Unset/nil/null cannot be differentiated from empty data. // // On chains running CosmWasm 1.x this field is never filled. - Payload []byte `json:"payload"` + Payload []byte `json:"payload,omitempty"` } // SubMsgResult is the raw response we return from wasmd after executing a SubMsg. diff --git a/types/submessages_test.go b/types/submessages_test.go index 1841ad59..4deca80a 100644 --- a/types/submessages_test.go +++ b/types/submessages_test.go @@ -38,6 +38,18 @@ func TestReplySerialization(t *testing.T) { serialized, err := json.Marshal(&reply1) require.NoError(t, err) require.Equal(t, `{"gas_used":4312324,"id":75,"result":{"ok":{"events":[{"type":"hi","attributes":[{"key":"si","value":"claro"}]}],"data":"PwCqXKs=","msg_responses":[{"type_url":"/cosmos.bank.v1beta1.MsgSendResponse","value":""}]}},"payload":"cGF5bG9hZA=="}`, string(serialized)) + + withoutPayload := Reply{ + GasUsed: 4312324, + ID: 75, + Result: SubMsgResult{ + Err: "some error", + }, + } + serialized2, err := json.Marshal(&withoutPayload) + require.NoError(t, err) + require.Equal(t, `{"gas_used":4312324,"id":75,"result":{"error": "some error"}}`, string(serialized2)) + } func TestSubMsgResponseSerialization(t *testing.T) { From f6047b16178402565f61fefbe8f5f0a118c426aa Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Thu, 15 Feb 2024 13:25:40 +0100 Subject: [PATCH 2/3] Fix SubMsg.Payload --- types/submessages.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/submessages.go b/types/submessages.go index 6e6abbb0..b0cb8174 100644 --- a/types/submessages.go +++ b/types/submessages.go @@ -71,7 +71,7 @@ type SubMsg struct { // Unset/nil/null cannot be differentiated from empty data. // // On chains running CosmWasm 1.x this field will be ignored. - Payload []byte `json:"payload"` + Payload []byte `json:"payload,omitempty"` // Gas limit measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md). // // Setting this to `None` means unlimited. Then the submessage execution can consume all gas of From 0b82148a07a1c866c945744c94a70744daf5f414 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Thu, 15 Feb 2024 13:27:56 +0100 Subject: [PATCH 3/3] Fix test --- types/submessages_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/types/submessages_test.go b/types/submessages_test.go index 4deca80a..5f3ec18a 100644 --- a/types/submessages_test.go +++ b/types/submessages_test.go @@ -48,8 +48,7 @@ func TestReplySerialization(t *testing.T) { } serialized2, err := json.Marshal(&withoutPayload) require.NoError(t, err) - require.Equal(t, `{"gas_used":4312324,"id":75,"result":{"error": "some error"}}`, string(serialized2)) - + require.Equal(t, `{"gas_used":4312324,"id":75,"result":{"error":"some error"}}`, string(serialized2)) } func TestSubMsgResponseSerialization(t *testing.T) {