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 (4895B)


      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 # The auditor tests inject faults into specific rows of the generated
     16 # database, so the wallet must pick the same coins and make the same
     17 # transactions on every run.  The coin selection introduced after 2024 is
     18 # not deterministic in that way; 'legacy-2024' restores the old behaviour
     19 # (see https://bugs.gnunet.org/view.php?id=11272).
     20 export TALER_WALLET_COINSEL="legacy-2024"
     21 
     22 . setup.sh
     23 
     24 CONF="generate-auditor-basedb.conf"
     25 # Parse command-line options
     26 while getopts ':c:d:h' OPTION; do
     27     case "$OPTION" in
     28         c)
     29             CONF="$OPTARG"
     30             ;;
     31         d)
     32             BASEDB="$OPTARG"
     33             ;;
     34         h)
     35             echo 'Supported options:'
     36 # shellcheck disable=SC2016
     37             echo '  -c $CONF     -- set configuration'
     38 # shellcheck disable=SC2016
     39             echo '  -d $DB       -- set database name'
     40             ;;
     41         ?)
     42         exit_fail "Unrecognized command line option"
     43         ;;
     44     esac
     45 done
     46 
     47 # Where do we write the result?
     48 if [ ! -v BASEDB ]
     49 then
     50     exit_fail "-d option required"
     51 fi
     52 echo -n "Testing for curl ..."
     53 curl --help >/dev/null </dev/null || exit_skip " MISSING"
     54 echo " FOUND"
     55 
     56 # reset database
     57 echo -n "Reset 'auditor-basedb' database at ${PGHOST:-} ..."
     58 dropdb --if-exists "auditor-basedb" > /dev/null 2> /dev/null || true
     59 createdb "auditor-basedb" || exit_skip "Could not create database '$BASEDB' at ${PGHOST:-}"
     60 echo " DONE"
     61 
     62 # Launch exchange, merchant and bank.
     63 setup -c "$CONF" \
     64       -abemw \
     65       -d "iban"
     66 
     67 # obtain key configuration data
     68 EXCHANGE_URL=$(taler-exchange-config -c "$CONF" -s EXCHANGE -o BASE_URL)
     69 MERCHANT_PORT=$(taler-merchant-config -c "$CONF" -s MERCHANT -o PORT)
     70 MERCHANT_URL="http://localhost:${MERCHANT_PORT}/"
     71 BANK_PORT=$(taler-exchange-config -c "$CONF" -s BANK -o HTTP_PORT)
     72 BANK_URL="http://localhost:${BANK_PORT}/"
     73 
     74 echo -n "Checking setup worked ..."
     75 wget \
     76     --tries=1 \
     77     --timeout=1 \
     78     "${EXCHANGE_URL}config" \
     79     -o /dev/null \
     80     -O /dev/null >/dev/null
     81 echo "DONE"
     82 
     83 export MERCHANT_URL
     84 echo -n "Setting up merchant ..."
     85 
     86 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"
     87 echo " DONE"
     88 
     89 echo -n "Setting up merchant account ..."
     90 FORTYTHREE="payto://iban/DE474361?receiver-name=Merchant43"
     91 STATUS=$(curl -H "Content-Type: application/json" -X POST \
     92     "${MERCHANT_URL}private/accounts" \
     93     -d '{"payto_uri":"'"$FORTYTHREE"'"}' \
     94     -w "%{http_code}" -s -o /dev/null)
     95 
     96 if [ "$STATUS" != "200" ]
     97 then
     98     exit_fail "Expected 200 OK. Got: $STATUS"
     99 fi
    100 echo " DONE"
    101 
    102 echo -n "Setting up libeufin merchant account ..."
    103 libeufin-bank create-account \
    104               --config="${CONF}" \
    105               --name="Merchant43" \
    106               --username="Merchant43" \
    107               --password="password" \
    108               --payto_uri="payto://iban/DE474361?receiver-name=Merchant43"
    109 
    110 echo " DONE"
    111 
    112 # delete existing wallet database
    113 export WALLET_DB="wallet.wdb"
    114 rm -f "$WALLET_DB"
    115 
    116 echo -n "Running wallet ..."
    117 wlog="taler-wallet-cli-withdraw.log"
    118 taler-wallet-cli \
    119     --no-throttle \
    120     --wallet-db="$WALLET_DB" \
    121     api \
    122     --expect-success \
    123     'runIntegrationTest' \
    124   "$(jq -n '
    125     {
    126       amountToSpend: "TESTKUDOS:4",
    127       amountToWithdraw: "TESTKUDOS:10",
    128       corebankApiBaseUrl: $BANK_URL,
    129       exchangeBaseUrl: $EXCHANGE_URL,
    130       merchantBaseUrl: $MERCHANT_URL,
    131     }' \
    132     --arg MERCHANT_URL "$MERCHANT_URL" \
    133     --arg EXCHANGE_URL "$EXCHANGE_URL" \
    134     --arg BANK_URL "$BANK_URL"
    135   )" &> $wlog || {
    136     echo " FAILED! Last lines from $wlog:"
    137     tail $wlog
    138     exit 2
    139   }
    140 echo " DONE"
    141 
    142 taler-wallet-cli --wallet-db="$WALLET_DB" run-until-done
    143 
    144 # Dump database
    145 mkdir -p "$(dirname "$BASEDB")"
    146 
    147 echo "Dumping database ${BASEDB}.sql"
    148 pg_dump -O "auditor-basedb" | sed -e '/AS integer/d' > "${BASEDB}.sql"
    149 cp "${CONF}.edited" "${BASEDB}.conf"
    150 cp "$(taler-exchange-config -c "${CONF}.edited" -s exchange-offline -o MASTER_PRIV_FILE -f)" "${BASEDB}.mpriv"
    151 
    152 # clean up
    153 echo -n "Final clean up ..."
    154 kill -TERM "$SETUP_PID"
    155 wait
    156 unset SETUP_PID
    157 dropdb "auditor-basedb"
    158 echo " DONE"
    159 
    160 echo "====================================="
    161 echo "Finished generation of ${BASEDB}.sql"
    162 echo "====================================="
    163 
    164 exit 0