test_merchant_order_autocleanup.sh (8732B)
1 #!/bin/bash 2 # This file is in the public domain. 3 4 set -eu 5 6 . setup.sh 7 8 9 # Replace with 0 for nexus... 10 USE_FAKEBANK=1 11 if [ 1 = "$USE_FAKEBANK" ] 12 then 13 ACCOUNT="exchange-account-2" 14 WIRE_METHOD="x-taler-bank" 15 BANK_FLAGS="-f -d $WIRE_METHOD -u $ACCOUNT" 16 BANK_URL="http://localhost:8082/" 17 else 18 ACCOUNT="exchange-account-1" 19 WIRE_METHOD="iban" 20 BANK_FLAGS="-ns -d $WIRE_METHOD -u $ACCOUNT" 21 BANK_URL="http://localhost:18082/" 22 echo -n "Testing for libeufin-bank" 23 libeufin-bank --help >/dev/null </dev/null || exit_skip " MISSING" 24 echo " FOUND" 25 26 fi 27 28 echo -n "Testing for taler-harness" 29 taler-harness --help >/dev/null </dev/null || exit_skip " MISSING" 30 echo " FOUND" 31 32 # Launch exchange, merchant and bank. 33 setup -c "test_template.conf" \ 34 -r "merchant-exchange-default" \ 35 -em \ 36 $BANK_FLAGS 37 LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX) 38 CONF="test_template.conf.edited" 39 WALLET_DB=$(mktemp -p "${TMPDIR:-/tmp}" test_wallet.json-XXXXXX) 40 EXCHANGE_URL="http://localhost:8081/" 41 42 43 echo -n "First, prepare wallet with coins..." 44 rm -f "$WALLET_DB" 45 taler-wallet-cli \ 46 --no-throttle \ 47 --wallet-db="$WALLET_DB" \ 48 api \ 49 --expect-success 'withdrawTestBalance' \ 50 "$(jq -n ' 51 { 52 amount: "TESTKUDOS:99", 53 corebankApiBaseUrl: $BANK_URL, 54 exchangeBaseUrl: $EXCHANGE_URL 55 }' \ 56 --arg BANK_URL "${BANK_URL}" \ 57 --arg EXCHANGE_URL "$EXCHANGE_URL" 58 )" 2>wallet-withdraw-1.err >wallet-withdraw-1.out 59 echo -n "." 60 if [ 1 = "$USE_FAKEBANK" ] 61 then 62 # Fakebank is instant... 63 sleep 0 64 else 65 sleep 10 66 # NOTE: once libeufin can do long-polling, we should 67 # be able to reduce the delay here and run wirewatch 68 # always in the background via setup 69 fi 70 echo -n "." 71 taler-exchange-wirewatch \ 72 -L "INFO" \ 73 -c "$CONF" \ 74 -t \ 75 &> taler-exchange-wirewatch.out 76 echo -n "." 77 78 taler-wallet-cli \ 79 --wallet-db="$WALLET_DB" \ 80 run-until-done \ 81 2>wallet-withdraw-finish-1.err \ 82 >wallet-withdraw-finish-1.out 83 echo " OK" 84 85 # 86 # CREATE INSTANCE FOR TESTING 87 # 88 89 echo -n "Configuring merchant instance ..." 90 if [ 1 = "$USE_FAKEBANK" ] 91 then 92 FORTYTHREE="payto://x-taler-bank/localhost/fortythree?receiver-name=fortythree" 93 else 94 FORTYTHREE=$(get_payto_uri fortythree x) 95 fi 96 97 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 98 -H 'Authorization: Bearer secret-token:super_secret' \ 99 "http://localhost:9966/management/instances" \ 100 -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}}' \ 101 -w "%{http_code}" -s -o /dev/null) 102 103 if [ "$STATUS" != "204" ] 104 then 105 exit_fail "Expected 204, instance created. got: $STATUS" 106 fi 107 108 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 109 -H 'Authorization: Bearer secret-token:super_secret' \ 110 http://localhost:9966/private/accounts \ 111 -d '{"payto_uri":"'"$FORTYTHREE"'"}' \ 112 -w "%{http_code}" -s -o /dev/null) 113 114 if [ "$STATUS" != "200" ] 115 then 116 exit_fail "Expected '200 OK' response. Got instead $STATUS" 117 fi 118 119 NOW=$(date +%s) 120 IN_TEN_SECS=$(( NOW + 10 )) 121 122 echo -n "Creating order to be claimed..." 123 STATUS=$(curl 'http://localhost:9966/private/orders' \ 124 -d '{"order":{"amount":"TESTKUDOS:1","summary":"payme","pay_deadline": {"t_s":'"$IN_TEN_SECS"'}}}' \ 125 -w "%{http_code}" -s -o "$LAST_RESPONSE") 126 127 if [ "$STATUS" != "200" ] 128 then 129 cat "$LAST_RESPONSE" 130 exit_fail "Expected 200 ok, order created. got: $STATUS" 131 fi 132 133 ORDER_ID=$(jq -e -r .order_id < "$LAST_RESPONSE") 134 TOKEN=$(jq -e -r .token < "$LAST_RESPONSE") 135 136 STATUS=$(curl "http://localhost:9966/private/orders/${ORDER_ID}" \ 137 -w "%{http_code}" -s -o "$LAST_RESPONSE") 138 139 if [ "$STATUS" != "200" ] 140 then 141 cat "$LAST_RESPONSE" 142 exit_fail "Expected 200 ok, getting order info before claming it. got: $STATUS" 143 fi 144 145 PAY_URL=$(jq -e -r .taler_pay_uri < "$LAST_RESPONSE") 146 147 echo "Ok (order $ORDER_ID)" 148 149 NOW=$(date +%s) 150 151 echo -n "Claim the order but do not pay it ..." 152 taler-wallet-cli \ 153 --no-throttle \ 154 --wallet-db="$WALLET_DB" \ 155 advanced pay-prepare \ 156 "${PAY_URL}" \ 157 2> wallet-claim1.err > wallet-claim1.log 158 159 STATUS=$(curl "http://localhost:9966/private/orders/${ORDER_ID}" \ 160 -w "%{http_code}" -s -o "$LAST_RESPONSE") 161 162 if [ "$STATUS" != "200" ] 163 then 164 cat "$LAST_RESPONSE" 165 exit_fail "Expected 200 ok, after pay. got: $STATUS" 166 fi 167 168 ORDER_STATUS=$(jq -r .order_status < "$LAST_RESPONSE") 169 170 if [ "$ORDER_STATUS" != "claimed" ] 171 then 172 cat "$LAST_RESPONSE" 173 exit_fail "Expected 'paid'. got: $ORDER_STATUS" 174 fi 175 NOW2=$(date +%s) 176 echo " OK (took $(( NOW2 - NOW)) secs)" 177 178 echo "Wait 8 secs ..." 179 sleep 8 180 181 echo -n "Trying to get the list of orders..." 182 STATUS=$(curl "http://localhost:9966/private/orders" \ 183 -w "%{http_code}" -s -o "$LAST_RESPONSE") 184 185 if [ "$STATUS" != "200" ] 186 then 187 cat "$LAST_RESPONSE" 188 exit_fail "Expected 200 ok. got: $STATUS" 189 fi 190 echo "ok" 191 192 echo -n "Creating a new order that will trigger the db cleanup..." 193 STATUS=$(curl 'http://localhost:9966/private/orders' \ 194 -d '{"order":{"amount":"TESTKUDOS:1","summary":"payme"}}' \ 195 -w "%{http_code}" -s -o "$LAST_RESPONSE") 196 197 if [ "$STATUS" != "200" ] 198 then 199 cat "$LAST_RESPONSE" 200 exit_fail "Expected 200 ok, order created. got: $STATUS" 201 fi 202 203 ORDER_ID=$(jq -e -r .order_id < "$LAST_RESPONSE") 204 TOKEN=$(jq -e -r .token < "$LAST_RESPONSE") 205 206 STATUS=$(curl "http://localhost:9966/private/orders/${ORDER_ID}" \ 207 -w "%{http_code}" -s -o "$LAST_RESPONSE") 208 209 if [ "$STATUS" != "200" ] 210 then 211 cat "$LAST_RESPONSE" 212 exit_fail "Expected 200 ok, getting order info before claming it. got: $STATUS" 213 fi 214 215 PAY_URL=$(jq -e -r .taler_pay_uri < "$LAST_RESPONSE") 216 217 echo "Ok (order $ORDER_ID)" 218 219 echo -n "Trying to get the list of orders (issue #7025)..." 220 STATUS=$(curl "http://localhost:9966/private/orders" \ 221 -w "%{http_code}" -s -o "$LAST_RESPONSE") 222 223 if [ "$STATUS" != "200" ] 224 then 225 cat "$LAST_RESPONSE" 226 exit_fail "Expected 200 ok. got: $STATUS" 227 fi 228 echo "OK" 229 230 # set -x 231 232 echo -n "Now paying this order..." 233 taler-wallet-cli \ 234 --no-throttle \ 235 --wallet-db="$WALLET_DB" \ 236 handle-uri "${PAY_URL}"\ 237 -y \ 238 2> wallet-pay1.err > wallet-pay1.log 239 240 STATUS=$(curl "http://localhost:9966/private/orders/${ORDER_ID}" \ 241 -w "%{http_code}" -s -o "$LAST_RESPONSE") 242 243 if [ "$STATUS" != "200" ] 244 then 245 cat "$LAST_RESPONSE" 246 exit_fail "Expected 200 ok, after pay. got: $STATUS" 247 fi 248 249 ORDER_STATUS=$(jq -r .order_status < "$LAST_RESPONSE") 250 251 if [ "$ORDER_STATUS" != "paid" ] 252 then 253 cat "$LAST_RESPONSE" 254 exit_fail "Expected 'paid'. got: $ORDER_STATUS" 255 fi 256 NOW2=$(date +%s) 257 echo " OK (took $(( NOW2 - NOW)) secs )" 258 259 260 echo -n "Trying to get the list of orders..." 261 STATUS=$(curl "http://localhost:9966/private/orders" \ 262 -w "%{http_code}" -s -o "$LAST_RESPONSE") 263 264 if [ "$STATUS" != "200" ] 265 then 266 cat "$LAST_RESPONSE" 267 exit_fail "Expected 200 ok. got: $STATUS" 268 fi 269 echo ok 270 271 272 echo -n "Finally, create another order..." 273 STATUS=$(curl 'http://localhost:9966/private/orders' \ 274 -d '{"order":{"amount":"TESTKUDOS:1","summary":"payme"}}' \ 275 -w "%{http_code}" -s -o "$LAST_RESPONSE") 276 277 if [ "$STATUS" != "200" ] 278 then 279 cat "$LAST_RESPONSE" 280 exit_fail "Expected 200 ok, order created. got: $STATUS" 281 fi 282 283 ORDER_ID=$(jq -e -r .order_id < "$LAST_RESPONSE") 284 TOKEN=$(jq -e -r .token < "$LAST_RESPONSE") 285 286 STATUS=$(curl "http://localhost:9966/private/orders/${ORDER_ID}" \ 287 -w "%{http_code}" -s -o "$LAST_RESPONSE") 288 289 if [ "$STATUS" != "200" ] 290 then 291 cat "$LAST_RESPONSE" 292 exit_fail "Expected 200 ok, getting order info before claiming it. got: $STATUS" 293 fi 294 295 PAY_URL=$(jq -e -r .taler_pay_uri < "$LAST_RESPONSE") 296 297 echo "Ok (order $ORDER_ID)" 298 299 echo -n "Now paying this order..." 300 taler-wallet-cli \ 301 --no-throttle \ 302 --wallet-db="$WALLET_DB" \ 303 handle-uri \ 304 "${PAY_URL}" \ 305 -y \ 306 2> wallet-pay1.err > wallet-pay1.log 307 308 STATUS=$(curl "http://localhost:9966/private/orders/${ORDER_ID}" \ 309 -w "%{http_code}" -s -o "$LAST_RESPONSE") 310 311 if [ "$STATUS" != "200" ] 312 then 313 cat "$LAST_RESPONSE" 314 exit_fail "Expected 200 ok. got: $STATUS" 315 fi 316 317 ORDER_STATUS=$(jq -r .order_status < "$LAST_RESPONSE") 318 319 if [ "$ORDER_STATUS" != "paid" ] 320 then 321 cat "$LAST_RESPONSE" 322 exit_fail "Expected 'paid'. got: $ORDER_STATUS" 323 fi 324 NOW2=$(date +%s) 325 echo " OK (took $( echo -n $(($NOW2 - $NOW)) ) secs )" 326 327 echo -n "Trying to get the list of orders..." 328 STATUS=$(curl "http://localhost:9966/private/orders" \ 329 -w "%{http_code}" -s -o "$LAST_RESPONSE") 330 331 if [ "$STATUS" != "200" ] 332 then 333 cat "$LAST_RESPONSE" 334 exit_fail "Expected 200 ok. got: $STATUS" 335 fi 336 echo "ok" 337 338 echo "Test PASSED" 339 340 exit 0