exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

generate-auditor-basedb.sh (4514B)


      1 #!/bin/bash
      2 # This file is in the public domain.
      3 #
      4 # Script to generate the basic database for auditor testing from a 'correct'
      5 # interaction between exchange, wallet and merchant.
      6 #
      7 # Creates "$1.sql".
      8 #
      9 # Requires the wallet CLI to be installed and in the path.  Furthermore, the
     10 # user running this script must be Postgres superuser and be allowed to
     11 # create/drop databases.
     12 #
     13 set -eu
     14 
     15 . setup.sh
     16 
     17 CONF="generate-auditor-basedb.conf"
     18 # Parse command-line options
     19 while getopts ':c:d:h' OPTION; do
     20     case "$OPTION" in
     21         c)
     22             CONF="$OPTARG"
     23             ;;
     24         d)
     25             BASEDB="$OPTARG"
     26             ;;
     27         h)
     28             echo 'Supported options:'
     29 # shellcheck disable=SC2016
     30             echo '  -c $CONF     -- set configuration'
     31 # shellcheck disable=SC2016
     32             echo '  -d $DB       -- set database name'
     33             ;;
     34         ?)
     35         exit_fail "Unrecognized command line option"
     36         ;;
     37     esac
     38 done
     39 
     40 # Where do we write the result?
     41 if [ ! -v BASEDB ]
     42 then
     43     exit_fail "-d option required"
     44 fi
     45 echo -n "Testing for curl ..."
     46 curl --help >/dev/null </dev/null || exit_skip " MISSING"
     47 echo " FOUND"
     48 
     49 # reset database
     50 echo -n "Reset 'auditor-basedb' database at ${PGHOST:-} ..."
     51 dropdb --if-exists "auditor-basedb" > /dev/null 2> /dev/null || true
     52 createdb "auditor-basedb" || exit_skip "Could not create database '$BASEDB' at ${PGHOST:-}"
     53 echo " DONE"
     54 
     55 # Launch exchange, merchant and bank.
     56 setup -c "$CONF" \
     57       -abemw \
     58       -d "iban"
     59 
     60 # obtain key configuration data
     61 EXCHANGE_URL=$(taler-exchange-config -c "$CONF" -s EXCHANGE -o BASE_URL)
     62 MERCHANT_PORT=$(taler-merchant-config -c "$CONF" -s MERCHANT -o PORT)
     63 MERCHANT_URL="http://localhost:${MERCHANT_PORT}/"
     64 BANK_PORT=$(taler-exchange-config -c "$CONF" -s BANK -o HTTP_PORT)
     65 BANK_URL="http://localhost:${BANK_PORT}/"
     66 
     67 echo -n "Checking setup worked ..."
     68 wget \
     69     --tries=1 \
     70     --timeout=1 \
     71     "${EXCHANGE_URL}config" \
     72     -o /dev/null \
     73     -O /dev/null >/dev/null
     74 echo "DONE"
     75 
     76 export MERCHANT_URL
     77 echo -n "Setting up merchant ..."
     78 
     79 curl -H "Content-Type: application/json" -X POST -d '{"auth":{"method":"external"},"id":"admin","name":"admin","address":{},"jurisdiction":{},"default_max_wire_fee":"TESTKUDOS:1", "default_max_deposit_fee":"TESTKUDOS:1","default_wire_fee_amortization":1,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000},"use_stefan":false}' "${MERCHANT_URL}management/instances"
     80 echo " DONE"
     81 
     82 echo -n "Setting up merchant account ..."
     83 FORTYTHREE="payto://iban/DE474361?receiver-name=Merchant43"
     84 STATUS=$(curl -H "Content-Type: application/json" -X POST \
     85     "${MERCHANT_URL}private/accounts" \
     86     -d '{"payto_uri":"'"$FORTYTHREE"'"}' \
     87     -w "%{http_code}" -s -o /dev/null)
     88 
     89 if [ "$STATUS" != "200" ]
     90 then
     91     exit_fail "Expected 200 OK. Got: $STATUS"
     92 fi
     93 echo " DONE"
     94 
     95 echo -n "Setting up libeufin merchant account ..."
     96 libeufin-bank create-account \
     97               --config="${CONF}" \
     98               --name="Merchant43" \
     99               --username="Merchant43" \
    100               --password="password" \
    101               --payto_uri="payto://iban/DE474361?receiver-name=Merchant43"
    102 
    103 echo " DONE"
    104 
    105 # delete existing wallet database
    106 export WALLET_DB="wallet.wdb"
    107 rm -f "$WALLET_DB"
    108 
    109 echo -n "Running wallet ..."
    110 wlog="taler-wallet-cli-withdraw.log"
    111 taler-wallet-cli \
    112     --no-throttle \
    113     --wallet-db="$WALLET_DB" \
    114     api \
    115     --expect-success \
    116     'runIntegrationTest' \
    117   "$(jq -n '
    118     {
    119       amountToSpend: "TESTKUDOS:4",
    120       amountToWithdraw: "TESTKUDOS:10",
    121       corebankApiBaseUrl: $BANK_URL,
    122       exchangeBaseUrl: $EXCHANGE_URL,
    123       merchantBaseUrl: $MERCHANT_URL,
    124     }' \
    125     --arg MERCHANT_URL "$MERCHANT_URL" \
    126     --arg EXCHANGE_URL "$EXCHANGE_URL" \
    127     --arg BANK_URL "$BANK_URL"
    128   )" &> $wlog || {
    129     echo " FAILED! Last lines from $wlog:"
    130     tail $wlog
    131     exit 2
    132   }
    133 echo " DONE"
    134 
    135 taler-wallet-cli --wallet-db="$WALLET_DB" run-until-done
    136 
    137 # Dump database
    138 mkdir -p "$(dirname "$BASEDB")"
    139 
    140 echo "Dumping database ${BASEDB}.sql"
    141 pg_dump -O "auditor-basedb" | sed -e '/AS integer/d' > "${BASEDB}.sql"
    142 cp "${CONF}.edited" "${BASEDB}.conf"
    143 cp "$(taler-exchange-config -c "${CONF}.edited" -s exchange-offline -o MASTER_PRIV_FILE -f)" "${BASEDB}.mpriv"
    144 
    145 # clean up
    146 echo -n "Final clean up ..."
    147 kill -TERM "$SETUP_PID"
    148 wait
    149 unset SETUP_PID
    150 dropdb "auditor-basedb"
    151 echo " DONE"
    152 
    153 echo "====================================="
    154 echo "Finished generation of ${BASEDB}.sql"
    155 echo "====================================="
    156 
    157 exit 0