libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit 1a8c7ebef9507dc8368b8c3ad12d040ff1db9d3d
parent b286dafa4d7d4aee682b6bb4c6fbb2cc663dbc96
Author: MS <ms@taler.net>
Date:   Tue, 23 May 2023 14:08:09 +0200

Conversion service tests.

Testing the DB cash-out fetcher and the buy-in
helper that applies ratio and fees.

Diffstat:
Mnexus/src/test/kotlin/ConversionServiceTest.kt | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mnexus/src/test/kotlin/SandboxCircuitApiTest.kt | 2+-
2 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/nexus/src/test/kotlin/ConversionServiceTest.kt b/nexus/src/test/kotlin/ConversionServiceTest.kt @@ -12,8 +12,65 @@ import org.junit.Test import tech.libeufin.nexus.server.nexusApp import tech.libeufin.sandbox.* import tech.libeufin.util.parseAmount +import java.math.BigDecimal class ConversionServiceTest { + // Tests the helper that fetches the new cash-out's to POST to Nexus. + @Test + fun testCashoutFetcher() { + withTestDatabase { + prepSandboxDb() + // making a transaction that means cash-out for bar, but not for foo. + // That lets test the singleton and empty result sets. + wireTransfer( + debitAccount = "foo", + creditAccount = "bar", + subject = "a cash-out for bar", + amount = "TESTKUDOS:3" + ) + // Expecting the fetcher to return an empty set. + val expectEmpty = getUnsubmittedTransactions("foo") + assert(expectEmpty.isEmpty()) + // Expecting the fetcher to return a one-element set. + val expectOne = getUnsubmittedTransactions("bar") + assert(expectOne.size == 1) + // Generating a bunch of cash-out operations for "foo" + for (i in 1..5) + wireTransfer( + debitAccount = "bar", + creditAccount = "foo", + subject = "foo #$i", + amount = "TESTKUDOS:3" + ) + // Expecting 5 entries for foo. + val expectFive = getUnsubmittedTransactions("foo") + assert(expectFive.size == 5) + /* Checking the order. The order should ensure that + * later payments get higher indexes. */ + assert(expectFive[0].subject == "foo #1") + assert(expectFive[4].subject == "foo #5") + } + } + // Tests the helper that applies buy-in ratio and fees + @Test + fun buyinRatioTest() { + val highFees = RatioAndFees( + buy_at_ratio = 1F, + buy_in_fee = 10F + ) + // Checks that negatives aren't let through. + assertException<UtilError>({ + applyBuyinRatioAndFees( + BigDecimal.ONE, + highFees) + }) + // Checks successful case. + val fees = RatioAndFees( + buy_at_ratio = 3.5F, + buy_in_fee = 0.33F + ) + assert(applyBuyinRatioAndFees(BigDecimal.valueOf(3), fees) == BigDecimal("10.17")) + } private fun CoroutineScope.launchBuyinMonitor(httpClient: HttpClient): Job { val job = launch { /** diff --git a/nexus/src/test/kotlin/SandboxCircuitApiTest.kt b/nexus/src/test/kotlin/SandboxCircuitApiTest.kt @@ -125,7 +125,7 @@ class SandboxCircuitApiTest { respJson = mapper.readTree(R.bodyAsText()) val debitAmount = respJson.get("amount_debit").asText() assertWithPrint( - "TESTKUDOS:2" == debitAmount || "TESTKUDOS:2.0" == debitAmount, + "TESTKUDOS:2.00" == debitAmount, "'debit_amount' was $debitAmount for a 'credit_amount' of CHF:1.9" ) R = client.get(