Merge pull request #1208 from dadamu/paul/fix-stargate-querier
fix: stargate querier does not reset the structure state
This commit is contained in:
@@ -600,6 +600,7 @@ func ConvertProtoToJSONMarshal(cdc codec.Codec, protoResponse codec.ProtoMarshal
|
|||||||
return nil, sdkerrors.Wrap(err, "to json")
|
return nil, sdkerrors.Wrap(err, "to json")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protoResponse.Reset()
|
||||||
return bz, nil
|
return bz, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
// TestDeterministicJsonMarshal tests that we get deterministic JSON marshalled response upon
|
||||||
// proto struct update in the state machine.
|
// proto struct update in the state machine.
|
||||||
func TestDeterministicJsonMarshal(t *testing.T) {
|
func TestDeterministicJsonMarshal(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user