From e4c093d61dc50268d769d962d08d90b924cc3730 Mon Sep 17 00:00:00 2001 From: atheesh Date: Tue, 14 Dec 2021 11:20:13 +0530 Subject: [PATCH 01/15] fix: max msgs (WIP) --- x/distribution/client/cli/tx.go | 2 +- x/distribution/client/testutil/cli_test.go | 3 +- x/distribution/client/testutil/suite.go | 109 +++++++++++++++++++++ 3 files changed, 112 insertions(+), 2 deletions(-) diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index ccbf5d8c6dbb..de48c11f0942 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -168,7 +168,7 @@ $ %[1]s tx distribution withdraw-all-rewards --from mykey } chunkSize, _ := cmd.Flags().GetInt(FlagMaxMessagesPerTx) - if clientCtx.BroadcastMode != flags.BroadcastBlock && chunkSize > 0 { + if !clientCtx.GenerateOnly && clientCtx.BroadcastMode != flags.BroadcastBlock && chunkSize > 0 { return fmt.Errorf("cannot use broadcast mode %[1]s with %[2]s != 0", clientCtx.BroadcastMode, FlagMaxMessagesPerTx) } diff --git a/x/distribution/client/testutil/cli_test.go b/x/distribution/client/testutil/cli_test.go index 742c1eb68086..49cd0598c6b9 100644 --- a/x/distribution/client/testutil/cli_test.go +++ b/x/distribution/client/testutil/cli_test.go @@ -1,3 +1,4 @@ +//go:build norace // +build norace package testutil @@ -12,7 +13,7 @@ import ( func TestIntegrationTestSuite(t *testing.T) { cfg := network.DefaultConfig() - cfg.NumValidators = 1 + cfg.NumValidators = 2 suite.Run(t, NewIntegrationTestSuite(cfg)) } diff --git a/x/distribution/client/testutil/suite.go b/x/distribution/client/testutil/suite.go index 3be8d5410aac..a8e22fe8f78a 100644 --- a/x/distribution/client/testutil/suite.go +++ b/x/distribution/client/testutil/suite.go @@ -10,12 +10,16 @@ import ( tmcli "github.com/tendermint/tendermint/libs/cli" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" 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" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + stakingcli "github.com/cosmos/cosmos-sdk/x/staking/client/cli" ) type IntegrationTestSuite struct { @@ -748,3 +752,108 @@ func (s *IntegrationTestSuite) TestGetCmdSubmitProposal() { }) } } + +func (s *IntegrationTestSuite) TestNewWithdrawAllRewardsWithMode() { + 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() + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) + require.NoError(err) + fmt.Println("1st delegate", out.String()) + + // 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()), + } + out, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) + require.NoError(err) + fmt.Println("2nd delegate", out.String()) + + clientCtx = clientCtx.WithBroadcastMode("sync") + 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.BroadcastSync), + 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) + + // var result sdk.TxResponse + // require.NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &result)) + + // fmt.Println(result.TxHash) + + fmt.Println("1st withdrawal of all rewards", out.String()) + + clientCtx = clientCtx.WithBroadcastMode("async") + 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.BroadcastAsync), + 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) + + // require.NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &result)) + + // fmt.Println(result.TxHash) + + fmt.Println("2nd withdrawal of all rewards", out.String()) + + // waiting txn to include in the block + // time.Sleep(10 * time.Second) + // // Query txn details by Hash + // args = []string{ + // result.TxHash, + // fmt.Sprintf("--%s=json", tmcli.OutputFlag), + // } + + // cmd = authcli.QueryTxCmd() + // out, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) + // require.NoError(err) + // fmt.Println(out.String()) + + require.True(false) +} From 267ed836121aa4b144ecb830ca8443b8cdaa8a8b Mon Sep 17 00:00:00 2001 From: atheesh Date: Mon, 27 Dec 2021 17:01:23 +0530 Subject: [PATCH 02/15] add tests --- x/distribution/client/testutil/suite.go | 40 ++++--------------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/x/distribution/client/testutil/suite.go b/x/distribution/client/testutil/suite.go index a8e22fe8f78a..b720e8ac10ba 100644 --- a/x/distribution/client/testutil/suite.go +++ b/x/distribution/client/testutil/suite.go @@ -786,9 +786,8 @@ func (s *IntegrationTestSuite) TestNewWithdrawAllRewardsWithMode() { fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), } cmd := stakingcli.NewDelegateCmd() - out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) + _, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) require.NoError(err) - fmt.Println("1st delegate", out.String()) // delegate 500 tokens to validator2 args = []string{ @@ -799,9 +798,8 @@ func (s *IntegrationTestSuite) TestNewWithdrawAllRewardsWithMode() { 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()), } - out, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) + _, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) require.NoError(err) - fmt.Println("2nd delegate", out.String()) clientCtx = clientCtx.WithBroadcastMode("sync") args = []string{ @@ -813,47 +811,21 @@ func (s *IntegrationTestSuite) TestNewWithdrawAllRewardsWithMode() { 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) + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) require.NoError(err) - - // var result sdk.TxResponse - // require.NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &result)) - - // fmt.Println(result.TxHash) - - fmt.Println("1st withdrawal of all rewards", out.String()) + s.Require().Equal(2, len(strings.Split(strings.Trim(out.String(), "\n"), "\n"))) clientCtx = clientCtx.WithBroadcastMode("async") 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=2", cli.FlagMaxMessagesPerTx), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastAsync), 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) - - // require.NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &result)) - - // fmt.Println(result.TxHash) - - fmt.Println("2nd withdrawal of all rewards", out.String()) - - // waiting txn to include in the block - // time.Sleep(10 * time.Second) - // // Query txn details by Hash - // args = []string{ - // result.TxHash, - // fmt.Sprintf("--%s=json", tmcli.OutputFlag), - // } - - // cmd = authcli.QueryTxCmd() - // out, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) - // require.NoError(err) - // fmt.Println(out.String()) - - require.True(false) + s.Require().Equal(1, len(strings.Split(strings.Trim(out.String(), "\n"), "\n"))) } From bdf70465b61d714bc2b1940363f1b66a4a1e9879 Mon Sep 17 00:00:00 2001 From: atheesh Date: Tue, 28 Dec 2021 11:31:00 +0530 Subject: [PATCH 03/15] fix tests --- x/distribution/client/testutil/suite.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/x/distribution/client/testutil/suite.go b/x/distribution/client/testutil/suite.go index b720e8ac10ba..467888e7934b 100644 --- a/x/distribution/client/testutil/suite.go +++ b/x/distribution/client/testutil/suite.go @@ -133,7 +133,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorOutstandingRewards() { fmt.Sprintf("--%s=json", tmcli.OutputFlag), }, false, - `{"rewards":[{"denom":"stake","amount":"1164.240000000000000000"}]}`, + `{"rewards":[{"denom":"stake","amount":"1144.440000000000000000"}]}`, }, { "text output", @@ -144,7 +144,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorOutstandingRewards() { }, false, `rewards: -- amount: "1164.240000000000000000" +- amount: "1144.440000000000000000" denom: stake`, }, } @@ -196,7 +196,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorCommission() { fmt.Sprintf("--%s=json", tmcli.OutputFlag), }, false, - `{"commission":[{"denom":"stake","amount":"464.520000000000000000"}]}`, + `{"commission":[{"denom":"stake","amount":"457.342500000000000000"}]}`, }, { "text output", @@ -207,7 +207,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorCommission() { }, false, `commission: -- amount: "464.520000000000000000" +- amount: "457.342500000000000000" denom: stake`, }, } @@ -349,7 +349,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDelegatorRewards() { fmt.Sprintf("--%s=json", tmcli.OutputFlag), }, false, - fmt.Sprintf(`{"rewards":[{"validator_address":"%s","reward":[{"denom":"stake","amount":"387.100000000000000000"}]}],"total":[{"denom":"stake","amount":"387.100000000000000000"}]}`, valAddr.String()), + fmt.Sprintf(`{"rewards":[{"validator_address":"%s","reward":[{"denom":"stake","amount":"391.050000000000000000"}]}],"total":[{"denom":"stake","amount":"391.050000000000000000"}]}`, valAddr.String()), }, { "json output (specific validator)", @@ -359,7 +359,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDelegatorRewards() { fmt.Sprintf("--%s=json", tmcli.OutputFlag), }, false, - `{"rewards":[{"denom":"stake","amount":"387.100000000000000000"}]}`, + `{"rewards":[{"denom":"stake","amount":"391.050000000000000000"}]}`, }, { "text output", @@ -371,11 +371,11 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDelegatorRewards() { false, fmt.Sprintf(`rewards: - reward: - - amount: "387.100000000000000000" + - amount: "391.050000000000000000" denom: stake validator_address: %s total: -- amount: "387.100000000000000000" +- amount: "391.050000000000000000" denom: stake`, valAddr.String()), }, { @@ -387,7 +387,7 @@ total: }, false, `rewards: -- amount: "387.100000000000000000" +- amount: "391.050000000000000000" denom: stake`, }, } @@ -424,13 +424,13 @@ func (s *IntegrationTestSuite) TestGetCmdQueryCommunityPool() { { "json output", []string{fmt.Sprintf("--%s=3", flags.FlagHeight), fmt.Sprintf("--%s=json", tmcli.OutputFlag)}, - `{"pool":[{"denom":"stake","amount":"4.740000000000000000"}]}`, + `{"pool":[{"denom":"stake","amount":"9.480000000000000000"}]}`, }, { "text output", []string{fmt.Sprintf("--%s=text", tmcli.OutputFlag), fmt.Sprintf("--%s=3", flags.FlagHeight)}, `pool: -- amount: "4.740000000000000000" +- amount: "9.480000000000000000" denom: stake`, }, } From cbe7effe0e77f81848e074537820e45f44cb5c1c Mon Sep 17 00:00:00 2001 From: atheesh Date: Wed, 5 Jan 2022 11:15:47 +0530 Subject: [PATCH 04/15] fix tess --- x/distribution/client/testutil/suite.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/distribution/client/testutil/suite.go b/x/distribution/client/testutil/suite.go index 467888e7934b..1c0cc4b3719f 100644 --- a/x/distribution/client/testutil/suite.go +++ b/x/distribution/client/testutil/suite.go @@ -196,7 +196,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorCommission() { fmt.Sprintf("--%s=json", tmcli.OutputFlag), }, false, - `{"commission":[{"denom":"stake","amount":"457.342500000000000000"}]}`, + `{"commission":[{"denom":"stake","amount":"473.167500000000000000"}]}`, }, { "text output", @@ -207,7 +207,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorCommission() { }, false, `commission: -- amount: "457.342500000000000000" +- amount: "473.167500000000000000" denom: stake`, }, } From 3ec48fe15a192e63450e422e5c518bacfa2dce4a Mon Sep 17 00:00:00 2001 From: atheesh Date: Thu, 6 Jan 2022 17:55:35 +0530 Subject: [PATCH 05/15] udpate tests --- x/distribution/client/testutil/suite.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/x/distribution/client/testutil/suite.go b/x/distribution/client/testutil/suite.go index 1c0cc4b3719f..d72b65ba315b 100644 --- a/x/distribution/client/testutil/suite.go +++ b/x/distribution/client/testutil/suite.go @@ -753,7 +753,7 @@ func (s *IntegrationTestSuite) TestGetCmdSubmitProposal() { } } -func (s *IntegrationTestSuite) TestNewWithdrawAllRewardsWithMode() { +func (s *IntegrationTestSuite) TestNewWithdrawAllRewardsGenerateOnly() { require := s.Require() val := s.network.Validators[0] val1 := s.network.Validators[1] @@ -801,7 +801,6 @@ func (s *IntegrationTestSuite) TestNewWithdrawAllRewardsWithMode() { _, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) require.NoError(err) - clientCtx = clientCtx.WithBroadcastMode("sync") args = []string{ fmt.Sprintf("--%s=%s", flags.FlagFrom, newAddr.String()), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), @@ -815,7 +814,6 @@ func (s *IntegrationTestSuite) TestNewWithdrawAllRewardsWithMode() { require.NoError(err) s.Require().Equal(2, len(strings.Split(strings.Trim(out.String(), "\n"), "\n"))) - clientCtx = clientCtx.WithBroadcastMode("async") args = []string{ fmt.Sprintf("--%s=%s", flags.FlagFrom, newAddr.String()), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), From 5469613fba1d7e72145b0bc5a1074f42ffb1272a Mon Sep 17 00:00:00 2001 From: atheesh Date: Thu, 6 Jan 2022 18:47:51 +0530 Subject: [PATCH 06/15] update tests --- x/distribution/client/testutil/suite.go | 141 ++++++++++++++++-------- 1 file changed, 95 insertions(+), 46 deletions(-) diff --git a/x/distribution/client/testutil/suite.go b/x/distribution/client/testutil/suite.go index d72b65ba315b..1b7db1ba37d3 100644 --- a/x/distribution/client/testutil/suite.go +++ b/x/distribution/client/testutil/suite.go @@ -25,8 +25,9 @@ import ( type IntegrationTestSuite struct { suite.Suite - cfg network.Config - network *network.Network + cfg network.Config + network *network.Network + delegator sdk.AccAddress } func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite { @@ -59,6 +60,53 @@ func (s *IntegrationTestSuite) SetupTest() { _, err = s.network.WaitForHeight(1) s.Require().NoError(err) + + 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) + s.Require().NoError(err) + + pubkey, err := info.GetPubKey() + s.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()), + ) + s.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) + s.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) + s.Require().NoError(err) + s.delegator = newAddr } // TearDownTest cleans up the curret test network after _each_ test. @@ -756,52 +804,53 @@ func (s *IntegrationTestSuite) TestGetCmdSubmitProposal() { func (s *IntegrationTestSuite) TestNewWithdrawAllRewardsGenerateOnly() { require := s.Require() val := s.network.Validators[0] - val1 := s.network.Validators[1] + // 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 + // 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) + + newAddr := s.delegator 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), @@ -809,7 +858,7 @@ func (s *IntegrationTestSuite) TestNewWithdrawAllRewardsGenerateOnly() { fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), } - cmd = cli.NewWithdrawAllRewardsCmd() + cmd := cli.NewWithdrawAllRewardsCmd() out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) require.NoError(err) s.Require().Equal(2, len(strings.Split(strings.Trim(out.String(), "\n"), "\n"))) From 862fc0978ddd93a501adc932377d0866231d5ca8 Mon Sep 17 00:00:00 2001 From: atheesh Date: Thu, 6 Jan 2022 18:52:11 +0530 Subject: [PATCH 07/15] update tests --- x/distribution/client/testutil/suite.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/distribution/client/testutil/suite.go b/x/distribution/client/testutil/suite.go index 1b7db1ba37d3..9dd7d4909912 100644 --- a/x/distribution/client/testutil/suite.go +++ b/x/distribution/client/testutil/suite.go @@ -804,7 +804,6 @@ func (s *IntegrationTestSuite) TestGetCmdSubmitProposal() { func (s *IntegrationTestSuite) 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) From fa554dbeac4c6d0ea70b075c503d0f5439c70081 Mon Sep 17 00:00:00 2001 From: atheesh Date: Thu, 6 Jan 2022 19:08:31 +0530 Subject: [PATCH 08/15] update changelog --- CHANGELOG.md | 2 ++ x/distribution/client/testutil/suite.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c92685869160..a5f4b252abef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -188,6 +188,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ibc-denom. * [\#10593](https://github.com/cosmos/cosmos-sdk/pull/10593) Update swagger-ui to v4.1.0 to fix xss vulnerability. * [\#10674](https://github.com/cosmos/cosmos-sdk/pull/10674) Fix issue with `Error.Wrap` and `Error.Wrapf` usage with `errors.Is`. +* [\#10842](https://github.com/cosmos/cosmos-sdk/pull/10842) Fix error when `--generate-only`, `--max-msgs` fags set while executing `WithdrawAllRewards` command. +. ### State Machine Breaking diff --git a/x/distribution/client/testutil/suite.go b/x/distribution/client/testutil/suite.go index 9dd7d4909912..ec4a3bcea627 100644 --- a/x/distribution/client/testutil/suite.go +++ b/x/distribution/client/testutil/suite.go @@ -860,6 +860,7 @@ func (s *IntegrationTestSuite) TestNewWithdrawAllRewardsGenerateOnly() { 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{ @@ -873,5 +874,6 @@ func (s *IntegrationTestSuite) TestNewWithdrawAllRewardsGenerateOnly() { 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"))) } From bb03e6dceeacd8f62ed1d17aa12ef01117205f5e Mon Sep 17 00:00:00 2001 From: atheesh Date: Thu, 6 Jan 2022 20:50:34 +0530 Subject: [PATCH 09/15] update tests --- x/distribution/client/testutil/suite.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/distribution/client/testutil/suite.go b/x/distribution/client/testutil/suite.go index ec4a3bcea627..c0007f81b672 100644 --- a/x/distribution/client/testutil/suite.go +++ b/x/distribution/client/testutil/suite.go @@ -58,7 +58,7 @@ func (s *IntegrationTestSuite) SetupTest() { s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) s.Require().NoError(err) - _, err = s.network.WaitForHeight(1) + _, err = s.network.WaitForHeight(6) s.Require().NoError(err) val := s.network.Validators[0] From 967766e0fecdeab9e895f52a766d3525f594b3dc Mon Sep 17 00:00:00 2001 From: atheesh Date: Thu, 6 Jan 2022 21:27:55 +0530 Subject: [PATCH 10/15] revert tests --- x/distribution/client/testutil/suite.go | 148 +++++++++--------------- 1 file changed, 52 insertions(+), 96 deletions(-) diff --git a/x/distribution/client/testutil/suite.go b/x/distribution/client/testutil/suite.go index c0007f81b672..6d9475e0813e 100644 --- a/x/distribution/client/testutil/suite.go +++ b/x/distribution/client/testutil/suite.go @@ -3,7 +3,6 @@ package testutil import ( "fmt" "strings" - "time" "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/suite" @@ -25,9 +24,8 @@ import ( type IntegrationTestSuite struct { suite.Suite - cfg network.Config - network *network.Network - delegator sdk.AccAddress + cfg network.Config + network *network.Network } func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite { @@ -58,55 +56,10 @@ func (s *IntegrationTestSuite) SetupTest() { s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) s.Require().NoError(err) - _, err = s.network.WaitForHeight(6) - s.Require().NoError(err) - - 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) - s.Require().NoError(err) - - pubkey, err := info.GetPubKey() - s.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()), - ) + _, err = s.network.WaitForHeight(1) s.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) - s.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) - s.Require().NoError(err) - s.delegator = newAddr + // s.delegator = newAddr } // TearDownTest cleans up the curret test network after _each_ test. @@ -362,7 +315,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDelegatorRewards() { addr := val.Address valAddr := sdk.ValAddress(addr) - _, err := s.network.WaitForHeightWithTimeout(11, time.Minute) + _, err := s.network.WaitForHeight(6) s.Require().NoError(err) testCases := []struct { @@ -804,52 +757,55 @@ func (s *IntegrationTestSuite) TestGetCmdSubmitProposal() { func (s *IntegrationTestSuite) 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) - - newAddr := s.delegator + 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) + + _, err = s.network.WaitForHeight(6) + 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), @@ -857,7 +813,7 @@ func (s *IntegrationTestSuite) TestNewWithdrawAllRewardsGenerateOnly() { fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), } - cmd := cli.NewWithdrawAllRewardsCmd() + 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. From 24e4a3a62c85f48a593990f2a5587cc75067db4a Mon Sep 17 00:00:00 2001 From: atheesh Date: Thu, 6 Jan 2022 22:07:03 +0530 Subject: [PATCH 11/15] udpate tests --- x/distribution/client/testutil/suite.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/distribution/client/testutil/suite.go b/x/distribution/client/testutil/suite.go index 6d9475e0813e..75e6130e882b 100644 --- a/x/distribution/client/testutil/suite.go +++ b/x/distribution/client/testutil/suite.go @@ -134,7 +134,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorOutstandingRewards() { fmt.Sprintf("--%s=json", tmcli.OutputFlag), }, false, - `{"rewards":[{"denom":"stake","amount":"1144.440000000000000000"}]}`, + `{"rewards":[{"denom":"stake","amount":"1184.040000000000000000"}]}`, }, { "text output", @@ -145,7 +145,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorOutstandingRewards() { }, false, `rewards: -- amount: "1144.440000000000000000" +- amount: "1184.040000000000000000" denom: stake`, }, } From a23e0ec8a9558908e0bc3ed17b93e416033f5081 Mon Sep 17 00:00:00 2001 From: atheesh Date: Thu, 6 Jan 2022 23:11:43 +0530 Subject: [PATCH 12/15] update tests --- x/distribution/client/testutil/suite.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/distribution/client/testutil/suite.go b/x/distribution/client/testutil/suite.go index 75e6130e882b..cd28d7e63bfd 100644 --- a/x/distribution/client/testutil/suite.go +++ b/x/distribution/client/testutil/suite.go @@ -3,6 +3,7 @@ package testutil import ( "fmt" "strings" + "time" "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/suite" @@ -315,7 +316,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDelegatorRewards() { addr := val.Address valAddr := sdk.ValAddress(addr) - _, err := s.network.WaitForHeight(6) + _, err := s.network.WaitForHeightWithTimeout(11, time.Minute) s.Require().NoError(err) testCases := []struct { From 0340a083bee4a15a48e2c87de2e622a1fb409292 Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 7 Jan 2022 09:32:14 +0530 Subject: [PATCH 13/15] fix tests --- x/distribution/client/testutil/suite.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x/distribution/client/testutil/suite.go b/x/distribution/client/testutil/suite.go index cd28d7e63bfd..4a5a730ce532 100644 --- a/x/distribution/client/testutil/suite.go +++ b/x/distribution/client/testutil/suite.go @@ -135,7 +135,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorOutstandingRewards() { fmt.Sprintf("--%s=json", tmcli.OutputFlag), }, false, - `{"rewards":[{"denom":"stake","amount":"1184.040000000000000000"}]}`, + `{"rewards":[{"denom":"stake","amount":"1144.440000000000000000"}]}`, }, { "text output", @@ -146,7 +146,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorOutstandingRewards() { }, false, `rewards: -- amount: "1184.040000000000000000" +- amount: "1144.440000000000000000" denom: stake`, }, } @@ -198,7 +198,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorCommission() { fmt.Sprintf("--%s=json", tmcli.OutputFlag), }, false, - `{"commission":[{"denom":"stake","amount":"473.167500000000000000"}]}`, + `{"commission":[{"denom":"stake","amount":"457.342500000000000000"}]}`, }, { "text output", @@ -209,7 +209,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorCommission() { }, false, `commission: -- amount: "473.167500000000000000" +- amount: "457.342500000000000000" denom: stake`, }, } From 6ad91607b674caf7203a97ec0d1dd607328e889f Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 7 Jan 2022 10:52:37 +0530 Subject: [PATCH 14/15] add separate suite for withdraw all msg --- x/distribution/client/testutil/cli_test.go | 8 +- x/distribution/client/testutil/suite.go | 109 ++--------------- .../client/testutil/withdraw_all_suite.go | 115 ++++++++++++++++++ 3 files changed, 134 insertions(+), 98 deletions(-) create mode 100644 x/distribution/client/testutil/withdraw_all_suite.go diff --git a/x/distribution/client/testutil/cli_test.go b/x/distribution/client/testutil/cli_test.go index 49cd0598c6b9..0499d501ae81 100644 --- a/x/distribution/client/testutil/cli_test.go +++ b/x/distribution/client/testutil/cli_test.go @@ -13,10 +13,16 @@ import ( func TestIntegrationTestSuite(t *testing.T) { cfg := network.DefaultConfig() - cfg.NumValidators = 2 + cfg.NumValidators = 1 suite.Run(t, NewIntegrationTestSuite(cfg)) } func TestGRPCQueryTestSuite(t *testing.T) { suite.Run(t, new(GRPCQueryTestSuite)) } + +func TestWithdrawAllSuite(t *testing.T) { + cfg1 := network.DefaultConfig() + cfg1.NumValidators = 2 + suite.Run(t, NewWithdrawAllTestSuite(cfg1)) +} diff --git a/x/distribution/client/testutil/suite.go b/x/distribution/client/testutil/suite.go index 4a5a730ce532..de9006d9f225 100644 --- a/x/distribution/client/testutil/suite.go +++ b/x/distribution/client/testutil/suite.go @@ -10,16 +10,12 @@ import ( tmcli "github.com/tendermint/tendermint/libs/cli" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/crypto/hd" - "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" 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" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - stakingcli "github.com/cosmos/cosmos-sdk/x/staking/client/cli" ) type IntegrationTestSuite struct { @@ -59,8 +55,6 @@ func (s *IntegrationTestSuite) SetupTest() { _, err = s.network.WaitForHeight(1) s.Require().NoError(err) - - // s.delegator = newAddr } // TearDownTest cleans up the curret test network after _each_ test. @@ -135,7 +129,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorOutstandingRewards() { fmt.Sprintf("--%s=json", tmcli.OutputFlag), }, false, - `{"rewards":[{"denom":"stake","amount":"1144.440000000000000000"}]}`, + `{"rewards":[{"denom":"stake","amount":"1164.240000000000000000"}]}`, }, { "text output", @@ -146,7 +140,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorOutstandingRewards() { }, false, `rewards: -- amount: "1144.440000000000000000" +- amount: "1164.240000000000000000" denom: stake`, }, } @@ -198,7 +192,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorCommission() { fmt.Sprintf("--%s=json", tmcli.OutputFlag), }, false, - `{"commission":[{"denom":"stake","amount":"457.342500000000000000"}]}`, + `{"commission":[{"denom":"stake","amount":"464.520000000000000000"}]}`, }, { "text output", @@ -209,7 +203,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorCommission() { }, false, `commission: -- amount: "457.342500000000000000" +- amount: "464.520000000000000000" denom: stake`, }, } @@ -351,7 +345,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDelegatorRewards() { fmt.Sprintf("--%s=json", tmcli.OutputFlag), }, false, - fmt.Sprintf(`{"rewards":[{"validator_address":"%s","reward":[{"denom":"stake","amount":"391.050000000000000000"}]}],"total":[{"denom":"stake","amount":"391.050000000000000000"}]}`, valAddr.String()), + fmt.Sprintf(`{"rewards":[{"validator_address":"%s","reward":[{"denom":"stake","amount":"387.100000000000000000"}]}],"total":[{"denom":"stake","amount":"387.100000000000000000"}]}`, valAddr.String()), }, { "json output (specific validator)", @@ -361,7 +355,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDelegatorRewards() { fmt.Sprintf("--%s=json", tmcli.OutputFlag), }, false, - `{"rewards":[{"denom":"stake","amount":"391.050000000000000000"}]}`, + `{"rewards":[{"denom":"stake","amount":"387.100000000000000000"}]}`, }, { "text output", @@ -373,11 +367,11 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDelegatorRewards() { false, fmt.Sprintf(`rewards: - reward: - - amount: "391.050000000000000000" + - amount: "387.100000000000000000" denom: stake validator_address: %s total: -- amount: "391.050000000000000000" +- amount: "387.100000000000000000" denom: stake`, valAddr.String()), }, { @@ -389,7 +383,7 @@ total: }, false, `rewards: -- amount: "391.050000000000000000" +- amount: "387.100000000000000000" denom: stake`, }, } @@ -413,6 +407,7 @@ total: } func (s *IntegrationTestSuite) TestGetCmdQueryCommunityPool() { + s.SetupTest() val := s.network.Validators[0] _, err := s.network.WaitForHeight(4) @@ -426,13 +421,13 @@ func (s *IntegrationTestSuite) TestGetCmdQueryCommunityPool() { { "json output", []string{fmt.Sprintf("--%s=3", flags.FlagHeight), fmt.Sprintf("--%s=json", tmcli.OutputFlag)}, - `{"pool":[{"denom":"stake","amount":"9.480000000000000000"}]}`, + `{"pool":[{"denom":"stake","amount":"4.740000000000000000"}]}`, }, { "text output", []string{fmt.Sprintf("--%s=text", tmcli.OutputFlag), fmt.Sprintf("--%s=3", flags.FlagHeight)}, `pool: -- amount: "9.480000000000000000" +- amount: "4.740000000000000000" denom: stake`, }, } @@ -754,83 +749,3 @@ func (s *IntegrationTestSuite) TestGetCmdSubmitProposal() { }) } } - -func (s *IntegrationTestSuite) 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) - - _, err = s.network.WaitForHeight(6) - 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.BroadcastSync), - 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.BroadcastAsync), - 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"))) -} diff --git a/x/distribution/client/testutil/withdraw_all_suite.go b/x/distribution/client/testutil/withdraw_all_suite.go new file mode 100644 index 000000000000..4f7ba8eb8216 --- /dev/null +++ b/x/distribution/client/testutil/withdraw_all_suite.go @@ -0,0 +1,115 @@ +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 NewWithdrawAllTestSuite(cfg network.Config) *IntegrationTestSuite { + return &IntegrationTestSuite{cfg: cfg} +} + +func (s *WithdrawAllTestSuite) SetupTest() { + 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) +} + +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.BroadcastSync), + 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.BroadcastAsync), + 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"))) +} From bf2d70556172abb426262fe9ab086738b83384da Mon Sep 17 00:00:00 2001 From: atheesh Date: Sat, 8 Jan 2022 13:29:35 +0530 Subject: [PATCH 15/15] fix tests --- x/distribution/client/testutil/cli_test.go | 13 +---- .../client/testutil/grpc_query_suite.go | 6 +++ x/distribution/client/testutil/suite.go | 51 ++++++++++++------- .../client/testutil/withdraw_all_suite.go | 20 +++++--- 4 files changed, 56 insertions(+), 34 deletions(-) diff --git a/x/distribution/client/testutil/cli_test.go b/x/distribution/client/testutil/cli_test.go index 0499d501ae81..d7ab22d41524 100644 --- a/x/distribution/client/testutil/cli_test.go +++ b/x/distribution/client/testutil/cli_test.go @@ -1,20 +1,13 @@ -//go:build norace -// +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) { @@ -22,7 +15,5 @@ func TestGRPCQueryTestSuite(t *testing.T) { } func TestWithdrawAllSuite(t *testing.T) { - cfg1 := network.DefaultConfig() - cfg1.NumValidators = 2 - suite.Run(t, NewWithdrawAllTestSuite(cfg1)) + suite.Run(t, new(WithdrawAllTestSuite)) } diff --git a/x/distribution/client/testutil/grpc_query_suite.go b/x/distribution/client/testutil/grpc_query_suite.go index b36e0d1d7c5b..956449a39743 100644 --- a/x/distribution/client/testutil/grpc_query_suite.go +++ b/x/distribution/client/testutil/grpc_query_suite.go @@ -37,6 +37,12 @@ func (s *GRPCQueryTestSuite) SetupSuite() { s.Require().NoError(err) } +// TearDownSuite cleans up the curret test network after _each_ test. +func (s *GRPCQueryTestSuite) TearDownSuite() { + s.T().Log("tearing down integration test suite1") + s.network.Cleanup() +} + func (s *GRPCQueryTestSuite) TestQueryParamsGRPC() { val := s.network.Validators[0] baseURL := val.APIAddress diff --git a/x/distribution/client/testutil/suite.go b/x/distribution/client/testutil/suite.go index de9006d9f225..07fe6e50dd09 100644 --- a/x/distribution/client/testutil/suite.go +++ b/x/distribution/client/testutil/suite.go @@ -29,13 +29,17 @@ func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite { return &IntegrationTestSuite{cfg: cfg} } -// SetupTest creates a new network for _each_ integration test. We create a new +// SetupSuite creates a new network for _each_ integration test. We create a new // network for each test because there are some state modifications that are // needed to be made in order to make useful queries. However, we don't want // these state changes to be present in other tests. -func (s *IntegrationTestSuite) SetupTest() { +func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") + cfg := network.DefaultConfig() + cfg.NumValidators = 1 + s.cfg = cfg + genesisState := s.cfg.GenesisState var mintData minttypes.GenesisState s.Require().NoError(s.cfg.Codec.UnmarshalJSON(genesisState[minttypes.ModuleName], &mintData)) @@ -57,9 +61,9 @@ func (s *IntegrationTestSuite) SetupTest() { s.Require().NoError(err) } -// TearDownTest cleans up the curret test network after _each_ test. -func (s *IntegrationTestSuite) TearDownTest() { - s.T().Log("tearing down integration test suite") +// TearDownSuite cleans up the curret test network after _each_ test. +func (s *IntegrationTestSuite) TearDownSuite() { + s.T().Log("tearing down integration test suite1") s.network.Cleanup() } @@ -129,7 +133,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorOutstandingRewards() { fmt.Sprintf("--%s=json", tmcli.OutputFlag), }, false, - `{"rewards":[{"denom":"stake","amount":"1164.240000000000000000"}]}`, + `{"rewards":[{"denom":"stake","amount":"232.260000000000000000"}]}`, }, { "text output", @@ -140,7 +144,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorOutstandingRewards() { }, false, `rewards: -- amount: "1164.240000000000000000" +- amount: "232.260000000000000000" denom: stake`, }, } @@ -192,7 +196,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorCommission() { fmt.Sprintf("--%s=json", tmcli.OutputFlag), }, false, - `{"commission":[{"denom":"stake","amount":"464.520000000000000000"}]}`, + `{"commission":[{"denom":"stake","amount":"116.130000000000000000"}]}`, }, { "text output", @@ -203,7 +207,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorCommission() { }, false, `commission: -- amount: "464.520000000000000000" +- amount: "116.130000000000000000" denom: stake`, }, } @@ -345,7 +349,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDelegatorRewards() { fmt.Sprintf("--%s=json", tmcli.OutputFlag), }, false, - fmt.Sprintf(`{"rewards":[{"validator_address":"%s","reward":[{"denom":"stake","amount":"387.100000000000000000"}]}],"total":[{"denom":"stake","amount":"387.100000000000000000"}]}`, valAddr.String()), + fmt.Sprintf(`{"rewards":[{"validator_address":"%s","reward":[{"denom":"stake","amount":"193.550000000000000000"}]}],"total":[{"denom":"stake","amount":"193.550000000000000000"}]}`, valAddr.String()), }, { "json output (specific validator)", @@ -355,7 +359,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDelegatorRewards() { fmt.Sprintf("--%s=json", tmcli.OutputFlag), }, false, - `{"rewards":[{"denom":"stake","amount":"387.100000000000000000"}]}`, + `{"rewards":[{"denom":"stake","amount":"193.550000000000000000"}]}`, }, { "text output", @@ -367,11 +371,11 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDelegatorRewards() { false, fmt.Sprintf(`rewards: - reward: - - amount: "387.100000000000000000" + - amount: "193.550000000000000000" denom: stake validator_address: %s total: -- amount: "387.100000000000000000" +- amount: "193.550000000000000000" denom: stake`, valAddr.String()), }, { @@ -383,7 +387,7 @@ total: }, false, `rewards: -- amount: "387.100000000000000000" +- amount: "193.550000000000000000" denom: stake`, }, } @@ -407,7 +411,6 @@ total: } func (s *IntegrationTestSuite) TestGetCmdQueryCommunityPool() { - s.SetupTest() val := s.network.Validators[0] _, err := s.network.WaitForHeight(4) @@ -686,7 +689,21 @@ func (s *IntegrationTestSuite) TestGetCmdSubmitProposal() { "deposit": -324foocoin }` + // fund some tokens to the community pool + args := []string{sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(5431))).String(), + fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.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())} + invalidPropFile := testutil.WriteToNewTempFile(s.T(), invalidProp) + cmd := cli.NewFundCommunityPoolCmd() + out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) + s.Require().NoError(err) + + var txResp sdk.TxResponse + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String()) + s.Require().Equal(uint32(0), txResp.Code) validProp := fmt.Sprintf(`{ "title": "Community Pool Spend", @@ -710,7 +727,7 @@ func (s *IntegrationTestSuite) TestGetCmdSubmitProposal() { invalidPropFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + 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()), }, true, 0, nil, @@ -721,7 +738,7 @@ func (s *IntegrationTestSuite) TestGetCmdSubmitProposal() { validPropFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), // sync mode as there are no funds yet + 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()), }, false, 0, &sdk.TxResponse{}, diff --git a/x/distribution/client/testutil/withdraw_all_suite.go b/x/distribution/client/testutil/withdraw_all_suite.go index 4f7ba8eb8216..7b459a4dfde1 100644 --- a/x/distribution/client/testutil/withdraw_all_suite.go +++ b/x/distribution/client/testutil/withdraw_all_suite.go @@ -23,11 +23,11 @@ type WithdrawAllTestSuite struct { network *network.Network } -func NewWithdrawAllTestSuite(cfg network.Config) *IntegrationTestSuite { - return &IntegrationTestSuite{cfg: cfg} -} +func (s *WithdrawAllTestSuite) SetupSuite() { + cfg := network.DefaultConfig() + cfg.NumValidators = 2 + s.cfg = cfg -func (s *WithdrawAllTestSuite) SetupTest() { s.T().Log("setting up integration test suite") network, err := network.New(s.T(), s.T().TempDir(), s.cfg) s.Require().NoError(err) @@ -37,6 +37,14 @@ func (s *WithdrawAllTestSuite) SetupTest() { 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] @@ -90,7 +98,7 @@ func (s *WithdrawAllTestSuite) TestNewWithdrawAllRewardsGenerateOnly() { 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.BroadcastSync), + 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() @@ -104,7 +112,7 @@ func (s *WithdrawAllTestSuite) TestNewWithdrawAllRewardsGenerateOnly() { 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.BroadcastAsync), + 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()