chore: check if fund exists for CancelContinuousFund in x/protocolpool (#24560)

This commit is contained in:
Alex | Interchain Labs 2025-04-28 16:12:50 -04:00 committed by GitHub
parent 018f9e1a1d
commit a21b5ef111
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 2 deletions

View File

@ -146,6 +146,15 @@ func (k MsgServer) CancelContinuousFund(ctx context.Context, msg *types.MsgCance
canceledHeight := sdkCtx.BlockHeight()
canceledTime := sdkCtx.BlockTime()
has, err := k.ContinuousFunds.Has(sdkCtx, recipient)
if err != nil {
return nil, fmt.Errorf("cannot get continuous fund for recipient %w", err)
}
if !has {
return nil, fmt.Errorf("cannot cancel continuous fund for recipient %s - does not exist", msg.Recipient)
}
if err := k.ContinuousFunds.Remove(sdkCtx, recipient); err != nil {
return nil, fmt.Errorf("failed to remove continuous fund for recipient %s: %w", msg.Recipient, err)
}

View File

@ -366,7 +366,7 @@ func (suite *KeeperTestSuite) TestCancelContinuousFund() {
expErrMsg: "decoding bech32 failed:",
},
{
name: "remove a continuous fund that already was removed - no error",
name: "remove a continuous fund that already was removed - error does not exist",
msg: &types.MsgCancelContinuousFund{
Authority: validAuthority,
Recipient: validRecipient.String(),
@ -377,7 +377,7 @@ func (suite *KeeperTestSuite) TestCancelContinuousFund() {
// Ensure the continuous fund is not set so that Remove fails.
_ = suite.poolKeeper.ContinuousFunds.Remove(suite.ctx, validRecipient)
},
expErr: false,
expErr: true,
},
{
name: "valid cancel continuous fund",