Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 0 additions & 74 deletions src/test/java/org/stellar/sdk/LedgerBoundsTest.java

This file was deleted.

76 changes: 0 additions & 76 deletions src/test/java/org/stellar/sdk/TimeBoundsTest.java

This file was deleted.

69 changes: 69 additions & 0 deletions src/test/kotlin/org/stellar/sdk/LedgerBoundsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package org.stellar.sdk

import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe

class LedgerBoundsTest :
FunSpec({
test("should throw IllegalArgumentException for negative minLedger") {
val exception = shouldThrow<IllegalArgumentException> { LedgerBounds(-1, 300) }
exception.message shouldBe "minLedger must be between 0 and 2^32-1"
}

test("should throw IllegalArgumentException for negative maxLedger") {
val exception = shouldThrow<IllegalArgumentException> { LedgerBounds(1, -300) }
exception.message shouldBe "maxLedger must be between 0 and 2^32-1"
}

test("should throw IllegalArgumentException for minLedger greater than uint32 max") {
val exception = shouldThrow<IllegalArgumentException> { LedgerBounds(4294967296L, 300) }
exception.message shouldBe "minLedger must be between 0 and 2^32-1"
}

test("should throw IllegalArgumentException for maxLedger greater than uint32 max") {
val exception = shouldThrow<IllegalArgumentException> { LedgerBounds(1, 4294967296L) }
exception.message shouldBe "maxLedger must be between 0 and 2^32-1"
}

test("should throw IllegalArgumentException when minLedger greater than maxLedger") {
val exception = shouldThrow<IllegalArgumentException> { LedgerBounds(300, 1) }
exception.message shouldBe "minLedger can not be greater than maxLedger"
}

test("should allow minLedger greater than maxLedger when maxLedger is zero") {
val ledgerBounds = LedgerBounds(300, 0)
ledgerBounds.minLedger shouldBe 300
ledgerBounds.maxLedger shouldBe 0
LedgerBounds.fromXdr(ledgerBounds.toXdr()) shouldBe ledgerBounds
}

test("should create valid LedgerBounds") {
val ledgerBounds = LedgerBounds(300, 400)
ledgerBounds.minLedger shouldBe 300
ledgerBounds.maxLedger shouldBe 400
LedgerBounds.fromXdr(ledgerBounds.toXdr()) shouldBe ledgerBounds
}

test("should handle zero values") {
val ledgerBounds = LedgerBounds(0, 0)
ledgerBounds.minLedger shouldBe 0
ledgerBounds.maxLedger shouldBe 0
LedgerBounds.fromXdr(ledgerBounds.toXdr()) shouldBe ledgerBounds
}

test("should handle uint32 max values") {
val maxUint32 = 4294967295L
val ledgerBounds = LedgerBounds(maxUint32, maxUint32)
ledgerBounds.minLedger shouldBe maxUint32
ledgerBounds.maxLedger shouldBe maxUint32
LedgerBounds.fromXdr(ledgerBounds.toXdr()) shouldBe ledgerBounds
}

test("should handle min equal to max") {
val ledgerBounds = LedgerBounds(100, 100)
ledgerBounds.minLedger shouldBe 100
ledgerBounds.maxLedger shouldBe 100
LedgerBounds.fromXdr(ledgerBounds.toXdr()) shouldBe ledgerBounds
}
})
78 changes: 78 additions & 0 deletions src/test/kotlin/org/stellar/sdk/TimeBoundsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package org.stellar.sdk

import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.longs.shouldBeInRange
import io.kotest.matchers.shouldBe

class TimeBoundsTest :
FunSpec({
test("should throw IllegalArgumentException for negative minTime") {
val exception = shouldThrow<IllegalArgumentException> { TimeBounds(-1, 300) }
exception.message shouldBe "minTime must be between 0 and 2^64-1"
}

test("should throw IllegalArgumentException for negative maxTime") {
val exception = shouldThrow<IllegalArgumentException> { TimeBounds(1, -300) }
exception.message shouldBe "maxTime must be between 0 and 2^64-1"
}

test("should throw IllegalArgumentException when minTime greater than maxTime") {
val exception = shouldThrow<IllegalArgumentException> { TimeBounds(300, 1) }
exception.message shouldBe "minTime must be <= maxTime"
}

test("should create TimeBounds with infinite timeout (maxTime = 0)") {
val timeBounds = TimeBounds(300, 0)
timeBounds.minTime.toLong() shouldBe 300
timeBounds.maxTime.toLong() shouldBe 0
TimeBounds.fromXdr(timeBounds.toXdr()) shouldBe timeBounds
}

test("should create TimeBounds with both times zero") {
val timeBounds = TimeBounds(0, 0)
timeBounds.minTime.toLong() shouldBe 0
timeBounds.maxTime.toLong() shouldBe 0
TimeBounds.fromXdr(timeBounds.toXdr()) shouldBe timeBounds
}

test("should create TimeBounds with valid range") {
val timeBounds = TimeBounds(1, 300)
timeBounds.minTime.toLong() shouldBe 1
timeBounds.maxTime.toLong() shouldBe 300
TimeBounds.fromXdr(timeBounds.toXdr()) shouldBe timeBounds
}

test("should create TimeBounds with equal min and max time") {
val timeBounds = TimeBounds(300, 300)
timeBounds.minTime.toLong() shouldBe 300
timeBounds.maxTime.toLong() shouldBe 300
TimeBounds.fromXdr(timeBounds.toXdr()) shouldBe timeBounds
}

test("should create TimeBounds with timeout using expiresAfter") {
val timeout = 300L
val timeBounds = TimeBounds.expiresAfter(timeout)
val now = System.currentTimeMillis() / 1000L

timeBounds.minTime.toLong() shouldBe 0
val actualMaxTime = timeBounds.maxTime.toLong()
actualMaxTime shouldBeInRange (now + timeout - 1)..(now + timeout + 1)
}

test("should handle large time values") {
val largeTime = Long.MAX_VALUE - 1
val timeBounds = TimeBounds(0, largeTime)
timeBounds.minTime.toLong() shouldBe 0
timeBounds.maxTime.toLong() shouldBe largeTime
TimeBounds.fromXdr(timeBounds.toXdr()) shouldBe timeBounds
}

test("should handle maximum valid long values") {
val maxTime = Long.MAX_VALUE
val timeBounds = TimeBounds(maxTime, maxTime)
timeBounds.minTime.toLong() shouldBe maxTime
timeBounds.maxTime.toLong() shouldBe maxTime
TimeBounds.fromXdr(timeBounds.toXdr()) shouldBe timeBounds
}
})