From 608f98864d72f6c571847782cee29da97c3e6823 Mon Sep 17 00:00:00 2001 From: Charles Dusek Date: Fri, 7 Jun 2024 14:58:10 -0500 Subject: [PATCH] Update tests for sqrt(XY) pool basis --- .../keeper/msg_server_create_order_test.go | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/x/market/keeper/msg_server_create_order_test.go b/x/market/keeper/msg_server_create_order_test.go index 9981c06e..a8b99460 100644 --- a/x/market/keeper/msg_server_create_order_test.go +++ b/x/market/keeper/msg_server_create_order_test.go @@ -24,7 +24,7 @@ func common(t *testing.T, testInput keepertest.TestInput) ( // TestData testdata = testData{coinAStr: "30CoinA", coinBStr: "40CoinB", RateAstrArray: []string{"60", "70"}, RateBstrArray: []string{"80", "90"}} - coinPair, _ = sample.SampleCoins("140CoinA", "140CoinB") + coinPair, _ = sample.SampleCoins("10000CoinA", "10000CoinB") denomA, denomB = sample.SampleDenoms(coinPair) pair = strings.Join([]string{denomA, denomB}, ",") @@ -56,6 +56,14 @@ func TestCreateOrder(t *testing.T) { beforecount := testInput.MarketKeeper.GetUidCount(testInput.Context) + // Calculate Product Before + memberAsk, memberAskFound := testInput.MarketKeeper.GetMember(testInput.Context, denomB, denomA) + require.True(t, memberAskFound) + memberBid, memberBidFound := testInput.MarketKeeper.GetMember(testInput.Context, denomA, denomB) + require.True(t, memberBidFound) + + productBefore := memberAsk.Balance.Mul(memberBid.Balance) + //Create Order var o = types.MsgCreateOrder{Creator: addr, DenomAsk: denomA, DenomBid: denomB, Rate: testdata.RateAstrArray, OrderType: "stop", Amount: "0", Prev: "0", Next: "0"} rate, _ := types.RateStringToInt(o.Rate) @@ -65,6 +73,15 @@ func TestCreateOrder(t *testing.T) { _, err := keeper.NewMsgServerImpl(*testInput.MarketKeeper).CreateOrder(sdk.WrapSDKContext(testInput.Context), &o) require.NoError(t, err) + // Calculate Product After + memberAsk, memberAskFound = testInput.MarketKeeper.GetMember(testInput.Context, denomB, denomA) + require.True(t, memberAskFound) + memberBid, memberBidFound = testInput.MarketKeeper.GetMember(testInput.Context, denomA, denomB) + require.True(t, memberBidFound) + + productAfter := memberAsk.Balance.Mul(memberBid.Balance) + require.True(t, productAfter.GTE(productBefore)) + aftercount := testInput.MarketKeeper.GetUidCount(testInput.Context) require.Equal(t, beforecount+1, aftercount) @@ -82,7 +99,7 @@ func TestCreateOrder(t *testing.T) { require.True(t, memberAskfound) require.Equal(t, memberAsk.DenomA, denomB) require.Equal(t, memberAsk.DenomB, denomA) - require.Equal(t, "33", memberAsk.Balance.String()) + require.Equal(t, "136", memberAsk.Balance.String()) require.Equal(t, memberAsk.Stop, uint64(0)) }