Skip to content

Commit

Permalink
feat: add cli tests
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <troian.ap@gmail.com>
  • Loading branch information
troian committed Sep 10, 2024
1 parent d823349 commit 82869fd
Show file tree
Hide file tree
Showing 30 changed files with 4,129 additions and 172 deletions.
60 changes: 30 additions & 30 deletions go/cli/auth_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"
"strings"

"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/cosmos/cosmos-sdk/types/tx"
Expand Down Expand Up @@ -101,8 +101,8 @@ func (s *AuthCLITestSuite) SetupSuite() {

func (s *AuthCLITestSuite) TestCLIValidateSignatures() {
sendTokens := sdk.NewCoins(
sdk.NewCoin("testtoken", sdk.NewInt(10)),
sdk.NewCoin("uakt", sdk.NewInt(10)))
sdk.NewCoin("testtoken", sdkmath.NewInt(10)),
sdk.NewCoin("uakt", sdkmath.NewInt(10)))

res, err := s.createBankMsg(
s.cctx,
Expand Down Expand Up @@ -161,8 +161,8 @@ func (s *AuthCLITestSuite) TestCLIValidateSignatures() {

func (s *AuthCLITestSuite) TestCLISignBatch() {
sendTokens := sdk.NewCoins(
sdk.NewCoin("testtoken", sdk.NewInt(10)),
sdk.NewCoin("uakt", sdk.NewInt(10)),
sdk.NewCoin("testtoken", sdkmath.NewInt(10)),
sdk.NewCoin("uakt", sdkmath.NewInt(10)),
)

generatedStd, err := s.createBankMsg(
Expand Down Expand Up @@ -347,14 +347,14 @@ func (s *AuthCLITestSuite) TestCLIQueryTxsCmdByEvents() {
{
"fee event happy case",
cli.TestFlags().
WithEvents(fmt.Sprintf("tx.fee=%s", sdk.NewCoins(sdk.NewCoin("uakt", sdk.NewInt(10))).String())).
WithEvents(fmt.Sprintf("tx.fee=%s", sdk.NewCoins(sdk.NewCoin("uakt", sdkmath.NewInt(10))).String())).
WithOutputJSON(),
"",
},
{
"no matching fee event",
cli.TestFlags().
WithEvents(fmt.Sprintf("tx.fee=%s", sdk.NewCoins(sdk.NewCoin("uakt", sdk.NewInt(0))).String())).
WithEvents(fmt.Sprintf("tx.fee=%s", sdk.NewCoins(sdk.NewCoin("uakt", sdkmath.NewInt(0))).String())).
WithOutputJSON(),
"",
},
Expand All @@ -372,7 +372,7 @@ func (s *AuthCLITestSuite) TestCLIQueryTxsCmdByEvents() {
}

func (s *AuthCLITestSuite) TestCLISendGenerateSignAndBroadcast() {
sendTokens := sdk.NewCoin("uakt", sdk.TokensFromConsensusPower(10, sdk.DefaultPowerReduction))
sendTokens := sdk.NewCoin("uakt", sdk.TokensFromConsensusPower(10, cli.DefaultPowerReduction))

normalGeneratedTx, err := s.createBankMsg(
s.cctx,
Expand Down Expand Up @@ -568,7 +568,7 @@ func (s *AuthCLITestSuite) TestCLIMultisignInsufficientCosigners() {
).
WithSkipConfirm().
WithBroadcastModeSync().
WithFees(sdk.NewCoins(sdk.NewCoin("uakt", sdk.NewInt(10)))).
WithFees(sdk.NewCoins(sdk.NewCoin("uakt", sdkmath.NewInt(10)))).
WithGenerateOnly()...)
s.Require().NoError(err)

Expand Down Expand Up @@ -627,7 +627,7 @@ func (s *AuthCLITestSuite) TestCLIMultisignInsufficientCosigners() {
}

func (s *AuthCLITestSuite) TestCLIEncode() {
sendTokens := sdk.NewCoin("uakt", sdk.TokensFromConsensusPower(10, sdk.DefaultPowerReduction))
sendTokens := sdk.NewCoin("uakt", sdk.TokensFromConsensusPower(10, cli.DefaultPowerReduction))

normalGeneratedTx, err := s.createBankMsg(
s.cctx,
Expand Down Expand Up @@ -699,7 +699,7 @@ func (s *AuthCLITestSuite) TestCLIMultisignSortSignatures() {
).
WithSkipConfirm().
WithBroadcastModeSync().
WithFees(sdk.NewCoins(sdk.NewCoin("uakt", sdk.NewInt(10)))).
WithFees(sdk.NewCoins(sdk.NewCoin("uakt", sdkmath.NewInt(10)))).
WithGenerateOnly()...)
s.Require().NoError(err)

Expand Down Expand Up @@ -826,7 +826,7 @@ func (s *AuthCLITestSuite) TestSignWithMultisig() {
WithSkipConfirm().
WithBroadcastModeSync().
WithGenerateOnly().
WithFees(sdk.NewCoins(sdk.NewCoin("uakt", sdk.NewInt(10))))...)
WithFees(sdk.NewCoins(sdk.NewCoin("uakt", sdkmath.NewInt(10))))...)
s.Require().NoError(err)

// Save multi tx to file
Expand Down Expand Up @@ -879,7 +879,7 @@ func (s *AuthCLITestSuite) TestCLIMultisign() {
WithSkipConfirm().
WithBroadcastModeSync().
WithGenerateOnly().
WithFees(sdk.NewCoins(sdk.NewCoin("uakt", sdk.NewInt(10))))...,
WithFees(sdk.NewCoins(sdk.NewCoin("uakt", sdkmath.NewInt(10))))...,
)
s.Require().NoError(err)

Expand Down Expand Up @@ -986,12 +986,12 @@ func (s *AuthCLITestSuite) TestSignBatchMultisig() {
addr.String(),
s.val.String(),
sdk.NewCoins(
sdk.NewCoin("uakt", sdk.NewInt(1)),
sdk.NewCoin("uakt", sdkmath.NewInt(1)),
).String(),
).
WithBroadcastModeSync().
WithSkipConfirm().
WithFees(sdk.NewCoins(sdk.NewCoin("uakt", sdk.NewInt(10)))).
WithFees(sdk.NewCoins(sdk.NewCoin("uakt", sdkmath.NewInt(10)))).
WithGenerateOnly()...,
)
s.Require().NoError(err)
Expand Down Expand Up @@ -1160,12 +1160,12 @@ func (s *AuthCLITestSuite) TestTxWithoutPublicKey() {
s.val,
s.val,
sdk.NewCoins(
sdk.NewCoin("Stake", sdk.NewInt(10)),
sdk.NewCoin("Stake", sdkmath.NewInt(10)),
))
err := txBuilder.SetMsgs(msg)
s.Require().NoError(err)

txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin("Stake", sdk.NewInt(150))))
txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin("Stake", sdkmath.NewInt(150))))
txBuilder.SetGasLimit(testdata.NewTestGasLimit())

// Create a file with the unsigned tx.
Expand Down Expand Up @@ -1225,8 +1225,8 @@ func (s *AuthCLITestSuite) TestTxWithoutPublicKey() {
// transaction to the blockchain.
func (s *AuthCLITestSuite) TestSignWithMultiSignersAminoJSON() {
val0, val1 := s.val, s.val1
val0Coin := sdk.NewCoin("test1token", sdk.NewInt(10))
val1Coin := sdk.NewCoin("test2token", sdk.NewInt(10))
val0Coin := sdk.NewCoin("test1token", sdkmath.NewInt(10))
val1Coin := sdk.NewCoin("test2token", sdkmath.NewInt(10))
_, _, addr1 := testdata.KeyTestPubAddr()

// Creating a tx with 2 msgs from 2 signers: val0 and val1.
Expand All @@ -1239,7 +1239,7 @@ func (s *AuthCLITestSuite) TestSignWithMultiSignersAminoJSON() {
banktypes.NewMsgSend(val1, addr1, sdk.NewCoins(val1Coin)),
)
s.Require().NoError(err)
txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin("uakt", sdk.NewInt(10))))
txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin("uakt", sdkmath.NewInt(10))))
txBuilder.SetGasLimit(testdata.NewTestGasLimit() * 2)
s.Require().Equal([]sdk.AccAddress{val0, val1}, txBuilder.GetTx().GetSigners())

