[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] 04/04: tests
From: |
gnunet |
Subject: |
[libeufin] 04/04: tests |
Date: |
Tue, 31 Jan 2023 17:23:00 +0100 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository libeufin.
commit 1aa9682001fd635e24270baaa0e661912a14db29
Author: MS <ms@taler.net>
AuthorDate: Tue Jan 31 17:21:47 2023 +0100
tests
---
nexus/src/test/kotlin/MakeEnv.kt | 52 ++++++++++++++++++++---
nexus/src/test/kotlin/TalerTest.kt | 87 ++++++++++++++++++++++++++++++++++++++
2 files changed, 134 insertions(+), 5 deletions(-)
diff --git a/nexus/src/test/kotlin/MakeEnv.kt b/nexus/src/test/kotlin/MakeEnv.kt
index bb25a0b6..b8adad2d 100644
--- a/nexus/src/test/kotlin/MakeEnv.kt
+++ b/nexus/src/test/kotlin/MakeEnv.kt
@@ -1,9 +1,13 @@
+import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.statements.api.ExposedBlob
import org.jetbrains.exposed.sql.transactions.transaction
+import org.jetbrains.exposed.sql.transactions.transactionManager
import tech.libeufin.nexus.*
import tech.libeufin.nexus.dbCreateTables
import tech.libeufin.nexus.dbDropTables
+import tech.libeufin.nexus.server.FetchLevel
+import tech.libeufin.nexus.server.FetchSpecAllJson
import tech.libeufin.sandbox.*
import tech.libeufin.util.CryptoUtil
import tech.libeufin.util.EbicsInitState
@@ -59,11 +63,10 @@ fun withTestDatabase(f: () -> Unit) {
}
}
Database.connect("jdbc:sqlite:$TEST_DB_FILE")
+ // ).transactionManager.defaultIsolationLevel =
java.sql.Connection.TRANSACTION_SERIALIZABLE
dbDropTables(TEST_DB_CONN)
tech.libeufin.sandbox.dbDropTables(TEST_DB_CONN)
- try {
- f()
- }
+ try { f() }
finally {
File(TEST_DB_FILE).also {
if (it.exists()) {
@@ -73,13 +76,22 @@ fun withTestDatabase(f: () -> Unit) {
}
}
+val reportSpec: String = jacksonObjectMapper().
+writerWithDefaultPrettyPrinter().
+writeValueAsString(
+ FetchSpecAllJson(
+ level = FetchLevel.REPORT,
+ "foo"
+ )
+)
+
fun prepNexusDb() {
dbCreateTables(TEST_DB_CONN)
transaction {
val u = NexusUserEntity.new {
username = "foo"
- passwordHash = "foo"
- superuser = false
+ passwordHash = CryptoUtil.hashpw("foo")
+ superuser = true
}
val c = NexusBankConnectionEntity.new {
connectionId = "foo"
@@ -118,6 +130,36 @@ fun prepNexusDb() {
highestSeenBankMessageSerialId = 0
accountHolder = "bar"
}
+ NexusScheduledTaskEntity.new {
+ resourceType = "bank-account"
+ resourceId = "foo"
+ this.taskCronspec = "* * *" // Every second.
+ this.taskName = "read-report"
+ this.taskType = "fetch"
+ this.taskParams = reportSpec
+ }
+ NexusScheduledTaskEntity.new {
+ resourceType = "bank-account"
+ resourceId = "foo"
+ this.taskCronspec = "* * *" // Every second.
+ this.taskName = "send-payment"
+ this.taskType = "submit"
+ this.taskParams = "{}"
+ }
+ // Giving 'foo' a Taler facade.
+ val f = FacadeEntity.new {
+ facadeName = "taler"
+ type = "taler-wire-gateway"
+ creator = u
+ }
+ FacadeStateEntity.new {
+ bankAccount = "foo"
+ bankConnection = "foo"
+ currency = "TESTKUDOS"
+ reserveTransferLevel = "report"
+ facade = f
+ highestSeenMessageSerialId = 0
+ }
}
}
diff --git a/nexus/src/test/kotlin/TalerTest.kt
b/nexus/src/test/kotlin/TalerTest.kt
new file mode 100644
index 00000000..bc117307
--- /dev/null
+++ b/nexus/src/test/kotlin/TalerTest.kt
@@ -0,0 +1,87 @@
+import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
+import io.ktor.client.plugins.*
+import io.ktor.client.request.*
+import io.ktor.http.*
+import io.ktor.server.testing.*
+import kotlinx.coroutines.*
+import org.jetbrains.exposed.sql.transactions.TransactionManager
+import org.jetbrains.exposed.sql.transactions.transaction
+import org.junit.Ignore
+import org.junit.Test
+import tech.libeufin.nexus.*
+import tech.libeufin.nexus.bankaccount.fetchBankAccountTransactions
+import tech.libeufin.nexus.server.FetchLevel
+import tech.libeufin.nexus.server.FetchSpecAllJson
+import tech.libeufin.nexus.server.client
+import tech.libeufin.nexus.server.nexusApp
+import tech.libeufin.sandbox.sandboxApp
+import tech.libeufin.sandbox.wireTransfer
+
+// This class tests the features related to the Taler facade.
+class TalerTest {
+
+ @Ignore // Ignoring because no assert takes place.
+ @Test // Triggering a refund because of a duplicate reserve pub.
+ fun refundTest() {
+ withNexusAndSandboxUser {
+ // Creating a Taler facade for the user 'foo'.
+ testApplication {
+ application(nexusApp)
+ client.post("/facades") {
+ expectSuccess = true
+ contentType(ContentType.Application.Json)
+ basicAuth("foo", "foo")
+ setBody("""
+ { "name":"foo-facade",
+ "type":"taler-wire-gateway",
+ "config": {
+ "bankAccount":"foo",
+ "bankConnection":"foo",
+ "currency":"TESTKUDOS",
+ "reserveTransferLevel":"report"
+ }
+ }""".trimIndent()
+ )
+ }
+ }
+ wireTransfer(
+ "bar",
+ "foo",
+ demobank = "default",
+ "5WFM8PXN7Y315RVZFJ280299B94W1HR1AAHH6XNDYEJBC0T3E5N0",
+ "TESTKUDOS:3"
+ )
+ testApplication {
+ application(sandboxApp)
+ // Nexus downloads the fresh transaction.
+ fetchBankAccountTransactions(
+ client,
+ fetchSpec = FetchSpecAllJson(
+ level = FetchLevel.REPORT,
+ "foo"
+ ),
+ "foo"
+ )
+ }
+ wireTransfer(
+ "bar",
+ "foo",
+ demobank = "default",
+ "5WFM8PXN7Y315RVZFJ280299B94W1HR1AAHH6XNDYEJBC0T3E5N0",
+ "TESTKUDOS:3"
+ )
+ testApplication {
+ application(sandboxApp)
+ // Nexus downloads the new transaction, having a duplicate
subject.
+ fetchBankAccountTransactions(
+ client,
+ fetchSpec = FetchSpecAllJson(
+ level = FetchLevel.REPORT,
+ "foo"
+ ),
+ "foo"
+ )
+ }
+ }
+ }
+}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.