libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit d13ac7ba520b7959800905260777f79b5e9bf04c
parent c094c812a75d373791ceb228d073b90ea2415f90
Author: MS <ms@taler.net>
Date:   Mon, 13 Mar 2023 09:46:48 +0100

Adapt tests to #7515.

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 1-
Mnexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt | 2+-
Mnexus/src/test/kotlin/MakeEnv.kt | 58++++++++++++++++++++++++----------------------------------
Mnexus/src/test/kotlin/SandboxAccessApiTest.kt | 5++---
Mnexus/src/test/kotlin/SandboxCircuitApiTest.kt | 14+++++++++++---
Mnexus/src/test/kotlin/TalerTest.kt | 3++-
6 files changed, 40 insertions(+), 43 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt @@ -387,7 +387,6 @@ class FacadeEntity(id: EntityID<Long>) : LongEntity(id) { return find { FacadesTable.facadeName eq name}.firstOrNull() } } - var facadeName by FacadesTable.facadeName var type by FacadesTable.type var creator by NexusUserEntity referencedOn FacadesTable.creator diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt @@ -483,7 +483,7 @@ private suspend fun historyOutgoing(call: ApplicationCall) { // Handle a /taler-wire-gateway/history/incoming request. private suspend fun historyIncoming(call: ApplicationCall) { val facadeId = expectNonNull(call.parameters["fcid"]) - val username = call.request.requirePermission( + call.request.requirePermission( PermissionQuery( "facade", facadeId, diff --git a/nexus/src/test/kotlin/MakeEnv.kt b/nexus/src/test/kotlin/MakeEnv.kt @@ -22,8 +22,6 @@ data class EbicsKeys( val enc: CryptoUtil.RsaCrtKeyPair, val sig: CryptoUtil.RsaCrtKeyPair ) -const val TEST_DB_FILE = "/tmp/nexus-test.sqlite3" -// const val TEST_DB_CONN = "jdbc:sqlite:$TEST_DB_FILE" // Convenience DB connection to switch to Postgresql: val currentUser = System.getProperty("user.name") val TEST_DB_CONN = "jdbc:postgresql://localhost:5432/libeufincheck?user=$currentUser" @@ -63,23 +61,11 @@ inline fun <reified ExceptionType> assertException( * Cleans up the DB file afterwards. */ fun withTestDatabase(f: () -> Unit) { - File(TEST_DB_FILE).also { - if (it.exists()) { - it.delete() - } - } Database.connect(TEST_DB_CONN) TransactionManager.manager.defaultIsolationLevel = java.sql.Connection.TRANSACTION_SERIALIZABLE dbDropTables(TEST_DB_CONN) tech.libeufin.sandbox.dbDropTables(TEST_DB_CONN) - try { f() } - finally { - File(TEST_DB_FILE).also { - if (it.exists()) { - it.delete() - } - } - } + f() } val reportSpec: String = jacksonObjectMapper(). @@ -169,19 +155,21 @@ fun prepNexusDb() { } } -fun prepSandboxDb() { +fun prepSandboxDb(usersDebtLimit: Int = 1000) { tech.libeufin.sandbox.dbCreateTables(TEST_DB_CONN) transaction { - val demoBank = DemobankConfigEntity.new { - currency = "TESTKUDOS" - bankDebtLimit = 10000 - usersDebtLimit = 1000 - allowRegistrations = true - name = "default" - this.withSignupBonus = false - captchaUrl = "http://example.com/" // unused + val config = DemobankConfig( + currency = "TESTKUDOS", + bankDebtLimit = 10000, + usersDebtLimit = usersDebtLimit, + allowRegistrations = true, + demobankName = "default", + withSignupBonus = false, + captchaUrl = "http://example.com/", suggestedExchangePayto = "payto://iban/${BAR_USER_IBAN}" - } + ) + insertConfigPairs(config) + val demoBank = DemobankConfigEntity.new { name = "default" } BankAccountEntity.new { iban = BANK_IBAN label = "admin" // used by the wire helper @@ -275,15 +263,17 @@ fun withSandboxTestDatabase(f: () -> Unit) { withTestDatabase { tech.libeufin.sandbox.dbCreateTables(TEST_DB_CONN) transaction { - val d = DemobankConfigEntity.new { - currency = "TESTKUDOS" - bankDebtLimit = 10000 - usersDebtLimit = 1000 - allowRegistrations = true - name = "default" - this.withSignupBonus = false + val config = DemobankConfig( + currency = "TESTKUDOS", + bankDebtLimit = 10000, + usersDebtLimit = 1000, + allowRegistrations = true, + demobankName = "default", + withSignupBonus = false, captchaUrl = "http://example.com/" // unused - } + ) + insertConfigPairs(config) + val d = DemobankConfigEntity.new { name = "default" } // admin's bank account. BankAccountEntity.new { iban = BANK_IBAN @@ -299,7 +289,7 @@ fun withSandboxTestDatabase(f: () -> Unit) { fun newNexusBankTransaction(currency: String, value: String, subject: String) { transaction { - val inc = NexusBankTransactionEntity.new { + NexusBankTransactionEntity.new { bankAccount = NexusBankAccountEntity.findByName("foo")!! accountTransactionId = "mock" creditDebitIndicator = "CRDT" diff --git a/nexus/src/test/kotlin/SandboxAccessApiTest.kt b/nexus/src/test/kotlin/SandboxAccessApiTest.kt @@ -5,6 +5,7 @@ import io.ktor.client.statement.* import io.ktor.http.* import io.ktor.server.testing.* import kotlinx.coroutines.runBlocking +import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.transactions.transaction import org.junit.Test import tech.libeufin.sandbox.* @@ -66,11 +67,9 @@ class SandboxAccessApiTest { @Test fun highAmountWithdraw() { withTestDatabase { - prepSandboxDb() - val b = getDefaultDemobank() + prepSandboxDb(usersDebtLimit = 900000000) testApplication { application(sandboxApp) - transaction { b.usersDebtLimit = 900000000 } // Create the operation. val r = client.post("/demobanks/default/access-api/accounts/foo/withdrawals") { expectSuccess = true diff --git a/nexus/src/test/kotlin/SandboxCircuitApiTest.kt b/nexus/src/test/kotlin/SandboxCircuitApiTest.kt @@ -5,6 +5,7 @@ import io.ktor.client.statement.* import io.ktor.http.* import io.ktor.server.testing.* import kotlinx.coroutines.runBlocking +import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.lowerCase import org.jetbrains.exposed.sql.transactions.transaction import org.junit.Ignore @@ -221,8 +222,15 @@ class SandboxCircuitApiTest { """.trimIndent()) } // Give initial balance to the new account. - val demobank = getDefaultDemobank() - transaction { demobank.usersDebtLimit = 0 } + // Forcing different debt limit: + transaction { + val configRaw = DemobankConfigPairEntity.find { + DemobankConfigPairsTable.demobankName eq "default" and( + DemobankConfigPairsTable.configKey eq "usersDebtLimit" + ) + }.first() + configRaw.configValue = 0.toString() + } val initialBalance = "TESTKUDOS:50.00" val balanceAfterCashout = "TESTKUDOS:30.00" wireTransfer( @@ -514,7 +522,7 @@ class SandboxCircuitApiTest { uCustomerProfile.delete() } val barBalanceUpdate = getBalance("bar") - assert(barBalance == BigDecimal("3")) + assert(barBalanceUpdate == BigDecimal("3")) } } } diff --git a/nexus/src/test/kotlin/TalerTest.kt b/nexus/src/test/kotlin/TalerTest.kt @@ -32,11 +32,12 @@ class TalerTest { application(nexusApp) runBlocking { launch { - val r = client.get("/facades/taler/taler-wire-gateway/history/incoming?delta=5&start=3") { + val r = client.get("/facades/taler/taler-wire-gateway/history/incoming?delta=5&start=0&long_poll_ms=3000") { expectSuccess = false contentType(ContentType.Application.Json) basicAuth("foo", "foo") } + println("maybe response body: ${r.bodyAsText()}") assert(r.status.value == HttpStatusCode.OK.value) val j = mapper.readTree(r.readBytes()) val reservePubFromTwg = j.get("incoming_transactions").get(0).get("reserve_pub").asText()