Merge pull request #1208 from dadamu/paul/fix-stargate-querier

fix: stargate querier does not reset the structure state
This commit is contained in:
Alexander Peters
2023-03-02 10:11:31 +01:00
committed by GitHub
2 changed files with 26 additions and 0 deletions

View File

@@ -600,6 +600,7 @@ func ConvertProtoToJSONMarshal(cdc codec.Codec, protoResponse codec.ProtoMarshal
return nil, sdkerrors.Wrap(err, "to json")
}
protoResponse.Reset()
return bz, nil
}

View File

@@ -749,6 +749,31 @@ func TestConvertProtoToJSONMarshal(t *testing.T) {
}
}
func TestResetProtoMarshalerAfterJsonMarshal(t *testing.T) {
appCodec := app.MakeEncodingConfig().Marshaler
protoMarshaler := &banktypes.QueryAllBalancesResponse{}
expected := appCodec.MustMarshalJSON(&banktypes.QueryAllBalancesResponse{
Balances: sdk.NewCoins(sdk.NewCoin("bar", sdk.NewInt(30))),
Pagination: &query.PageResponse{
NextKey: []byte("foo"),
},
})
bz, err := hex.DecodeString("0a090a036261721202333012050a03666f6f")
require.NoError(t, err)
// first marshal
response, err := keeper.ConvertProtoToJSONMarshal(appCodec, protoMarshaler, bz)
require.NoError(t, err)
require.Equal(t, expected, response)
// second marshal
response, err = keeper.ConvertProtoToJSONMarshal(appCodec, protoMarshaler, bz)
require.NoError(t, err)
require.Equal(t, expected, response)
}
// TestDeterministicJsonMarshal tests that we get deterministic JSON marshalled response upon
// proto struct update in the state machine.
func TestDeterministicJsonMarshal(t *testing.T) {