Skip to content

Commit

Permalink
Merge pull request #519 from CosmWasm/fix-payload-json
Browse files Browse the repository at this point in the history
Omit `Payload` from json if empty
  • Loading branch information
chipshort committed Feb 16, 2024
2 parents a26470d + 0b82148 commit ad6f170
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions types/submessages.go
Expand Up @@ -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
Expand All @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions types/submessages_test.go
Expand Up @@ -38,6 +38,17 @@ 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) {
Expand Down

0 comments on commit ad6f170

Please sign in to comment.