Skip to content

Commit

Permalink
fix some error assert
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani committed Oct 14, 2024
1 parent 5563291 commit 2ba349e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions x/participation/keeper/msg_server_participate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (k msgServer) Participate(ctx context.Context, msg *types.MsgParticipate) (

participantAddress, err := k.addressCodec.StringToBytes(msg.Participant)
if err != nil {
return nil, sdkerrors.Wrap(err, "invalid participant address")
return nil, sdkerrors.Wrapf(types.ErrInvalidAddress, "invalid participant address %s", msg.Participant)
}

availableAlloc, err := k.GetAvailableAllocations(ctx, msg.Participant)
Expand Down Expand Up @@ -52,10 +52,12 @@ func (k msgServer) Participate(ctx context.Context, msg *types.MsgParticipate) (

// check if the user is already added as an allowed bidder for the auction
_, err = k.AuctionUsedAllocations.Get(ctx, collections.Join(sdk.AccAddress(participantAddress), msg.AuctionID))
if err != nil {
if err == nil {
return nil, sdkerrors.Wrapf(types.ErrAlreadyParticipating,
"address %s is already a participant for auction %d",
msg.Participant, msg.AuctionID)
} else if !errors.Is(err, collections.ErrNotFound) {
return nil, ignterrors.Critical(err.Error())
}

tier, found := types.GetTierFromID(params.ParticipationTierList, msg.TierID)
Expand Down Expand Up @@ -84,9 +86,9 @@ func (k msgServer) Participate(ctx context.Context, msg *types.MsgParticipate) (
// set used allocations
numUsedAllocations := sdkmath.ZeroInt()
used, err := k.UsedAllocations.Get(ctx, msg.Participant)
if errors.Is(err, collections.ErrNotFound) {
if err == nil {
numUsedAllocations = used.NumAllocations
} else if err != nil {
} else if !errors.Is(err, collections.ErrNotFound) {
return nil, ignterrors.Criticalf("failed to get used allocations %s", err.Error())
}

Expand Down
2 changes: 1 addition & 1 deletion x/participation/keeper/msg_server_participate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func Test_msgServer_Participate(t *testing.T) {
AuctionID: auctionLowerRegistrationPeriodID + 1000,
TierID: 1,
},
err: types.ErrAuctionNotFound,
err: fundraisingtypes.ErrAuctionNotFound,
blockTime: validRegistrationTime,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func Test_msgServer_WithdrawAllocations(t *testing.T) {
AuctionID: auctionID + 1000,
},
blockTime: validWithdrawalTime,
err: types.ErrAuctionNotFound,
err: fundraisingtypes.ErrAuctionNotFound,
},
{
name: "should prevent withdrawal before withdrawal delay has passed",
Expand Down

0 comments on commit 2ba349e

Please sign in to comment.