fix: fix the cli test for cancel unbond (#11579)
## Description Closes: #XXXX --- ### 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)
This commit is contained in:
parent
83f5ecf2e7
commit
398583a040
|
@ -348,7 +348,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryUnbondingDelegation() {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Equal(ubd.Unbond.DelegatorAddress, val.Address.String())
|
s.Require().Equal(ubd.Unbond.DelegatorAddress, val.Address.String())
|
||||||
s.Require().Equal(ubd.Unbond.ValidatorAddress, val.ValAddress.String())
|
s.Require().Equal(ubd.Unbond.ValidatorAddress, val.ValAddress.String())
|
||||||
s.Require().Len(ubd.Unbond.Entries, 1)
|
s.Require().Len(ubd.Unbond.Entries, 2)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||||
|
"github.com/cosmos/cosmos-sdk/testutil/rest"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/cosmos/cosmos-sdk/types/query"
|
"github.com/cosmos/cosmos-sdk/types/query"
|
||||||
|
@ -72,14 +73,21 @@ func (s *IntegrationTestSuite) SetupSuite() {
|
||||||
s.Require().Equal(uint32(0), txRes.Code)
|
s.Require().Equal(uint32(0), txRes.Code)
|
||||||
_, err = s.network.WaitForHeight(1)
|
_, err = s.network.WaitForHeight(1)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
// unbonding
|
|
||||||
out, err = MsgUnbondExec(val.ClientCtx, val.Address, val.ValAddress, unbond)
|
unbondingAmount := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(5))
|
||||||
|
// unbonding the amount
|
||||||
|
out, err = MsgUnbondExec(val.ClientCtx, val.Address, val.ValAddress, unbondingAmount)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txRes))
|
||||||
|
s.Require().Equal(uint32(0), txRes.Code)
|
||||||
|
// unbonding the amount
|
||||||
|
out, err = MsgUnbondExec(val.ClientCtx, val.Address, val.ValAddress, unbondingAmount)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txRes))
|
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txRes))
|
||||||
s.Require().Equal(uint32(0), txRes.Code)
|
s.Require().Equal(uint32(0), txRes.Code)
|
||||||
|
|
||||||
_, err = s.network.WaitForHeight(1)
|
err = s.network.WaitForNextBlock()
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -595,7 +603,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryUnbondingDelegation() {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Equal(ubd.DelegatorAddress, val.Address.String())
|
s.Require().Equal(ubd.DelegatorAddress, val.Address.String())
|
||||||
s.Require().Equal(ubd.ValidatorAddress, val.ValAddress.String())
|
s.Require().Equal(ubd.ValidatorAddress, val.ValAddress.String())
|
||||||
s.Require().Len(ubd.Entries, 1)
|
s.Require().Len(ubd.Entries, 2)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1362,7 +1370,6 @@ func (s *IntegrationTestSuite) TestNewCancelUnbondingDelegationCmd() {
|
||||||
[]string{
|
[]string{
|
||||||
val.ValAddress.String(),
|
val.ValAddress.String(),
|
||||||
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10000)).String(),
|
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10000)).String(),
|
||||||
sdk.NewInt(3).String(),
|
|
||||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
||||||
|
@ -1374,8 +1381,7 @@ func (s *IntegrationTestSuite) TestNewCancelUnbondingDelegationCmd() {
|
||||||
"valid transaction of canceling unbonding delegation",
|
"valid transaction of canceling unbonding delegation",
|
||||||
[]string{
|
[]string{
|
||||||
val.ValAddress.String(),
|
val.ValAddress.String(),
|
||||||
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)).String(),
|
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(5)).String(),
|
||||||
sdk.NewInt(3).String(),
|
|
||||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
||||||
|
@ -1391,6 +1397,22 @@ func (s *IntegrationTestSuite) TestNewCancelUnbondingDelegationCmd() {
|
||||||
s.Run(tc.name, func() {
|
s.Run(tc.name, func() {
|
||||||
cmd := cli.NewCancelUnbondingDelegation()
|
cmd := cli.NewCancelUnbondingDelegation()
|
||||||
clientCtx := val.ClientCtx
|
clientCtx := val.ClientCtx
|
||||||
|
if !tc.expectErr && tc.expectedCode != sdkerrors.ErrNotFound.ABCICode() {
|
||||||
|
getCreationHeight := func() int64 {
|
||||||
|
// fethichg the unbonding delegations
|
||||||
|
resp, err := rest.GetRequest(fmt.Sprintf("%s/cosmos/staking/v1beta1/delegators/%s/unbonding_delegations", val.APIAddress, val.Address.String()))
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
var ubds types.QueryDelegatorUnbondingDelegationsResponse
|
||||||
|
|
||||||
|
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &ubds)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Len(ubds.UnbondingResponses, 1)
|
||||||
|
s.Require().Equal(ubds.UnbondingResponses[0].DelegatorAddress, val.Address.String())
|
||||||
|
return ubds.UnbondingResponses[0].Entries[1].CreationHeight
|
||||||
|
}
|
||||||
|
tc.args = append(tc.args, fmt.Sprint(getCreationHeight()))
|
||||||
|
}
|
||||||
|
|
||||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||||
if tc.expectErr {
|
if tc.expectErr {
|
||||||
|
|
|
@ -411,6 +411,10 @@ func SimulateMsgCancelUnbondingDelegate(ak types.AccountKeeper, bk types.BankKee
|
||||||
// get random unbonding delegation entry at block height
|
// get random unbonding delegation entry at block height
|
||||||
unbondingDelegationEntry := unbondingDelegation.Entries[r.Intn(len(unbondingDelegation.Entries))]
|
unbondingDelegationEntry := unbondingDelegation.Entries[r.Intn(len(unbondingDelegation.Entries))]
|
||||||
|
|
||||||
|
if unbondingDelegationEntry.CompletionTime.Before(ctx.BlockTime()) {
|
||||||
|
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCancelUnbondingDelegation, "unbonding delegation is already processed"), nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
if !unbondingDelegationEntry.Balance.IsPositive() {
|
if !unbondingDelegationEntry.Balance.IsPositive() {
|
||||||
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCancelUnbondingDelegation, "delegator receiving balance is negative"), nil, nil
|
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCancelUnbondingDelegation, "delegator receiving balance is negative"), nil, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue