commit 6e2ee7ff28ac6894e6d9acbea0ce77521b3c1b01
parent 8a6e63869af864673aeaa7dd2409695b10db23af
Author: MS <ms@taler.net>
Date: Fri, 15 Sep 2023 11:22:07 +0200
.equals() method for TalerAmount
Diffstat:
4 files changed, 15 insertions(+), 25 deletions(-)
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Database.kt b/bank/src/main/kotlin/tech/libeufin/bank/Database.kt
@@ -62,6 +62,13 @@ class TalerAmount(
?: throw internalServerError("internal_currency not found in the config")
internalCurrency
} else maybeCurrency
+
+ override fun equals(other: Any?): Boolean {
+ return other is TalerAmount &&
+ other.value == this.value &&
+ other.frac == this.frac &&
+ other.currency == this.currency
+ }
}
// BIC got removed, because it'll be expressed in the internal_payto_uri.
diff --git a/bank/src/test/kotlin/Common.kt b/bank/src/test/kotlin/Common.kt
@@ -35,5 +35,6 @@ fun initDb(): Database {
throwIfFails = true
)
val db = Database("jdbc:postgresql:///libeufincheck")
+ db.configSet("internal_currency", "KUDOS")
return db
}
\ No newline at end of file
diff --git a/bank/src/test/kotlin/DatabaseTest.kt b/bank/src/test/kotlin/DatabaseTest.kt
@@ -50,14 +50,14 @@ class DatabaseTest {
lastNexusFetchRowId = 1L,
owningCustomerId = 1L,
hasDebt = false,
- maxDebt = TalerAmount(10, 1)
+ maxDebt = TalerAmount(10, 1, "KUDOS")
)
private val bankAccountBar = BankAccount(
internalPaytoUri = "BAR-IBAN-ABC",
lastNexusFetchRowId = 1L,
owningCustomerId = 2L,
hasDebt = false,
- maxDebt = TalerAmount(10, 1)
+ maxDebt = TalerAmount(10, 1, "KUDOS")
)
@Test
@@ -155,8 +155,8 @@ class DatabaseTest {
// Foo should have returned to zero and no debt, same for Bar.
// Foo: debit -> credit
assert(fooAccount?.hasDebt == false && barAccount?.hasDebt == false)
- assert(fooAccount?.balance?.equals(TalerAmount(0, 0)) == true)
- assert(barAccount?.balance?.equals(TalerAmount(0, 0)) == true)
+ assert(fooAccount?.balance?.equals(TalerAmount(0, 0, "KUDOS")) == true)
+ assert(barAccount?.balance?.equals(TalerAmount(0, 0, "KUDOS")) == true)
// Bringing Bar to debit.
val barPaysMore = db.bankTransactionCreate(barPaysFoo)
assert(barPaysAgain == Database.BankTransactionResult.SUCCESS)
@@ -164,8 +164,8 @@ class DatabaseTest {
fooAccount = db.bankAccountGetFromOwnerId(fooId)
// Bar: credit -> debit
assert(fooAccount?.hasDebt == false && barAccount?.hasDebt == true)
- assert(fooAccount?.balance?.equals(TalerAmount(10, 0)) == true)
- assert(barAccount?.balance?.equals(TalerAmount(10, 0)) == true)
+ assert(fooAccount?.balance?.equals(TalerAmount(10, 0, "KUDOS")) == true)
+ assert(barAccount?.balance?.equals(TalerAmount(10, 0, "KUDOS")) == true)
}
@Test
fun customerCreationTest() {
diff --git a/bank/src/test/kotlin/LibeuFinApiTest.kt b/bank/src/test/kotlin/LibeuFinApiTest.kt
@@ -9,24 +9,6 @@ import tech.libeufin.util.CryptoUtil
import tech.libeufin.util.execCommand
class LibeuFinApiTest {
- fun initDb(): Database {
- System.setProperty(
- "BANK_DB_CONNECTION_STRING",
- "jdbc:postgresql:///libeufincheck"
- )
- execCommand(
- listOf(
- "libeufin-bank-dbinit",
- "-d",
- "libeufincheck",
- "-r"
- ),
- throwIfFails = true
- )
- val db = Database("jdbc:postgresql:///libeufincheck")
- return db
- }
-
/**
* Testing the account creation, its idempotency and
* the restriction to admin to create accounts.
@@ -36,7 +18,7 @@ class LibeuFinApiTest {
testApplication {
val db = initDb()
val ibanPayto = genIbanPaytoUri()
- // Bank needs that to operate:
+ // Bank needs those to operate:
db.configSet("max_debt_ordinary_customers", "KUDOS:11")
application(webApp)
var resp = client.post("/accounts") {