From da400156c31f673d7c1bab5d78e8c1d4975bc9bd Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Thu, 26 Mar 2020 12:50:39 -0400 Subject: [PATCH] Fix tests --- baseapp/baseapp_test.go | 5 +++-- client/tx/tx.go | 6 ++++-- client/tx/tx_test.go | 6 +++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 11d3e346c4..9de25e7010 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -3,12 +3,13 @@ package baseapp import ( "bytes" "encoding/binary" - "encoding/json" "fmt" "os" + "strings" "sync" "testing" + "github.com/gogo/protobuf/jsonpb" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -937,7 +938,7 @@ func TestSimulateTx(t *testing.T) { require.True(t, queryResult.IsOK(), queryResult.Log) var simRes sdk.SimulationResponse - require.NoError(t, json.Unmarshal(queryResult.Value, &simRes)) + require.NoError(t, jsonpb.Unmarshal(strings.NewReader(string(queryResult.Value)), &simRes)) require.Equal(t, gInfo, simRes.GasInfo) require.Equal(t, result.Log, simRes.Result.Log) diff --git a/client/tx/tx.go b/client/tx/tx.go index 7088a0bfda..6d1c1cd081 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -2,11 +2,13 @@ package tx import ( "bufio" - "encoding/json" "errors" "fmt" "net/http" "os" + "strings" + + "github.com/gogo/protobuf/jsonpb" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" @@ -277,7 +279,7 @@ func CalculateGas( } var simRes sdk.SimulationResponse - if err := json.Unmarshal(bz, &simRes); err != nil { + if err := jsonpb.Unmarshal(strings.NewReader(string(bz)), &simRes); err != nil { return sdk.SimulationResponse{}, 0, err } diff --git a/client/tx/tx_test.go b/client/tx/tx_test.go index 6fb3ceafb4..13e94f819b 100644 --- a/client/tx/tx_test.go +++ b/client/tx/tx_test.go @@ -1,13 +1,13 @@ package tx_test import ( - "encoding/json" "errors" "testing" "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/std" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" @@ -20,12 +20,12 @@ func TestCalculateGas(t *testing.T) { if wantErr { return nil, 0, errors.New("query failed") } - simRes := sdk.SimulationResponse{ + simRes := &sdk.SimulationResponse{ GasInfo: sdk.GasInfo{GasUsed: gasUsed, GasWanted: gasUsed}, Result: &sdk.Result{Data: []byte("tx data"), Log: "log"}, } - bz, err := json.Marshal(simRes) + bz, err := codec.ProtoMarshalJSON(simRes) if err != nil { return nil, 0, err }