Skip to content

Commit

Permalink
Add back limit orders and make pool reasonable
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Dusek committed Jun 13, 2024
1 parent fc977f7 commit 853cb07
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions x/market/keeper/msg_server_simulate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
)

func simulateCommon(t *testing.T, testInput keepertest.TestInput) (pair string, denomA string, denomB string, testdata testData) {
coinPair, _ := sample.SampleCoins("1000000CoinA", "1000000CoinB")
testdata = testData{coinAStr: "30CoinA", coinBStr: "40CoinB", RateAstrArray: []string{"60", "70"}, RateBstrArray: []string{"80", "90"}}
coinPair, _ := sample.SampleCoins("100000000000000000CoinA", "100000000000000000CoinB")
testdata = testData{coinAStr: "3000000000CoinA", coinBStr: "4000000000CoinB", RateAstrArray: []string{"60", "70"}, RateBstrArray: []string{"80", "90"}}
denomA = "CoinA"
denomB = "CoinB"
pair = strings.Join([]string{denomA, denomB}, ",")
Expand Down Expand Up @@ -112,16 +112,18 @@ func TestSimulate(t *testing.T) {
if spend1.Equal(sdk.ZeroInt()) {
continue
}
denom1 := balances[0].Denom

m := rand.Uint64N(99)
if m == 0 {
if m < 10 || m > 90 {
continue
}
spend2 := balances[1].Amount.Quo(sdk.NewIntFromUint64(m))
// denom2 := balances[1].Denom
if spend2.Equal(sdk.ZeroInt()) {
continue
}
denom2 := balances[1].Denom

switch j {
case 1:
Expand All @@ -134,6 +136,10 @@ func TestSimulate(t *testing.T) {
if amountB.GT(spend2) {
continue
}
drops = drops.Sub(sdk.NewIntFromUint64(1))
if drops.LTE(sdk.ZeroInt()) {
continue
}
dropMsg := types.MsgCreateDrop{Creator: userAddr.String(), Pair: pair, Drops: drops.String()}
createDropRes, err := keeper.NewMsgServerImpl(*testInput.MarketKeeper).CreateDrop(sdk.WrapSDKContext(testInput.Context), &dropMsg)
require.NoErrorf(t, err, strings.Join(operations, ", "))
Expand All @@ -150,6 +156,27 @@ func TestSimulate(t *testing.T) {
operations = append(operations, "redeem_drop")
}
case 3:
// Create Order
o := rand.IntN(3)
order := types.MsgCreateOrder{Creator: users[k].Addr, DenomAsk: denom1, DenomBid: denom2, Rate: []string{spend1.String(), spend2.String()}, OrderType: "limit", Amount: spend2.String(), Prev: "0", Next: "0"}
if o == 0 {
order = types.MsgCreateOrder{Creator: users[k].Addr, DenomAsk: denom1, DenomBid: denom2, Rate: []string{spend2.String(), spend1.String()}, OrderType: "limit", Amount: spend2.String(), Prev: "0", Next: "0"}
}
if o == 1 {
order = types.MsgCreateOrder{Creator: users[k].Addr, DenomAsk: denom2, DenomBid: denom1, Rate: []string{spend1.String(), spend2.String()}, OrderType: "limit", Amount: spend1.String(), Prev: "0", Next: "0"}
}
if o == 2 {
order = types.MsgCreateOrder{Creator: users[k].Addr, DenomAsk: denom2, DenomBid: denom1, Rate: []string{spend2.String(), spend1.String()}, OrderType: "limit", Amount: spend1.String(), Prev: "0", Next: "0"}
}
rate, _ := types.RateStringToInt(order.Rate)
bookends := testInput.MarketKeeper.BookEnds(testInput.Context, order.DenomAsk, order.DenomBid, order.OrderType, rate)
order.Prev = strconv.FormatUint(bookends[0], 10)
order.Next = strconv.FormatUint(bookends[1], 10)
createOrderResponse, err := keeper.NewMsgServerImpl(*testInput.MarketKeeper).CreateOrder(sdk.WrapSDKContext(testInput.Context), &order)
require.NoErrorf(t, err, strings.Join(operations, ", "))
users[k].Orders = append(users[k].Orders, createOrderResponse.Uid)
operations = append(operations, "create_order")
case 4:
// Cancel Order
if len(users[k].Orders) > 0 {
p := rand.IntN(len(users[k].Orders))
Expand All @@ -159,14 +186,14 @@ func TestSimulate(t *testing.T) {
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)}
co := types.MsgCancelOrder{Creator: users[k].Addr, Uid: strconv.FormatUint(users[k].Orders[p], 10)}
_, err = keeper.NewMsgServerImpl(*testInput.MarketKeeper).CancelOrder(sdk.WrapSDKContext(testInput.Context), &co)
require.NoErrorf(t, err, strings.Join(operations, ", "))
users[k].Orders, _ = removeUid(users[k].Orders, users[k].Orders[p])
operations = append(operations, "cancel_order")
}

case 4:
case 5:
// Market Order
q := rand.IntN(2)
mo := types.MsgMarketOrder{Creator: users[k].Addr, DenomAsk: denomA, AmountAsk: spend1.String(), DenomBid: denomB, AmountBid: spend2.String(), Slippage: "9999"}
Expand All @@ -177,28 +204,5 @@ func TestSimulate(t *testing.T) {
operations = append(operations, "market_order")

}
/*
case 3:
// Create Order
o := rand.IntN(3)
order := types.MsgCreateOrder{Creator: addr, DenomAsk: denom1, DenomBid: denom2, Rate: []string{spend1.String(), spend2.String()}, OrderType: "limit", Amount: spend2.String(), Prev: "0", Next: "0"}
if o == 0 {
order = types.MsgCreateOrder{Creator: addr, DenomAsk: denom1, DenomBid: denom2, Rate: []string{spend2.String(), spend1.String()}, OrderType: "limit", Amount: spend2.String(), Prev: "0", Next: "0"}
}
if o == 1 {
order = types.MsgCreateOrder{Creator: addr, DenomAsk: denom2, DenomBid: denom1, Rate: []string{spend1.String(), spend2.String()}, OrderType: "limit", Amount: spend1.String(), Prev: "0", Next: "0"}
}
if o == 2 {
order = types.MsgCreateOrder{Creator: addr, DenomAsk: denom2, DenomBid: denom1, Rate: []string{spend2.String(), spend1.String()}, OrderType: "limit", Amount: spend1.String(), Prev: "0", Next: "0"}
}
rate, _ := types.RateStringToInt(order.Rate)
bookends := testInput.MarketKeeper.BookEnds(testInput.Context, order.DenomAsk, order.DenomBid, order.OrderType, rate)
order.Prev = strconv.FormatUint(bookends[0], 10)
order.Next = strconv.FormatUint(bookends[1], 10)
createOrderResponse, err := keeper.NewMsgServerImpl(*testInput.MarketKeeper).CreateOrder(sdk.WrapSDKContext(testInput.Context), &order)
require.NoErrorf(t, err, strings.Join(operations, ", "))
users[k].Orders = append(users[k].Orders, createOrderResponse.Uid)
operations = append(operations, "create_order")
*/
}
}

0 comments on commit 853cb07

Please sign in to comment.