From 9a355d2664841457f6ed59e48946278bc37fa055 Mon Sep 17 00:00:00 2001 From: Charles Dusek Date: Sun, 23 Jun 2024 01:51:22 -0500 Subject: [PATCH] Fix tests --- .../keeper/msg_server_cancel_order_test.go | 18 +++++++++--------- x/market/keeper/msg_server_create_drop.go | 4 ---- x/market/keeper/msg_server_create_drop_test.go | 8 ++++---- .../keeper/msg_server_create_order_test.go | 4 ++-- .../keeper/msg_server_market_order_test.go | 2 +- x/market/keeper/msg_server_redeem_drop_test.go | 4 ++-- 6 files changed, 18 insertions(+), 22 deletions(-) diff --git a/x/market/keeper/msg_server_cancel_order_test.go b/x/market/keeper/msg_server_cancel_order_test.go index 7557802..00f2283 100644 --- a/x/market/keeper/msg_server_cancel_order_test.go +++ b/x/market/keeper/msg_server_cancel_order_test.go @@ -68,7 +68,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, "136", memberA.Balance.String()) + require.Equal(t, "135", memberA.Balance.String()) require.Equal(t, memberA.Stop, uint64(0)) // Cancel Order @@ -84,7 +84,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, "136", memberA.Balance.String()) + require.Equal(t, "135", memberA.Balance.String()) require.Equal(t, memberA.Stop, uint64(0)) //Validate Order @@ -113,7 +113,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, "181", memberBid.Balance.String()) + require.Equal(t, "180", memberBid.Balance.String()) require.Equal(t, memberBid.Stop, uint64(0)) // Create Order @@ -136,7 +136,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, "181", memberBid.Balance.String()) + require.Equal(t, "180", memberBid.Balance.String()) require.Equal(t, memberBid.Stop, uint64(0)) memberBid.Stop = orders.Uid @@ -155,7 +155,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, "181", memberBid.Balance.String()) + require.Equal(t, "180", memberBid.Balance.String()) require.Equal(t, memberBid.Stop, uint64(orders.Uid)) //Validate Order @@ -211,7 +211,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, "136", memberAsk.Balance.String()) + require.Equal(t, "135", memberAsk.Balance.String()) require.Equal(t, memberAsk.Stop, uint64(0)) o.Next = strconv.FormatUint(beforecount, 10) @@ -236,7 +236,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, "181", memberBid.Balance.String()) + require.Equal(t, "180", memberBid.Balance.String()) require.Equal(t, memberBid.Stop, beforecount) // Validate Order @@ -284,7 +284,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, "136", memberAsk.Balance.String()) + require.Equal(t, "135", memberAsk.Balance.String()) require.Equal(t, memberAsk.Stop, uint64(0)) // Validate RedeemDrop @@ -326,7 +326,7 @@ func TestCancelOrder_case1_market_filled(t *testing.T) { require.True(t, memberfoundBid) require.Equal(t, memberBid.DenomA, denomA) require.Equal(t, memberBid.DenomB, denomB) - require.Equal(t, "181", memberBid.Balance.String()) + require.Equal(t, "180", memberBid.Balance.String()) require.Equal(t, memberBid.Stop, uint64(0)) //Create Order diff --git a/x/market/keeper/msg_server_create_drop.go b/x/market/keeper/msg_server_create_drop.go index dda8e34..6d5614c 100644 --- a/x/market/keeper/msg_server_create_drop.go +++ b/x/market/keeper/msg_server_create_drop.go @@ -63,10 +63,6 @@ func (k msgServer) CreateDrop(goCtx context.Context, msg *types.MsgCreateDrop) ( return nil, error } - if !drops.GT(sdk.ZeroInt()) { - return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "drops not >0") - } - sqrtDropProduct := sqrtInt(dropAmtMember1.Mul(dropAmtMember2)) sqrtMembers := sqrtInt(member1.Balance.Mul(member2.Balance)) diff --git a/x/market/keeper/msg_server_create_drop_test.go b/x/market/keeper/msg_server_create_drop_test.go index 0d7a09b..2381299 100644 --- a/x/market/keeper/msg_server_create_drop_test.go +++ b/x/market/keeper/msg_server_create_drop_test.go @@ -129,7 +129,7 @@ func TestCreateDrop(t *testing.T) { rst2, found := testInput.MarketKeeper.GetPool(testInput.Context, pair) require.True(t, found) require.Equal(t, rst2.Pair, pair) - require.Equal(t, "165", rst2.Drops.String()) + require.Equal(t, "166", rst2.Drops.String()) require.Equal(t, "154", rst2.Leaders[0].Drops.String()) require.Equal(t, rst2.Leaders[0].Address, addr) require.Equal(t, rst2.Leaders[1].Address, addr2) @@ -155,7 +155,7 @@ func TestCreateDrop(t *testing.T) { pool, found = testInput.MarketKeeper.GetPool(testInput.Context, pair) require.True(t, found) require.Equal(t, pool.Pair, pair) - require.Equal(t, "1165", pool.Drops.String()) + require.Equal(t, "1166", pool.Drops.String()) require.Equal(t, 3, len(pool.Leaders)) require.Equal(t, "1000", pool.Leaders[0].Drops.String()) @@ -175,11 +175,11 @@ func TestCreateDrop(t *testing.T) { pool, found = testInput.MarketKeeper.GetPool(testInput.Context, pair) require.True(t, found) require.Equal(t, pool.Pair, pair) - require.Equal(t, "1565", pool.Drops.String()) + require.Equal(t, "1566", pool.Drops.String()) require.Equal(t, 3, len(pool.Leaders)) require.Equal(t, "1400", pool.Leaders[0].Drops.String()) require.Equal(t, "154", pool.Leaders[1].Drops.String()) - require.Equal(t, "11", pool.Leaders[2].Drops.String()) + require.Equal(t, "12", pool.Leaders[2].Drops.String()) require.Equalf(t, addr3, pool.Leaders[0].Address, pool.Leaders[0].Address) require.Equalf(t, addr, pool.Leaders[1].Address, addr3) require.Equalf(t, addr2, pool.Leaders[2].Address, pool.Leaders[2].Address) diff --git a/x/market/keeper/msg_server_create_order_test.go b/x/market/keeper/msg_server_create_order_test.go index d6c2444..399bdc8 100644 --- a/x/market/keeper/msg_server_create_order_test.go +++ b/x/market/keeper/msg_server_create_order_test.go @@ -99,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, "136", memberAsk.Balance.String()) + require.Equal(t, "135", memberAsk.Balance.String()) require.Equal(t, memberAsk.Stop, uint64(0)) } @@ -201,7 +201,7 @@ func TestBookEnds(t *testing.T) { require.True(t, memberAskfound) require.Equal(t, memberAsk.DenomA, denomB) require.Equal(t, memberAsk.DenomB, denomA) - require.Equal(t, "136", memberAsk.Balance.String()) + require.Equal(t, "135", memberAsk.Balance.String()) require.Equal(t, memberAsk.Stop, uint64(0)) // Create Order Msg Type diff --git a/x/market/keeper/msg_server_market_order_test.go b/x/market/keeper/msg_server_market_order_test.go index d34c55b..ee9c11e 100644 --- a/x/market/keeper/msg_server_market_order_test.go +++ b/x/market/keeper/msg_server_market_order_test.go @@ -69,7 +69,7 @@ func TestMarketOrder(t *testing.T) { require.True(t, memberAskFound) require.Equal(t, memberAsk.DenomA, denomB) require.Equal(t, memberAsk.DenomB, denomA) - require.Equal(t, "121", memberAsk.Balance.String()) + require.Equal(t, "120", memberAsk.Balance.String()) require.Equal(t, memberAsk.Stop, uint64(0)) // Validate order estimation diff --git a/x/market/keeper/msg_server_redeem_drop_test.go b/x/market/keeper/msg_server_redeem_drop_test.go index a6140f8..4784203 100644 --- a/x/market/keeper/msg_server_redeem_drop_test.go +++ b/x/market/keeper/msg_server_redeem_drop_test.go @@ -96,12 +96,12 @@ func TestRedeemDrop(t *testing.T) { require.True(t, memberFoundA) require.Equal(t, memberA.DenomA, denomB) require.Equal(t, memberA.DenomB, denomA) - require.Equal(t, memberA.Balance.String(), "31") + require.Equal(t, "30", memberA.Balance.String()) require.True(t, memberFoundB) require.Equal(t, memberB.DenomA, denomA) require.Equal(t, memberB.DenomB, denomB) - require.Equal(t, memberB.Balance.String(), "41") + require.Equal(t, "40", memberB.Balance.String()) createPoolCoinA, err := sdk.ParseCoinNormalized(p.CoinA) require.NoError(t, err)