-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description Closes: #10841 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
- Loading branch information
Showing
6 changed files
with
170 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
// +build norace | ||
|
||
package testutil | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/testutil/network" | ||
|
||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
func TestIntegrationTestSuite(t *testing.T) { | ||
cfg := network.DefaultConfig() | ||
cfg.NumValidators = 1 | ||
suite.Run(t, NewIntegrationTestSuite(cfg)) | ||
suite.Run(t, new(IntegrationTestSuite)) | ||
} | ||
|
||
func TestGRPCQueryTestSuite(t *testing.T) { | ||
suite.Run(t, new(GRPCQueryTestSuite)) | ||
} | ||
|
||
func TestWithdrawAllSuite(t *testing.T) { | ||
suite.Run(t, new(WithdrawAllTestSuite)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package testutil | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/crypto/hd" | ||
"github.com/cosmos/cosmos-sdk/crypto/keyring" | ||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" | ||
"github.com/cosmos/cosmos-sdk/testutil/network" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/client/testutil" | ||
"github.com/cosmos/cosmos-sdk/x/distribution/client/cli" | ||
stakingcli "github.com/cosmos/cosmos-sdk/x/staking/client/cli" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type WithdrawAllTestSuite struct { | ||
suite.Suite | ||
|
||
cfg network.Config | ||
network *network.Network | ||
} | ||
|
||
func (s *WithdrawAllTestSuite) SetupSuite() { | ||
cfg := network.DefaultConfig() | ||
cfg.NumValidators = 2 | ||
s.cfg = cfg | ||
|
||
s.T().Log("setting up integration test suite") | ||
network, err := network.New(s.T(), s.T().TempDir(), s.cfg) | ||
s.Require().NoError(err) | ||
s.network = network | ||
|
||
_, err = s.network.WaitForHeight(1) | ||
s.Require().NoError(err) | ||
} | ||
|
||
// TearDownSuite cleans up the curret test network after _each_ test. | ||
func (s *WithdrawAllTestSuite) TearDownSuite() { | ||
s.T().Log("tearing down integration test suite") | ||
s.network.Cleanup() | ||
} | ||
|
||
// This test requires multiple validators, if I add this test to `IntegrationTestSuite` by increasing | ||
// `NumValidators` the existing tests are leading to non-determnism so created new suite for this test. | ||
func (s *WithdrawAllTestSuite) TestNewWithdrawAllRewardsGenerateOnly() { | ||
require := s.Require() | ||
val := s.network.Validators[0] | ||
val1 := s.network.Validators[1] | ||
clientCtx := val.ClientCtx | ||
|
||
info, _, err := val.ClientCtx.Keyring.NewMnemonic("newAccount", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) | ||
require.NoError(err) | ||
|
||
pubkey, err := info.GetPubKey() | ||
require.NoError(err) | ||
|
||
newAddr := sdk.AccAddress(pubkey.Address()) | ||
_, err = banktestutil.MsgSendExec( | ||
val.ClientCtx, | ||
val.Address, | ||
newAddr, | ||
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2000))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), | ||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), | ||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), | ||
) | ||
require.NoError(err) | ||
|
||
// delegate 500 tokens to validator1 | ||
args := []string{ | ||
val.ValAddress.String(), | ||
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(500)).String(), | ||
fmt.Sprintf("--%s=%s", flags.FlagFrom, newAddr.String()), | ||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), | ||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), | ||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), | ||
} | ||
cmd := stakingcli.NewDelegateCmd() | ||
_, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) | ||
require.NoError(err) | ||
|
||
// delegate 500 tokens to validator2 | ||
args = []string{ | ||
val1.ValAddress.String(), | ||
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(500)).String(), | ||
fmt.Sprintf("--%s=%s", flags.FlagFrom, newAddr.String()), | ||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), | ||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), | ||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), | ||
} | ||
_, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) | ||
require.NoError(err) | ||
|
||
args = []string{ | ||
fmt.Sprintf("--%s=%s", flags.FlagFrom, newAddr.String()), | ||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), | ||
fmt.Sprintf("--%s=true", flags.FlagGenerateOnly), | ||
fmt.Sprintf("--%s=1", cli.FlagMaxMessagesPerTx), | ||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), | ||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), | ||
} | ||
cmd = cli.NewWithdrawAllRewardsCmd() | ||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) | ||
require.NoError(err) | ||
// expect 2 transactions in the generated file when --max-msgs in a tx set 1. | ||
s.Require().Equal(2, len(strings.Split(strings.Trim(out.String(), "\n"), "\n"))) | ||
|
||
args = []string{ | ||
fmt.Sprintf("--%s=%s", flags.FlagFrom, newAddr.String()), | ||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), | ||
fmt.Sprintf("--%s=true", flags.FlagGenerateOnly), | ||
fmt.Sprintf("--%s=2", cli.FlagMaxMessagesPerTx), | ||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), | ||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), | ||
} | ||
cmd = cli.NewWithdrawAllRewardsCmd() | ||
out, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) | ||
require.NoError(err) | ||
// expect 1 transaction in the generated file when --max-msgs in a tx set 2, since there are only delegations. | ||
s.Require().Equal(1, len(strings.Split(strings.Trim(out.String(), "\n"), "\n"))) | ||
} |