Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: --max-msgs with generate-only should not throw error #10842

Merged
merged 31 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e4c093d
fix: max msgs (WIP)
atheeshp Dec 14, 2021
ce38f34
Merge branch 'master' of github.com:cosmos/cosmos-sdk into ap/max-msg…
atheeshp Dec 14, 2021
7620a56
Merge branch 'master' of github.com:cosmos/cosmos-sdk into ap/max-msg…
atheeshp Dec 27, 2021
267ed83
add tests
atheeshp Dec 27, 2021
bdf7046
fix tests
atheeshp Dec 28, 2021
11b3014
Merge branch 'master' into ap/max-msgs-all-rewards
atheeshp Jan 3, 2022
9912321
Merge branch 'master' into ap/max-msgs-all-rewards
alexanderbez Jan 3, 2022
daa339a
Merge branch 'master' into ap/max-msgs-all-rewards
atheeshp Jan 5, 2022
cbe7eff
fix tess
atheeshp Jan 5, 2022
986eeb2
Merge branch 'master' of github.com:cosmos/cosmos-sdk into ap/max-msg…
atheeshp Jan 5, 2022
32d4a88
Merge branch 'ap/max-msgs-all-rewards' of github.com:cosmos/cosmos-sd…
atheeshp Jan 5, 2022
3ec48fe
udpate tests
atheeshp Jan 6, 2022
5469613
update tests
atheeshp Jan 6, 2022
6101381
Merge branch 'master' of github.com:cosmos/cosmos-sdk into ap/max-msg…
atheeshp Jan 6, 2022
862fc09
update tests
atheeshp Jan 6, 2022
fa554db
update changelog
atheeshp Jan 6, 2022
bb03e6d
update tests
atheeshp Jan 6, 2022
967766e
revert tests
atheeshp Jan 6, 2022
24e4a3a
udpate tests
atheeshp Jan 6, 2022
d6a72d2
Merge branch 'master' into ap/max-msgs-all-rewards
atheeshp Jan 6, 2022
44c9361
Merge branch 'master' into ap/max-msgs-all-rewards
atheeshp Jan 6, 2022
a23e0ec
update tests
atheeshp Jan 6, 2022
c8adb66
Merge branch 'ap/max-msgs-all-rewards' of github.com:cosmos/cosmos-sd…
atheeshp Jan 6, 2022
0340a08
fix tests
atheeshp Jan 7, 2022
2c8ad69
Merge branch 'master' of github.com:cosmos/cosmos-sdk into ap/max-msg…
atheeshp Jan 7, 2022
6ad9160
add separate suite for withdraw all msg
atheeshp Jan 7, 2022
410800e
Merge branch 'master' of github.com:cosmos/cosmos-sdk into ap/max-msg…
atheeshp Jan 8, 2022
bf2d705
fix tests
atheeshp Jan 8, 2022
e7621c8
Merge branch 'master' into ap/max-msgs-all-rewards
atheeshp Jan 11, 2022
b765c02
Merge branch 'master' into ap/max-msgs-all-rewards
alexanderbez Jan 17, 2022
16d7ebd
Merge branch 'master' into ap/max-msgs-all-rewards
mergify[bot] Jan 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x/distribution/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion x/distribution/client/testutil/cli_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build norace
// +build norace

package testutil
Expand All @@ -12,7 +13,7 @@ import (

func TestIntegrationTestSuite(t *testing.T) {
cfg := network.DefaultConfig()
cfg.NumValidators = 1
cfg.NumValidators = 2
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
suite.Run(t, NewIntegrationTestSuite(cfg))
}

Expand Down
103 changes: 92 additions & 11 deletions x/distribution/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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":"1144.440000000000000000"}]}`,
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
},
{
"text output",
Expand All @@ -140,7 +144,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorOutstandingRewards() {
},
false,
`rewards:
- amount: "1164.240000000000000000"
- amount: "1144.440000000000000000"
denom: stake`,
},
}
Expand Down Expand Up @@ -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":"457.342500000000000000"}]}`,
},
{
"text output",
Expand All @@ -203,7 +207,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorCommission() {
},
false,
`commission:
- amount: "464.520000000000000000"
- amount: "457.342500000000000000"
denom: stake`,
},
}
Expand Down Expand Up @@ -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":"391.050000000000000000"}]}],"total":[{"denom":"stake","amount":"391.050000000000000000"}]}`, valAddr.String()),
},
{
"json output (specific validator)",
Expand All @@ -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":"391.050000000000000000"}]}`,
},
{
"text output",
Expand All @@ -367,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()),
},
{
Expand All @@ -383,7 +387,7 @@ total:
},
false,
`rewards:
- amount: "387.100000000000000000"
- amount: "391.050000000000000000"
denom: stake`,
},
}
Expand Down Expand Up @@ -420,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`,
},
}
Expand Down Expand Up @@ -748,3 +752,80 @@ 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()
_, 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)

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)
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=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)
s.Require().Equal(1, len(strings.Split(strings.Trim(out.String(), "\n"), "\n")))
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
}