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
|
import io.ktor.http.*
import org.junit.Test
import tech.libeufin.sandbox.SandboxError
import tech.libeufin.sandbox.getBalance
import tech.libeufin.sandbox.sandboxApp
import tech.libeufin.sandbox.wireTransfer
import tech.libeufin.util.buildBasicAuthLine
import tech.libeufin.util.parseDecimal
import tech.libeufin.util.roundToTwoDigits
class SandboxBankAccountTest {
// Check if the balance shows debit.
@Test
fun debitBalance() {
withTestDatabase {
prepSandboxDb()
wireTransfer(
"admin",
"foo",
"default",
"Show up in logging!",
"TESTKUDOS:1"
)
/**
* Bank gave 1 to foo, should be -1 debit now. Because
* the payment is still pending (= not booked), the pending
* transactions must be included in the calculation.
*/
var bankBalance = getBalance("admin")
assert(bankBalance.roundToTwoDigits() == parseDecimal("-1").roundToTwoDigits())
wireTransfer(
"foo",
"admin",
"default",
"Show up in logging!",
"TESTKUDOS:5"
)
bankBalance = getBalance("admin")
assert(bankBalance.roundToTwoDigits() == parseDecimal("4").roundToTwoDigits())
// Trigger Insufficient funds case for users.
try {
wireTransfer(
"foo",
"admin",
"default",
"Show up in logging!",
"TESTKUDOS:5000"
)
} catch (e: SandboxError) {
// Future versions may wrap this case into a dedicate exception type.
assert(e.statusCode == HttpStatusCode.PreconditionFailed)
}
// Trigger Insufficient funds case for the bank.
try {
wireTransfer(
"admin",
"foo",
"default",
"Show up in logging!",
"TESTKUDOS:5000000"
)
} catch (e: SandboxError) {
// Future versions may wrap this case into a dedicate exception type.
assert(e.statusCode == HttpStatusCode.PreconditionFailed)
}
// Check balance didn't change for both parties.
bankBalance = getBalance("admin")
assert(bankBalance.roundToTwoDigits() == parseDecimal("4").roundToTwoDigits())
val fooBalance = getBalance("foo")
assert(fooBalance.roundToTwoDigits() == parseDecimal("-4").roundToTwoDigits())
}
}
}
|