1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
import com.fasterxml.jackson.databind.ObjectMapper
import io.ktor.client.call.*
import io.ktor.client.plugins.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.server.testing.*
import kotlinx.coroutines.*
import org.jetbrains.exposed.sql.transactions.transaction
import org.junit.Ignore
import org.junit.Test
import tech.libeufin.nexus.bankaccount.fetchBankAccountTransactions
import tech.libeufin.nexus.ingestFacadeTransactions
import tech.libeufin.nexus.maybeTalerRefunds
import tech.libeufin.nexus.server.*
import tech.libeufin.nexus.talerFilter
import tech.libeufin.sandbox.sandboxApp
import tech.libeufin.sandbox.wireTransfer
import tech.libeufin.util.NotificationsChannelDomains
// This class tests the features related to the Taler facade.
class TalerTest {
val mapper = ObjectMapper()
// Checking that a correct wire transfer (with Taler-compatible subject)
// is responded by the Taler facade.
@Test
fun historyIncomingTest() {
val reservePub = "GX5H5RME193FDRCM1HZKERXXQ2K21KH7788CKQM8X6MYKYRBP8F0"
withNexusAndSandboxUser {
testApplication {
application(nexusApp)
runBlocking {
launch {
val r = client.get("/facades/taler/taler-wire-gateway/history/incoming?delta=5") {
expectSuccess = false
contentType(ContentType.Application.Json)
basicAuth("foo", "foo")
}
val j = mapper.readTree(r.readBytes())
val reservePubFromTwg = j.get("incoming_transactions").get(0).get("reserve_pub").asText()
assert(reservePubFromTwg == reservePub)
}
newNexusBankTransaction(
"KUDOS",
"10",
reservePub
)
ingestFacadeTransactions(
"foo", // bank account local to Nexus.
"taler-wire-gateway",
::talerFilter,
::maybeTalerRefunds
)
}
}
}
}
@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"
)
}
}
}
}
|