* Migrate encode, decode, and broadcast cmd's to use TxGenerator marshal methods * Fix tests, add EncodingConfig * Add simapp/encoding.go and wire up with simcli * add godocs * fix tests * Debugging CLI Tests * Fix integration test * 6391 - lint issues and code coverage (#6414) * fixed lint issue of "txEncodeRespStr" * added tests for encode.go * WIP: added tests for decode.go * added txEncoder at bytes * updated decode test * updated txBytes to use TxEncoder in decoder test * added a require after TxEncoder * removed file save * debug decode command * fixed decode tests * added decode cli * updated encode and decode in a single file * separated decode test from encode test * review changes * removed register interface * review change * Fix tests * WIP add test for tx sign * removed commented code * Fix flags * WIP add test for sign * Address review suggestions * fixed command issue * Add tests for TxEncoder * Revert sign changes * Fix TxEncoder tests * Fix GetSign Cmd * Add tx test * Remove duplicate validation * Add tests for TxDecoder * Fix tests * Fix tests * Output to clientCtx.Output * Fix cli_tests Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com> Co-authored-by: atheesh <atheesh@vitwit.com> Co-authored-by: anilCSE <anil@vitwit.com> Co-authored-by: sahith-narahari <sahithnarahari@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
72 lines
2.1 KiB
Go
72 lines
2.1 KiB
Go
package cli
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"testing"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
|
|
"github.com/cosmos/cosmos-sdk/tests"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGetCommandEncode(t *testing.T) {
|
|
encodingConfig := simappparams.MakeEncodingConfig()
|
|
clientCtx := client.Context{}
|
|
clientCtx = clientCtx.
|
|
WithTxGenerator(encodingConfig.TxGenerator).
|
|
WithJSONMarshaler(encodingConfig.Marshaler)
|
|
|
|
cmd := GetEncodeCommand(clientCtx)
|
|
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 := tests.WriteToNewTempFile(t, string(JSONEncoded))
|
|
txFileName := txFile.Name()
|
|
t.Cleanup(cleanup)
|
|
|
|
err = cmd.RunE(cmd, []string{txFileName})
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
func TestGetCommandDecode(t *testing.T) {
|
|
encodingConfig := simappparams.MakeEncodingConfig()
|
|
|
|
clientCtx := client.Context{}
|
|
clientCtx = clientCtx.
|
|
WithTxGenerator(encodingConfig.TxGenerator).
|
|
WithJSONMarshaler(encodingConfig.Marshaler)
|
|
|
|
cmd := GetDecodeCommand(clientCtx)
|
|
|
|
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)
|
|
|
|
// Execute the command
|
|
err = runDecodeTxString(clientCtx)(cmd, []string{base64Encoded})
|
|
require.NoError(t, err)
|
|
}
|