#!/bin/bash # This file is in the public domain. . setup.sh # Launch exchange, merchant and bank. setup -c "test_template.conf" -enms -u "exchange-account-1" -d "iban" LAST_RESPONSE=$(mktemp test_response.conf-XXXXXX) CONF="test_template.conf.edited" WALLET_DB=$(mktemp test_wallet.json-XXXXXX) BANK_URL="http://localhost:18082/demobanks/default/" EXCHANGE_URL="http://localhost:8081/" echo -n "First, prepare wallet with coins..." rm -f "$WALLET_DB" taler-wallet-cli \ --no-throttle \ --wallet-db="$WALLET_DB" \ api \ --expect-success 'withdrawTestBalance' \ "$(jq -n ' { amount: "TESTKUDOS:99", bankAccessApiBaseUrl: $BANK_URL, exchangeBaseUrl: $EXCHANGE_URL }' \ --arg BANK_URL "${BANK_URL}access-api/" \ --arg EXCHANGE_URL "$EXCHANGE_URL" )" 2>wallet-withdraw-1.err >wallet-withdraw-1.out echo -n "." sleep 10 echo -n "." # NOTE: once libeufin can do long-polling, we should # be able to reduce the delay here and run wirewatch # always in the background via setup taler-exchange-wirewatch -L "INFO" -c "$CONF" -t &> taler-exchange-wirewatch.out echo -n "." taler-wallet-cli \ --wallet-db="$WALLET_DB" \ run-until-done \ 2>wallet-withdraw-finish-1.err >wallet-withdraw-finish-1.out echo " OK" # # CREATE INSTANCE FOR TESTING # echo -n "Configuring merchant instance ..." FORTYTHREE=$(get_payto_uri fortythree x) # create with 2 address STATUS=$(curl -H "Content-Type: application/json" -X POST \ -H 'Authorization: Bearer secret-token:super_secret' \ "http://localhost:9966/management/instances" \ -d '{"auth":{"method":"external"},"accounts":[{"payto_uri":"'"$FORTYTHREE"'"}],"id":"default","name":"default","user_type":"business","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" : 50000000},"default_pay_delay":{"d_us": 60000000}}' \ -w "%{http_code}" -s -o /dev/null) if [ "$STATUS" != "204" ] then exit_fail "Expected 204, instance created. got: $STATUS" fi NOW=$(date +%s) IN_TEN_SECS=$(( NOW + 10 )) echo -n "Creating order to be claimed..." STATUS=$(curl 'http://localhost:9966/instances/default/private/orders' \ -d '{"order":{"amount":"TESTKUDOS:1","summary":"payme","pay_deadline": {"t_s":'"$IN_TEN_SECS"'}}}' \ -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then cat "$LAST_RESPONSE" exit_fail "Expected 200 ok, order created. got: $STATUS" fi ORDER_ID=$(jq -e -r .order_id < "$LAST_RESPONSE") TOKEN=$(jq -e -r .token < "$LAST_RESPONSE") STATUS=$(curl "http://localhost:9966/instances/default/private/orders/${ORDER_ID}" \ -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then cat "$LAST_RESPONSE" exit_fail "Expected 200 ok, getting order info before claming it. got: $STATUS" fi PAY_URL=$(jq -e -r .taler_pay_uri < "$LAST_RESPONSE") echo "Ok (order $ORDER_ID)" NOW=$(date +%s) echo -n "Claim the order but do not pay it ..." taler-wallet-cli \ --no-throttle \ --wallet-db="$WALLET_DB" \ advanced pay-prepare \ "${PAY_URL}" \ 2> wallet-claim1.err > wallet-claim1.log STATUS=$(curl "http://localhost:9966/instances/default/private/orders/${ORDER_ID}" \ -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then cat "$LAST_RESPONSE" exit_fail "Expected 200 ok, after pay. got: $STATUS" fi ORDER_STATUS=$(jq -r .order_status < "$LAST_RESPONSE") if [ "$ORDER_STATUS" != "claimed" ] then cat "$LAST_RESPONSE" exit_fail "Expected 'paid'. got: $ORDER_STATUS" fi NOW2=$(date +%s) echo " OK (took $(( NOW2 - NOW)) secs)" echo "Wait 8 secs ..." sleep 8 echo -n "Trying to get the list of orders..." STATUS=$(curl "http://localhost:9966/instances/default/private/orders" \ -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then cat "$LAST_RESPONSE" exit_fail "Expected 200 ok. got: $STATUS" fi echo "ok" echo -n "Creating a new order that will trigger the db cleanup..." STATUS=$(curl 'http://localhost:9966/instances/default/private/orders' \ -d '{"order":{"amount":"TESTKUDOS:1","summary":"payme"}}' \ -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then cat "$LAST_RESPONSE" exit_fail "Expected 200 ok, order created. got: $STATUS" fi ORDER_ID=$(jq -e -r .order_id < "$LAST_RESPONSE") TOKEN=$(jq -e -r .token < "$LAST_RESPONSE") STATUS=$(curl "http://localhost:9966/instances/default/private/orders/${ORDER_ID}" \ -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then cat "$LAST_RESPONSE" exit_fail "Expected 200 ok, getting order info before claming it. got: $STATUS" fi PAY_URL=$(jq -e -r .taler_pay_uri < "$LAST_RESPONSE") echo "Ok (order $ORDER_ID)" echo -n "Trying to get the list of orders (issue #7025)..." STATUS=$(curl "http://localhost:9966/instances/default/private/orders" \ -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then cat "$LAST_RESPONSE" exit_fail "Expected 200 ok. got: $STATUS" fi echo "OK" # set -x echo -n "Now paying this order..." taler-wallet-cli \ --no-throttle \ --wallet-db="$WALLET_DB" \ handle-uri "${PAY_URL}"\ -y \ 2> wallet-pay1.err > wallet-pay1.log STATUS=$(curl "http://localhost:9966/instances/default/private/orders/${ORDER_ID}" \ -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then cat "$LAST_RESPONSE" exit_fail "Expected 200 ok, after pay. got: $STATUS" fi ORDER_STATUS=$(jq -r .order_status < "$LAST_RESPONSE") if [ "$ORDER_STATUS" != "paid" ] then cat "$LAST_RESPONSE" exit_fail "Expected 'paid'. got: $ORDER_STATUS" fi NOW2=$(date +%s) echo " OK (took $(( NOW2 - NOW)) secs )" echo -n "Trying to get the list of orders..." STATUS=$(curl "http://localhost:9966/instances/default/private/orders" \ -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then cat "$LAST_RESPONSE" exit_fail "Expected 200 ok. got: $STATUS" fi echo ok echo -n "Finally, create another order..." STATUS=$(curl 'http://localhost:9966/instances/default/private/orders' \ -d '{"order":{"amount":"TESTKUDOS:1","summary":"payme"}}' \ -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then cat "$LAST_RESPONSE" exit_fail "Expected 200 ok, order created. got: $STATUS" fi ORDER_ID=$(jq -e -r .order_id < "$LAST_RESPONSE") TOKEN=$(jq -e -r .token < "$LAST_RESPONSE") STATUS=$(curl "http://localhost:9966/instances/default/private/orders/${ORDER_ID}" \ -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then cat "$LAST_RESPONSE" exit_fail "Expected 200 ok, getting order info before claiming it. got: $STATUS" fi PAY_URL=$(jq -e -r .taler_pay_uri < "$LAST_RESPONSE") echo "Ok (order $ORDER_ID)" echo -n "Now paying this order..." taler-wallet-cli \ --no-throttle \ --wallet-db="$WALLET_DB" \ handle-uri \ "${PAY_URL}" \ -y \ 2> wallet-pay1.err > wallet-pay1.log STATUS=$(curl "http://localhost:9966/instances/default/private/orders/${ORDER_ID}" \ -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then cat "$LAST_RESPONSE" exit_fail "Expected 200 ok. got: $STATUS" fi ORDER_STATUS=$(jq -r .order_status < "$LAST_RESPONSE") if [ "$ORDER_STATUS" != "paid" ] then cat "$LAST_RESPONSE" exit_fail "Expected 'paid'. got: $ORDER_STATUS" fi NOW2=$(date +%s) echo " OK (took $( echo -n $(($NOW2 - $NOW)) ) secs )" echo -n "Trying to get the list of orders..." STATUS=$(curl "http://localhost:9966/instances/default/private/orders" \ -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then cat "$LAST_RESPONSE" exit_fail "Expected 200 ok. got: $STATUS" fi echo "ok" echo "Test PASSED" exit 0