From fd0323541dd291ef8ce2f68cbe82c15f4a39efa8 Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 23 Feb 2023 18:32:30 +0800 Subject: [PATCH 1/2] fix: stargate querier does not reset the state --- x/wasm/keeper/query_plugins.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/wasm/keeper/query_plugins.go b/x/wasm/keeper/query_plugins.go index 91abcf5d..e6be4dde 100644 --- a/x/wasm/keeper/query_plugins.go +++ b/x/wasm/keeper/query_plugins.go @@ -600,6 +600,7 @@ func ConvertProtoToJSONMarshal(cdc codec.Codec, protoResponse codec.ProtoMarshal return nil, sdkerrors.Wrap(err, "to json") } + protoResponse.Reset() return bz, nil } From 6d8018ac59b65b74ed9822ba9fc7d7a611ab5c60 Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 25 Feb 2023 00:43:43 +0800 Subject: [PATCH 2/2] test: add unit test --- x/wasm/keeper/query_plugins_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/x/wasm/keeper/query_plugins_test.go b/x/wasm/keeper/query_plugins_test.go index c28a4462..fb5f6951 100644 --- a/x/wasm/keeper/query_plugins_test.go +++ b/x/wasm/keeper/query_plugins_test.go @@ -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) {