Skip to content

Commit

Permalink
Merge pull request #335 from comdex-official/locker_unit_tests
Browse files Browse the repository at this point in the history
Adding dutch tests
  • Loading branch information
dheerajkd30 authored Jul 11, 2022
2 parents 39c7084 + 00fdb64 commit e5fced7
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 213 deletions.
10 changes: 0 additions & 10 deletions x/auction/keeper/debt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,3 @@ func (s *KeeperTestSuite) TestCloseDebtAuction() {
}

}

/* 1. auction closed but no bids then auction should restart
2. make sure code enter every if condition or every part of code
3. make sure to change numbers
4.test maths this where quo involved with smaller numbers and also places sdk.Int involved in quo
5.check chost block entered
6.advance time in dutch test so that collateral gets over but target cmst is still left
7.make fetch price dynamic in dutch as of now linear is hard coded
8.handle if auctiontype is empty in setters
// */
8 changes: 5 additions & 3 deletions x/auction/keeper/dutch.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (k Keeper) PlaceDutchAuctionBid(ctx sdk.Context, appID, auctionMappingID, a
return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "bid denom %s not found", bid.Denom)
}
if bid.Amount.GT(auction.OutflowTokenCurrentAmount.Amount) {
return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "bid denom can't be greater than collateral available")
return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "bid amount can't be greater than collateral available")
}

max = k.GetUUSDFromUSD(ctx, max)
Expand All @@ -197,7 +197,9 @@ func (k Keeper) PlaceDutchAuctionBid(ctx sdk.Context, appID, auctionMappingID, a
//owe is $cmdx to be given to user
owe := slice.Mul(outFlowTokenCurrentPrice)
inFlowTokenAmount := owe.Quo(inFlowTokenCurrentPrice)
TargetReachedFlag := false
if inFlowTokenAmount.GT(tab) {
TargetReachedFlag = true
inFlowTokenAmount = tab
owe = inFlowTokenAmount.Mul(inFlowTokenCurrentPrice)
slice = owe.Quo(outFlowTokenCurrentPrice)
Expand Down Expand Up @@ -231,10 +233,10 @@ func (k Keeper) PlaceDutchAuctionBid(ctx sdk.Context, appID, auctionMappingID, a
//here tab is divided by price again so price ration is only considered , we are not using owe again in this function so no problem
//As tab is the amount calculated from difference of target and current inflow token we will be using same as inflow token

if amountLeftInPUSD.LT(dust) && !amountLeftInPUSD.Equal(sdk.ZeroInt()) {
if amountLeftInPUSD.LT(dust) && !amountLeftInPUSD.Equal(sdk.ZeroInt()) && !TargetReachedFlag {
coll := auction.OutflowTokenCurrentAmount.Amount.Uint64()
dust := dust.Uint64()
return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "either bid all the amount %d (UTOKEN) or bid amount by leaving dust greater than %d UUSD", coll, dust)
return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "either bid all the amount %d (UTOKEN) or bid amount by leaving dust greater than %d PUSD", coll, dust)
}

outFlowTokenCoin := sdk.NewCoin(auction.OutflowTokenInitAmount.Denom, slice)
Expand Down
Loading

0 comments on commit e5fced7

Please sign in to comment.