Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang committed Sep 9, 2024
1 parent da6310b commit b495d10
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,22 @@ class IsolatedMarginModeTests : V4BaseTests(true) {
}

private fun testDefaultTargetLeverage() {
test(
{
perp.tradeInMarket("NEAR-USD", 0)
},
"""
if (perp.staticTyping) {
perp.tradeInMarket("NEAR-USD", 0)

val input = perp.internalState.input
assertEquals(InputType.TRADE, input.currentType)
val trade = input.trade
assertEquals("NEAR-USD", trade.marketId)
assertEquals(MarginMode.Cross, trade.marginMode)
assertEquals(true, trade.options.needsMarginMode)
assertEquals(10.0, trade.targetLeverage)
} else {
test(
{
perp.tradeInMarket("NEAR-USD", 0)
},
"""
{
"input": {
"current": "trade",
Expand All @@ -220,8 +231,9 @@ class IsolatedMarginModeTests : V4BaseTests(true) {
}
}
}
""".trimIndent(),
)
""".trimIndent(),
)
}
}

// MarginMode should automatically to match the current market based on a variety of factors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ open class V4TradeInputTests : V4BaseTests() {

val subaccount = perp.internalState.wallet.account.subaccounts[0]!!
assertEquals(100000.0, subaccount.calculated[CalculationPeriod.current]?.equity)
assertEquals(99985.0, subaccount.calculated[CalculationPeriod.post]?.equity)
assertEquals(99980.61224492347, subaccount.calculated[CalculationPeriod.post]?.equity)

val error = perp.internalState.input.errors?.first()
assertEquals(ErrorType.error, error?.type)
Expand Down Expand Up @@ -663,15 +663,15 @@ open class V4TradeInputTests : V4BaseTests() {
}

if (perp.staticTyping) {
perp.trade("0.1", TradeInputField.size, 0)
perp.trade("1", TradeInputField.size, 0)

val subaccount = perp.internalState.wallet.account.subaccounts[0]!!
assertEquals(100000.0, subaccount.calculated[CalculationPeriod.current]?.equity)
assertEquals(99850.0, subaccount.calculated[CalculationPeriod.post]?.equity)
assertEquals(99923.4693877551, subaccount.calculated[CalculationPeriod.post]?.equity)
} else {
test(
{
perp.trade("0.1", TradeInputField.size, 0)
perp.trade("1", TradeInputField.size, 0)
},
"""
{
Expand All @@ -681,7 +681,7 @@ open class V4TradeInputTests : V4BaseTests() {
"0": {
"equity": {
"current": 100000.0,
"postOrder": 99980.0
"postOrder": 99923.4693877551
}
}
}
Expand Down

0 comments on commit b495d10

Please sign in to comment.