Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(auction): return error on Not Found auction ID #2544

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions x/auction/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/umee-network/umee/v6/util/coin"
"github.com/umee-network/umee/v6/x/auction"
Expand Down Expand Up @@ -34,17 +36,20 @@
*auction.QueryRewardsAuctionResponse, error,
) {
ctx := sdk.UnwrapSDKContext(goCtx)
bid, id := q.Keeper(&ctx).getRewardsBid(msg.Id)
k := q.Keeper(&ctx)
rewards, id := k.getRewardsAuction(msg.Id)
if rewards == nil {
return nil, status.Error(codes.NotFound, "wrong ID")

Check warning on line 42 in x/auction/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/grpc_query.go#L39-L42

Added lines #L39 - L42 were not covered by tests
}
r := &auction.QueryRewardsAuctionResponse{Id: id}
r.Rewards = rewards.Rewards
r.EndsAt = rewards.EndsAt

Check warning on line 46 in x/auction/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/grpc_query.go#L45-L46

Added lines #L45 - L46 were not covered by tests

Comment on lines +39 to +47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error handling for a non-existent auction ID is correctly implemented. Consider improving the error message for clarity.

- return nil, status.Error(codes.NotFound, "wrong ID")
+ return nil, status.Error(codes.NotFound, "Auction ID not found")
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
k := q.Keeper(&ctx)
rewards, id := k.getRewardsAuction(msg.Id)
if rewards == nil {
return nil, status.Error(codes.NotFound, "wrong ID")
}
r := &auction.QueryRewardsAuctionResponse{Id: id}
r.Rewards = rewards.Rewards
r.EndsAt = rewards.EndsAt
k := q.Keeper(&ctx)
rewards, id := k.getRewardsAuction(msg.Id)
if rewards == nil {
return nil, status.Error(codes.NotFound, "Auction ID not found")
}
r := &auction.QueryRewardsAuctionResponse{Id: id}
r.Rewards = rewards.Rewards
r.EndsAt = rewards.EndsAt

bid, _ := q.Keeper(&ctx).getRewardsBid(id)

Check warning on line 48 in x/auction/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/grpc_query.go#L48

Added line #L48 was not covered by tests
if bid != nil {
r.Bidder = bid.Bidder
r.Bid = coin.UmeeInt(bid.Amount)
}
rewards, _ := q.Keeper(&ctx).getRewardsAuction(msg.Id)
if rewards != nil {
r.Rewards = rewards.Rewards
r.EndsAt = rewards.EndsAt
}

return r, nil
}
Loading