diff --git a/tests/dex_test.go b/tests/dex_test.go index e37e61b6d6..787723aba7 100644 --- a/tests/dex_test.go +++ b/tests/dex_test.go @@ -17,23 +17,56 @@ func TestOrders(t *testing.T) { admin := app.NewSignableAccount("admin") app.FundAccount(admin, 100000000) alice := app.NewSignableAccount("alice") - app.FundAccount(alice, 1000000) + app.FundAccount(alice, 10000000) + bob := app.NewSignableAccount("bob") + app.FundAccount(bob, 10000000) + charlie := app.NewSignableAccount("charlie") + app.FundAccount(charlie, 10000000) contract := app.NewContract(admin, "./mars.wasm") market := msgs.NewMarket(contract.String(), "SEI", "ATOM") + newContract := app.NewContract(admin, "./mars.wasm") registerTx := app.Sign(admin, market.Register(admin, []string{}, 20000000), 1000000) block1 := []signing.Tx{registerTx} require.Equal(t, []uint32{0}, app.RunBlock(block1)) // 1st block to register contract/pair aliceLimitOrder := market.LongLimitOrder(alice, "10.5", "5") - msgs := []sdk.Msg{aliceLimitOrder} - tx := app.Sign(alice, msgs, 10000) + m := []sdk.Msg{aliceLimitOrder} + tx := app.Sign(alice, m, 10000) block2 := []signing.Tx{tx} - blockRunner := func() []uint32 { return app.RunBlock(block2) } // 2nd block to place order + blockRunner := func() []uint32 { return app.RunBlock(block2) } // 2nd block to place the first limit order blockRunner = verify.DexOrders(t, app, blockRunner, block2) blockRunner = verify.Balance(t, app, blockRunner, block2) require.Equal(t, []uint32{0}, blockRunner()) + + newMarket := msgs.NewMarket(newContract.String(), "USDC", "BTC") + bobMarketOrder := market.ShortMarketOrder(bob, "10", "2") + charlieLimitOrder := market.ShortLimitOrder(charlie, "11", "3") + block3 := []signing.Tx{ + app.Sign(admin, newMarket.Register(admin, []string{}, 20000000), 1000000), + app.Sign(bob, []sdk.Msg{bobMarketOrder}, 10000), + app.Sign(charlie, []sdk.Msg{charlieLimitOrder}, 10000), + } + blockRunner = func() []uint32 { return app.RunBlock(block3) } // 2nd block to place more orders + blockRunner = verify.DexOrders(t, app, blockRunner, block3) + blockRunner = verify.Balance(t, app, blockRunner, block3) + + require.Equal(t, []uint32{0, 0, 0}, blockRunner()) + + aliceLimitOrder = newMarket.ShortLimitOrder(alice, "100", "50") + bobLimitOrder := market.LongLimitOrder(bob, "11", "1") + charlieMarketOrder := market.LongMarketOrder(charlie, "12", "4") + block4 := []signing.Tx{ + app.Sign(alice, []sdk.Msg{aliceLimitOrder}, 10000), + app.Sign(bob, []sdk.Msg{bobLimitOrder}, 10000), + app.Sign(charlie, []sdk.Msg{charlieMarketOrder}, 10000), + } + blockRunner = func() []uint32 { return app.RunBlock(block4) } // 2nd block to place more orders + blockRunner = verify.DexOrders(t, app, blockRunner, block4) + blockRunner = verify.Balance(t, app, blockRunner, block4) + + require.Equal(t, []uint32{0, 0, 0}, blockRunner()) } diff --git a/testutil/processblock/verify/bank.go b/testutil/processblock/verify/bank.go index e8cd25e382..580ee5b85d 100644 --- a/testutil/processblock/verify/bank.go +++ b/testutil/processblock/verify/bank.go @@ -35,6 +35,9 @@ func Balance(t *testing.T, app *processblock.App, f BlockRunnable, txs []signing case *dextypes.MsgPlaceOrders: updateMultipleExpectedBalanceChange(expectedChanges, m.Creator, m.Funds, false) updateMultipleExpectedBalanceChange(expectedChanges, m.ContractAddr, m.Funds, true) + case *dextypes.MsgRegisterContract: + funds := sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(int64(m.Contract.RentBalance)))) + updateMultipleExpectedBalanceChange(expectedChanges, m.Creator, funds, false) default: // TODO: add coverage for other balance-affecting messages to enable testing for those message types continue diff --git a/testutil/processblock/verify/dex.go b/testutil/processblock/verify/dex.go index c0ae2decc6..6684959f06 100644 --- a/testutil/processblock/verify/dex.go +++ b/testutil/processblock/verify/dex.go @@ -30,6 +30,7 @@ func DexOrders(t *testing.T, app *processblock.App, f BlockRunnable, txs []signi o.Id = app.DexKeeper.GetNextOrderID(app.Ctx(), m.ContractAddr) + uint64(len(orders)) orderPlacementsByMarket[id] = append(orders, o) } else { + o.Id = app.DexKeeper.GetNextOrderID(app.Ctx(), m.ContractAddr) orderPlacementsByMarket[id] = []*dextypes.Order{o} } }