* remove unused functions * create helper func to send tx * refactor to use test help to send tx by client * Commit before getting backend. * Temporal commit * temp commit * remove the creation of txbuilder from cli * fix imports * update changelog * Remove unused function. * Add flag home into tx sign command. * migrade TestCLIValidateSignatures to use new test suite * migrate test one * Add changes to make sign batch. * make test pass * refactor common logic * First part of cli sign. * Add test for sign batch. * refactor a little and improve the test * migrate broadcast command * fix linter * Remove printf for debug in bank module. * Fix unused err var. * fix linter * fix test * fix tests client * Fix linter. * Temp commit signature. * encode tx * migrate tests * Fix imports. * Remove changelog * fix tests * Fix tests. * Update x/bank/client/testutil/cli_helpers.go * Remove alias. * Remove wait for N block func. * export callCmd function into its own file. * fix imports * bring back to inner functions * apply mock io * the helpers use mockio * fix bug * Add Helpers. * return to put the function in testutil package * return BufferWriter in ExecTestCLICmd Co-authored-by: Alessio Treglia <alessio@tendermint.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
82 lines
2.3 KiB
Go
82 lines
2.3 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"encoding/base64"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
|
|
"github.com/cosmos/cosmos-sdk/testutil"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
)
|
|
|
|
func TestGetCommandEncode(t *testing.T) {
|
|
encodingConfig := simappparams.MakeEncodingConfig()
|
|
|
|
cmd := GetEncodeCommand()
|
|
_ = testutil.ApplyMockIODiscardOutErr(cmd)
|
|
|
|
authtypes.RegisterCodec(encodingConfig.Amino)
|
|
sdk.RegisterCodec(encodingConfig.Amino)
|
|
|
|
txGen := encodingConfig.TxGenerator
|
|
|
|
// Build a test transaction
|
|
fee := authtypes.NewStdFee(50000, sdk.Coins{sdk.NewInt64Coin("atom", 150)})
|
|
stdTx := authtypes.NewStdTx([]sdk.Msg{}, fee, []authtypes.StdSignature{}, "foomemo")
|
|
JSONEncoded, err := txGen.TxJSONEncoder()(stdTx)
|
|
require.NoError(t, err)
|
|
|
|
txFile, cleanup := testutil.WriteToNewTempFile(t, string(JSONEncoded))
|
|
txFileName := txFile.Name()
|
|
t.Cleanup(cleanup)
|
|
|
|
ctx := context.Background()
|
|
clientCtx := client.Context{}.
|
|
WithTxGenerator(encodingConfig.TxGenerator).
|
|
WithJSONMarshaler(encodingConfig.Marshaler)
|
|
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
|
|
|
|
cmd.SetArgs([]string{txFileName})
|
|
err = cmd.ExecuteContext(ctx)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
func TestGetCommandDecode(t *testing.T) {
|
|
encodingConfig := simappparams.MakeEncodingConfig()
|
|
|
|
clientCtx := client.Context{}.
|
|
WithTxGenerator(encodingConfig.TxGenerator).
|
|
WithJSONMarshaler(encodingConfig.Marshaler)
|
|
|
|
cmd := GetDecodeCommand()
|
|
_ = testutil.ApplyMockIODiscardOutErr(cmd)
|
|
|
|
sdk.RegisterCodec(encodingConfig.Amino)
|
|
|
|
txGen := encodingConfig.TxGenerator
|
|
clientCtx = clientCtx.WithTxGenerator(txGen)
|
|
|
|
// Build a test transaction
|
|
fee := authtypes.NewStdFee(50000, sdk.Coins{sdk.NewInt64Coin("atom", 150)})
|
|
stdTx := authtypes.NewStdTx([]sdk.Msg{}, fee, []authtypes.StdSignature{}, "foomemo")
|
|
|
|
// Encode transaction
|
|
txBytes, err := clientCtx.TxGenerator.TxEncoder()(stdTx)
|
|
require.NoError(t, err)
|
|
|
|
// Convert the transaction into base64 encoded string
|
|
base64Encoded := base64.StdEncoding.EncodeToString(txBytes)
|
|
|
|
ctx := context.Background()
|
|
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
|
|
|
|
// Execute the command
|
|
cmd.SetArgs([]string{base64Encoded})
|
|
require.NoError(t, cmd.ExecuteContext(ctx))
|
|
}
|