Skip to content

Commit

Permalink
Update msg_server and affected tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iverc committed Dec 20, 2024
1 parent 4a7b2a4 commit 06bdcaa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
28 changes: 14 additions & 14 deletions x/tier/keeper/msg_cancel_unlocking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestMsgCancelUnlocking(t *testing.T) {
initializeValidator(t, k.GetStakingKeeper().(*stakingkeeper.Keeper), ctx, valAddress, initialValidatorBalance)
err = k.Lock(ctx, delAddress, valAddress, validCoin.Amount)
require.NoError(t, err)
_, _, _, err = k.Unlock(ctx, delAddress, valAddress, validCoin.Amount)
_, _, err = k.Unlock(ctx, delAddress, valAddress, validCoin.Amount)
require.NoError(t, err)
return ctx
}
Expand Down Expand Up @@ -105,6 +105,17 @@ func TestMsgCancelUnlocking(t *testing.T) {
expErr: true,
expErrMsg: "invalid amount",
},
{
name: "excess unlocking amount",
input: &types.MsgCancelUnlocking{
DelegatorAddress: delAddr,
ValidatorAddress: valAddr,
CreationHeight: 1,
Stake: excessCoin,
},
expErr: true,
expErrMsg: "invalid amount",
},
{
name: "non-existent unlocking",
input: &types.MsgCancelUnlocking{
Expand All @@ -114,7 +125,7 @@ func TestMsgCancelUnlocking(t *testing.T) {
Stake: validCoin,
},
expErr: true,
expErrMsg: "no unbonding delegation found",
expErrMsg: "not found",
},
{
name: "invalid delegator address",
Expand Down Expand Up @@ -158,18 +169,7 @@ func TestMsgCancelUnlocking(t *testing.T) {
Stake: validCoin,
},
expErr: false,
expectedAmount: validCoin.Amount.Sub(math.OneInt()),
},
{
name: "excess unlocking amount",
input: &types.MsgCancelUnlocking{
DelegatorAddress: delAddr,
ValidatorAddress: valAddr,
CreationHeight: 1,
Stake: excessCoin,
},
expErr: false,
expectedAmount: validCoin.Amount.Sub(math.OneInt()),
expectedAmount: validCoin.Amount,
},
}

Expand Down
11 changes: 4 additions & 7 deletions x/tier/keeper/msg_redelegate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ func TestMsgRedelegate(t *testing.T) {
err = k.Lock(ctx, delAddress, srcValAddress, validCoin.Amount)
require.NoError(t, err)

stakingParams, err := k.GetStakingKeeper().(*stakingkeeper.Keeper).GetParams(ctx)
require.NoError(t, err)

// expectedCompletionTime should match the default staking unbonding time (e.g. 21 days)
expectedCompletionTime := sdkCtx.BlockTime().Add(stakingParams.UnbondingTime)
// expectedCompletionTime should match current block time
expectedCompletionTime := sdkCtx.BlockTime()

testCases := []struct {
name string
Expand All @@ -74,7 +71,7 @@ func TestMsgRedelegate(t *testing.T) {
Stake: sdk.NewCoin(appparams.DefaultBondDenom, math.NewInt(500)),
},
expErr: true,
expErrMsg: "subtract locked stake from source validator",
expErrMsg: "subtract lockup from source validator",
},
{
name: "invalid stake amount (zero)",
Expand Down Expand Up @@ -110,7 +107,7 @@ func TestMsgRedelegate(t *testing.T) {
Stake: validCoin,
},
expErr: true,
expErrMsg: "subtract locked stake from source validator",
expErrMsg: "subtract lockup from source validator",
},
{
name: "source and destination validator are the same",
Expand Down
9 changes: 5 additions & 4 deletions x/tier/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,20 @@ func (m msgServer) Unlock(ctx context.Context, msg *types.MsgUnlock) (*types.Msg
delAddr := sdk.MustAccAddressFromBech32(msg.DelegatorAddress)
valAddr := types.MustValAddressFromBech32(msg.ValidatorAddress)

_, unlockTime, _, err := m.Keeper.Unlock(ctx, delAddr, valAddr, msg.Stake.Amount)
unlockTime, creationHeight, err := m.Keeper.Unlock(ctx, delAddr, valAddr, msg.Stake.Amount)
if err != nil {
return nil, errorsmod.Wrap(err, "undelegate")
}

return &types.MsgUnlockResponse{CompletionTime: unlockTime}, nil
return &types.MsgUnlockResponse{CompletionTime: *unlockTime, CreationHeight: creationHeight}, nil
}

func (m msgServer) CancelUnlocking(ctx context.Context, msg *types.MsgCancelUnlocking) (*types.MsgCancelUnlockingResponse, error) {
// Input validation has been done by ValidateBasic.
delAddr := sdk.MustAccAddressFromBech32(msg.DelegatorAddress)
valAddr := types.MustValAddressFromBech32(msg.ValidatorAddress)

err := m.Keeper.CancelUnlocking(ctx, delAddr, valAddr, msg.CreationHeight, &msg.Stake.Amount)
err := m.Keeper.CancelUnlocking(ctx, delAddr, valAddr, msg.CreationHeight, msg.Stake.Amount)
if err != nil {
return nil, errorsmod.Wrap(err, "cancel unlocking")
}
Expand All @@ -87,5 +88,5 @@ func (m msgServer) Redelegate(ctx context.Context, msg *types.MsgRedelegate) (*t
return nil, errorsmod.Wrap(err, "redelegate")
}

return &types.MsgRedelegateResponse{CompletionTime: completionTime}, nil
return &types.MsgRedelegateResponse{CompletionTime: *completionTime}, nil
}

0 comments on commit 06bdcaa

Please sign in to comment.