Skip to content

Commit

Permalink
Update TestMsgLock, TestMsgUnlock, and TestMsgUpdateParams, fix error…
Browse files Browse the repository at this point in the history
… messages
  • Loading branch information
iverc committed Dec 14, 2024
1 parent 30d046f commit 2fad51c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
31 changes: 30 additions & 1 deletion x/tier/keeper/msg_lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,40 @@ func TestMsgLock(t *testing.T) {
expErr: true,
expErrMsg: "invalid amount",
},
{
name: "invalid delegator address",
input: &types.MsgLock{
DelegatorAddress: "invalid-delegator-address",
ValidatorAddress: valAddr,
Stake: validCoin1,
},
expErr: true,
expErrMsg: "delegator address",
},
{
name: "invalid validator address",
input: &types.MsgLock{
DelegatorAddress: delAddr,
ValidatorAddress: "invalid-validator-address",
Stake: validCoin1,
},
expErr: true,
expErrMsg: "validator address",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
_, err := ms.Lock(sdkCtx, tc.input)
err := tc.input.ValidateBasic()
if err != nil {
if tc.expErr {
require.Contains(t, err.Error(), tc.expErrMsg)
return
}
t.Fatalf("unexpected error in ValidateBasic: %v", err)
}

_, err = ms.Lock(sdkCtx, tc.input)

if tc.expErr {
require.Error(t, err)
Expand Down
2 changes: 1 addition & 1 deletion x/tier/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer {
func (m msgServer) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
authority := m.Keeper.GetAuthority()
if msg.Authority != authority {
return nil, types.ErrUnauthorized.Wrapf("expected authority: %s, got: %s", authority, msg.Authority)
return nil, types.ErrUnauthorized.Wrapf("invalid authority: %s", msg.Authority)
}

err := msg.Params.Validate()
Expand Down
29 changes: 29 additions & 0 deletions x/tier/keeper/msg_unlock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,39 @@ func TestMsgUnlock(t *testing.T) {
expErr: true,
expErrMsg: "subtract lockup",
},
{
name: "invalid delegator address",
input: &types.MsgUnlock{
DelegatorAddress: "invalid-delegator-address",
ValidatorAddress: valAddr,
Stake: validCoin,
},
expErr: true,
expErrMsg: "delegator address",
},
{
name: "invalid validator address",
input: &types.MsgUnlock{
DelegatorAddress: delAddr,
ValidatorAddress: "invalid-validator-address",
Stake: validCoin,
},
expErr: true,
expErrMsg: "validator address",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := tc.input.ValidateBasic()
if err != nil {
if tc.expErr {
require.Contains(t, err.Error(), tc.expErrMsg)
return
}
t.Fatalf("unexpected error in ValidateBasic: %v", err)
}

resp, err := ms.Unlock(sdkCtx, tc.input)

if tc.expErr {
Expand Down
2 changes: 1 addition & 1 deletion x/tier/keeper/msg_update_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestMsgUpdateParams(t *testing.T) {
Params: params,
},
expErr: true,
expErrMsg: "expected authority: source10d07y265gmmuvt4z0w9aw880jnsr700ju32mxd, got: invalid: unauthorized",
expErrMsg: "invalid authority",
},
{
name: "send enabled param",
Expand Down
2 changes: 1 addition & 1 deletion x/tier/types/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func NewMsgRedelegate(delAddress, srcValAddr, dstValAddr string, stake sdk.Coin)

func (msg *MsgRedelegate) ValidateBasic() error {
if msg.SrcValidatorAddress == msg.DstValidatorAddress {
return ErrInvalidAddress.Wrapf("src and dst validator addresses are the sames")
return ErrInvalidAddress.Wrapf("src and dst validator addresses are the same")
}
if err := validateAccAddr(msg.DelegatorAddress); err != nil {
return err
Expand Down

0 comments on commit 2fad51c

Please sign in to comment.