From b043797a079457900f3d459956edd4d189ee201b Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Tue, 1 Sep 2020 15:44:07 -0700 Subject: [PATCH] Fix "auto" Gas (#7207) * init commit * Add simulation request * Push progress * revert CalculateGas changes * Fix simulation response unmarshal * Fix tests * Fix import * Fix tests * refactor * fix simulation response unmarshalling Co-authored-by: Jack Zampolin Co-authored-by: Alessio Treglia Co-authored-by: anilCSE --- client/tx/tx.go | 2 +- client/tx/tx_test.go | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/client/tx/tx.go b/client/tx/tx.go index 5aa1d800cd..2babbf625e 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -256,7 +256,7 @@ func BuildSimTx(txf Factory, msgs ...sdk.Msg) ([]byte, error) { // sentinel pubkey. sig := signing.SignatureV2{ Data: &signing.SingleSignatureData{ - SignMode: txf.WithSignMode(signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON).signMode, + SignMode: txf.signMode, }, Sequence: txf.Sequence(), } diff --git a/client/tx/tx_test.go b/client/tx/tx_test.go index 117feb0b3d..587e497db6 100644 --- a/client/tx/tx_test.go +++ b/client/tx/tx_test.go @@ -4,19 +4,17 @@ import ( "errors" "testing" - "github.com/cosmos/cosmos-sdk/testutil" - "github.com/cosmos/cosmos-sdk/x/auth/signing" - "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/grpc/simulate" + "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" - - "github.com/cosmos/cosmos-sdk/client" - sim "github.com/cosmos/cosmos-sdk/client/grpc/simulate" - "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/signing" "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -32,7 +30,7 @@ func TestCalculateGas(t *testing.T) { if wantErr { return nil, 0, errors.New("query failed") } - simRes := &sim.SimulateResponse{ + simRes := &simulate.SimulateResponse{ GasInfo: &sdk.GasInfo{GasUsed: gasUsed, GasWanted: gasUsed}, Result: &sdk.Result{Data: []byte("tx data"), Log: "log"}, } @@ -65,7 +63,11 @@ func TestCalculateGas(t *testing.T) { for _, tc := range testCases { stc := tc - txf := tx.Factory{}.WithChainID("test-chain").WithTxConfig(NewTestTxConfig()) + txCfg := NewTestTxConfig() + + txf := tx.Factory{}. + WithChainID("test-chain"). + WithTxConfig(txCfg).WithSignMode(txCfg.SignModeHandler().DefaultMode()) t.Run(stc.name, func(t *testing.T) { queryFunc := makeQueryFunc(stc.args.queryFuncGasUsed, stc.args.queryFuncWantErr) @@ -84,13 +86,16 @@ func TestCalculateGas(t *testing.T) { } func TestBuildSimTx(t *testing.T) { + txCfg := NewTestTxConfig() + txf := tx.Factory{}. - WithTxConfig(NewTestTxConfig()). + WithTxConfig(txCfg). WithAccountNumber(50). WithSequence(23). WithFees("50stake"). WithMemo("memo"). - WithChainID("test-chain") + WithChainID("test-chain"). + WithSignMode(txCfg.SignModeHandler().DefaultMode()) msg := banktypes.NewMsgSend(sdk.AccAddress("from"), sdk.AccAddress("to"), nil) bz, err := tx.BuildSimTx(txf, msg)