Skip to content

Commit

Permalink
chore: return insufficient fee error nicely
Browse files Browse the repository at this point in the history
  • Loading branch information
kingcre committed Jul 27, 2023
1 parent f94b071 commit 08fc9b8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions x/amm/keeper/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func (k Keeper) CreatePool(ctx sdk.Context, creatorAddr sdk.AccAddress, marketId

creationFee := k.GetPoolCreationFee(ctx)
if err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, creatorAddr, types.ModuleName, creationFee); err != nil {
err = sdkerrors.Wrap(err, "insufficient pool creation fee")
return
}

Expand Down
2 changes: 1 addition & 1 deletion x/amm/keeper/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (s *KeeperTestSuite) TestCreatePool_InsufficientFee() {
market := s.CreateMarket("ucre", "uusd")
creatorAddr := utils.TestAddress(1)
_, err := s.keeper.CreatePool(s.Ctx, creatorAddr, market.Id, utils.ParseDec("5"))
s.Require().EqualError(err, "0ucre is smaller than 100000000ucre: insufficient funds")
s.Require().EqualError(err, "insufficient pool creation fee: 0ucre is smaller than 100000000ucre: insufficient funds")
}

func (s *KeeperTestSuite) TestCreatePool() {
Expand Down
2 changes: 1 addition & 1 deletion x/exchange/keeper/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (k Keeper) CreateMarket(
fees := k.GetFees(ctx)
if err = k.bankKeeper.SendCoinsFromAccountToModule(
ctx, creatorAddr, types.ModuleName, fees.MarketCreationFee); err != nil {
return
return market, sdkerrors.Wrap(err, "insufficient market creation fee")
}

marketId := k.GetNextMarketIdWithUpdate(ctx)
Expand Down
22 changes: 22 additions & 0 deletions x/exchange/keeper/market_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package keeper_test

import (
utils "github.com/crescent-network/crescent/v5/types"
)

func (s *KeeperTestSuite) TestCreateMarket() {
creatorAddr := s.FundedAccount(1, enoughCoins)
_, err := s.keeper.CreateMarket(s.Ctx, creatorAddr, "nonexistent1", "nonexistent2")
s.Require().EqualError(err, "base denom nonexistent1 has no supply: invalid request")
_, err = s.keeper.CreateMarket(s.Ctx, creatorAddr, "ucre", "nonexistent2")
s.Require().EqualError(err, "quote denom nonexistent2 has no supply: invalid request")

s.CreateMarket("ucre", "uusd")

_, err = s.keeper.CreateMarket(s.Ctx, creatorAddr, "ucre", "uusd")
s.Require().EqualError(err, "market already exists: 1: invalid request")

emptyAddr := utils.TestAddress(2)
_, err = s.keeper.CreateMarket(s.Ctx, emptyAddr, "uatom", "uusd")
s.Require().EqualError(err, "insufficient market creation fee: 0stake is smaller than 1000000stake: insufficient funds")
}

0 comments on commit 08fc9b8

Please sign in to comment.