commit 341bd2ae1c5654321f893d7e5ac2e282425184e3
parent d1dcd5d2fccefc7ccffae3a86918c52517bff654
Author: Antoine A <>
Date: Fri, 27 Oct 2023 00:40:20 +0000
Fix test and remove dead code
Diffstat:
5 files changed, 25 insertions(+), 117 deletions(-)
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Database.kt b/bank/src/main/kotlin/tech/libeufin/bank/Database.kt
@@ -750,69 +750,7 @@ class Database(dbConfig: String, private val bankCurrency: String, private val f
}
}
}
-
- suspend fun bankTransactionCreate(
- tx: BankInternalTransaction
- ): BankTransactionResult = conn { conn ->
- conn.transaction {
- val stmt = conn.prepareStatement("""
- SELECT
- out_same_account
- ,out_debtor_not_found
- ,out_creditor_not_found
- ,out_balance_insufficient
- ,out_credit_row_id
- ,out_debit_row_id
- ,out_creditor_is_exchange
- ,out_debtor_is_exchange
- FROM bank_wire_transfer(?,?,TEXT(?),(?,?)::taler_amount,?,TEXT(?),TEXT(?),TEXT(?))
- """
- )
- stmt.setLong(1, tx.creditorAccountId)
- stmt.setLong(2, tx.debtorAccountId)
- stmt.setString(3, tx.subject)
- stmt.setLong(4, tx.amount.value)
- stmt.setInt(5, tx.amount.frac)
- stmt.setLong(6, tx.transactionDate.toDbMicros() ?: throw faultyTimestampByBank())
- stmt.setString(7, tx.accountServicerReference)
- stmt.setString(8, tx.paymentInformationId)
- stmt.setString(9, tx.endToEndId)
- stmt.executeQuery().use {
- when {
- !it.next() -> throw internalServerError("Bank transaction didn't properly return")
- it.getBoolean("out_debtor_not_found") -> {
- logger.error("No debtor account found")
- BankTransactionResult.NO_DEBTOR
- }
- it.getBoolean("out_creditor_not_found") -> {
- logger.error("No creditor account found")
- BankTransactionResult.NO_CREDITOR
- }
- it.getBoolean("out_same_account") -> BankTransactionResult.SAME_ACCOUNT
- it.getBoolean("out_balance_insufficient") -> {
- logger.error("Balance insufficient")
- BankTransactionResult.BALANCE_INSUFFICIENT
- }
- else -> {
- handleExchangeTx(conn, tx.subject, tx.creditorAccountId, tx.debtorAccountId, it)
- BankTransactionResult.SUCCESS
- }
- }
- }
- }
- }
-
- suspend fun checkReservePubReuse(reservePub: EddsaPublicKey): Boolean = conn { conn ->
- val stmt = conn.prepareStatement("""
- SELECT 1 FROM taler_exchange_incoming WHERE reserve_pub = ?
- UNION ALL
- SELECT 1 FROM taler_withdrawal_operations WHERE reserve_pub = ?
- """)
- stmt.setBytes(1, reservePub.raw)
- stmt.setBytes(2, reservePub.raw)
- stmt.oneOrNull { } != null
- }
-
+
// Get the bank transaction whose row ID is rowId
suspend fun bankTransactionGetFromInternalId(rowId: Long): BankAccountTransaction? = conn { conn ->
val stmt = conn.prepareStatement("""
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt b/bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt
@@ -174,25 +174,6 @@ data class BearerToken(
)
/**
- * Convenience type to _communicate_ a bank transfer to the
- * database procedure, NOT representing therefore any particular
- * table. The procedure will then retrieve all the tables data
- * from this type.
- */
-data class BankInternalTransaction(
- // Database row ID of the internal bank account sending the payment.
- val creditorAccountId: Long,
- // Database row ID of the internal bank account receiving the payment.
- val debtorAccountId: Long,
- val subject: String,
- val amount: TalerAmount,
- val transactionDate: Instant,
- val accountServicerReference: String = "not used", // ISO20022
- val endToEndId: String = "not used", // ISO20022
- val paymentInformationId: String = "not used" // ISO20022
-)
-
-/**
* Convenience type representing bank transactions as they
* are in the respective database table. Only used to _get_
* the information from the database.
diff --git a/bank/src/test/kotlin/DatabaseTest.kt b/bank/src/test/kotlin/DatabaseTest.kt
@@ -28,23 +28,6 @@ import java.util.UUID
import kotlin.experimental.inv
import kotlin.test.*
-// Foo pays Bar with custom subject.
-fun genTx(
- subject: String = "test",
- creditorId: Long = 2,
- debtorId: Long = 1
-): BankInternalTransaction =
- BankInternalTransaction(
- creditorAccountId = creditorId,
- debtorAccountId = debtorId,
- subject = subject,
- amount = TalerAmount( 10, 0, "KUDOS"),
- accountServicerReference = "acct-svcr-ref",
- endToEndId = "end-to-end-id",
- paymentInformationId = "pmtinfid",
- transactionDate = Instant.now()
- )
-
class DatabaseTest {
// Testing the helper that creates the admin account.
diff --git a/bank/src/test/kotlin/StatsTest.kt b/bank/src/test/kotlin/StatsTest.kt
@@ -124,8 +124,8 @@ class StatsTest {
val now = OffsetDateTime.now(ZoneOffset.UTC)
val otherHour = now.withHour((now.hour + 1) % 24)
- val otherDay = now.withDayOfMonth((now.dayOfMonth + 1) % 28)
- val otherMonth = now.withMonth((now.monthValue + 1) % 12)
+ val otherDay = now.withDayOfMonth((now.dayOfMonth) % 28 + 1)
+ val otherMonth = now.withMonth((now.monthValue) % 12 + 1)
val otherYear = now.minusYears(1)
register(now, TalerAmount("KUDOS:10.0"))
diff --git a/bank/src/test/kotlin/WireGatewayApiTest.kt b/bank/src/test/kotlin/WireGatewayApiTest.kt
@@ -37,7 +37,7 @@ class WireGatewayApiTest {
talerAddIncomingCreate(
req = AddIncomingRequest(
reserve_pub = randShortHashCode(),
- amount = TalerAmount(10, 0, "KUDOS"),
+ amount = TalerAmount("KUDOS:10"),
debit_account = from,
),
username = to,
@@ -47,6 +47,18 @@ class WireGatewayApiTest {
}
}
+ suspend fun Database.genTransaction(from: String, to: IbanPayTo, subject: String) {
+ bankTransaction(
+ creditAccountPayto = to,
+ debitAccountUsername = from,
+ subject = subject,
+ amount = TalerAmount("KUDOS:10"),
+ timestamp = Instant.now(),
+ ).run {
+ assertEquals(BankTransactionResult.SUCCESS, this)
+ }
+ }
+
// Test endpoint is correctly authenticated
suspend fun ApplicationTestBuilder.authRoutine(path: String, body: JsonObject? = null, method: HttpMethod = HttpMethod.Post) {
// No body when authentication must happen before parsing the body
@@ -249,13 +261,11 @@ class WireGatewayApiTest {
db.genIncoming("exchange", IbanPayTo("payto://iban/MERCHANT-IBAN-XYZ"))
}
// Should not show up in the taler wire gateway API history
- db.bankTransactionCreate(genTx("bogus foobar")).assertSuccess()
- // Bar pays Foo once, but that should not appear in the result.
- db.bankTransactionCreate(genTx("payout", creditorId = 1, debtorId = 2)).assertSuccess()
+ db.genTransaction("merchant", IbanPayTo("payto://iban/exchange-IBAN-XYZ"), "bogus")
+ // Exchange pays merchant once, but that should not appear in the result
+ db.genTransaction("exchange", IbanPayTo("payto://iban/merchant-IBAN-XYZ"), "ignored")
// Gen one transaction using raw bank transaction logic
- db.bankTransactionCreate(
- genTx(IncomingTxMetadata(randShortHashCode()).encode(), 2, 1)
- ).assertSuccess()
+ db.genTransaction("merchant", IbanPayTo("payto://iban/exchange-IBAN-XYZ"), IncomingTxMetadata(randShortHashCode()).encode())
// Gen one transaction using withdraw logic
client.post("/accounts/merchant/withdrawals") {
basicAuth("merchant", "merchant-password")
@@ -327,9 +337,7 @@ class WireGatewayApiTest {
}
}
delay(200)
- db.bankTransactionCreate(
- genTx(IncomingTxMetadata(randShortHashCode()).encode(), 2, 1)
- ).assertSuccess()
+ db.genTransaction("merchant", IbanPayTo("payto://iban/exchange-IBAN-XYZ"), IncomingTxMetadata(randShortHashCode()).encode())
}
// Test trigger by withdraw operationr
@@ -428,14 +436,12 @@ class WireGatewayApiTest {
db.genTransfer("exchange", IbanPayTo("payto://iban/MERCHANT-IBAN-XYZ"))
}
// Should not show up in the taler wire gateway API history
- db.bankTransactionCreate(genTx("bogus foobar", 1, 2)).assertSuccess()
- // Foo pays Bar once, but that should not appear in the result.
- db.bankTransactionCreate(genTx("payout")).assertSuccess()
+ db.genTransaction("exchange", IbanPayTo("payto://iban/MERCHANT-IBAN-XYZ"), "bogus")
+ // Merchant pays exchange once, but that should not appear in the result
+ db.genTransaction("merchant", IbanPayTo("payto://iban/exchange-IBAN-XYZ"), "ignored")
// Gen two transactions using raw bank transaction logic
repeat(2) {
- db.bankTransactionCreate(
- genTx(OutgoingTxMetadata(randShortHashCode(), ExchangeUrl("http://exchange.example.com/")).encode(), 1, 2)
- ).assertSuccess()
+ db.genTransaction("exchange", IbanPayTo("payto://iban/MERCHANT-IBAN-XYZ"), OutgoingTxMetadata(randShortHashCode(), ExchangeUrl("http://exchange.example.com/")).encode())
}
// Check ignore bogus subject