From 2b70a426f5e1c73fc0ca585429f25fd2d04a0fd8 Mon Sep 17 00:00:00 2001 From: Charles Dusek Date: Fri, 7 Jun 2024 19:43:41 -0500 Subject: [PATCH] Update tests to Sqrt(XY) pool basis --- .../keeper/msg_server_cancel_order_test.go | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/x/market/keeper/msg_server_cancel_order_test.go b/x/market/keeper/msg_server_cancel_order_test.go index 02751e6..c13ee81 100644 --- a/x/market/keeper/msg_server_cancel_order_test.go +++ b/x/market/keeper/msg_server_cancel_order_test.go @@ -2,12 +2,10 @@ package keeper_test import ( "strconv" - "strings" "testing" sdk "github.com/cosmos/cosmos-sdk/types" keepertest "github.com/pendulum-labs/market/testutil/keeper" - "github.com/pendulum-labs/market/testutil/sample" "github.com/pendulum-labs/market/x/market/keeper" "github.com/pendulum-labs/market/x/market/types" "github.com/stretchr/testify/require" @@ -15,11 +13,6 @@ import ( func TestCancelOrder_case1_stop(t *testing.T) { testInput := keepertest.CreateTestEnvironment(t) - // TestData - testdata := testData{coinAStr: "30CoinA", coinBStr: "40CoinB", RateAstrArray: []string{"60", "70"}, RateBstrArray: []string{"80", "90"}} - coinPair, _ := sample.SampleCoins("70CoinA", "70CoinB") - denomA, denomB := sample.SampleDenoms(coinPair) - pair := strings.Join([]string{denomA, denomB}, ",") // MintCoins require.NoError(t, testInput.BankKeeper.MintCoins(testInput.Context, types.ModuleName, coinPair)) @@ -61,7 +54,7 @@ func TestCancelOrder_case1_stop(t *testing.T) { require.True(t, memberfound) require.Equal(t, memberA.DenomA, denomB) require.Equal(t, memberA.DenomB, denomA) - require.Equal(t, "33", memberA.Balance.String()) + require.Equal(t, "136", memberA.Balance.String()) require.Equal(t, memberA.Stop, uint64(0)) // Cancel Order @@ -77,7 +70,7 @@ func TestCancelOrder_case1_stop(t *testing.T) { require.True(t, memberfound) require.Equal(t, memberA.DenomA, denomB) require.Equal(t, memberA.DenomB, denomA) - require.Equal(t, "33", memberA.Balance.String()) + require.Equal(t, "136", memberA.Balance.String()) require.Equal(t, memberA.Stop, uint64(0)) //Validate Order @@ -94,11 +87,6 @@ func TestCancelOrder_case1_stop(t *testing.T) { func TestCancelOrder_case1_limit(t *testing.T) { testInput := keepertest.CreateTestEnvironment(t) - // TestData - testdata := testData{coinAStr: "30CoinA", coinBStr: "40CoinB", RateAstrArray: []string{"60", "70"}, RateBstrArray: []string{"80", "90"}} - coinPair, _ := sample.SampleCoins("70CoinA", "70CoinB") - denomA, denomB := sample.SampleDenoms(coinPair) - pair := strings.Join([]string{denomA, denomB}, ",") // MintCoins require.NoError(t, testInput.BankKeeper.MintCoins(testInput.Context, types.ModuleName, coinPair)) @@ -122,6 +110,14 @@ func TestCancelOrder_case1_limit(t *testing.T) { balanceBefore := testInput.BankKeeper.GetBalance(testInput.Context, sdk.AccAddress(addr), denomB) + //Validate GetMember + memberBid, memberfoundBid := testInput.MarketKeeper.GetMember(testInput.Context, denomA, denomB) + require.True(t, memberfoundBid) + require.Equal(t, memberBid.DenomA, denomA) + require.Equal(t, memberBid.DenomB, denomB) + require.Equal(t, "182", memberBid.Balance.String()) + require.Equal(t, memberBid.Stop, uint64(0)) + // Create Order var o = types.MsgCreateOrder{Creator: addr, DenomAsk: denomA, DenomBid: denomB, Rate: testdata.RateAstrArray, OrderType: "limit", Amount: "0", Prev: "0", Next: "0"} _, err = keeper.NewMsgServerImpl(*testInput.MarketKeeper).CreateOrder(sdk.WrapSDKContext(testInput.Context), &o) @@ -138,11 +134,11 @@ func TestCancelOrder_case1_limit(t *testing.T) { require.Equal(t, orders.Amount.String(), o.Amount) //Validate GetMember - memberBid, memberfoundBid := testInput.MarketKeeper.GetMember(testInput.Context, orders.DenomAsk, orders.DenomBid) + memberBid, memberfoundBid = testInput.MarketKeeper.GetMember(testInput.Context, orders.DenomAsk, orders.DenomBid) require.True(t, memberfoundBid) require.Equal(t, memberBid.DenomA, denomA) require.Equal(t, memberBid.DenomB, denomB) - require.Equal(t, "44", memberBid.Balance.String()) + require.Equal(t, "182", memberBid.Balance.String()) require.Equal(t, memberBid.Stop, uint64(0)) memberBid.Stop = orders.Uid @@ -161,7 +157,7 @@ func TestCancelOrder_case1_limit(t *testing.T) { require.True(t, memberfoundBid) require.Equal(t, memberBid.DenomA, denomA) require.Equal(t, memberBid.DenomB, denomB) - require.Equal(t, "44", memberBid.Balance.String()) + require.Equal(t, "182", memberBid.Balance.String()) require.Equal(t, memberBid.Stop, uint64(orders.Uid)) //Validate Order @@ -173,16 +169,23 @@ func TestCancelOrder_case1_limit(t *testing.T) { require.Equal(t, orders.Amount.String(), o.Amount) require.Equal(t, orders.OrderType, "limit") + // Validate GetPool + rst, found := testInput.MarketKeeper.GetPool(testInput.Context, pair) + require.True(t, found) + + // 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(rst.Drops)) } func TestCancelOrder_case2_stop(t *testing.T) { testInput := keepertest.CreateTestEnvironment(t) - // TestData - testdata := testData{coinAStr: "30CoinA", coinBStr: "40CoinB", RateAstrArray: []string{"60", "70"}, RateBstrArray: []string{"80", "90"}} - coinPair, _ := sample.SampleCoins("70CoinA", "70CoinB") - denomA, denomB := sample.SampleDenoms(coinPair) - pair := strings.Join([]string{denomA, denomB}, ",") // MintCoins require.NoError(t, testInput.BankKeeper.MintCoins(testInput.Context, types.ModuleName, coinPair)) @@ -226,7 +229,7 @@ func TestCancelOrder_case2_stop(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)) o.Next = strconv.FormatUint(beforecount, 10) @@ -251,7 +254,7 @@ func TestCancelOrder_case2_stop(t *testing.T) { require.True(t, memberBidfound) require.Equal(t, memberBid.DenomA, denomA) require.Equal(t, memberBid.DenomB, denomB) - require.Equal(t, "44", memberBid.Balance.String()) + require.Equal(t, "182", memberBid.Balance.String()) require.Equal(t, memberBid.Stop, beforecount) // Validate Order @@ -299,7 +302,7 @@ func TestCancelOrderEmptyPool(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)) // Validate RedeemDrop