Skip to content

Commit

Permalink
Merge pull request #28 from lukema95/fix-withdraw
Browse files Browse the repository at this point in the history
feat: Add withdrawal message verification
  • Loading branch information
liangping authored Dec 4, 2023
2 parents 47fc3fe + a58bd43 commit c364426
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions x/gmm/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ var (
ErrInvalidAmp = sdkerrors.Register(ModuleName, 1120, "amp has to be zero to 100")
ErrNotMeetSlippage = sdkerrors.Register(ModuleName, 1121, "not meet slippage")
ErrInvalidSlippage = sdkerrors.Register(ModuleName, 1122, "invalid slippage")
ErrMismatchedShareDenom = sdkerrors.Register(ModuleName, 1123, "mismatched share denom")
)
4 changes: 4 additions & 0 deletions x/gmm/types/message_withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,9 @@ func (msg *MsgWithdraw) ValidateBasic() error {
if msg.Share.Amount.IsZero() {
return sdkerrors.Wrap(ErrInvalidTokenAmount, "share amount cannot be zero")
}

if msg.PoolId != msg.Share.GetDenom() {
return sdkerrors.Wrapf(ErrMismatchedShareDenom, "share denom and pool id do not match")
}
return nil
}
15 changes: 14 additions & 1 deletion x/gmm/types/message_withdraw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,26 @@ func TestMsgWithdraw_ValidateBasic(t *testing.T) {
err: ErrInvalidTokenAmount,
},
{
name: "valid message",
name: "mismatched share denom",
msg: MsgWithdraw{
Sender: sample.AccAddress(),
Receiver: sample.AccAddress(),
PoolId: "test1",
Share: sdk.NewCoin(
"test",
sdk.NewInt(1),
),
},
err: ErrMismatchedShareDenom,
},
{
name: "valid message",
msg: MsgWithdraw{
Sender: sample.AccAddress(),
Receiver: sample.AccAddress(),
PoolId: "test1",
Share: sdk.NewCoin(
"test1",
sdk.NewInt(10),
),
},
Expand Down

0 comments on commit c364426

Please sign in to comment.