gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] 02/02: nexus fetch, bouncing low amounts


From: gnunet
Subject: [libeufin] 02/02: nexus fetch, bouncing low amounts
Date: Wed, 22 Nov 2023 08:09:57 +0100

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository libeufin.

commit 545bce3b826a9980cb1991b9f07964f3707b5413
Author: MS <ms@taler.net>
AuthorDate: Wed Nov 22 08:08:37 2023 +0100

    nexus fetch, bouncing low amounts
    
    fixing the refund initiator by passing an explicit refund amount
---
 database-versioning/libeufin-nexus-procedures.sql  |  5 +-
 .../main/kotlin/tech/libeufin/nexus/Database.kt    | 12 ++---
 nexus/src/test/kotlin/DatabaseTest.kt              | 53 ++++++++++++++++++++++
 3 files changed, 62 insertions(+), 8 deletions(-)

diff --git a/database-versioning/libeufin-nexus-procedures.sql 
b/database-versioning/libeufin-nexus-procedures.sql
index 7a36b91a..918bedf3 100644
--- a/database-versioning/libeufin-nexus-procedures.sql
+++ b/database-versioning/libeufin-nexus-procedures.sql
@@ -9,6 +9,7 @@ CREATE OR REPLACE FUNCTION create_incoming_and_bounce(
   ,IN in_bank_transfer_id TEXT
   ,IN in_timestamp BIGINT
   ,IN in_request_uid TEXT
+  ,IN in_refund_amount taler_amount
   ,OUT out_ok BOOLEAN
 ) RETURNS BOOLEAN
 LANGUAGE plpgsql AS $$
@@ -39,7 +40,7 @@ INSERT INTO initiated_outgoing_transactions (
   ,initiation_time
   ,request_uid
   ) VALUES (
-    in_amount
+    in_refund_amount
     ,'refund: ' || in_wire_transfer_subject
     ,in_debit_payto_uri
     ,in_timestamp
@@ -56,7 +57,7 @@ INSERT INTO bounced_transactions (
 out_ok = TRUE;
 END $$;
 
-COMMENT ON FUNCTION create_incoming_and_bounce(taler_amount, TEXT, BIGINT, 
TEXT, TEXT, BIGINT, TEXT)
+COMMENT ON FUNCTION create_incoming_and_bounce(taler_amount, TEXT, BIGINT, 
TEXT, TEXT, BIGINT, TEXT, taler_amount)
   IS 'creates one incoming transaction with a bounced state and initiates its 
related refund.';
 
 CREATE OR REPLACE FUNCTION create_outgoing_payment(
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Database.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Database.kt
index 7e4c98e5..778db5b9 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Database.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Database.kt
@@ -309,19 +309,19 @@ class Database(dbConfig: String): java.io.Closeable {
               ,?
               ,?
               ,?
+              ,(?,?)::taler_amount
             )""")
-
-        var finalAmount = paymentData.amount
-        if (refundAmount != null) finalAmount = refundAmount
-
-        stmt.setLong(1, finalAmount.value)
-        stmt.setInt(2, finalAmount.fraction)
+        stmt.setLong(1, paymentData.amount.value)
+        stmt.setInt(2, paymentData.amount.fraction)
         stmt.setString(3, paymentData.wireTransferSubject)
         stmt.setLong(4, executionTime)
         stmt.setString(5, paymentData.debitPaytoUri)
         stmt.setString(6, paymentData.bankTransferId)
         stmt.setLong(7, refundTimestamp)
         stmt.setString(8, requestUid)
+        val finalRefundAmount: TalerAmount = refundAmount ?: paymentData.amount
+        stmt.setLong(9, finalRefundAmount.value)
+        stmt.setInt(10, finalRefundAmount.fraction)
         val res = stmt.executeQuery()
         res.use {
             if (!it.next()) return@runConn false
diff --git a/nexus/src/test/kotlin/DatabaseTest.kt 
b/nexus/src/test/kotlin/DatabaseTest.kt
index cacec157..03a709a7 100644
--- a/nexus/src/test/kotlin/DatabaseTest.kt
+++ b/nexus/src/test/kotlin/DatabaseTest.kt
@@ -45,6 +45,59 @@ class OutgoingPaymentsTest {
 
 // @Ignore // enable after having modified the bouncing logic in Kotlin
 class IncomingPaymentsTest {
+    @Test
+    fun bounceWithCustomRefund() {
+        val db = prepDb(TalerConfig(NEXUS_CONFIG_SOURCE))
+        runBlocking {
+            // creating and bouncing one incoming transaction.
+            assertTrue(
+                db.incomingPaymentCreateBounced(
+                    genIncPay("incoming and bounced"),
+                    "UID",
+                    TalerAmount(2, 53000000, "KUDOS")
+                )
+            )
+            db.runConn {
+                // check incoming shows up.
+                val checkIncoming = it.prepareStatement("""
+                    SELECT 
+                      (amount).val as amount_value
+                      ,(amount).frac as amount_frac
+                     FROM incoming_transactions
+                     WHERE incoming_transaction_id = 1;
+                """).executeQuery()
+                assertTrue(checkIncoming.next())
+                assertEquals(44, checkIncoming.getLong("amount_value"))
+                assertEquals(0, checkIncoming.getLong("amount_frac"))
+                // check bounced has the custom value
+                val findBounced = it.prepareStatement("""
+                    SELECT 
+                      initiated_outgoing_transaction_id
+                      FROM bounced_transactions
+                      WHERE incoming_transaction_id = 1;
+                """).executeQuery()
+                assertTrue(findBounced.next())
+                val initiatedId = 
findBounced.getLong("initiated_outgoing_transaction_id")
+                assertEquals(1, initiatedId)
+                val findInitiatedAmount = it.prepareStatement("""
+                    SELECT
+                      (amount).val as amount_value
+                      ,(amount).frac as amount_frac
+                    FROM initiated_outgoing_transactions
+                    WHERE initiated_outgoing_transaction_id = 1;
+                """).executeQuery()
+                assertTrue(findInitiatedAmount.next())
+                assertEquals(
+                    53000000,
+                    findInitiatedAmount.getInt("amount_frac")
+                )
+                assertEquals(
+                    2,
+                    findInitiatedAmount.getInt("amount_value")
+                )
+            }
+        }
+    }
     // Tests creating and bouncing incoming payments in one DB transaction.
     @Test
     fun incomingAndBounce() {

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]