Skip to content

Commit bcf4f90

Browse files
authored
test: migrate LedgerBoundsTest and TimeBoundsTest to Kotlin. (#729)
1 parent 46898eb commit bcf4f90

File tree

4 files changed

+147
-150
lines changed

4 files changed

+147
-150
lines changed

src/test/java/org/stellar/sdk/LedgerBoundsTest.java

Lines changed: 0 additions & 74 deletions
This file was deleted.

src/test/java/org/stellar/sdk/TimeBoundsTest.java

Lines changed: 0 additions & 76 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package org.stellar.sdk
2+
3+
import io.kotest.assertions.throwables.shouldThrow
4+
import io.kotest.core.spec.style.FunSpec
5+
import io.kotest.matchers.shouldBe
6+
7+
class LedgerBoundsTest :
8+
FunSpec({
9+
test("should throw IllegalArgumentException for negative minLedger") {
10+
val exception = shouldThrow<IllegalArgumentException> { LedgerBounds(-1, 300) }
11+
exception.message shouldBe "minLedger must be between 0 and 2^32-1"
12+
}
13+
14+
test("should throw IllegalArgumentException for negative maxLedger") {
15+
val exception = shouldThrow<IllegalArgumentException> { LedgerBounds(1, -300) }
16+
exception.message shouldBe "maxLedger must be between 0 and 2^32-1"
17+
}
18+
19+
test("should throw IllegalArgumentException for minLedger greater than uint32 max") {
20+
val exception = shouldThrow<IllegalArgumentException> { LedgerBounds(4294967296L, 300) }
21+
exception.message shouldBe "minLedger must be between 0 and 2^32-1"
22+
}
23+
24+
test("should throw IllegalArgumentException for maxLedger greater than uint32 max") {
25+
val exception = shouldThrow<IllegalArgumentException> { LedgerBounds(1, 4294967296L) }
26+
exception.message shouldBe "maxLedger must be between 0 and 2^32-1"
27+
}
28+
29+
test("should throw IllegalArgumentException when minLedger greater than maxLedger") {
30+
val exception = shouldThrow<IllegalArgumentException> { LedgerBounds(300, 1) }
31+
exception.message shouldBe "minLedger can not be greater than maxLedger"
32+
}
33+
34+
test("should allow minLedger greater than maxLedger when maxLedger is zero") {
35+
val ledgerBounds = LedgerBounds(300, 0)
36+
ledgerBounds.minLedger shouldBe 300
37+
ledgerBounds.maxLedger shouldBe 0
38+
LedgerBounds.fromXdr(ledgerBounds.toXdr()) shouldBe ledgerBounds
39+
}
40+
41+
test("should create valid LedgerBounds") {
42+
val ledgerBounds = LedgerBounds(300, 400)
43+
ledgerBounds.minLedger shouldBe 300
44+
ledgerBounds.maxLedger shouldBe 400
45+
LedgerBounds.fromXdr(ledgerBounds.toXdr()) shouldBe ledgerBounds
46+
}
47+
48+
test("should handle zero values") {
49+
val ledgerBounds = LedgerBounds(0, 0)
50+
ledgerBounds.minLedger shouldBe 0
51+
ledgerBounds.maxLedger shouldBe 0
52+
LedgerBounds.fromXdr(ledgerBounds.toXdr()) shouldBe ledgerBounds
53+
}
54+
55+
test("should handle uint32 max values") {
56+
val maxUint32 = 4294967295L
57+
val ledgerBounds = LedgerBounds(maxUint32, maxUint32)
58+
ledgerBounds.minLedger shouldBe maxUint32
59+
ledgerBounds.maxLedger shouldBe maxUint32
60+
LedgerBounds.fromXdr(ledgerBounds.toXdr()) shouldBe ledgerBounds
61+
}
62+
63+
test("should handle min equal to max") {
64+
val ledgerBounds = LedgerBounds(100, 100)
65+
ledgerBounds.minLedger shouldBe 100
66+
ledgerBounds.maxLedger shouldBe 100
67+
LedgerBounds.fromXdr(ledgerBounds.toXdr()) shouldBe ledgerBounds
68+
}
69+
})
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package org.stellar.sdk
2+
3+
import io.kotest.assertions.throwables.shouldThrow
4+
import io.kotest.core.spec.style.FunSpec
5+
import io.kotest.matchers.longs.shouldBeInRange
6+
import io.kotest.matchers.shouldBe
7+
8+
class TimeBoundsTest :
9+
FunSpec({
10+
test("should throw IllegalArgumentException for negative minTime") {
11+
val exception = shouldThrow<IllegalArgumentException> { TimeBounds(-1, 300) }
12+
exception.message shouldBe "minTime must be between 0 and 2^64-1"
13+
}
14+
15+
test("should throw IllegalArgumentException for negative maxTime") {
16+
val exception = shouldThrow<IllegalArgumentException> { TimeBounds(1, -300) }
17+
exception.message shouldBe "maxTime must be between 0 and 2^64-1"
18+
}
19+
20+
test("should throw IllegalArgumentException when minTime greater than maxTime") {
21+
val exception = shouldThrow<IllegalArgumentException> { TimeBounds(300, 1) }
22+
exception.message shouldBe "minTime must be <= maxTime"
23+
}
24+
25+
test("should create TimeBounds with infinite timeout (maxTime = 0)") {
26+
val timeBounds = TimeBounds(300, 0)
27+
timeBounds.minTime.toLong() shouldBe 300
28+
timeBounds.maxTime.toLong() shouldBe 0
29+
TimeBounds.fromXdr(timeBounds.toXdr()) shouldBe timeBounds
30+
}
31+
32+
test("should create TimeBounds with both times zero") {
33+
val timeBounds = TimeBounds(0, 0)
34+
timeBounds.minTime.toLong() shouldBe 0
35+
timeBounds.maxTime.toLong() shouldBe 0
36+
TimeBounds.fromXdr(timeBounds.toXdr()) shouldBe timeBounds
37+
}
38+
39+
test("should create TimeBounds with valid range") {
40+
val timeBounds = TimeBounds(1, 300)
41+
timeBounds.minTime.toLong() shouldBe 1
42+
timeBounds.maxTime.toLong() shouldBe 300
43+
TimeBounds.fromXdr(timeBounds.toXdr()) shouldBe timeBounds
44+
}
45+
46+
test("should create TimeBounds with equal min and max time") {
47+
val timeBounds = TimeBounds(300, 300)
48+
timeBounds.minTime.toLong() shouldBe 300
49+
timeBounds.maxTime.toLong() shouldBe 300
50+
TimeBounds.fromXdr(timeBounds.toXdr()) shouldBe timeBounds
51+
}
52+
53+
test("should create TimeBounds with timeout using expiresAfter") {
54+
val timeout = 300L
55+
val timeBounds = TimeBounds.expiresAfter(timeout)
56+
val now = System.currentTimeMillis() / 1000L
57+
58+
timeBounds.minTime.toLong() shouldBe 0
59+
val actualMaxTime = timeBounds.maxTime.toLong()
60+
actualMaxTime shouldBeInRange (now + timeout - 1)..(now + timeout + 1)
61+
}
62+
63+
test("should handle large time values") {
64+
val largeTime = Long.MAX_VALUE - 1
65+
val timeBounds = TimeBounds(0, largeTime)
66+
timeBounds.minTime.toLong() shouldBe 0
67+
timeBounds.maxTime.toLong() shouldBe largeTime
68+
TimeBounds.fromXdr(timeBounds.toXdr()) shouldBe timeBounds
69+
}
70+
71+
test("should handle maximum valid long values") {
72+
val maxTime = Long.MAX_VALUE
73+
val timeBounds = TimeBounds(maxTime, maxTime)
74+
timeBounds.minTime.toLong() shouldBe maxTime
75+
timeBounds.maxTime.toLong() shouldBe maxTime
76+
TimeBounds.fromXdr(timeBounds.toXdr()) shouldBe timeBounds
77+
}
78+
})

0 commit comments

Comments
 (0)