libeufin

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

commit 951341c6e940e04bebd8c5d7d853043bf8b5e28d
parent bfeebd4f3f3cb3ad388f150c7da11d902f0c8b22
Author: Antoine A <>
Date:   Wed, 29 Nov 2023 12:42:53 +0000

Add currency check when changing conversion rates and use FIAT_CURRENCY config field again

Diffstat:
Mbank/conf/test.conf | 15+++------------
Mbank/conf/test_bonus.conf | 4+++-
Mbank/conf/test_no_tan.conf | 4+++-
Mbank/conf/test_restrict.conf | 2--
Mbank/src/main/kotlin/tech/libeufin/bank/Config.kt | 2+-
Mbank/src/main/kotlin/tech/libeufin/bank/ConversionApi.kt | 6++++++
Mcontrib/bank.conf | 3+++
Aintegration/conf/integration.conf | 22++++++++++++++++++++++
Mintegration/test/IntegrationTest.kt | 10+++++-----
9 files changed, 46 insertions(+), 22 deletions(-)

diff --git a/bank/conf/test.conf b/bank/conf/test.conf @@ -2,22 +2,13 @@ CURRENCY = KUDOS DEFAULT_CUSTOMER_DEBT_LIMIT = KUDOS:100 DEFAULT_ADMIN_DEBT_LIMIT = KUDOS:10000 -REGISTRATION_BONUS = KUDOS:0 SUGGESTED_WITHDRAWAL_EXCHANGE = https://exchange.example.com +ALLOW_REGISTRATION = yes +ALLOW_ACCOUNT_DELETION = yes allow_conversion = YES +FIAT_CURRENCY = EUR tan_sms = libeufin-tan-file.sh tan_email = libeufin-tan-fail.sh -spa = $DATADIR/spa/ [libeufin-bankdb-postgres] -SQL_DIR = $DATADIR/sql/ CONFIG = postgresql:///libeufincheck - -[nexus-ebics] -currency = EUR - -[nexus-postgres] -CONFIG = postgres:///libeufincheck - -[libeufin-nexusdb-postgres] -SQL_DIR = $DATADIR/sql/ diff --git a/bank/conf/test_bonus.conf b/bank/conf/test_bonus.conf @@ -1,8 +1,10 @@ [libeufin-bank] CURRENCY = KUDOS +DEFAULT_CUSTOMER_DEBT_LIMIT = KUDOS:0 DEFAULT_ADMIN_DEBT_LIMIT = KUDOS:10000 REGISTRATION_BONUS = KUDOS:100 +ALLOW_REGISTRATION = yes +ALLOW_ACCOUNT_DELETION = yes [libeufin-bankdb-postgres] -SQL_DIR = $DATADIR/sql/ CONFIG = postgresql:///libeufincheck \ No newline at end of file diff --git a/bank/conf/test_no_tan.conf b/bank/conf/test_no_tan.conf @@ -4,9 +4,11 @@ DEFAULT_CUSTOMER_DEBT_LIMIT = KUDOS:100 DEFAULT_ADMIN_DEBT_LIMIT = KUDOS:10000 SUGGESTED_WITHDRAWAL_EXCHANGE = https://exchange.example.com allow_conversion = YES +FIAT_CURRENCY = EUR +ALLOW_REGISTRATION = yes +ALLOW_ACCOUNT_DELETION = yes [libeufin-bankdb-postgres] -SQL_DIR = $DATADIR/sql/ CONFIG = postgresql:///libeufincheck [nexus-ebics] diff --git a/bank/conf/test_restrict.conf b/bank/conf/test_restrict.conf @@ -2,8 +2,6 @@ CURRENCY = KUDOS DEFAULT_CUSTOMER_DEBT_LIMIT = KUDOS:100 DEFAULT_ADMIN_DEBT_LIMIT = KUDOS:10000 -ALLOW_REGISTRATION = NO [libeufin-bankdb-postgres] -SQL_DIR = $DATADIR/sql/ CONFIG = postgresql:///libeufincheck \ No newline at end of file diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Config.kt b/bank/src/main/kotlin/tech/libeufin/bank/Config.kt @@ -104,7 +104,7 @@ fun TalerConfig.loadBankConfig(): BankConfig = catchError { var fiatCurrencySpec: CurrencySpecification? = null val allowConversion = lookupBoolean("libeufin-bank", "allow_conversion") ?: false; if (allowConversion) { - fiatCurrency = requireString("nexus-ebics", "currency"); + fiatCurrency = requireString("libeufin-bank", "fiat_currency"); fiatCurrencySpec = currencySpecificationFor(fiatCurrency) } BankConfig( diff --git a/bank/src/main/kotlin/tech/libeufin/bank/ConversionApi.kt b/bank/src/main/kotlin/tech/libeufin/bank/ConversionApi.kt @@ -101,6 +101,12 @@ fun Routing.conversionApi(db: Database, ctx: BankConfig) = conditional(ctx.allow authAdmin(db, TokenScope.readwrite) { post("/conversion-info/conversion-rate") { val req = call.receive<ConversionRate>() + for (regionalAmount in sequenceOf(req.cashin_fee, req.cashin_tiny_amount, req.cashout_min_amount)) { + ctx.checkRegionalCurrency(regionalAmount) + } + for (fiatAmount in sequenceOf(req.cashout_fee, req.cashout_tiny_amount, req.cashin_min_amount)) { + ctx.checkFiatCurrency(fiatAmount) + } db.conversion.updateConfig(req); call.respond(HttpStatusCode.NoContent) } diff --git a/contrib/bank.conf b/contrib/bank.conf @@ -21,6 +21,9 @@ # Enable regional currency conversion #ALLOW_CONVERSION = no +# External currency used during cashin and cashout +#FIAT_CURRENCY = EUR + # Path to TAN challenge transmission script via sms. If not specified, this TAN channel wil be unuspported. #TAN_SMS = diff --git a/integration/conf/integration.conf b/integration/conf/integration.conf @@ -0,0 +1,22 @@ +[libeufin-bank] +CURRENCY = KUDOS +DEFAULT_CUSTOMER_DEBT_LIMIT = KUDOS:100 +DEFAULT_ADMIN_DEBT_LIMIT = KUDOS:10000 +SUGGESTED_WITHDRAWAL_EXCHANGE = https://exchange.example.com +ALLOW_REGISTRATION = yes +ALLOW_ACCOUNT_DELETION = yes +allow_conversion = YES +FIAT_CURRENCY = EUR +tan_sms = libeufin-tan-file.sh +tan_email = libeufin-tan-fail.sh +SERVE = tcp +PORT = 8080 + +[libeufin-bankdb-postgres] +CONFIG = postgresql:///libeufincheck + +[nexus-ebics] +currency = EUR + +[nexus-postgres] +CONFIG = postgres:///libeufincheck diff --git a/integration/test/IntegrationTest.kt b/integration/test/IntegrationTest.kt @@ -60,19 +60,19 @@ class IntegrationTest { @Test fun db() { val nexusCmd = LibeufinNexusCommand() - nexusCmd.run("dbinit -c ../bank/conf/test.conf -r") + nexusCmd.run("dbinit -c conf/integration.conf -r") val bankCmd = LibeufinBankCommand(); - bankCmd.run("dbinit -c ../bank/conf/test.conf -r") - bankCmd.run("passwd admin password -c ../bank/conf/test.conf") + bankCmd.run("dbinit -c conf/integration.conf -r") + bankCmd.run("passwd admin password -c conf/integration.conf") val json = obj { "username" to "exchange" "password" to "password" "name" to "Mr Money" "is_taler_exchange" to true } - bankCmd.run("create-account '$json' -c ../bank/conf/test.conf") + bankCmd.run("create-account '$json' -c conf/integration.conf") kotlin.concurrent.thread(isDaemon = true) { - bankCmd.run("serve -c ../bank/conf/test.conf") + bankCmd.run("serve -c conf/integration.conf") } runBlocking {