test_merchant_wirewatch.sh (11613B)
1 #!/bin/bash 2 # This file is part of TALER 3 # Copyright (C) 2014-2023 Taler Systems SA 4 # 5 # TALER is free software; you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as 7 # published by the Free Software Foundation; either version 3, or 8 # (at your option) any later version. 9 # 10 # TALER is distributed in the hope that it will be useful, but 11 # WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public 16 # License along with TALER; see the file COPYING. If not, see 17 # <http://www.gnu.org/licenses/> 18 # 19 # Testcase for #6363 (WiP) 20 set -eu 21 22 # Exit, with status code "skip" (no 'real' failure) 23 function exit_skip() { 24 echo $1 25 exit 77 26 } 27 28 echo -n "Testing for taler-harness" 29 taler-harness --help >/dev/null </dev/null || exit_skip " MISSING" 30 echo " FOUND" 31 32 33 # Replace with 0 for nexus... 34 USE_FAKEBANK=1 35 if [ 1 = "$USE_FAKEBANK" ] 36 then 37 ACCOUNT="exchange-account-2" 38 WIRE_METHOD="x-taler-bank" 39 BANK_FLAGS="-f -d $WIRE_METHOD -u $ACCOUNT" 40 BANK_URL="http://localhost:8082/" 41 else 42 echo -n "Testing for libeufin-bank" 43 libeufin-bank --help >/dev/null </dev/null || exit_skip " MISSING" 44 echo " FOUND" 45 46 ACCOUNT="exchange-account-1" 47 WIRE_METHOD="iban" 48 BANK_FLAGS="-n -d $WIRE_METHOD -u $ACCOUNT" 49 BANK_URL="http://localhost:18082/" 50 fi 51 52 . setup.sh 53 # Launch exchange, merchant and bank. 54 setup -c "test_template.conf" \ 55 -em \ 56 -r "merchant-exchange-default" \ 57 $BANK_FLAGS 58 LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX) 59 CONF="test_template.conf.edited" 60 WALLET_DB=$(mktemp -p "${TMPDIR:-/tmp}" test_wallet.json-XXXXXX) 61 EXCHANGE_URL="http://localhost:8081/" 62 63 64 if [ 1 = "$USE_FAKEBANK" ] 65 then 66 FACADE_URL="http://localhost:8082/accounts/gnunet/taler-revenue/" 67 FACADE_USERNAME="gnunet" 68 FACADE_PASSWORD="password" 69 else 70 echo "not implemented for current libeufin-bank" 71 exit 1 72 export LIBEUFIN_SANDBOX_DB_CONNECTION='postgresql:///talercheck' 73 export LIBEUFIN_SANDBOX_ADMIN_PASSWORD="secret" 74 export LIBEUFIN_SANDBOX_URL="http://localhost:18082/" 75 76 export EBICS_HOST="talerebics" 77 export LIBEUFIN_SANDBOX_USERNAME="admin" 78 export LIBEUFIN_SANDBOX_PASSWORD="secret" 79 export EBICS_USER_ID="gnunet_ebics" 80 export EBICS_PARTNER="GnunetPartner" 81 export BANK_CONNECTION_NAME="gnunet-connection" 82 export NEXUS_ACCOUNT_NAME="GnunetCredit" 83 # The 'gnunet' account is created by 84 # taler-bank-manage-testing and used for 85 # the 'admin' instance, so this must be used here. 86 export SANDBOX_ACCOUNT_NAME="gnunet" 87 88 export LIBEUFIN_NEXUS_URL="http://localhost:8082" 89 # These two are from taler-bank-manage-testing... 90 91 # Define credentials for wirewatch user, will be Merchant client. 92 CREDIT_USERNAME="merchant-wirewatch" 93 CREDIT_PASSWORD="merchant-wirewatch-password" 94 95 echo -n "Create credit user (for gnunet-merchant) at Nexus ..." 96 97 export LIBEUFIN_NEXUS_DB_CONNECTION='postgresql:///talercheck' 98 libeufin-nexus \ 99 superuser "$CREDIT_USERNAME" \ 100 --password="$CREDIT_PASSWORD" \ 101 &> nexus-credit-create.log 102 echo " OK" 103 export LIBEUFIN_NEXUS_USERNAME="$CREDIT_USERNAME" 104 export LIBEUFIN_NEXUS_PASSWORD="$CREDIT_PASSWORD" 105 export GNUNET_CREDIT_FACADE=facade-gnunet-credit 106 107 libeufin-cli sandbox \ 108 demobank \ 109 new-ebicssubscriber \ 110 --host-id ${EBICS_HOST} \ 111 --user-id ${NEXUS_ACCOUNT_NAME} \ 112 --partner-id ${EBICS_PARTNER} \ 113 --bank-account ${SANDBOX_ACCOUNT_NAME} \ 114 &> sandbox-subscriber-create.log 115 116 libeufin-cli \ 117 connections \ 118 new-ebics-connection \ 119 --ebics-url="${LIBEUFIN_SANDBOX_URL}ebicsweb" \ 120 --host-id=${EBICS_HOST} \ 121 --partner-id=${EBICS_PARTNER} \ 122 --ebics-user-id=${NEXUS_ACCOUNT_NAME} \ 123 ${BANK_CONNECTION_NAME} \ 124 &> nexus-connection-create.log 125 126 libeufin-cli \ 127 connections \ 128 connect \ 129 ${BANK_CONNECTION_NAME} \ 130 &> nexus-connection-connect.log 131 132 libeufin-cli \ 133 connections \ 134 download-bank-accounts \ 135 ${BANK_CONNECTION_NAME} \ 136 &> nexus-account-download.log 137 138 libeufin-cli \ 139 connections \ 140 import-bank-account \ 141 --offered-account-id=${SANDBOX_ACCOUNT_NAME} \ 142 --nexus-bank-account-id=${NEXUS_ACCOUNT_NAME} \ 143 ${BANK_CONNECTION_NAME} \ 144 &> nexus-account-import.log 145 146 libeufin-cli \ 147 facades \ 148 new-anastasis-facade \ 149 --currency=TESTKUDOS \ 150 --facade-name=${GNUNET_CREDIT_FACADE} \ 151 ${BANK_CONNECTION_NAME} \ 152 ${NEXUS_ACCOUNT_NAME} \ 153 &> nexus-new-facade.log 154 155 FACADE_URL="http://localhost:18082/accounts/admin/taler-revenue/" 156 # WAS: $(libeufin-cli facades list | jq .facades[0].baseUrl | tr -d \") 157 158 # FIXME: is this correct? Strange to use the super-user 159 # credentials here! 160 FACADE_USERNAME="${CREDIT_USERNAME}" 161 FACADE_PASSWORD="${CREDIT_PASSWORD}" 162 fi 163 164 echo -n "First prepare wallet with coins..." 165 rm -f "${WALLET_DB}" 166 taler-wallet-cli \ 167 --no-throttle \ 168 --wallet-db="$WALLET_DB" \ 169 api \ 170 --expect-success 'withdrawTestBalance' \ 171 "$(jq -n ' 172 { 173 amount: "TESTKUDOS:99", 174 corebankApiBaseUrl: $BANK_URL, 175 exchangeBaseUrl: $EXCHANGE_URL 176 }' \ 177 --arg BANK_URL "$BANK_URL" \ 178 --arg EXCHANGE_URL "$EXCHANGE_URL" 179 )" 2>wallet-withdraw-1.err >wallet-withdraw-1.out 180 echo -n "." 181 if [ 1 = "$USE_FAKEBANK" ] 182 then 183 # Fakebank is instant... 184 sleep 0 185 else 186 sleep 10 187 # NOTE: once libeufin can do long-polling, we should 188 # be able to reduce the delay here and run wirewatch 189 # always in the background via setup 190 fi 191 echo -n "." 192 taler-exchange-wirewatch \ 193 -L "INFO" \ 194 -c "$CONF" \ 195 -t \ 196 &> taler-exchange-wirewatch.out 197 echo -n "." 198 taler-wallet-cli \ 199 --wallet-db="$WALLET_DB" \ 200 run-until-done \ 201 2>wallet-withdraw-finish-1.err \ 202 >wallet-withdraw-finish-1.out 203 echo " OK" 204 205 # 206 # CREATE INSTANCE FOR TESTING 207 # 208 209 echo -n "Configuring merchant admin instance ..." 210 if [ 1 = "$USE_FAKEBANK" ] 211 then 212 GNUNET_PAYTO="payto://x-taler-bank/localhost/gnunet?receiver-name=gnunet" 213 else 214 GNUNET_PAYTO=$(get_payto_uri gnunet x) 215 fi 216 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 217 -H 'Authorization: Bearer secret-token:super_secret' \ 218 http://localhost:9966/management/instances \ 219 -d '{"auth":{"method":"external"},"id":"admin","name":"default","user_type":"business","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 50000000},"default_pay_delay":{"d_us": 60000000}}' \ 220 -w "%{http_code}" -s -o /dev/null) 221 222 if [ "$STATUS" != "204" ] 223 then 224 exit_fail "Expected 204 no content. Got: $STATUS" 225 fi 226 echo "OK" 227 228 echo -n "Configuring bank account..." 229 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 230 -H 'Authorization: Bearer secret-token:super_secret' \ 231 http://localhost:9966/private/accounts \ 232 -d '{"payto_uri":"'"$GNUNET_PAYTO"'","credit_facade_url":"'"${FACADE_URL}"'","credit_facade_credentials":{"type":"basic","username":"'"$FACADE_USERNAME"'","password":"'"$FACADE_PASSWORD"'"}}' \ 233 -w "%{http_code}" -s -o /dev/null) 234 235 if [ "$STATUS" != "200" ] 236 then 237 exit_fail "Expected 200 OK. Got: $STATUS" 238 fi 239 240 echo "OK" 241 242 # CREATE ORDER AND SELL IT 243 echo -n "Creating order to be paid..." 244 STATUS=$(curl 'http://localhost:9966/private/orders' \ 245 -d '{"refund_delay":{"d_us":0},"order":{"amount":"TESTKUDOS:1","summary":"payme"}}' \ 246 -w "%{http_code}" \ 247 -s \ 248 -o "$LAST_RESPONSE") 249 250 if [ "$STATUS" != "200" ] 251 then 252 exit_fail "Expected 200 OK. Got: $STATUS " "$(cat "$LAST_RESPONSE")" 253 fi 254 255 ORDER_ID=$(jq -e -r .order_id < "$LAST_RESPONSE") 256 STATUS=$(curl "http://localhost:9966/private/orders/${ORDER_ID}" \ 257 -w "%{http_code}" \ 258 -s \ 259 -o "$LAST_RESPONSE") 260 261 if [ "$STATUS" != "200" ] 262 then 263 exit_fail "Expected 200 ok. Got: $STATUS" "$(cat "$LAST_RESPONSE")" 264 fi 265 PAY_URL=$(jq -e -r .taler_pay_uri < "$LAST_RESPONSE") 266 echo OK 267 268 NOW=$(date +%s) 269 echo -n "Pay first order ..." 270 taler-wallet-cli \ 271 --no-throttle \ 272 --wallet-db="$WALLET_DB" \ 273 handle-uri "${PAY_URL}" \ 274 -y 2> wallet-pay1.err > wallet-pay1.log 275 NOW2=$(date +%s) 276 echo "OK. Took $(( NOW2 - NOW))s." 277 278 STATUS=$(curl "http://localhost:9966/private/orders/${ORDER_ID}" \ 279 -w "%{http_code}" \ 280 -s \ 281 -o "$LAST_RESPONSE") 282 283 if [ "$STATUS" != "200" ] 284 then 285 exit_fail "Expected 200 Ok. Got: $STATUS" "$(cat "$LAST_RESPONSE")" 286 fi 287 288 ORDER_STATUS=$(jq -r .order_status < "$LAST_RESPONSE") 289 if [ "$ORDER_STATUS" != "paid" ] 290 then 291 exit_fail "Expected order status 'paid'. Got: $ORDER_STATUS" "$(cat "$LAST_RESPONSE")" 292 fi 293 294 # 295 # WIRE TRANSFER TO MERCHANT AND NOTIFY BACKEND 296 # 297 298 WIRE_DEADLINE=$(jq -r .contract_terms.wire_transfer_deadline.t_s < "$LAST_RESPONSE") 299 NOW=$(date +%s) 300 301 TO_SLEEP="$(( 3600 + WIRE_DEADLINE - NOW ))" 302 echo -n "Perform wire transfers (with ${TO_SLEEP}s timeshift) ..." 303 taler-exchange-aggregator \ 304 -y \ 305 -c "$CONF" \ 306 -T "${TO_SLEEP}000000" \ 307 -t \ 308 -L INFO &> aggregator.log 309 taler-exchange-transfer\ 310 -c "$CONF" \ 311 -t \ 312 -L INFO &> transfer.log 313 echo " DONE" 314 315 if [ 1 != "$USE_FAKEBANK" ] 316 then 317 echo -n "Waiting for Nexus and Sandbox to settle the payment ..." 318 sleep 3 # FIXME-MS: replace with call to Nexus to right now poll the sandbox ... 319 libeufin-cli \ 320 accounts \ 321 fetch-transactions \ 322 ${NEXUS_ACCOUNT_NAME} \ 323 &> libeufin-transfer-fetch.out 324 echo " DONE" 325 fi 326 327 echo -n "Obtaining wire transfer details from bank..." 328 taler-merchant-wirewatch \ 329 -c "$CONF" \ 330 -t \ 331 -L INFO &> merchant-wirewatch.log 332 echo " OK" 333 334 echo -n "Obtaining deposit data from exchange..." 335 taler-merchant-depositcheck \ 336 -c "$CONF" \ 337 -e "http://localhost:8081/" \ 338 -T "${TO_SLEEP}000000" \ 339 -t \ 340 -L INFO &> merchant-depositcheck.log 341 echo " OK" 342 343 echo -n "Obtaining reconciliation data from exchange..." 344 taler-merchant-reconciliation \ 345 -c "$CONF" \ 346 -T "${TO_SLEEP}000000" \ 347 -t \ 348 -L INFO &> merchant-reconciliation.log 349 echo " OK" 350 351 echo -n "Fetching wire transfers of ADMIN instance ..." 352 STATUS=$(curl 'http://localhost:9966/private/transfers' \ 353 -w "%{http_code}" \ 354 -s \ 355 -o "$LAST_RESPONSE") 356 if [ "$STATUS" != "200" ] 357 then 358 exit_fail "Expected response 200 Ok. Got: $STATUS" "$(jq . < "$LAST_RESPONSE")" 359 fi 360 TRANSFERS_LIST_SIZE=$(jq -r '.transfers | length' < "$LAST_RESPONSE") 361 if [ "$TRANSFERS_LIST_SIZE" != "1" ] 362 then 363 exit_fail "Expected one transfer. Got: $TRANSFERS_LIST_SIZE" "$(jq . < "$LAST_RESPONSE")" 364 fi 365 echo " OK" 366 367 echo -n "Reconciling wire transfer data with exchange..." 368 taler-merchant-reconciliation \ 369 -c "$CONF" \ 370 -t \ 371 -L INFO &> merchant-reconciliation.log 372 echo " OK" 373 374 echo -n "Checking order status ..." 375 STATUS=$(curl "http://localhost:9966/private/orders/${ORDER_ID}?transfer=YES" \ 376 -w "%{http_code}" \ 377 -s \ 378 -o "$LAST_RESPONSE") 379 380 if [ "$STATUS" != "200" ] 381 then 382 jq . < "$LAST_RESPONSE" 383 exit_fail "Expected 200 ok. got: $STATUS" "$(cat "$LAST_RESPONSE")" 384 fi 385 386 WAS_WIRED=$(jq -r .wired < "$LAST_RESPONSE") 387 if [ "$WAS_WIRED" != "true" ] 388 then 389 jq . < "$LAST_RESPONSE" 390 exit_fail "Got .wired 'false', expected 'true'" 391 fi 392 echo " OK" 393 394 exit 0