summaryrefslogtreecommitdiff
path: root/src/cli/test_iban.sh
blob: d5bceda49f0197c0cf2d3c91e27f9dac74acd29b (plain)
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
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash

set -eu

# Exit, with status code "skip" (no 'real' failure)
function exit_skip() {
    echo " SKIP: $1"
    exit 77
}

# Exit, with error message (hard failure)
function exit_fail() {
    echo " FAIL: $1"
    exit 1
}

# Cleanup to run whenever we exit
function cleanup()
{
    for n in `jobs -p`
    do
        kill $n 2> /dev/null || true
    done
    wait
}

# Install cleanup handler (except for kill -9)
trap cleanup EXIT

# Script's guidelines:

#* uses 'CURRENCY=TESTKUDOS' and uses $CURRENCY for all
#  currencies in what follows ...
#* for databases, use either 'anastasischeck' for Postgres
#  or an sqlite file created via "mktemp /tmp/test-XXXXXX"
#  or something like that
#* exits with 77 if libeufin is not properly installed/available
#* exits with 77 if Postgres with 'anastasischeck' is not properly
#  installed/available
#* starts Nexus (in background)
#* starts sandbox (in background)
#  ~~~~~~~~~
#* creates two IBAN accounts
#* stores IBANs of both accounts in shell variables,
#  call them IBAN_CREDIT and IBAN_DEBIT.
#* configures an Anastasis facade for IBAN_CREDIT.
#* exports authentication credentials (URL, access token)
#  for the facade to shell variables
#  (FACADE_URL, FACADE_AUTH_TOKEN)
#* contains a command to do a wire-transfer (pick your amount)
#  from DEBIT to CREDIT (setup authentication as needed to
#  trigger the transfer)
#
#
#Make sure 'set -eu' and include some progress indicators, like:
#
#echo -n "Starting nexus ..."
## DO WORK
#echo " DONE"
#echo -n "Starting sandbox ..."
## DO WORK
#echo " DONE"

if ! libeufin-cli --version &> /dev/null; then
  echo "libeufin-cli not found"
  exit 77;
fi

if ! libeufin-nexus --version &> /dev/null; then
  echo "libeufin-nexus not found"
  exit 77;
fi

if ! libeufin-sandbox --version &> /dev/null; then
  echo "libeufin-sandbox not found"
  exit 77;
fi

if ! psql -d anastasischeck -c "\q" &> /dev/null; then
  echo "Postgresql database 'anastasischeck' not reachable"
  exit 77
fi

CURRENCY="TESTKUDOS"
export LIBEUFIN_NEXUS_DB_CONNECTION="jdbc:sqlite:$(mktemp -u /tmp/nexus-db-XXXXXX.sqlite)"
export LIBEUFIN_SANDBOX_DB_CONNECTION="jdbc:sqlite:$(mktemp -u /tmp/sandbox-db-XXXXXX.sqlite)"
NEXUS_URL="http://localhost:5001/"
SANDBOX_URL="http://localhost:5000/"

echo "Starting Nexus .."
libeufin-nexus serve &> nexus.log &
nexus_pid=$!
if ! curl -s --retry 5 --retry-connrefused $NEXUS_URL > /dev/null; then
  echo "Could not launch Nexus"
  exit 77
fi
echo "Nexus started."

echo "Starting Sandbox .."
libeufin-sandbox serve &> sandbox.log &
sandbox_pid=$!
if ! curl -s --retry 5 --retry-connrefused $SANDBOX_URL > /dev/null; then
  echo "Could not launch Sandbox"
  exit 77
fi
echo "Sandbox started."

#libeufin-nexus serve &> nexus.log &
#nexus_pid=$!
#echo "Starting Sandbox .."
#libeufin-sandbox serve &> sandbox.log &
#sandbox_pid=$!
#
#
#curl -s --retry 5 --retry-connrefused $NEXUS_URL > /dev/null
#curl -s --retry 5 --retry-connrefused $SANDBOX_URL > /dev/null