libeufin

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

commit 440da053a012c4ab1e44a0661d444785c081b026
parent bdab4291a7c2d2760c4c5fdbd79e7ecfeb00727b
Author: MS <ms@taler.net>
Date:   Thu, 12 Jan 2023 17:41:52 +0100

testing #7525

Diffstat:
MMakefile | 8++++----
Acli/bin/debit_test.sh | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mnexus/src/test/kotlin/DownloadAndSubmit.kt | 14++++++++++++--
Mnexus/src/test/kotlin/MakeEnv.kt | 7++++++-
4 files changed, 99 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile @@ -36,8 +36,8 @@ assemble: check: @./gradlew check @cd ./cli/bin && ./circuit_test.sh + @cd ./cli/bin && ./debit_test.sh - -.PHONY: parse -parse: - @cd parsing-tests; py.test -s checks.py +# .PHONY: parse +# parse: +# @cd parsing-tests; py.test -s checks.py diff --git a/cli/bin/debit_test.sh b/cli/bin/debit_test.sh @@ -0,0 +1,77 @@ +#!/bin/bash + +# Tests successful cases of the CLI acting +# as the client of the Circuit API. + +set -eu + +echo TESTING DEBIT THRESHOLD +jq --version &> /dev/null || (echo "'jq' command not found"; exit 77) +curl --version &> /dev/null || (echo "'curl' command not found"; exit 77) + +DB_PATH=/tmp/debit-test.sqlite3 +export LIBEUFIN_SANDBOX_DB_CONNECTION=jdbc:sqlite:$DB_PATH + +echo -n Delete previous data.. +rm -f $DB_PATH +echo DONE +echo -n Configure the default demobank, with users limit 0... +libeufin-sandbox config --currency MANA default --users-debt-limit=0 +echo DONE +echo -n Start the bank... +export LIBEUFIN_SANDBOX_ADMIN_PASSWORD=circuit +libeufin-sandbox serve &> sandbox.log & +SANDBOX_PID=$! +trap "echo -n 'killing the bank (pid $SANDBOX_PID)...'; kill $SANDBOX_PID; wait; echo DONE" EXIT +echo DONE +echo -n Wait for the bank... +curl --max-time 2 --retry-connrefused --retry-delay 1 --retry 10 http://localhost:5000/ &> /dev/null +echo DONE + +echo -n "Register new account..." +export LIBEUFIN_SANDBOX_USERNAME=www +export LIBEUFIN_SANDBOX_PASSWORD=foo + +./libeufin-cli \ + sandbox --sandbox-url http://localhost:5000/ \ + demobank \ + register +echo DONE +echo -n "Get the admin's IBAN..." +ADMIN_IBAN=$(echo "SELECT iban FROM BankAccounts WHERE label='admin'" | sqlite3 $DB_PATH) +echo "DONE ($ADMIN_IBAN)" +echo -n "Try to surpass the debit threshold (user pays admin)..." +./libeufin-cli \ + sandbox --sandbox-url http://localhost:5000/ \ + demobank \ + new-transaction \ + --bank-account www \ + --payto-with-subject "payto://iban/SANDBOXX/${ADMIN_IBAN}?message=go-debit" \ + --amount MANA:99999 &> /dev/null || true +echo DONE + +echo -n Check the amount is zero... +RESP=$(libeufin-cli sandbox --sandbox-url http://localhost:5000/ demobank info --bank-account www) +BALANCE=$(echo $RESP | jq -r '.balance.amount') +if [ "$BALANCE" != "MANA:0" ]; then + echo Debit threshold of MANA:0 not respected. + exit 1 +fi +echo DONE + +echo -n "Try to surpass the debit threshold via low-level libeufin-sandbox command..." +libeufin-sandbox \ + make-transaction \ + --credit-account=admin \ + --debit-account=www \ + MANA:9999 "Go debit again." &> /dev/null || true +echo DONE + +echo -n Check the amount is again zero... +RESP=$(libeufin-cli sandbox --sandbox-url http://localhost:5000/ demobank info --bank-account www) +BALANCE=$(echo $RESP | jq -r '.balance.amount') +if [ "$BALANCE" != "MANA:0" ]; then + echo Debit threshold of MANA:0 not respected via low-level libeufin-sandbox command. + exit 1 +fi +echo DONE diff --git a/nexus/src/test/kotlin/DownloadAndSubmit.kt b/nexus/src/test/kotlin/DownloadAndSubmit.kt @@ -31,6 +31,7 @@ import tech.libeufin.util.* import tech.libeufin.util.ebics_h004.EbicsRequest import tech.libeufin.util.ebics_h004.EbicsResponse import tech.libeufin.util.ebics_h004.EbicsTypes +import kotlin.reflect.full.isSubclassOf /** * Data to make the test server return for EBICS @@ -324,7 +325,7 @@ class DownloadAndSubmit { ), "foo" ) - assertException<EbicsProtocolError> { submitAllPaymentInitiations(client, "foo") } + assertException<EbicsProtocolError>({ submitAllPaymentInitiations(client, "foo") }) } } } @@ -349,7 +350,16 @@ class DownloadAndSubmit { ), "foo" ) - assertException<EbicsProtocolError> { submitAllPaymentInitiations(client, "foo") } + assertException<EbicsProtocolError>( + { submitAllPaymentInitiations(client, "foo") }, + { + val nexusEbicsException = it as EbicsProtocolError + assert( + EbicsReturnCode.EBICS_AMOUNT_CHECK_FAILED.errorCode == + nexusEbicsException.ebicsTechnicalCode?.errorCode + ) + } + ) } } } diff --git a/nexus/src/test/kotlin/MakeEnv.kt b/nexus/src/test/kotlin/MakeEnv.kt @@ -33,11 +33,16 @@ val userKeys = EbicsKeys( ) // New versions of JUnit provide this! -inline fun <reified ExceptionType> assertException(block: () -> Unit) { +inline fun <reified ExceptionType> assertException( + block: () -> Unit, + assertBlock: (Throwable) -> Unit = {} +) { try { block() } catch (e: Throwable) { assert(e.javaClass == ExceptionType::class.java) + // Expected type, try more custom asserts on it + assertBlock(e) return } return assert(false)