From e3ad8793e98f00c4c49541f1ad1a58beb165af4e Mon Sep 17 00:00:00 2001 From: Charles Dusek Date: Sun, 26 May 2024 10:19:09 -0500 Subject: [PATCH] Fix duplicate redeem bug --- x/market/keeper/msg_server_redeem_drop.go | 4 ++++ x/market/keeper/msg_server_redeem_drop_test.go | 4 ++++ x/market/types/errors.go | 2 ++ 3 files changed, 10 insertions(+) diff --git a/x/market/keeper/msg_server_redeem_drop.go b/x/market/keeper/msg_server_redeem_drop.go index 361cd1ab..8848070b 100644 --- a/x/market/keeper/msg_server_redeem_drop.go +++ b/x/market/keeper/msg_server_redeem_drop.go @@ -21,6 +21,10 @@ func (k msgServer) RedeemDrop(goCtx context.Context, msg *types.MsgRedeemDrop) ( return nil, sdkerrors.Wrapf(types.ErrDropNotFound, "%s", msg.Uid) } + if !drop.Active { + return nil, sdkerrors.Wrapf(types.ErrDropNotActive, "%s", msg.Uid) + } + if drop.Owner != msg.Creator { return nil, sdkerrors.Wrapf(types.ErrNotDrops, "%s", msg.Uid) } diff --git a/x/market/keeper/msg_server_redeem_drop_test.go b/x/market/keeper/msg_server_redeem_drop_test.go index 10d99286..c91b7e1a 100644 --- a/x/market/keeper/msg_server_redeem_drop_test.go +++ b/x/market/keeper/msg_server_redeem_drop_test.go @@ -161,6 +161,10 @@ func TestRedeemDrop(t *testing.T) { require.NoError(t, redeemdropErr2) require.Contains(t, rd2.GetCreator(), createRedeemDropResponse2.String()) + // Validate RedeemDrop Duplicate Error + _, redeemdropErr3 := keeper.NewMsgServerImpl(*testInput.MarketKeeper).RedeemDrop(sdk.WrapSDKContext(testInput.Context), &rd2) + require.Error(t, redeemdropErr3) + // Validate GetPool After Redeem Drop rst, found = testInput.MarketKeeper.GetPool(testInput.Context, pair) require.True(t, found) diff --git a/x/market/types/errors.go b/x/market/types/errors.go index 0ab33889..89e75696 100644 --- a/x/market/types/errors.go +++ b/x/market/types/errors.go @@ -52,4 +52,6 @@ var ( ErrProductInvalid = sdkerrors.Register(ModuleName, 21, "product less than beg") // nolint: gomnd // ErrDenomExists - denom already exists ErrDenomExists = sdkerrors.Register(ModuleName, 22, "denom already exists") // nolint: gomnd + // DropNotActive - drop is no longer active + ErrDropNotActive = sdkerrors.Register(ModuleName, 23, "drop not active") // nolint: gomnd )