refactor(staking): add missing msgServer tests and move ValidateBasic() logic to msgServer (#15820)
This commit is contained in:
@@ -87,6 +87,7 @@ func TestUnJailNotBonded(t *testing.T) {
|
||||
amt := f.stakingKeeper.TokensFromConsensusPower(f.ctx, 50)
|
||||
msg := tstaking.CreateValidatorMsg(addr, val, amt)
|
||||
msg.MinSelfDelegation = amt
|
||||
msg.Description = stakingtypes.Description{Moniker: "TestValidator"}
|
||||
res, err := tstaking.CreateValidatorWithMsg(f.ctx, msg)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, res != nil)
|
||||
|
||||
@@ -76,47 +76,58 @@ func TestCancelUnbondingDelegation(t *testing.T) {
|
||||
assert.DeepEqual(t, ubd, resUnbond)
|
||||
|
||||
testCases := []struct {
|
||||
Name string
|
||||
ExceptErr bool
|
||||
name string
|
||||
exceptErr bool
|
||||
req types.MsgCancelUnbondingDelegation
|
||||
expErrMsg string
|
||||
}{
|
||||
{
|
||||
Name: "invalid height",
|
||||
ExceptErr: true,
|
||||
name: "entry not found at height",
|
||||
exceptErr: true,
|
||||
req: types.MsgCancelUnbondingDelegation{
|
||||
DelegatorAddress: resUnbond.DelegatorAddress,
|
||||
ValidatorAddress: resUnbond.ValidatorAddress,
|
||||
Amount: sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(4)),
|
||||
CreationHeight: 11,
|
||||
},
|
||||
expErrMsg: "unbonding delegation entry is not found at block height",
|
||||
},
|
||||
{
|
||||
name: "invalid height",
|
||||
exceptErr: true,
|
||||
req: types.MsgCancelUnbondingDelegation{
|
||||
DelegatorAddress: resUnbond.DelegatorAddress,
|
||||
ValidatorAddress: resUnbond.ValidatorAddress,
|
||||
Amount: sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(4)),
|
||||
CreationHeight: 0,
|
||||
},
|
||||
expErrMsg: "unbonding delegation entry is not found at block height",
|
||||
expErrMsg: "invalid height",
|
||||
},
|
||||
{
|
||||
Name: "invalid coin",
|
||||
ExceptErr: true,
|
||||
name: "invalid coin",
|
||||
exceptErr: true,
|
||||
req: types.MsgCancelUnbondingDelegation{
|
||||
DelegatorAddress: resUnbond.DelegatorAddress,
|
||||
ValidatorAddress: resUnbond.ValidatorAddress,
|
||||
Amount: sdk.NewCoin("dump_coin", sdk.NewInt(4)),
|
||||
CreationHeight: 0,
|
||||
CreationHeight: 10,
|
||||
},
|
||||
expErrMsg: "invalid coin denomination",
|
||||
},
|
||||
{
|
||||
Name: "validator not exists",
|
||||
ExceptErr: true,
|
||||
name: "validator not exists",
|
||||
exceptErr: true,
|
||||
req: types.MsgCancelUnbondingDelegation{
|
||||
DelegatorAddress: resUnbond.DelegatorAddress,
|
||||
ValidatorAddress: sdk.ValAddress(sdk.AccAddress("asdsad")).String(),
|
||||
Amount: unbondingAmount,
|
||||
CreationHeight: 0,
|
||||
CreationHeight: 10,
|
||||
},
|
||||
expErrMsg: "validator does not exist",
|
||||
},
|
||||
{
|
||||
Name: "invalid delegator address",
|
||||
ExceptErr: true,
|
||||
name: "invalid delegator address",
|
||||
exceptErr: true,
|
||||
req: types.MsgCancelUnbondingDelegation{
|
||||
DelegatorAddress: "invalid_delegator_addrtess",
|
||||
ValidatorAddress: resUnbond.ValidatorAddress,
|
||||
@@ -126,8 +137,8 @@ func TestCancelUnbondingDelegation(t *testing.T) {
|
||||
expErrMsg: "decoding bech32 failed",
|
||||
},
|
||||
{
|
||||
Name: "invalid amount",
|
||||
ExceptErr: true,
|
||||
name: "invalid amount",
|
||||
exceptErr: true,
|
||||
req: types.MsgCancelUnbondingDelegation{
|
||||
DelegatorAddress: resUnbond.DelegatorAddress,
|
||||
ValidatorAddress: resUnbond.ValidatorAddress,
|
||||
@@ -137,8 +148,8 @@ func TestCancelUnbondingDelegation(t *testing.T) {
|
||||
expErrMsg: "amount is greater than the unbonding delegation entry balance",
|
||||
},
|
||||
{
|
||||
Name: "success",
|
||||
ExceptErr: false,
|
||||
name: "success",
|
||||
exceptErr: false,
|
||||
req: types.MsgCancelUnbondingDelegation{
|
||||
DelegatorAddress: resUnbond.DelegatorAddress,
|
||||
ValidatorAddress: resUnbond.ValidatorAddress,
|
||||
@@ -147,8 +158,8 @@ func TestCancelUnbondingDelegation(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "success",
|
||||
ExceptErr: false,
|
||||
name: "success",
|
||||
exceptErr: false,
|
||||
req: types.MsgCancelUnbondingDelegation{
|
||||
DelegatorAddress: resUnbond.DelegatorAddress,
|
||||
ValidatorAddress: resUnbond.ValidatorAddress,
|
||||
@@ -159,9 +170,9 @@ func TestCancelUnbondingDelegation(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.Name, func(t *testing.T) {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
_, err := msgServer.CancelUnbondingDelegation(ctx, &testCase.req)
|
||||
if testCase.ExceptErr {
|
||||
if testCase.exceptErr {
|
||||
assert.ErrorContains(t, err, testCase.expErrMsg)
|
||||
} else {
|
||||
assert.NilError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user