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 <jack.zampolin@gmail.com>
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: anilCSE <anil@vitwit.com>
This commit is contained in:
Alexander Bezobchuk 2020-09-01 15:44:07 -07:00 committed by GitHub
parent 7d64086d33
commit b043797a07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 12 deletions

View File

@ -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(),
}

View File

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