-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
last price was being set to 0 if there was no matching in phase 2
- Loading branch information
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"time" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
utils "github.com/crescent-network/crescent/v5/types" | ||
) | ||
|
||
func (s *KeeperTestSuite) TestBatchMatchingEdgecase() { | ||
market := s.CreateMarket("ucre", "uusd") | ||
|
||
mmAddr := s.FundedAccount(1, enoughCoins) | ||
s.MakeLastPrice(market.Id, mmAddr, utils.ParseDec("1")) | ||
|
||
ordererAddr1 := s.FundedAccount(2, enoughCoins) | ||
ordererAddr2 := s.FundedAccount(3, enoughCoins) | ||
|
||
s.PlaceBatchLimitOrder( | ||
market.Id, ordererAddr1, false, utils.ParseDec("1"), sdk.NewDec(5_000000), time.Hour) | ||
s.PlaceBatchLimitOrder( | ||
market.Id, ordererAddr1, false, utils.ParseDec("1.001"), sdk.NewDec(10_000000), time.Hour) | ||
s.PlaceBatchLimitOrder( | ||
market.Id, ordererAddr1, false, utils.ParseDec("1.002"), sdk.NewDec(10_000000), time.Hour) | ||
|
||
order := s.PlaceBatchLimitOrder( | ||
market.Id, ordererAddr2, true, utils.ParseDec("1"), sdk.NewDec(10_000000), time.Hour) | ||
s.PlaceBatchLimitOrder( | ||
market.Id, ordererAddr2, true, utils.ParseDec("1.01"), sdk.NewDec(1_000000), time.Hour) | ||
|
||
// Order book looks like: | ||
// | 1.010 | # | ||
// ########## | 1.001 | | ||
// ########## | 1.002 | | ||
// ##### | 1.000 | ########## | ||
|
||
// After batch matching, it should look like: | ||
// | 1.010 | | ||
// ########## | 1.001 | | ||
// ########## | 1.002 | | ||
// | 1.000 | ###### | ||
|
||
s.NextBlock() | ||
|
||
s.AssertEqual(utils.ParseDec("1"), *s.App.ExchangeKeeper.MustGetMarketState(s.Ctx, market.Id).LastPrice) | ||
order = s.keeper.MustGetOrder(s.Ctx, order.Id) | ||
s.AssertEqual(sdk.NewDec(6_000000), order.OpenQuantity) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters