test_merchant_wirewatch.sh (11922B)
1 #!/usr/bin/env 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 timeout 60 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 http://localhost:9966/management/instances \ 218 -d '{"auth":{"method":"token","password":"super_secret"},"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}}' \ 219 -w "%{http_code}" -s -o /dev/null) 220 221 if [ "$STATUS" != "204" ] 222 then 223 exit_fail "Expected 204 no content. Got: $STATUS" 224 fi 225 ADMIN_TOKEN=$(merchant_login admin super_secret) 226 echo "OK" 227 228 echo -n "Configuring bank account..." 229 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 230 -H "Authorization: Bearer $ADMIN_TOKEN" \ 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 -H "Authorization: Bearer $ADMIN_TOKEN" \ 246 -d '{"refund_delay":{"d_us":0},"order":{"amount":"TESTKUDOS:1","summary":"payme"}}' \ 247 -w "%{http_code}" \ 248 -s \ 249 -o "$LAST_RESPONSE") 250 251 if [ "$STATUS" != "200" ] 252 then 253 exit_fail "Expected 200 OK. Got: $STATUS " "$(cat "$LAST_RESPONSE")" 254 fi 255 256 ORDER_ID=$(jq -e -r .order_id < "$LAST_RESPONSE") 257 STATUS=$(curl "http://localhost:9966/private/orders/${ORDER_ID}" \ 258 -H "Authorization: Bearer $ADMIN_TOKEN" \ 259 -w "%{http_code}" \ 260 -s \ 261 -o "$LAST_RESPONSE") 262 263 if [ "$STATUS" != "200" ] 264 then 265 exit_fail "Expected 200 ok. Got: $STATUS" "$(cat "$LAST_RESPONSE")" 266 fi 267 PAY_URL=$(jq -e -r .taler_pay_uri < "$LAST_RESPONSE") 268 echo OK 269 270 NOW=$(date +%s) 271 echo -n "Pay first order ..." 272 taler-wallet-cli \ 273 --no-throttle \ 274 --wallet-db="$WALLET_DB" \ 275 handle-uri "${PAY_URL}" \ 276 -y 2> wallet-pay1.err > wallet-pay1.log 277 NOW2=$(date +%s) 278 echo "OK. Took $(( NOW2 - NOW))s." 279 280 STATUS=$(curl "http://localhost:9966/private/orders/${ORDER_ID}" \ 281 -H "Authorization: Bearer $ADMIN_TOKEN" \ 282 -w "%{http_code}" \ 283 -s \ 284 -o "$LAST_RESPONSE") 285 286 if [ "$STATUS" != "200" ] 287 then 288 exit_fail "Expected 200 Ok. Got: $STATUS" "$(cat "$LAST_RESPONSE")" 289 fi 290 291 ORDER_STATUS=$(jq -r .order_status < "$LAST_RESPONSE") 292 if [ "$ORDER_STATUS" != "paid" ] 293 then 294 exit_fail "Expected order status 'paid'. Got: $ORDER_STATUS" "$(cat "$LAST_RESPONSE")" 295 fi 296 297 # 298 # WIRE TRANSFER TO MERCHANT AND NOTIFY BACKEND 299 # 300 301 WIRE_DEADLINE=$(jq -r .contract_terms.wire_transfer_deadline.t_s < "$LAST_RESPONSE") 302 NOW=$(date +%s) 303 304 TO_SLEEP="$(( 3600 + WIRE_DEADLINE - NOW ))" 305 echo -n "Perform wire transfers (with ${TO_SLEEP}s timeshift) ..." 306 taler-exchange-aggregator \ 307 -y \ 308 -c "$CONF" \ 309 -T "${TO_SLEEP}000000" \ 310 -t \ 311 -L INFO &> aggregator.log 312 taler-exchange-transfer\ 313 -c "$CONF" \ 314 -t \ 315 -L INFO &> transfer.log 316 echo " DONE" 317 318 if [ 1 != "$USE_FAKEBANK" ] 319 then 320 echo -n "Waiting for Nexus and Sandbox to settle the payment ..." 321 sleep 3 # FIXME-MS: replace with call to Nexus to right now poll the sandbox ... 322 libeufin-cli \ 323 accounts \ 324 fetch-transactions \ 325 ${NEXUS_ACCOUNT_NAME} \ 326 &> libeufin-transfer-fetch.out 327 echo " DONE" 328 fi 329 330 echo -n "Obtaining wire transfer details from bank..." 331 taler-merchant-wirewatch \ 332 -c "$CONF" \ 333 -t \ 334 -L INFO &> merchant-wirewatch.log 335 echo " OK" 336 337 echo -n "Obtaining deposit data from exchange..." 338 taler-merchant-depositcheck \ 339 -c "$CONF" \ 340 -e "http://localhost:8081/" \ 341 -T "${TO_SLEEP}000000" \ 342 -t \ 343 -L INFO &> merchant-depositcheck.log 344 echo " OK" 345 346 echo -n "Obtaining reconciliation data from exchange..." 347 taler-merchant-reconciliation \ 348 -c "$CONF" \ 349 -T "${TO_SLEEP}000000" \ 350 -t \ 351 -L INFO &> merchant-reconciliation.log 352 echo " OK" 353 354 echo -n "Fetching wire transfers of ADMIN instance ..." 355 STATUS=$(curl 'http://localhost:9966/private/transfers' \ 356 -H "Authorization: Bearer $ADMIN_TOKEN" \ 357 -w "%{http_code}" \ 358 -s \ 359 -o "$LAST_RESPONSE") 360 if [ "$STATUS" != "200" ] 361 then 362 exit_fail "Expected response 200 Ok. Got: $STATUS" "$(jq . < "$LAST_RESPONSE")" 363 fi 364 TRANSFERS_LIST_SIZE=$(jq -r '.transfers | length' < "$LAST_RESPONSE") 365 if [ "$TRANSFERS_LIST_SIZE" != "1" ] 366 then 367 exit_fail "Expected one transfer. Got: $TRANSFERS_LIST_SIZE" "$(jq . < "$LAST_RESPONSE")" 368 fi 369 echo " OK" 370 371 echo -n "Reconciling wire transfer data with exchange..." 372 taler-merchant-reconciliation \ 373 -c "$CONF" \ 374 -t \ 375 -L INFO &> merchant-reconciliation.log 376 echo " OK" 377 378 echo -n "Checking order status ..." 379 STATUS=$(curl "http://localhost:9966/private/orders/${ORDER_ID}?transfer=YES" \ 380 -H "Authorization: Bearer $ADMIN_TOKEN" \ 381 -w "%{http_code}" \ 382 -s \ 383 -o "$LAST_RESPONSE") 384 385 if [ "$STATUS" != "200" ] 386 then 387 jq . < "$LAST_RESPONSE" 388 exit_fail "Expected 200 ok. got: $STATUS" "$(cat "$LAST_RESPONSE")" 389 fi 390 391 WAS_WIRED=$(jq -r .wired < "$LAST_RESPONSE") 392 if [ "$WAS_WIRED" != "true" ] 393 then 394 jq . < "$LAST_RESPONSE" 395 exit_fail "Got .wired 'false', expected 'true'" 396 fi 397 echo " OK" 398 399 echo "Test PASSED" 400 401 exit 0