Skip to content

Commit

Permalink
Update tests for sqrt(XY) pool basis
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Dusek committed Jun 7, 2024
1 parent 795f837 commit 608f988
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions x/market/keeper/msg_server_create_order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}, ",")

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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))

}
Expand Down

0 comments on commit 608f988

Please sign in to comment.