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
|
import org.junit.Test
import tech.libeufin.sandbox.*
import tech.libeufin.util.execCommand
class DatabaseTest {
private val c = Customer(
login = "foo",
passwordHash = "hash",
name = "Foo",
phone = "+00",
email = "foo@b.ar",
cashoutPayto = "payto://external-IBAN",
cashoutCurrency = "KUDOS"
)
private val c1 = Customer(
login = "bar",
passwordHash = "hash",
name = "Bar",
phone = "+00",
email = "foo@b.ar",
cashoutPayto = "payto://external-IBAN",
cashoutCurrency = "KUDOS"
)
fun initDb(): Database {
execCommand(
listOf(
"libeufin-bank-dbinit",
"-d",
"libeufincheck",
"-r"
),
throwIfFails = true
)
return Database("jdbc:postgresql:///libeufincheck")
}
@Test
fun bankTransactionTest() {
val db = initDb()
// Need accounts first.
db.customerCreate(c)
db.customerCreate(c1)
db.bankAccountCreate(BankAccount(
iban = "XYZ",
bic = "not used",
bankAccountLabel = "foo",
lastNexusFetchRowId = 1L,
owningCustomerId = 1L
))
db.bankAccountCreate(BankAccount(
iban = "ABC",
bic = "not used",
bankAccountLabel = "bar",
lastNexusFetchRowId = 1L,
owningCustomerId = 2L
))
db.bankAccountSetMaxDebt("foo", TalerAmount(100, 0))
val res = db.bankTransactionCreate(BankInternalTransaction(
creditorAccountId = 2,
debtorAccountId = 1,
subject = "test",
amount = TalerAmount(3, 333),
accountServicerReference = "acct-svcr-ref",
endToEndId = "end-to-end-id",
paymentInformationId = "pmtinfid",
transactionDate = 100000L
))
assert(res == Database.BankTransactionResult.SUCCESS)
}
@Test
fun customerCreationTest() {
val db = initDb()
assert(db.customerGetFromLogin("foo") == null)
db.customerCreate(c)
assert(db.customerGetFromLogin("foo")?.name == "Foo")
// Trigger conflict.
assert(!db.customerCreate(c))
}
@Test
fun configTest() {
val db = initDb()
assert(db.configGet("bar") == null)
assert(db.configGet("bar") == null)
db.configSet("foo", "bar")
assert(db.configGet("foo") == "bar")
}
@Test
fun bankAccountTest() {
val db = initDb()
assert(db.bankAccountGetFromLabel("foo") == null)
val bankAccount = BankAccount(
iban = "not used",
bic = "not used",
bankAccountLabel = "foo",
lastNexusFetchRowId = 1L,
owningCustomerId = 1L
)
db.customerCreate(c) // Satisfies the REFERENCE
assert(db.bankAccountCreate(bankAccount))
assert(!db.bankAccountCreate(bankAccount)) // Triggers conflict.
assert(db.bankAccountGetFromLabel("foo")?.bankAccountLabel == "foo")
assert(db.bankAccountGetFromLabel("foo")?.balance?.equals(TalerAmount(0, 0)) == true)
}
}
|