batch.sh (7333B)
1 #!/bin/bash 2 set -eu 3 4 # Cleanup to run whenever we exit 5 function cleanup() 6 { 7 for n in `jobs -p` 8 do 9 kill $n 2> /dev/null || true 10 done 11 wait 12 } 13 14 # Install cleanup handler (except for kill -9) 15 trap cleanup EXIT 16 17 18 # Exit, with status code "skip" (no 'real' failure) 19 function exit_skip() { 20 echo $1 21 exit 77 22 } 23 24 # Where do we write the result? 25 BASEDB=${1:-"batch"} 26 27 # Name of the Postgres database we will use for the script. 28 # Will be dropped, do NOT use anything that might be used 29 # elsewhere 30 export TARGET_DB=`basename ${BASEDB}` 31 32 export WALLET_DB=${BASEDB:-"wallet"}.wdb 33 34 # delete existing wallet database 35 rm -f $WALLET_DB 36 37 38 # Configuration file will be edited, so we create one 39 # from the template. 40 CONF=${BASEDB}.conf 41 cp generate-auditor-basedb.conf $CONF 42 43 44 echo -n "Testing for taler-fakebank-run" 45 taler-fakebank-run -h >/dev/null </dev/null || exit_skip " MISSING" 46 echo " FOUND" 47 echo -n "Testing for taler-wallet-cli" 48 taler-wallet-cli -v >/dev/null </dev/null || exit_skip " MISSING" 49 echo " FOUND" 50 echo -n "Testing for curl" 51 curl --help >/dev/null </dev/null || exit_skip " MISSING" 52 echo " FOUND" 53 54 55 pwd 56 # Clean up 57 58 DATA_DIR=`taler-exchange-config -f -c $CONF -s PATHS -o TALER_HOME` 59 rm -rf $DATA_DIR || true 60 61 # reset database 62 dropdb $TARGET_DB >/dev/null 2>/dev/null || true 63 createdb $TARGET_DB || exit_skip "Could not create database $TARGET_DB" 64 65 66 # obtain key configuration data 67 MASTER_PRIV_FILE=$(taler-exchange-config -f -c $CONF -s exchange-offline -o MASTER_PRIV_FILE) 68 MASTER_PRIV_DIR=$(dirname $MASTER_PRIV_FILE) 69 mkdir -p $MASTER_PRIV_DIR 70 gnunet-ecc -g1 $MASTER_PRIV_FILE > /dev/null 71 MASTER_PUB=$(gnunet-ecc -p $MASTER_PRIV_FILE) 72 EXCHANGE_URL=$(taler-exchange-config -c $CONF -s EXCHANGE -o BASE_URL) 73 MERCHANT_PORT=$(taler-merchant-config -c $CONF -s MERCHANT -o PORT) 74 MERCHANT_URL=http://localhost:${MERCHANT_PORT}/ 75 BANK_PORT=$(taler-exchange-config -c $CONF -s BANK -o HTTP_PORT) 76 BANK_URL=http://localhost:${BANK_PORT}/ 77 AUDITOR_URL=http://localhost:8083/ 78 AUDITOR_PRIV_FILE=$(taler-auditor-config -f -c $CONF -s AUDITOR -o AUDITOR_PRIV_FILE) 79 AUDITOR_PRIV_DIR=$(dirname $AUDITOR_PRIV_FILE) 80 mkdir -p $AUDITOR_PRIV_DIR 81 gnunet-ecc -g1 $AUDITOR_PRIV_FILE > /dev/null 82 AUDITOR_PUB=$(gnunet-ecc -p $AUDITOR_PRIV_FILE) 83 84 echo "AUDITOR PUB is $AUDITOR_PUB using file $AUDITOR_PRIV_FILE" 85 86 # patch configuration 87 taler-exchange-config \ 88 -c $CONF \ 89 -s exchange \ 90 -o MASTER_PUBLIC_KEY \ 91 -V $MASTER_PUB 92 taler-auditor-config \ 93 -c $CONF \ 94 -s auditor \ 95 -o PUBLIC_KEY \ 96 -V $AUDITOR_PUB 97 taler-merchant-config \ 98 -c $CONF \ 99 -s merchant-exchange-default \ 100 -o MASTER_KEY \ 101 -V $MASTER_PUB 102 taler-exchange-config \ 103 -c $CONF \ 104 -s exchangedb-postgres \ 105 -o CONFIG \ 106 -V postgres:///$TARGET_DB 107 taler-auditor-config \ 108 -c $CONF \ 109 -s auditordb-postgres \ 110 -o CONFIG \ 111 -V postgres:///$TARGET_DB 112 taler-merchant-config \ 113 -c $CONF \ 114 -s merchantdb-postgres \ 115 -o CONFIG \ 116 -V postgres:///$TARGET_DB 117 taler-exchange-config \ 118 -c $CONF \ 119 -s bank \ 120 -o database \ 121 -V postgres:///$TARGET_DB 122 123 # setup exchange 124 echo "Setting up exchange" 125 taler-exchange-dbinit -c $CONF 126 127 echo "Setting up merchant" 128 taler-merchant-dbinit -c $CONF 129 130 # setup auditor 131 echo "Setting up auditor" 132 taler-auditor-dbinit -c $CONF || exit_skip "Failed to initialize auditor DB" 133 taler-auditor-exchange -c $CONF -m $MASTER_PUB -u $EXCHANGE_URL || exit_skip "Failed to add exchange to auditor" 134 135 # Launch services 136 echo "Launching services" 137 taler-fakebank-run -c $CONF &> taler-bank.log & 138 TFN=`which taler-exchange-httpd` 139 TBINPFX=`dirname $TFN` 140 TLIBEXEC=${TBINPFX}/../lib/taler/libexec/ 141 taler-exchange-secmod-eddsa -c $CONF 2> taler-exchange-secmod-eddsa.log & 142 taler-exchange-secmod-rsa -c $CONF 2> taler-exchange-secmod-rsa.log & 143 taler-exchange-secmod-cs -c $CONF 2> taler-exchange-secmod-cs.log & 144 taler-exchange-httpd -c $CONF 2> taler-exchange-httpd.log & 145 taler-merchant-httpd -c $CONF -L INFO 2> taler-merchant-httpd.log & 146 taler-exchange-wirewatch -c $CONF 2> taler-exchange-wirewatch.log & 147 taler-auditor-httpd -L INFO -c $CONF 2> taler-auditor-httpd.log & 148 149 # Wait for all bank to be available (usually the slowest) 150 for n in `seq 1 50` 151 do 152 echo -n "." 153 sleep 0.2 154 OK=0 155 # bank 156 wget http://localhost:8082/ -o /dev/null -O /dev/null >/dev/null || continue 157 OK=1 158 break 159 done 160 161 if [ 1 != $OK ] 162 then 163 exit_skip "Failed to launch services" 164 fi 165 166 # Wait for all services to be available 167 for n in `seq 1 50` 168 do 169 echo -n "." 170 sleep 0.1 171 OK=0 172 # exchange 173 wget http://localhost:8081/seed -o /dev/null -O /dev/null >/dev/null || continue 174 # merchant 175 wget http://localhost:9966/ -o /dev/null -O /dev/null >/dev/null || continue 176 # Auditor 177 wget http://localhost:8083/ -o /dev/null -O /dev/null >/dev/null || continue 178 OK=1 179 break 180 done 181 182 if [ 1 != $OK ] 183 then 184 exit_skip "Failed to launch services" 185 fi 186 echo " DONE" 187 188 echo -n "Setting up keys" 189 taler-exchange-offline -c $CONF \ 190 download sign \ 191 enable-account payto://x-taler-bank/localhost/Exchange \ 192 enable-auditor $AUDITOR_PUB $AUDITOR_URL "TESTKUDOS Auditor" \ 193 wire-fee now x-taler-bank TESTKUDOS:0.01 TESTKUDOS:0.01 TESTKUDOS:0.01 \ 194 global-fee now TESTKUDOS:0.01 TESTKUDOS:0.01 TESTKUDOS:0.01 TESTKUDOS:0.01 1h 1h 1year 5 \ 195 upload &> taler-exchange-offline.log 196 197 echo -n "." 198 199 for n in `seq 1 2` 200 do 201 echo -n "." 202 OK=0 203 wget --timeout=1 http://localhost:8081/keys -o /dev/null -O /dev/null >/dev/null || continue 204 OK=1 205 break 206 done 207 208 if [ 1 != $OK ] 209 then 210 exit_skip "Failed to setup keys" 211 fi 212 213 echo " DONE" 214 echo -n "Adding auditor signatures ..." 215 216 taler-auditor-offline -c $CONF \ 217 download sign upload &> taler-auditor-offline.log 218 219 echo " DONE" 220 # Setup merchant 221 222 echo -n "Setting up merchant" 223 224 curl -H "Content-Type: application/json" -X POST -d '{"auth":{"method":"external"},"accounts":[{"payto_uri":"payto://x-taler-bank/localhost/43"}],"id":"default","name":"default","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}}' http://localhost:9966/management/instances 225 226 227 echo " DONE" 228 229 # run wallet CLI 230 echo "Ready to run wallet" 231 export WALLET_DB 232 export EXCHANGE_URL 233 export MERCHANT_URL 234 export BANK_URL 235 unset TALER_WALLET_INSECURE_TRUST_EXCHANGE 236 export TALER_WALLET_BATCH_WITHDRAWAL=1 237 echo 'taler-wallet-cli --wallet-db=$WALLET_DB -L TRACE advanced bench1 --config-json "{ \"exchange\": \"$EXCHANGE_URL\", \"bank\": \"${BANK_URL}\", \"currency\": \"TESTKUDOS\", \"payto\": \"payto://x-taler-bank/localhost/foo\", \"iterations\": 100000, \"deposits\": 10, \"restartAfter\": 2 }"' 238 bash 239 240 #taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB api 'runIntegrationTest' \ 241 # "$(jq -n ' 242 # { 243 # amountToSpend: "TESTKUDOS:4", 244 # amountToWithdraw: "TESTKUDOS:10", 245 # corebankApiBaseUrl: $BANK_URL, 246 # exchangeBaseUrl: $EXCHANGE_URL, 247 # merchantBaseUrl: $MERCHANT_URL, 248 # }' \ 249 # --arg MERCHANT_URL "$MERCHANT_URL" \ 250 # --arg EXCHANGE_URL "$EXCHANGE_URL" \ 251 # --arg BANK_URL "$BANK_URL" 252 # )" &> taler-wallet-cli.log 253 254 255 echo "Shutting down services" 256 cleanup 257 258 # clean up 259 echo "Final clean up" 260 dropdb $TARGET_DB 261 262 rm -rf $DATA_DIR || true 263 exit 0