From 649ef617dc9bdefbc1d80f00e28414c7be5dde77 Mon Sep 17 00:00:00 2001 From: Charles Dusek Date: Tue, 11 Jun 2024 11:36:28 -0500 Subject: [PATCH] Fix user order spend --- x/market/keeper/msg_server_simulate_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/x/market/keeper/msg_server_simulate_test.go b/x/market/keeper/msg_server_simulate_test.go index a2e03a7..316a240 100644 --- a/x/market/keeper/msg_server_simulate_test.go +++ b/x/market/keeper/msg_server_simulate_test.go @@ -86,7 +86,7 @@ func TestSimulate(t *testing.T) { users := []User{user1, user2, user3} - for i := 1; i < 100; i++ { + for i := 1; i < 10000; i++ { j := rand.IntN(6) k := rand.IntN(2) @@ -98,7 +98,9 @@ func TestSimulate(t *testing.T) { userAddr, _ := sdk.AccAddressFromBech32(users[k].Addr) spendable := testInput.BankKeeper.SpendableCoins(testInput.Context, userAddr) - + if len(spendable) < 2 { + continue + } l := rand.Uint64N(99) if l == 0 { continue @@ -165,6 +167,12 @@ func TestSimulate(t *testing.T) { // Cancel Order if len(users[k].Orders) > 0 { p := rand.IntN(len(users[k].Orders)) + order, found := testInput.MarketKeeper.GetOrder(testInput.Context, users[k].Orders[p]) + require.True(t, found) + if order.Status == "filled" || order.Status == "cancelled" { + users[k].Orders, _ = removeUid(users[k].Orders, users[k].Orders[p]) + continue + } co := types.MsgCancelOrder{Creator: addr, Uid: strconv.FormatUint(users[k].Orders[p], 10)} _, err = keeper.NewMsgServerImpl(*testInput.MarketKeeper).CancelOrder(sdk.WrapSDKContext(testInput.Context), &co) require.NoError(t, err)