-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0446f53
commit 6d40313
Showing
7 changed files
with
10,102 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 49 additions & 14 deletions
63
service/src/test/kotlin/io/provenance/explorer/domain/extensions/NavEventExtensionsKtTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,93 @@ | ||
package io.provenance.explorer.domain.extensions | ||
|
||
import io.provlabs.flow.api.NavEvent | ||
import org.joda.time.DateTime | ||
Check failure on line 3 in service/src/test/kotlin/io/provenance/explorer/domain/extensions/NavEventExtensionsKtTest.kt GitHub Actions / ktlint
|
||
import io.provlabs.flow.api.NavEvent as FlowNavEvent | ||
import io.provenance.explorer.domain.entities.NavEvent as ExplorerNavEvent | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
import java.math.BigDecimal | ||
|
||
class NavEventExtensionsKtTest { | ||
|
||
@Test | ||
fun `test calculateUsdPricePerUnit for flow nav events`() { | ||
fun `test calculateUsdPricePerUnit for flow NavEvent`() { | ||
val usdDenom = "usd" | ||
val nonUsdDenom = "non-usd" | ||
|
||
val navEventUsdVolume1Price1 = NavEvent.newBuilder() | ||
val navEventUsdVolume1Price1 = FlowNavEvent.newBuilder() | ||
.setPriceAmount(1) | ||
.setPriceDenom(usdDenom) | ||
.setVolume(1L) | ||
.build() | ||
|
||
val navEventUsdVolume1Price12 = NavEvent.newBuilder() | ||
val navEventUsdVolume1Price12 = FlowNavEvent.newBuilder() | ||
.setPriceAmount(12) | ||
.setPriceDenom(usdDenom) | ||
.setVolume(1L) | ||
.build() | ||
|
||
val navEventUsdVolume1Price123 = NavEvent.newBuilder() | ||
val navEventUsdVolume1Price123 = FlowNavEvent.newBuilder() | ||
.setPriceAmount(123) | ||
.setPriceDenom(usdDenom) | ||
.setVolume(1L) | ||
.build() | ||
|
||
val navEventUsdVolume1Price1234 = NavEvent.newBuilder() | ||
val navEventUsdVolume1Price1234 = FlowNavEvent.newBuilder() | ||
.setPriceAmount(1234) | ||
.setPriceDenom(usdDenom) | ||
.setVolume(1L) | ||
.build() | ||
|
||
val navEventNonUsd = NavEvent.newBuilder() | ||
val navEventNonUsd = FlowNavEvent.newBuilder() | ||
.setPriceAmount(1234) | ||
.setPriceDenom(nonUsdDenom) | ||
.setVolume(1L) | ||
.build() | ||
|
||
val navEventZeroVolume = NavEvent.newBuilder() | ||
val navEventZeroVolume = FlowNavEvent.newBuilder() | ||
.setPriceAmount(1234) | ||
.setPriceDenom(usdDenom) | ||
.setVolume(0L) | ||
.build() | ||
|
||
assertEquals(BigDecimal("0.001"), navEventUsdVolume1Price1.calculateUsdPricePerUnit(), "Price amount 1 should be converted to 0.001") | ||
assertEquals(BigDecimal("0.012"), navEventUsdVolume1Price12.calculateUsdPricePerUnit(), "Price amount 12 should be converted to 0.012") | ||
assertEquals(BigDecimal("0.123"), navEventUsdVolume1Price123.calculateUsdPricePerUnit(), "Price amount 123 should be converted to 0.123") | ||
assertEquals(BigDecimal("1.234"), navEventUsdVolume1Price1234.calculateUsdPricePerUnit(), "Price amount 1234 should be converted to 1.234") | ||
assertEquals(BigDecimal.ZERO, navEventNonUsd.calculateUsdPricePerUnit(), "Non-USD denomination should return 0") | ||
assertEquals(BigDecimal.ZERO, navEventZeroVolume.calculateUsdPricePerUnit(), "Zero volume should return 0") | ||
assertEquals(BigDecimal("0.001"), navEventUsdVolume1Price1.calculateUsdPricePerUnit()) | ||
assertEquals(BigDecimal("0.012"), navEventUsdVolume1Price12.calculateUsdPricePerUnit()) | ||
assertEquals(BigDecimal("0.123"), navEventUsdVolume1Price123.calculateUsdPricePerUnit()) | ||
assertEquals(BigDecimal("1.234"), navEventUsdVolume1Price1234.calculateUsdPricePerUnit()) | ||
assertEquals(BigDecimal.ZERO, navEventNonUsd.calculateUsdPricePerUnit()) | ||
assertEquals(BigDecimal.ZERO, navEventZeroVolume.calculateUsdPricePerUnit()) | ||
} | ||
|
||
@Test | ||
fun `test calculateUsdPricePerUnit for explorer NavEvent`() { | ||
val usdDenom = "usd" | ||
val nonUsdDenom = "non-usd" | ||
|
||
val navEventUsdVolume1Price1 = ExplorerNavEvent( | ||
blockHeight = 1, | ||
blockTime = DateTime.now(), | ||
txHash = "hash1", | ||
eventOrder = 1, | ||
eventType = "type", | ||
scopeId = "scope1", | ||
denom = "denom1", | ||
priceAmount = 1, | ||
priceDenom = usdDenom, | ||
volume = 1L, | ||
source = "source1" | ||
) | ||
|
||
val navEventUsdVolume1Price12 = navEventUsdVolume1Price1.copy(priceAmount = 12) | ||
val navEventUsdVolume1Price123 = navEventUsdVolume1Price1.copy(priceAmount = 123) | ||
val navEventUsdVolume1Price1234 = navEventUsdVolume1Price1.copy(priceAmount = 1234) | ||
val navEventNonUsd = navEventUsdVolume1Price1.copy(priceDenom = nonUsdDenom) | ||
val navEventZeroVolume = navEventUsdVolume1Price1.copy(volume = 0L) | ||
|
||
assertEquals(BigDecimal("0.001"), navEventUsdVolume1Price1.calculateUsdPricePerUnit()) | ||
assertEquals(BigDecimal("0.012"), navEventUsdVolume1Price12.calculateUsdPricePerUnit()) | ||
assertEquals(BigDecimal("0.123"), navEventUsdVolume1Price123.calculateUsdPricePerUnit()) | ||
assertEquals(BigDecimal("1.234"), navEventUsdVolume1Price1234.calculateUsdPricePerUnit()) | ||
assertEquals(BigDecimal.ZERO, navEventNonUsd.calculateUsdPricePerUnit()) | ||
assertEquals(BigDecimal.ZERO, navEventZeroVolume.calculateUsdPricePerUnit()) | ||
} | ||
} |
Oops, something went wrong.