Skip to content

Commit f8748be

Browse files
[ci]Fix in test for getTotalAmuletBalance returning Future[Option[T]]
Signed-off-by: Raymond Roestenburg <[email protected]>
1 parent fe56f0a commit f8748be

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

apps/app/src/test/scala/org/lfdecentralizedtrust/splice/integration/tests/ScanTimeBasedIntegrationTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,11 @@ class ScanTimeBasedIntegrationTest
364364
val total0 =
365365
sv1ScanBackend
366366
.getTotalAmuletBalance(firstRound + 0)
367-
.valueOrFail("Amulet balance not yet computed")
367+
.getOrElse(BigDecimal(0))
368368
val total1 =
369369
sv1ScanBackend
370370
.getTotalAmuletBalance(firstRound + 1)
371-
.valueOrFail("Amulet balance not yet computed")
371+
.getOrElse(BigDecimal(0))
372372
val total2 =
373373
sv1ScanBackend
374374
.getTotalAmuletBalance(firstRound + 2)

apps/scan/src/main/scala/org/lfdecentralizedtrust/splice/scan/store/db/DbScanStore.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -603,16 +603,19 @@ class DbScanStore(
603603
// which is why the first entry found <= asOfEndOfRound is used
604604
sql"""
605605
select greatest(
606-
0,
607-
sum_cumulative_change_to_initial_amount_as_of_round_zero -
608-
sum_cumulative_change_to_holding_fees_rate * ($asOfEndOfRound + 1)
609-
)
606+
0,
607+
coalesce(
608+
sum_cumulative_change_to_initial_amount_as_of_round_zero -
609+
sum_cumulative_change_to_holding_fees_rate * ($asOfEndOfRound + 1),
610+
0
611+
)
612+
)
610613
from round_total_amulet_balance
611614
where store_id = $roundTotalsStoreId
612615
and closed_round <= $asOfEndOfRound
613616
order by closed_round desc
614617
limit 1;
615-
""".as[Option[BigDecimal]].head,
618+
""".as[BigDecimal].headOption,
616619
"getTotalAmuletBalance",
617620
)
618621
}

apps/scan/src/test/scala/org/lfdecentralizedtrust/splice/store/db/ScanStoreTest.scala

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,11 @@ abstract class ScanStoreTest
138138
)
139139
_ <- store.aggregate()
140140
} yield {
141-
store.getTotalAmuletBalance(1).futureValue shouldBe (0.0)
141+
// nothing occurs before the mint so there is no total amulet balance
142+
store.getTotalAmuletBalance(1).futureValue shouldBe empty
142143
// 100.0 is the initial amount as of round 0, so at the end of round 2 the holding fee was applied three times
143-
store.getTotalAmuletBalance(2).futureValue shouldBe (amuletAmount - 3 * holdingFee)
144-
store.getTotalAmuletBalance(3).futureValue shouldBe (amuletAmount - 4 * holdingFee)
144+
store.getTotalAmuletBalance(2).futureValue.value shouldBe (amuletAmount - 3 * holdingFee)
145+
store.getTotalAmuletBalance(3).futureValue.value shouldBe (amuletAmount - 4 * holdingFee)
145146
}
146147
}
147148

@@ -179,13 +180,15 @@ abstract class ScanStoreTest
179180
)
180181
_ <- store.aggregate()
181182
} yield {
182-
store.getTotalAmuletBalance(1).futureValue shouldBe (amuletRound1 - 1 * holdingFee)
183+
store.getTotalAmuletBalance(1).futureValue.value shouldBe (amuletRound1 - 1 * holdingFee)
183184
store
184185
.getTotalAmuletBalance(2)
185-
.futureValue shouldBe (amuletRound1 - 2 * holdingFee + changeToInitialAmountAsOfRoundZero - 3 * holdingFee)
186+
.futureValue
187+
.value shouldBe (amuletRound1 - 2 * holdingFee + changeToInitialAmountAsOfRoundZero - 3 * holdingFee)
186188
store
187189
.getTotalAmuletBalance(3)
188-
.futureValue shouldBe (amuletRound1 - 3 * holdingFee + changeToInitialAmountAsOfRoundZero - 4 * holdingFee)
190+
.futureValue
191+
.value shouldBe (amuletRound1 - 3 * holdingFee + changeToInitialAmountAsOfRoundZero - 4 * holdingFee)
189192
}
190193
}
191194

@@ -226,13 +229,15 @@ abstract class ScanStoreTest
226229
)
227230
_ <- store.aggregate()
228231
} yield {
229-
store.getTotalAmuletBalance(1).futureValue shouldBe (amuletRound1 - 1 * holdingFee)
232+
store.getTotalAmuletBalance(1).futureValue.value shouldBe (amuletRound1 - 1 * holdingFee)
230233
store
231234
.getTotalAmuletBalance(2)
232-
.futureValue shouldBe (amuletRound1 - 2 * holdingFee + changeToInitialAmountAsOfRoundZero - 3 * holdingFee)
235+
.futureValue
236+
.value shouldBe (amuletRound1 - 2 * holdingFee + changeToInitialAmountAsOfRoundZero - 3 * holdingFee)
233237
store
234238
.getTotalAmuletBalance(3)
235-
.futureValue shouldBe (amuletRound1 - 3 * holdingFee + changeToInitialAmountAsOfRoundZero - 4 * holdingFee)
239+
.futureValue
240+
.value shouldBe (amuletRound1 - 3 * holdingFee + changeToInitialAmountAsOfRoundZero - 4 * holdingFee)
236241
}
237242
}
238243

@@ -253,10 +258,11 @@ abstract class ScanStoreTest
253258
)
254259
_ <- store.aggregate()
255260
} yield {
256-
store.getTotalAmuletBalance(1).futureValue shouldBe (0.0)
261+
// nothing occurs before the mint so there is no total amulet balance calculated
262+
store.getTotalAmuletBalance(1).futureValue shouldBe empty
257263
// The amulet is minted at round 2, so at the end of that round it's already incurring 1 x holding fee
258-
store.getTotalAmuletBalance(2).futureValue shouldBe (mintAmount - 1 * holdingFee)
259-
store.getTotalAmuletBalance(3).futureValue shouldBe (mintAmount - 2 * holdingFee)
264+
store.getTotalAmuletBalance(2).futureValue.value shouldBe (mintAmount - 1 * holdingFee)
265+
store.getTotalAmuletBalance(3).futureValue.value shouldBe (mintAmount - 2 * holdingFee)
260266
}
261267
}
262268

0 commit comments

Comments
 (0)