Some checks are pending
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
275 lines
6.7 KiB
Go
275 lines
6.7 KiB
Go
package cli_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"testing"
|
|
"time"
|
|
|
|
rpcclientmock "git.cw.tr/mukan-network/mukan-consensus/rpc/client/mock"
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
sdkmath "cosmossdk.io/math"
|
|
|
|
"git.cw.tr/mukan-network/mukan-sdk/client"
|
|
"git.cw.tr/mukan-network/mukan-sdk/client/flags"
|
|
"git.cw.tr/mukan-network/mukan-sdk/codec/address"
|
|
"git.cw.tr/mukan-network/mukan-sdk/crypto/keyring"
|
|
svrcmd "git.cw.tr/mukan-network/mukan-sdk/server/cmd"
|
|
"git.cw.tr/mukan-network/mukan-sdk/testutil"
|
|
clitestutil "git.cw.tr/mukan-network/mukan-sdk/testutil/cli"
|
|
sdk "git.cw.tr/mukan-network/mukan-sdk/types"
|
|
testutilmod "git.cw.tr/mukan-network/mukan-sdk/types/module/testutil"
|
|
"git.cw.tr/mukan-network/mukan-sdk/x/auth/vesting"
|
|
"git.cw.tr/mukan-network/mukan-sdk/x/auth/vesting/client/cli"
|
|
)
|
|
|
|
type CLITestSuite struct {
|
|
suite.Suite
|
|
|
|
kr keyring.Keyring
|
|
encCfg testutilmod.TestEncodingConfig
|
|
baseCtx client.Context
|
|
}
|
|
|
|
func TestMigrateTestSuite(t *testing.T) {
|
|
suite.Run(t, new(CLITestSuite))
|
|
}
|
|
|
|
func (s *CLITestSuite) SetupSuite() {
|
|
s.encCfg = testutilmod.MakeTestEncodingConfig(vesting.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)
|
|
}
|
|
|
|
func (s *CLITestSuite) TestNewMsgCreateVestingAccountCmd() {
|
|
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
|
cmd := cli.NewMsgCreateVestingAccountCmd(address.NewBech32Codec("cosmos"))
|
|
cmd.SetOut(io.Discard)
|
|
|
|
extraArgs := []string{
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("photon", sdkmath.NewInt(10))).String()),
|
|
fmt.Sprintf("--%s=test-chain", flags.FlagChainID),
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, accounts[0].Address),
|
|
}
|
|
|
|
t := time.Date(2033, time.April, 1, 12, 34, 56, 789, time.UTC).Unix()
|
|
|
|
testCases := []struct {
|
|
name string
|
|
ctxGen func() client.Context
|
|
from, to sdk.AccAddress
|
|
amount sdk.Coins
|
|
endTime int64
|
|
extraArgs []string
|
|
expectErr bool
|
|
}{
|
|
{
|
|
"valid transaction",
|
|
func() client.Context {
|
|
return s.baseCtx
|
|
},
|
|
accounts[0].Address,
|
|
accounts[0].Address,
|
|
sdk.NewCoins(
|
|
sdk.NewCoin("stake", sdkmath.NewInt(10)),
|
|
sdk.NewCoin("photon", sdkmath.NewInt(40)),
|
|
),
|
|
t,
|
|
extraArgs,
|
|
false,
|
|
},
|
|
{
|
|
"invalid to Address",
|
|
func() client.Context {
|
|
return s.baseCtx
|
|
},
|
|
accounts[0].Address,
|
|
sdk.AccAddress{},
|
|
sdk.NewCoins(
|
|
sdk.NewCoin("stake", sdkmath.NewInt(10)),
|
|
sdk.NewCoin("photon", sdkmath.NewInt(40)),
|
|
),
|
|
t,
|
|
extraArgs,
|
|
true,
|
|
},
|
|
{
|
|
"invalid coins",
|
|
func() client.Context {
|
|
return s.baseCtx
|
|
},
|
|
accounts[0].Address,
|
|
accounts[0].Address,
|
|
nil,
|
|
t,
|
|
extraArgs,
|
|
true,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
s.Run(tc.name, func() {
|
|
ctx := svrcmd.CreateExecuteContext(context.Background())
|
|
|
|
cmd.SetContext(ctx)
|
|
fmt.Println(tc.amount.String())
|
|
cmd.SetArgs(append([]string{tc.to.String(), tc.amount.String(), fmt.Sprint(tc.endTime)}, tc.extraArgs...))
|
|
|
|
s.Require().NoError(client.SetCmdClientContextHandler(tc.ctxGen(), cmd))
|
|
|
|
err := cmd.Execute()
|
|
if tc.expectErr {
|
|
s.Require().Error(err)
|
|
} else {
|
|
s.Require().NoError(err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func (s *CLITestSuite) TestNewMsgCreatePermanentLockedAccountCmd() {
|
|
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
|
cmd := cli.NewMsgCreatePermanentLockedAccountCmd(address.NewBech32Codec("cosmos"))
|
|
cmd.SetOut(io.Discard)
|
|
|
|
extraArgs := []string{
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("photon", sdkmath.NewInt(10))).String()),
|
|
fmt.Sprintf("--%s=test-chain", flags.FlagChainID),
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, accounts[0].Address),
|
|
}
|
|
|
|
testCases := []struct {
|
|
name string
|
|
ctxGen func() client.Context
|
|
to sdk.AccAddress
|
|
amount sdk.Coins
|
|
extraArgs []string
|
|
expectErr bool
|
|
}{
|
|
{
|
|
"valid transaction",
|
|
func() client.Context {
|
|
return s.baseCtx
|
|
},
|
|
accounts[0].Address,
|
|
sdk.NewCoins(
|
|
sdk.NewCoin("stake", sdkmath.NewInt(10)),
|
|
sdk.NewCoin("photon", sdkmath.NewInt(40)),
|
|
),
|
|
extraArgs,
|
|
false,
|
|
},
|
|
{
|
|
"invalid to Address",
|
|
func() client.Context {
|
|
return s.baseCtx
|
|
},
|
|
sdk.AccAddress{},
|
|
sdk.NewCoins(
|
|
sdk.NewCoin("stake", sdkmath.NewInt(10)),
|
|
sdk.NewCoin("photon", sdkmath.NewInt(40)),
|
|
),
|
|
extraArgs,
|
|
true,
|
|
},
|
|
{
|
|
"invalid coins",
|
|
func() client.Context {
|
|
return s.baseCtx
|
|
},
|
|
accounts[0].Address,
|
|
nil,
|
|
extraArgs,
|
|
true,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
s.Run(tc.name, func() {
|
|
ctx := svrcmd.CreateExecuteContext(context.Background())
|
|
|
|
cmd.SetContext(ctx)
|
|
cmd.SetArgs(append([]string{tc.to.String(), tc.amount.String()}, tc.extraArgs...))
|
|
|
|
s.Require().NoError(client.SetCmdClientContextHandler(tc.ctxGen(), cmd))
|
|
|
|
err := cmd.Execute()
|
|
if tc.expectErr {
|
|
s.Require().Error(err)
|
|
} else {
|
|
s.Require().NoError(err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func (s *CLITestSuite) TestNewMsgCreatePeriodicVestingAccountCmd() {
|
|
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
|
cmd := cli.NewMsgCreatePeriodicVestingAccountCmd(address.NewBech32Codec("cosmos"))
|
|
cmd.SetOut(io.Discard)
|
|
|
|
extraArgs := []string{
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("photon", sdkmath.NewInt(10))).String()),
|
|
fmt.Sprintf("--%s=test-chain", flags.FlagChainID),
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, accounts[0].Address),
|
|
}
|
|
|
|
testCases := []struct {
|
|
name string
|
|
ctxGen func() client.Context
|
|
to sdk.AccAddress
|
|
extraArgs []string
|
|
expectErr bool
|
|
}{
|
|
{
|
|
"valid transaction",
|
|
func() client.Context {
|
|
return s.baseCtx
|
|
},
|
|
accounts[0].Address,
|
|
extraArgs,
|
|
false,
|
|
},
|
|
{
|
|
"invalid to Address",
|
|
func() client.Context {
|
|
return s.baseCtx
|
|
},
|
|
sdk.AccAddress{},
|
|
extraArgs,
|
|
true,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
s.Run(tc.name, func() {
|
|
ctx := svrcmd.CreateExecuteContext(context.Background())
|
|
|
|
cmd.SetContext(ctx)
|
|
cmd.SetArgs(append([]string{tc.to.String(), "./test.json"}, tc.extraArgs...))
|
|
|
|
s.Require().NoError(client.SetCmdClientContextHandler(tc.ctxGen(), cmd))
|
|
|
|
err := cmd.Execute()
|
|
if tc.expectErr {
|
|
s.Require().Error(err)
|
|
} else {
|
|
s.Require().NoError(err)
|
|
}
|
|
})
|
|
}
|
|
}
|