From 084b5b33428429451d15eb05779b0aaacc0bc529 Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 23 Oct 2024 12:07:34 -0400 Subject: [PATCH] fix tests --- .../functional/vault/Vault.kt | 2 +- .../state/v2/supervisor/VaultSupervisor.kt | 1 - .../functional/vault/VaultTests.kt | 37 ++++++++++++++++--- .../TradingStateMachine+TestUtils.kt | 2 +- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/Vault.kt b/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/Vault.kt index f82afc73f..b12b9f35b 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/Vault.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/Vault.kt @@ -95,7 +95,7 @@ object VaultCalculator { } fun calculateVaultSummary(historicals: List?): VaultDetails? { - val combinedPnls = historicals?.flatMap { it.megavaultPnl?.toList() ?: emptyList() } // Convert Array to List + val combinedPnls = historicals?.flatMap { it.megavaultPnl?.toList() ?: emptyList() } // Convert Array to List if (combinedPnls.isNullOrEmpty()) { return null diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/VaultSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/VaultSupervisor.kt index 54e5fc78f..d698919b4 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/VaultSupervisor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/VaultSupervisor.kt @@ -17,7 +17,6 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.launch -import kotlin.coroutines.CoroutineContext internal class VaultSupervisor( stateMachine: TradingStateMachine, diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultTests.kt b/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultTests.kt index 1c85ce5c8..e375c8e9e 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultTests.kt @@ -27,7 +27,7 @@ class VaultTests { @Test fun calculateVaultSummary_basic() { - val historicalPnl = IndexerMegavaultHistoricalPnlResponse( + val historicalPnl1 = IndexerMegavaultHistoricalPnlResponse( megavaultPnl = arrayOf( IndexerPnlTicksResponseObject( equity = "10000.0", @@ -44,7 +44,24 @@ class VaultTests { ), ) - val vaultDetails = calculateVaultSummary(historicalPnl) + val historicalPnl2 = IndexerMegavaultHistoricalPnlResponse( + megavaultPnl = arrayOf( + IndexerPnlTicksResponseObject( + equity = "10000.0", + totalPnl = "1000.0", + netTransfers = "0.0", + createdAt = Instant.fromEpochMilliseconds(1659465500000).toString(), + ), + IndexerPnlTicksResponseObject( + equity = "5000.0", + totalPnl = "500", + netTransfers = "0.0", + createdAt = Instant.fromEpochMilliseconds(1659379200001).toString(), + ), + ), + ) + + val vaultDetails = calculateVaultSummary(listOf(historicalPnl1, historicalPnl2)) val expectedVaultDetails = VaultDetails( totalValue = 10000.0, @@ -55,6 +72,16 @@ class VaultTests { equity = 10000.0, totalPnl = 1000.0, ), + VaultHistoryEntry( + date = 1659465500000.0, + equity = 10000.0, + totalPnl = 1000.0, + ), + VaultHistoryEntry( + date = 1659379200001.0, + equity = 5000.0, + totalPnl = 500.0, + ), VaultHistoryEntry( date = 1659379200000.0, equity = 5000.0, @@ -71,8 +98,8 @@ class VaultTests { val nullHistoricalPnl = IndexerMegavaultHistoricalPnlResponse(megavaultPnl = null) val emptyHistoricalPnl = IndexerMegavaultHistoricalPnlResponse(megavaultPnl = arrayOf()) - val nullVaultDetails = calculateVaultSummary(nullHistoricalPnl) - val emptyVaultDetails = calculateVaultSummary(emptyHistoricalPnl) + val nullVaultDetails = calculateVaultSummary(listOf(nullHistoricalPnl)) + val emptyVaultDetails = calculateVaultSummary(listOf(emptyHistoricalPnl)) assertEquals(null, nullVaultDetails) assertEquals(null, emptyVaultDetails) @@ -120,7 +147,7 @@ class VaultTests { ), ) - val vaultDetails = calculateVaultSummary(historicalPnl) + val vaultDetails = calculateVaultSummary(listOf(historicalPnl)) assertNotNull(vaultDetails) assertEquals(0.6403508771929824, vaultDetails.thirtyDayReturnPercent) diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/tests/extensions/TradingStateMachine+TestUtils.kt b/src/commonTest/kotlin/exchange.dydx.abacus/tests/extensions/TradingStateMachine+TestUtils.kt index 4f8bcbd9a..caeba4796 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/tests/extensions/TradingStateMachine+TestUtils.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/tests/extensions/TradingStateMachine+TestUtils.kt @@ -597,7 +597,7 @@ fun TradingStateMachine.rest( } "/v4/vault/v1/megavault/historicalPnl" -> { - changes = onMegaVaultPnl(payload) + changes = onMegaVaultPnl(listOf(payload)) } "/v4/vault/v1/megavault/positions" -> {