test: add unit test

This commit is contained in:
Paul
2023-02-25 00:43:43 +08:00
parent fd0323541d
commit 6d8018ac59

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) {