summaryrefslogtreecommitdiff
path: root/testbench
diff options
context:
space:
mode:
authorAntoine A <>2024-02-25 19:06:50 +0100
committerAntoine A <>2024-02-25 19:06:50 +0100
commit0067499c54fc60784f2cf2ec9be8340da7a5459e (patch)
treeb4a6029887d25859e7ebaa1b1960986981c8458f /testbench
parentb421a7b263d97ade06c7e87dda543d4b7706f59d (diff)
downloadlibeufin-0067499c54fc60784f2cf2ec9be8340da7a5459e.tar.gz
libeufin-0067499c54fc60784f2cf2ec9be8340da7a5459e.tar.bz2
libeufin-0067499c54fc60784f2cf2ec9be8340da7a5459e.zip
Fix nexus failing to parse wellformed incoming transactions subject and share more code between nexus and bank
Diffstat (limited to 'testbench')
-rw-r--r--testbench/src/main/kotlin/Main.kt6
-rw-r--r--testbench/src/test/kotlin/IntegrationTest.kt22
2 files changed, 8 insertions, 20 deletions
diff --git a/testbench/src/main/kotlin/Main.kt b/testbench/src/main/kotlin/Main.kt
index 8586c2aa..cf50c59d 100644
--- a/testbench/src/main/kotlin/Main.kt
+++ b/testbench/src/main/kotlin/Main.kt
@@ -34,12 +34,6 @@ import java.time.Instant
import kotlinx.coroutines.runBlocking
import io.ktor.client.request.*
-fun randBytes(length: Int): ByteArray {
- val bytes = ByteArray(length)
- kotlin.random.Random.nextBytes(bytes)
- return bytes
-}
-
val nexusCmd = LibeufinNexusCommand()
val client = HttpClient(CIO)
diff --git a/testbench/src/test/kotlin/IntegrationTest.kt b/testbench/src/test/kotlin/IntegrationTest.kt
index ddc43ced..b398ad03 100644
--- a/testbench/src/test/kotlin/IntegrationTest.kt
+++ b/testbench/src/test/kotlin/IntegrationTest.kt
@@ -50,12 +50,6 @@ fun HttpResponse.assertNoContent() {
assertEquals(HttpStatusCode.NoContent, this.status)
}
-fun randBytes(length: Int): ByteArray {
- val bytes = ByteArray(length)
- kotlin.random.Random.nextBytes(bytes)
- return bytes
-}
-
fun server(lambda: () -> Unit) {
// Start the HTTP server in another thread
kotlin.concurrent.thread(isDaemon = true) {
@@ -148,11 +142,11 @@ class IntegrationTest {
it.execSQLUpdate("SET search_path TO libeufin_nexus;")
}
- val reservePub = randBytes(32)
+ val reservePub = EddsaPublicKey.rand()
val payment = IncomingPayment(
amount = TalerAmount("EUR:10"),
debitPaytoUri = userPayTo.toString(),
- wireTransferSubject = "Error test ${Base32Crockford.encode(reservePub)}",
+ wireTransferSubject = "Error test $reservePub",
executionTime = Instant.now(),
bankId = "error"
)
@@ -211,7 +205,7 @@ class IntegrationTest {
ingestIncomingPayment(db, IncomingPayment(
amount = TalerAmount("EUR:10"),
debitPaytoUri = userPayTo.toString(),
- wireTransferSubject = "Success ${Base32Crockford.encode(randBytes(32))}",
+ wireTransferSubject = "Success ${Base32Crockford32B.rand().encoded()}",
executionTime = Instant.now(),
bankId = "success"
))
@@ -278,9 +272,9 @@ class IntegrationTest {
// Cashin
repeat(3) { i ->
- val reservePub = randBytes(32)
+ val reservePub = EddsaPublicKey.rand()
val amount = TalerAmount("EUR:${20+i}")
- val subject = "cashin test $i: ${Base32Crockford.encode(reservePub)}"
+ val subject = "cashin test $i: $reservePub"
nexusCmd.run("testing fake-incoming $flags --subject \"$subject\" --amount $amount $userPayTo")
val converted = client.get("http://0.0.0.0:8080/conversion-info/cashin-rate?amount_debit=EUR:${20 + i}")
.assertOkJson<ConversionResponse>().amount_credit
@@ -296,20 +290,20 @@ class IntegrationTest {
}.assertOkJson<IncomingHistory> {
val tx = it.incoming_transactions.first()
assertEquals(converted, tx.amount)
- assert(reservePub.contentEquals(tx.reserve_pub.raw))
+ assertEquals(reservePub, tx.reserve_pub)
}
}
// Cashout
repeat(3) { i ->
- val requestUid = randBytes(32)
+ val requestUid = ShortHashCode.rand()
val amount = TalerAmount("KUDOS:${10+i}")
val convert = client.get("http://0.0.0.0:8080/conversion-info/cashout-rate?amount_debit=$amount")
.assertOkJson<ConversionResponse>().amount_credit
client.post("http://0.0.0.0:8080/accounts/customer/cashouts") {
basicAuth("customer", "password")
json {
- "request_uid" to ShortHashCode(requestUid)
+ "request_uid" to requestUid
"amount_debit" to amount
"amount_credit" to convert
}