Some checks failed
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
Build & Push SDK Proto Builder / build (push) Has been cancelled
142 lines
4.3 KiB
Go
142 lines
4.3 KiB
Go
package cli_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
abci "github.com/cometbft/cometbft/abci/types"
|
|
rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock"
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
sdkmath "cosmossdk.io/math"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
|
"github.com/cosmos/cosmos-sdk/codec/address"
|
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
|
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
|
|
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
|
testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
|
"github.com/cosmos/cosmos-sdk/x/genutil"
|
|
"github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
|
|
stakingcli "github.com/cosmos/cosmos-sdk/x/staking/client/cli"
|
|
)
|
|
|
|
type CLITestSuite struct {
|
|
suite.Suite
|
|
|
|
kr keyring.Keyring
|
|
encCfg testutilmod.TestEncodingConfig
|
|
baseCtx client.Context
|
|
clientCtx client.Context
|
|
}
|
|
|
|
func TestCLITestSuite(t *testing.T) {
|
|
suite.Run(t, new(CLITestSuite))
|
|
}
|
|
|
|
func (s *CLITestSuite) SetupSuite() {
|
|
s.encCfg = testutilmod.MakeTestEncodingConfig(genutil.AppModuleBasic{})
|
|
s.kr = keyring.NewInMemory(s.encCfg.Codec)
|
|
s.baseCtx = client.Context{}.
|
|
WithKeyring(s.kr).
|
|
WithTxConfig(s.encCfg.TxConfig).
|
|
WithCodec(s.encCfg.Codec).
|
|
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
|
|
WithAccountRetriever(client.MockAccountRetriever{}).
|
|
WithOutput(io.Discard).
|
|
WithChainID("test-chain")
|
|
|
|
ctxGen := func() client.Context {
|
|
bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{})
|
|
c := clitestutil.NewMockCometRPC(abci.ResponseQuery{
|
|
Value: bz,
|
|
})
|
|
return s.baseCtx.WithClient(c)
|
|
}
|
|
s.clientCtx = ctxGen()
|
|
}
|
|
|
|
func (s *CLITestSuite) TestGenTxCmd() {
|
|
amount := sdk.NewCoin("stake", sdkmath.NewInt(12))
|
|
|
|
tests := []struct {
|
|
name string
|
|
args []string
|
|
expCmdOutput string
|
|
}{
|
|
{
|
|
name: "invalid commission rate returns error",
|
|
args: []string{
|
|
fmt.Sprintf("--%s=%s", flags.FlagChainID, s.baseCtx.ChainID),
|
|
fmt.Sprintf("--%s=1", stakingcli.FlagCommissionRate),
|
|
"node0",
|
|
amount.String(),
|
|
},
|
|
expCmdOutput: fmt.Sprintf("--%s=%s --%s=1 %s %s", flags.FlagChainID, s.baseCtx.ChainID, stakingcli.FlagCommissionRate, "node0", amount.String()),
|
|
},
|
|
{
|
|
name: "valid gentx",
|
|
args: []string{
|
|
fmt.Sprintf("--%s=%s", flags.FlagChainID, s.baseCtx.ChainID),
|
|
"node0",
|
|
amount.String(),
|
|
},
|
|
expCmdOutput: fmt.Sprintf("--%s=%s %s %s", flags.FlagChainID, s.baseCtx.ChainID, "node0", amount.String()),
|
|
},
|
|
{
|
|
name: "invalid pubkey",
|
|
args: []string{
|
|
fmt.Sprintf("--%s=%s", flags.FlagChainID, "test-chain-1"),
|
|
fmt.Sprintf("--%s={\"key\":\"BOIkjkFruMpfOFC9oNPhiJGfmY2pHF/gwHdLDLnrnS0=\"}", stakingcli.FlagPubKey),
|
|
"node0",
|
|
amount.String(),
|
|
},
|
|
expCmdOutput: fmt.Sprintf("--%s=test-chain-1 --%s={\"key\":\"BOIkjkFruMpfOFC9oNPhiJGfmY2pHF/gwHdLDLnrnS0=\"} %s %s ", flags.FlagChainID, stakingcli.FlagPubKey, "node0", amount.String()),
|
|
},
|
|
{
|
|
name: "valid pubkey flag",
|
|
args: []string{
|
|
fmt.Sprintf("--%s=%s", flags.FlagChainID, "test-chain-1"),
|
|
fmt.Sprintf("--%s={\"@type\":\"/cosmos.crypto.ed25519.PubKey\",\"key\":\"BOIkjkFruMpfOFC9oNPhiJGfmY2pHF/gwHdLDLnrnS0=\"}", stakingcli.FlagPubKey),
|
|
"node0",
|
|
amount.String(),
|
|
},
|
|
expCmdOutput: fmt.Sprintf("--%s=test-chain-1 --%s={\"@type\":\"/cosmos.crypto.ed25519.PubKey\",\"key\":\"BOIkjkFruMpfOFC9oNPhiJGfmY2pHF/gwHdLDLnrnS0=\"} %s %s ", flags.FlagChainID, stakingcli.FlagPubKey, "node0", amount.String()),
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
|
|
dir := s.T().TempDir()
|
|
genTxFile := filepath.Join(dir, "myTx")
|
|
tc.args = append(tc.args, fmt.Sprintf("--%s=%s", flags.FlagOutputDocument, genTxFile))
|
|
|
|
s.Run(tc.name, func() {
|
|
clientCtx := s.clientCtx
|
|
ctx := svrcmd.CreateExecuteContext(context.Background())
|
|
|
|
cmd := cli.GenTxCmd(
|
|
module.NewBasicManager(),
|
|
clientCtx.TxConfig,
|
|
banktypes.GenesisBalancesIterator{},
|
|
clientCtx.HomeDir,
|
|
address.NewBech32Codec("cosmosvaloper"),
|
|
)
|
|
cmd.SetContext(ctx)
|
|
cmd.SetArgs(tc.args)
|
|
|
|
s.Require().NoError(client.SetCmdClientContextHandler(clientCtx, cmd))
|
|
|
|
if len(tc.args) != 0 {
|
|
s.Require().Contains(fmt.Sprint(cmd), tc.expCmdOutput)
|
|
}
|
|
})
|
|
}
|
|
}
|