summaryrefslogtreecommitdiff
path: root/nlnet/task5/date-range/start.sh
diff options
context:
space:
mode:
Diffstat (limited to 'nlnet/task5/date-range/start.sh')
-rwxr-xr-xnlnet/task5/date-range/start.sh155
1 files changed, 155 insertions, 0 deletions
diff --git a/nlnet/task5/date-range/start.sh b/nlnet/task5/date-range/start.sh
new file mode 100755
index 0000000..c61cfee
--- /dev/null
+++ b/nlnet/task5/date-range/start.sh
@@ -0,0 +1,155 @@
+#!/bin/bash
+
+# This script shows how Nexus can request histories from
+# a particular time frame. Such request must succeed via
+# two connection types: EBICS and x-libeufin-bank. EBICS
+# ensures the fetching of fiat payments made to the regional
+# currency authority, whereas x-libeufin-bank does it for
+# the regional currency circuit. Note: the time-framed
+# request is exceptional: it's used only after a complaint
+# from a user where they didn't get their funds as expected.
+
+set -eu
+
+service postgresql start
+sudo -u postgres createuser -s root
+createdb libeufincheck
+
+echo -n Launching and confirguring LibEuFin..
+source /start-libeufin.sh &> /dev/null
+# Register the Sandbox account.
+export LIBEUFIN_SANDBOX_USERNAME=sandbox-user
+export LIBEUFIN_SANDBOX_PASSWORD=foo
+libeufin-cli \
+ sandbox --sandbox-url http://localhost:5000/ \
+ demobank \
+ register
+# x-libeufin-bank connection.
+# Creating the x-libeufin-bank connection at Nexus.
+export LIBEUFIN_NEXUS_USERNAME=test-user
+export LIBEUFIN_NEXUS_PASSWORD=x
+export LIBEUFIN_NEXUS_URL=http://localhost:5001
+libeufin-cli connections new-xlibeufinbank-connection \
+ --bank-url "http://localhost:5000/demobanks/default/access-api" \
+ --username sandbox-user \
+ --password foo \
+ xlibeufinbankconn
+# Connecting the x-libeufin-bank connection...
+libeufin-cli connections connect xlibeufinbankconn
+# Importing the bank account under a local name at Nexus.
+# Importing the x-libeufin-bank account locally..
+libeufin-cli connections import-bank-account \
+ --offered-account-id sandbox-user \
+ --nexus-bank-account-id foo-at-nexus xlibeufinbankconn
+
+# EBICS connection.
+## Sandbox side.
+export LIBEUFIN_SANDBOX_USERNAME=admin
+# "Create EBICS host at Sandbox..."
+libeufin-cli sandbox \
+ --sandbox-url http://localhost:5000 \
+ ebicshost create --host-id wwwebics
+# Create nlnet EBICS subscriber at Sandbox
+libeufin-cli sandbox \
+ --sandbox-url http://localhost:5000 \
+ demobank new-ebicssubscriber --host-id wwwebics \
+ --user-id nlnet --partner-id nlnet \
+ --bank-account sandbox-user # that's a username _and_ a bank account name
+## Nexus side.
+export LIBEUFIN_NEXUS_USERNAME=test-user
+export LIBEUFIN_NEXUS_PASSWORD=x
+export LIBEUFIN_NEXUS_URL=http://localhost:5001
+# Creating the EBICS connection at Nexus...
+libeufin-cli connections new-ebics-connection \
+ --ebics-url "http://localhost:5000/ebicsweb" \
+ --host-id wwwebics \
+ --partner-id nlnet \
+ --ebics-user-id nlnet \
+ ebicsconn
+# Setup EBICS keying...
+libeufin-cli connections connect ebicsconn > /dev/null
+# Download bank account name from Sandbox...
+libeufin-cli connections download-bank-accounts ebicsconn
+# Importing bank account info into Nexus...
+libeufin-cli connections import-bank-account \
+ --offered-account-id sandbox-user \
+ --nexus-bank-account-id bar-at-nexus ebicsconn
+echo DONE
+
+FIRST_JAN_2020="1577833200000" # in milliseconds
+END_DEC_2019="2019-12-30"
+MID_JAN_2020="2020-01-15"
+
+echo Make sample transaction..
+# 0, setup and start services.
+libeufin-sandbox make-transaction \
+ --credit-account=admin \
+ --debit-account=sandbox-user MANA:2 \
+ "task5" # subject.
+echo DONE
+
+echo -n Articifially set the transaction date to $FIRST_JAN_2020..
+# 1, set artificial time for the transaction at January, 1st 2020.
+echo "UPDATE bankaccounttransactions SET date='$FIRST_JAN_2020' WHERE subject='task5'" | psql -q -d libeufincheck
+echo DONE
+
+# 2, retrieve the transaction via Nexus, for both
+# connections and by asking for a (narrow) time frame
+# that includes the 2020-01-01 payment.
+
+echo -n Nexus: syncing banking records for the time frame $END_DEC_2019-$MID_JAN_2020 via EBICS..
+# Fetch time-framed payments via EBICS.
+libeufin-cli \
+ accounts \
+ fetch-transactions \
+ --level=report \
+ --range-type=time-range \
+ --start=$END_DEC_2019 \
+ --end=$MID_JAN_2020 \
+ bar-at-nexus > /dev/null # EBICS
+echo DONE
+
+echo Showing the synced data..
+# Now checks if Nexus ingested and shows the
+# expected payment.
+libeufin-cli \
+ accounts \
+ transactions \
+ bar-at-nexus
+echo DONE
+
+echo Resetting the Nexus database..
+# Bring the database state so that Nexus does not hold any payment.
+echo "DELETE FROM nexusbanktransactions" | psql -d libeufincheck
+echo "DELETE FROM nexusbankmessages" | psql -d libeufincheck
+echo DONE
+
+echo Checking that no payment data appears after the reset..
+# Double-checking that the future steps start
+# without the previous transactions.
+libeufin-cli \
+ accounts \
+ transactions \
+ foo-at-nexus # FIXME: put a 204 No Content check?
+echo DONE
+
+# Fetch time-framed payments via x-libeufin-bank.
+echo Nexus: syncing banking records for the time frame ${END_DEC_2019}_${MID_JAN_2020} via x-libeufin-bank..
+libeufin-cli \
+ accounts \
+ fetch-transactions \
+ --level=statement \
+ --range-type=time-range \
+ --start=$END_DEC_2019 \
+ --end=$MID_JAN_2020 \
+ foo-at-nexus
+echo DONE
+
+# As in the previous case, now Nexus should show
+# the 2020-01-01 the payment.
+echo Showing the synced data..
+libeufin-cli \
+ accounts \
+ transactions \
+ foo-at-nexus # FIXME: put a 200 OK check?
+echo DONE