Expand Down Expand Up @@ -1300,7 +1300,7 @@ func (s *AuthCLITestSuite) TestSignWithMultiSignersAminoJSON() {
}

func (s *AuthCLITestSuite) TestAuxSigner() {
val0Coin := sdk.NewCoin("testtoken", sdk.NewInt(10))
val0Coin := sdk.NewCoin("testtoken", sdkmath.NewInt(10))

testCases := []struct {
name string
Expand Down Expand Up @@ -1364,11 +1364,11 @@ func (s *AuthCLITestSuite) TestAuxToFeeWithTips() {

tipper, err := acc.GetAddress()
require.NoError(err)
tipperInitialBal := sdk.NewCoin("testtoken", sdk.NewInt(10000))
tipperInitialBal := sdk.NewCoin("testtoken", sdkmath.NewInt(10000))

feePayer := s.val
fee := sdk.NewCoin("uakt", sdk.NewInt(1000))
tip := sdk.NewCoin("testtoken", sdk.NewInt(1000))
fee := sdk.NewCoin("uakt", sdkmath.NewInt(1000))
tip := sdk.NewCoin("testtoken", sdkmath.NewInt(1000))

_, err = s.createBankMsg(s.cctx, tipper, sdk.NewCoins(tipperInitialBal))
require.NoError(err)
Expand Down Expand Up @@ -1439,7 +1439,7 @@ func (s *AuthCLITestSuite) TestAuxToFeeWithTips() {
name: "--tip flag unset: no error",
tipper: tipper,
feePayer: feePayer,
tip: sdk.Coin{Denom: "testtoken", Amount: sdk.NewInt(0)},
tip: sdk.Coin{Denom: "testtoken", Amount: sdkmath.NewInt(0)},
tipperArgs: cli.TestFlags().
WithSignMode(cflags.SignModeDirectAux).
WithAux(),
Expand Down Expand Up @@ -1504,10 +1504,10 @@ func (s *AuthCLITestSuite) TestAuxToFeeWithTips() {
name: "wrong denom in tip: error",
tipper: tipper,
feePayer: feePayer,
tip: sdk.Coin{Denom: "testtoken", Amount: sdk.NewInt(0)},
tip: sdk.Coin{Denom: "testtoken", Amount: sdkmath.NewInt(0)},
tipperArgs: cli.TestFlags().
WithSignMode(cflags.SignModeDirectAux).
WithTip(sdk.Coin{Denom: "wrongDenom", Amount: sdk.NewInt(100)}).
WithTip(sdk.Coin{Denom: "wrongDenom", Amount: sdkmath.NewInt(100)}).
WithAux(),
feePayerArgs: cli.TestFlags().
WithSignMode(cflags.SignModeDirect).
Expand All @@ -1521,7 +1521,7 @@ func (s *AuthCLITestSuite) TestAuxToFeeWithTips() {
name: "insufficient fees: error",
tipper: tipper,
feePayer: feePayer,
tip: sdk.Coin{Denom: "testtoken", Amount: sdk.NewInt(0)},
tip: sdk.Coin{Denom: "testtoken", Amount: sdkmath.NewInt(0)},
tipperArgs: cli.TestFlags().
WithSignMode(cflags.SignModeDirectAux).
WithTip(tip).
Expand Down Expand Up @@ -1596,7 +1596,7 @@ func (s *AuthCLITestSuite) TestAuxToFeeWithTips() {
}
}

func (s *AuthCLITestSuite) getBalances(cctx client.Context, addr sdk.AccAddress, denom string) math.Int {
func (s *AuthCLITestSuite) getBalances(cctx client.Context, addr sdk.AccAddress, denom string) sdkmath.Int {
resp, err := clitestutil.QueryBalancesExec(
context.Background(),
cctx,
Expand All @@ -1622,6 +1622,6 @@ func (s *AuthCLITestSuite) createBankMsg(cctx client.Context, toAddr sdk.AccAddr
amount.String()).
WithSkipConfirm().
WithBroadcastModeSync().
WithFees(sdk.NewCoins(sdk.NewCoin("uakt", sdk.NewInt(10)))).
WithFees(sdk.NewCoins(sdk.NewCoin("uakt", sdkmath.NewInt(10)))).
Append(extraFlags)...)
}
7 changes: 4 additions & 3 deletions go/cli/authz_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"time"

sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/authz"
Expand All @@ -29,9 +30,9 @@ func (s *AuthzCLITestSuite) TestQueryAuthorizations() {
WithSkipConfirm().
WithFrom(val[0].Address.String()).
WithBroadcastModeSync().
WithExpiration(twoHours).
WithExpiration(fmt.Sprintf("%d", twoHours)).
WithSignMode("direct").
WithFees(sdk.NewCoins(sdk.NewCoin("uakt", sdk.NewInt(10))))...,
WithFees(sdk.NewCoins(sdk.NewCoin("uakt", sdkmath.NewInt(10))))...,
)
s.Require().NoError(err)

Expand Down Expand Up @@ -105,7 +106,7 @@ func (s *AuthzCLITestSuite) TestQueryAuthorization() {
fmt.Sprintf("--%s=%s", cflags.FlagFrom, val[0].Address),
fmt.Sprintf("--%s=%s", cflags.FlagBroadcastMode, cflags.BroadcastSync),
fmt.Sprintf("--%s=%d", cflags.FlagExpiration, twoHours),
fmt.Sprintf("--%s=%s", cflags.FlagFees, sdk.NewCoins(sdk.NewCoin("uakt", sdk.NewInt(10))).String()),
fmt.Sprintf("--%s=%s", cflags.FlagFees, sdk.NewCoins(sdk.NewCoin("uakt", sdkmath.NewInt(10))).String()),
)
s.Require().NoError(err)

Expand Down
16 changes: 9 additions & 7 deletions go/cli/authz_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package cli_test
import (
"bytes"
"context"
"fmt"
"io"
"time"

sdkmath "cosmossdk.io/math"
abci "github.com/cometbft/cometbft/abci/types"
rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock"
"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -82,7 +84,7 @@ func (s *AuthzCLITestSuite) SetupSuite() {
WithSkipConfirm().
WithDescription("Where is the title!?").
WithProposalType(govv1beta1.ProposalTypeText).
WithDeposit(sdk.NewCoin("uakt", govv1.DefaultMinDepositTokens))...)
WithDeposit(sdk.NewCoin("uakt", sdkmath.NewInt(10000000)))...)
s.Require().NoError(err)

// Create new account in the keyring.
Expand All @@ -100,8 +102,8 @@ func (s *AuthzCLITestSuite) SetupSuite() {
WithFrom(val[0].Address.String()).
WithSkipConfirm().
WithBroadcastModeSync().
WithFees(sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10)))).
WithExpiration(time.Now().Add(time.Minute*time.Duration(120)).Unix())...)
WithFees(sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(10)))).
WithExpiration(fmt.Sprintf("%d", time.Now().Add(time.Minute*time.Duration(120)).Unix()))...)
s.Require().NoError(err)

var response sdk.TxResponse
Expand All @@ -120,8 +122,8 @@ func (s *AuthzCLITestSuite) SetupSuite() {
WithFrom(val[0].Address.String()).
WithSkipConfirm().
WithBroadcastModeSync().
WithFees(sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10)))).
WithExpiration(time.Now().Add(time.Minute*time.Duration(120)).Unix())...)
WithFees(sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(10)))).
WithExpiration(fmt.Sprintf("%d", time.Now().Add(time.Minute*time.Duration(120)).Unix()))...)
s.Require().NoError(err)

// Create new accounts in the keyring.
Expand All @@ -141,8 +143,8 @@ func (s *AuthzCLITestSuite) SetupSuite() {
WithFrom(val[0].Address.String()).
WithSkipConfirm().
WithBroadcastModeSync().
WithFees(sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10)))).
WithExpiration(time.Now().Add(time.Minute*time.Duration(120)).Unix()).
WithFees(sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(10)))).
WithExpiration(fmt.Sprintf("%d", time.Now().Add(time.Minute*time.Duration(120)).Unix())).
WithAllowList(s.grantee[4].String())...)
s.Require().NoError(err)

Expand Down
Loading

0 comments on commit 82869fd

Please sign in to comment.