Skip to content

Commit

Permalink
Fix "auto" Gas (cosmos#7207)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Alessio Treglia <[email protected]>
Co-authored-by: anilCSE <[email protected]>
  • Loading branch information
4 people authored Sep 1, 2020
1 parent 7d64086 commit b043797
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion client/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand Down
27 changes: 16 additions & 11 deletions client/tx/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/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/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/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"
)
Expand All @@ -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"},
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit b043797

Please sign in to comment.