gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] 04/04: test latest changes


From: gnunet
Subject: [libeufin] 04/04: test latest changes
Date: Tue, 20 Dec 2022 17:29:43 +0100

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

ms pushed a commit to branch master
in repository libeufin.

commit d8438142db43975ea348f00bdf51106ecef67d69
Author: MS <ms@taler.net>
AuthorDate: Tue Dec 20 17:29:28 2022 +0100

    test latest changes
---
 nexus/src/test/kotlin/MakeEnv.kt                |  2 +-
 nexus/src/test/kotlin/SandboxAccessApiTest.kt   | 44 +++++++++++++-
 nexus/src/test/kotlin/SandboxBankAccountTest.kt | 77 +++++++++++++++++++++++++
 3 files changed, 121 insertions(+), 2 deletions(-)

diff --git a/nexus/src/test/kotlin/MakeEnv.kt b/nexus/src/test/kotlin/MakeEnv.kt
index 58b2affb..a6ade67f 100644
--- a/nexus/src/test/kotlin/MakeEnv.kt
+++ b/nexus/src/test/kotlin/MakeEnv.kt
@@ -176,7 +176,7 @@ fun prepSandboxDb() {
         }
         DemobankCustomerEntity.new {
             username = "foo"
-            passwordHash = "foo"
+            passwordHash = CryptoUtil.hashpw("foo")
             name = "Foo"
         }
     }
diff --git a/nexus/src/test/kotlin/SandboxAccessApiTest.kt 
b/nexus/src/test/kotlin/SandboxAccessApiTest.kt
index ac230203..53763292 100644
--- a/nexus/src/test/kotlin/SandboxAccessApiTest.kt
+++ b/nexus/src/test/kotlin/SandboxAccessApiTest.kt
@@ -12,8 +12,50 @@ import tech.libeufin.sandbox.sandboxApp
 import tech.libeufin.util.buildBasicAuthLine
 
 class SandboxAccessApiTest {
-
     val mapper = ObjectMapper()
+    // Check successful and failing case due to insufficient funds.
+    @Test
+    fun debitWithdraw() {
+        withTestDatabase {
+            prepSandboxDb()
+            withTestApplication(sandboxApp) {
+                runBlocking {
+                    // Normal, successful withdrawal.
+                    
client.post<Any>("/demobanks/default/access-api/accounts/foo/withdrawals") {
+                        expectSuccess = true
+                        headers {
+                            append(
+                                HttpHeaders.ContentType,
+                                ContentType.Application.Json
+                            )
+                            append(
+                                HttpHeaders.Authorization,
+                                buildBasicAuthLine("foo", "foo")
+                            )
+                        }
+                        this.body = "{\"amount\": \"TESTKUDOS:1\"}"
+                    }
+                    // Withdrawal over the debit threshold.
+                    val r: HttpStatusCode = 
client.post("/demobanks/default/access-api/accounts/foo/withdrawals") {
+                        expectSuccess = false
+                        headers {
+                            append(
+                                HttpHeaders.ContentType,
+                                ContentType.Application.Json
+                            )
+                            append(
+                                HttpHeaders.Authorization,
+                                buildBasicAuthLine("foo", "foo")
+                            )
+                        }
+                        this.body = "{\"amount\": \"TESTKUDOS:99999999999\"}"
+                    }
+                    assert(HttpStatusCode.Forbidden.value == r.value)
+                }
+            }
+        }
+    }
+
     @Test
     fun registerTest() {
         // Test IBAN conflict detection.
diff --git a/nexus/src/test/kotlin/SandboxBankAccountTest.kt 
b/nexus/src/test/kotlin/SandboxBankAccountTest.kt
new file mode 100644
index 00000000..f2f25705
--- /dev/null
+++ b/nexus/src/test/kotlin/SandboxBankAccountTest.kt
@@ -0,0 +1,77 @@
+import io.ktor.client.features.*
+import io.ktor.client.request.*
+import io.ktor.client.statement.*
+import io.ktor.http.*
+import io.ktor.server.testing.*
+import kotlinx.coroutines.runBlocking
+import org.junit.Test
+import tech.libeufin.sandbox.SandboxError
+import tech.libeufin.sandbox.getBalance
+import tech.libeufin.sandbox.sandboxApp
+import tech.libeufin.sandbox.wireTransfer
+import tech.libeufin.util.buildBasicAuthLine
+import tech.libeufin.util.parseDecimal
+
+class SandboxBankAccountTest {
+    // Check if the balance shows debit.
+    @Test
+    fun debitBalance() {
+        withTestDatabase {
+            prepSandboxDb()
+            wireTransfer(
+                "bank",
+                "foo",
+                "default",
+                "Show up in logging!",
+                "TESTKUDOS:1"
+            )
+            /**
+             * Bank gave 1 to foo, should be -1 debit now.  Because
+             * the payment is still pending (= not booked), the pending
+             * transactions must be included in the calculation.
+             */
+            var bankBalance = getBalance("bank", true)
+            assert(bankBalance == parseDecimal("-1"))
+            wireTransfer(
+                "foo",
+                "bank",
+                "default",
+                "Show up in logging!",
+                "TESTKUDOS:5"
+            )
+            bankBalance = getBalance("bank", true)
+            assert(bankBalance == parseDecimal("4"))
+            // Trigger Insufficient funds case for users.
+            try {
+                wireTransfer(
+                    "foo",
+                    "bank",
+                    "default",
+                    "Show up in logging!",
+                    "TESTKUDOS:5000"
+                )
+            } catch (e: SandboxError) {
+                // Future versions may wrap this case into a dedicate 
exception type.
+                assert(e.statusCode == HttpStatusCode.PreconditionFailed)
+            }
+            // Trigger Insufficient funds case for the bank.
+            try {
+                wireTransfer(
+                    "bank",
+                    "foo",
+                    "default",
+                    "Show up in logging!",
+                    "TESTKUDOS:5000000"
+                )
+            } catch (e: SandboxError) {
+                // Future versions may wrap this case into a dedicate 
exception type.
+                assert(e.statusCode == HttpStatusCode.PreconditionFailed)
+            }
+            // Check balance didn't change for both parties.
+            bankBalance = getBalance("bank", true)
+            assert(bankBalance == parseDecimal("4"))
+            val fooBalance = getBalance("foo", true)
+            assert(fooBalance == parseDecimal("-4"))
+        }
+    }
+}
\ No newline at end of file

-- 
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]