diff options
author | Christian Grothoff <christian@grothoff.org> | 2023-06-22 16:30:55 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2023-06-22 16:30:55 +0200 |
commit | 99543152e9ddb1aab29d4e69dffb26c97d36040a (patch) | |
tree | a15f35206bf35183e986add028e684d59f31c310 /src/testing/test_merchant_order_creation.sh | |
parent | 52c49785fe20844a52f083de4adf9fea6e0c403d (diff) | |
download | merchant-99543152e9ddb1aab29d4e69dffb26c97d36040a.tar.gz merchant-99543152e9ddb1aab29d4e69dffb26c97d36040a.tar.bz2 merchant-99543152e9ddb1aab29d4e69dffb26c97d36040a.zip |
-clean up test scripts
Diffstat (limited to 'src/testing/test_merchant_order_creation.sh')
-rwxr-xr-x | src/testing/test_merchant_order_creation.sh | 332 |
1 files changed, 159 insertions, 173 deletions
diff --git a/src/testing/test_merchant_order_creation.sh b/src/testing/test_merchant_order_creation.sh index 1b1aeb23..479caeaa 100755 --- a/src/testing/test_merchant_order_creation.sh +++ b/src/testing/test_merchant_order_creation.sh @@ -3,36 +3,48 @@ set -eu -. initialize_taler_system.sh - -# $1: sandbox username -# $2: sandbox password -# $3: payto with subject -# $4: amount -function wire_funds() { - libeufin-cli sandbox demobank new-transaction +function clean_wallet() { + rm -f "${WALLET_DB}" + exit_cleanup } +. 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/" + +# Install cleanup handler (except for kill -9) +trap clean_wallet EXIT + echo -n "First prepare wallet with coins ..." -rm $WALLET_DB -taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB api --expect-success 'withdrawTestBalance' \ +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 BANK_URL "${BANK_URL}access-api/" \ --arg EXCHANGE_URL "$EXCHANGE_URL" )" 2>wallet-withdraw-1.err >wallet-withdraw-1.out -taler-wallet-cli --wallet-db=$WALLET_DB run-until-done 2>wallet-withdraw-finish-1.err >wallet-withdraw-finish-1.out +# FIXME-MS: add logic to have nexus check immediately here. +sleep 10 +# 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 +taler-wallet-cli --wallet-db="$WALLET_DB" run-until-done 2>wallet-withdraw-finish-1.err >wallet-withdraw-finish-1.out echo " OK" -CURRENCY_COUNT=$(taler-wallet-cli --wallet-db=$WALLET_DB balance | jq '.balances|length') +CURRENCY_COUNT=$(taler-wallet-cli --wallet-db="$WALLET_DB" balance | jq '.balances|length') if [ "$CURRENCY_COUNT" = "0" ] then - echo 'should have at least one currency, withdrawal failed. check log.' - exit 1 + exit_fail "Expected least one currency, withdrawal failed. check log." fi # @@ -42,17 +54,16 @@ fi echo -n "Configuring merchant instance ..." # create with 2 address -FORTYTHREE=`get_payto_uri fortythree x` +FORTYTHREE=$(get_payto_uri fortythree x) 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'"},{"payto_uri":"payto://iban/SANDBOXX/DE270744?receiver-name=Forty+Four"}],"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" : 50000000000},"default_pay_delay":{"d_us": 60000000000}}' \ + -d '{"auth":{"method":"external"},"accounts":[{"payto_uri":"'"$FORTYTHREE"'"},{"payto_uri":"payto://iban/SANDBOXX/DE270744?receiver-name=Forty+Four"}],"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" : 50000000000},"default_pay_delay":{"d_us": 60000000000}}' \ -w "%{http_code}" -s -o /dev/null) if [ "$STATUS" != "204" ] then - echo "Expected '204 No content' response. Got instead $STATUS" - exit 1 + exit_fail "Expected '204 No content' response. Got instead $STATUS" fi # remove one account address @@ -60,13 +71,12 @@ fi STATUS=$(curl -H "Content-Type: application/json" -X PATCH \ -H 'Authorization: Bearer secret-token:super_secret' \ http://localhost:9966/instances/default/private/ \ - -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" : 50000000000},"default_pay_delay":{"d_us": 60000000000}}' \ + -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" : 50000000000},"default_pay_delay":{"d_us": 60000000000}}' \ -w "%{http_code}" -s -o /dev/null) if [ "$STATUS" != "204" ] then - echo "Expected '204 No content' response. Got instead: $STATUS" - exit 1 + exit_fail "Expected '204 No content' response. Got instead: $STATUS" fi echo "OK" @@ -78,37 +88,33 @@ RANDOM_IMG='data:image/png;base64,abcdefg' echo -n "Creating order without TOKEN..." STATUS=$(curl 'http://localhost:9966/instances/default/private/orders' \ - -d '{"create_token":false,"order":{"amount":"TESTKUDOS:7","summary":"3","products":[{"description":"desct","image":"'$RANDOM_IMG'","price":"TESTKUDOS:1","taxes":[],"unit":"u","quantity":1}]}}' \ - -w "%{http_code}" -s -o $LAST_RESPONSE) + -d '{"create_token":false,"order":{"amount":"TESTKUDOS:7","summary":"3","products":[{"description":"desct","image":"'"$RANDOM_IMG"'","price":"TESTKUDOS:1","taxes":[],"unit":"u","quantity":1}]}}' \ + -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then - echo 'should response ok, order created. got:' $STATUS `cat $LAST_RESPONSE` - exit 1 + cat "$LAST_RESPONSE" >&2 + exit_fail "Expected 200, order created. got: $STATUS" fi -ORDER_ID=`jq -r .order_id < $LAST_RESPONSE` -TOKEN=`jq -r .token < $LAST_RESPONSE` +ORDER_ID=$(jq -r .order_id < "$LAST_RESPONSE") +TOKEN=$(jq -r .token < "$LAST_RESPONSE") if [ "$TOKEN" != "null" ] then - echo 'token should be null, got:' $TOKEN - exit 1 + exit_fail "token should be null, got: $TOKEN" fi echo "OK" echo -n "Checking created order without TOKEN..." - -STATUS=$(curl http://localhost:9966/orders/$ORDER_ID \ - -w "%{http_code}" -s -o $LAST_RESPONSE) - -PAY_URI=`jq -r .taler_pay_uri < $LAST_RESPONSE` - +STATUS=$(curl http://localhost:9966/orders/"$ORDER_ID" \ + -w "%{http_code}" -s -o "$LAST_RESPONSE") +PAY_URI=$(jq -r .taler_pay_uri < "$LAST_RESPONSE") if [ "$PAY_URI" == "null" ] then - echo 'should have a payuri. got:' $PAY_URI `cat $LAST_RESPONSE` - exit 1 + cat "$LAST_RESPONSE" >&2 + exit_fail "Expected non-NULL payuri. got $PAY_URI" fi echo "OK" @@ -118,40 +124,39 @@ echo "OK" echo -n "Creating order without TOKEN and fullfilment URL..." STATUS=$(curl 'http://localhost:9966/instances/default/private/orders' \ - -d '{"create_token":false,"order":{"fulfillment_url":"go_here_please", "amount":"TESTKUDOS:7","summary":"3","products":[{"description":"desct","image":"'$RANDOM_IMG'","price":"TESTKUDOS:1","taxes":[],"unit":"u","quantity":1}]}}' \ - -w "%{http_code}" -s -o $LAST_RESPONSE) + -d '{"create_token":false,"order":{"fulfillment_url":"go_here_please", "amount":"TESTKUDOS:7","summary":"3","products":[{"description":"desct","image":"'"$RANDOM_IMG"'","price":"TESTKUDOS:1","taxes":[],"unit":"u","quantity":1}]}}' \ + -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then - echo 'should response ok, order created. got:' $STATUS `cat $LAST_RESPONSE` - exit 1 + cat "$LAST_RESPONSE" >&2 + exit_fail "Expected 200, order created. got: $STATUS" fi -ORDER_ID=`jq -r .order_id < $LAST_RESPONSE` -TOKEN=`jq -r .token < $LAST_RESPONSE` +ORDER_ID=$(jq -r .order_id < "$LAST_RESPONSE") +TOKEN=$(jq -r .token < "$LAST_RESPONSE") if [ "$TOKEN" != "null" ] then - echo 'token should be null, got:' $TOKEN - exit 1 + exit_fail "Token should be null, got: $TOKEN" fi -STATUS=$(curl http://localhost:9966/orders/$ORDER_ID \ - -w "%{http_code}" -s -o $LAST_RESPONSE) +STATUS=$(curl http://localhost:9966/orders/"$ORDER_ID" \ + -w "%{http_code}" -s -o "$LAST_RESPONSE") -PAY_URI=`jq -r .taler_pay_uri < $LAST_RESPONSE` -FULLFILMENT_URL=`jq -r .fulfillment_url < $LAST_RESPONSE` +PAY_URI=$(jq -r .taler_pay_uri < "$LAST_RESPONSE") +FULLFILMENT_URL=$(jq -r .fulfillment_url < "$LAST_RESPONSE") if [ "$FULLFILMENT_URL" != "go_here_please" ] then - echo 'should have a payuri. got:' $PAY_URI `cat $LAST_RESPONSE` - exit 1 + cat "$LAST_RESPONSE" >&2 + exit_fail "Expected a pay URI. got: $PAY_URI" fi if [ "$PAY_URI" == "null" ] then - echo 'should have a payuri. got:' $PAY_URI `cat $LAST_RESPONSE` - exit 1 + cat "$LAST_RESPONSE" >&2 + exit_fail "Expected non-NULL pay URI. Got: $PAY_URI" fi echo "OK" @@ -161,40 +166,38 @@ echo "OK" echo -n "Creating order with non-inventory products..." STATUS=$(curl 'http://localhost:9966/instances/default/private/orders' \ - -d '{"order":{"amount":"TESTKUDOS:7","summary":"3","products":[{"description":"desct","image":"'$RANDOM_IMG'","price":"TESTKUDOS:1","taxes":[],"unit":"u","quantity":1}]}}' \ - -w "%{http_code}" -s -o $LAST_RESPONSE) + -d '{"order":{"amount":"TESTKUDOS:7","summary":"3","products":[{"description":"desct","image":"'"$RANDOM_IMG"'","price":"TESTKUDOS:1","taxes":[],"unit":"u","quantity":1}]}}' \ + -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then - echo 'should response ok, order created. got:' $STATUS `cat $LAST_RESPONSE` - exit 1 + cat "$LAST_RESPONSE" >&2 + exit_fail "Expected 200, order created. got: $STATUS" fi -ORDER_ID=`jq -r .order_id < $LAST_RESPONSE` -TOKEN=`jq -r .token < $LAST_RESPONSE` +ORDER_ID=$(jq -r .order_id < "$LAST_RESPONSE") +TOKEN=$(jq -r .token < "$LAST_RESPONSE") -STATUS=$(curl http://localhost:9966/orders/$ORDER_ID/claim \ - -d '{"nonce":"","token":"'$TOKEN'"}' \ - -w "%{http_code}" -s -o $LAST_RESPONSE) +STATUS=$(curl http://localhost:9966/orders/"$ORDER_ID"/claim \ + -d '{"nonce":"","token":"'"$TOKEN"'"}' \ + -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then - echo 'should response ok, order claimed. got:' $STATUS `cat $LAST_RESPONSE` - exit 1 + cat "$LAST_RESPONSE" >&2 + exit_fail "Expected 200, order claimed. got: $STATUS" fi -QUANTITY=`jq -r .contract_terms.products[0].quantity < $LAST_RESPONSE` +QUANTITY=$(jq -r .contract_terms.products[0].quantity < "$LAST_RESPONSE") if [ "$QUANTITY" != "1" ] then - echo 'should get quantity 1. got:' $QUANTITY # `jq .contract_terms.products[0] < $LAST_RESPONSE` - exit 1 + exit_fail "Expected quantity 1. got: $QUANTITY" fi -IMAGE=`jq -r .contract_terms.products[0].image < $LAST_RESPONSE` +IMAGE=$(jq -r .contract_terms.products[0].image < "$LAST_RESPONSE") if [ "$IMAGE" != "$RANDOM_IMG" ] then - echo 'should get image but got something else. got:' $IMAGE - exit 1 + exit_fail "Expected $RANDOM_IMG but got something else: $IMAGE" fi echo "OK" @@ -210,42 +213,40 @@ STATUS=$(curl 'http://localhost:9966/instances/default/private/products' \ if [ "$STATUS" != "204" ] then - echo 'should respond ok, product created. got:' $STATUS - exit 1 + exit_fail "Expected 204, product created. got: $STATUS" fi echo "OK" echo -n "Creating order with inventory products..." STATUS=$(curl 'http://localhost:9966/instances/default/private/orders' \ -d '{"order":{"amount":"TESTKUDOS:7","summary":"3"},"inventory_products":[{"product_id":"2","quantity":1}]}' \ - -w "%{http_code}" -s -o $LAST_RESPONSE) + -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then - echo 'Expected 200 OK, order created response. Got:' $STATUS `cat $LAST_RESPONSE` - exit 1 + jq . < "$LAST_RESPONSE" + exit_fail "Expected 200 OK, order created response. Got: $STATUS" fi -ORDER_ID=`jq -e -r .order_id < $LAST_RESPONSE` -TOKEN=`jq -e -r .token < $LAST_RESPONSE` +ORDER_ID=$(jq -e -r .order_id < "$LAST_RESPONSE") +TOKEN=$(jq -e -r .token < "$LAST_RESPONSE") -STATUS=$(curl http://localhost:9966/orders/$ORDER_ID/claim \ - -d '{"nonce":"","token":"'$TOKEN'"}' \ - -w "%{http_code}" -s -o $LAST_RESPONSE) +STATUS=$(curl http://localhost:9966/orders/"$ORDER_ID"/claim \ + -d '{"nonce":"","token":"'"$TOKEN"'"}' \ + -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then - echo 'should response ok, order claimed. got:' $STATUS `cat $LAST_RESPONSE` - exit 1 + jq . < "$LAST_RESPONSE" + exit_fail "Expected 200, order claimed. got: $STATUS" fi -QUANTITY=`jq -r .contract_terms.products[0].quantity < $LAST_RESPONSE` +QUANTITY=$(jq -r .contract_terms.products[0].quantity < "$LAST_RESPONSE") if [ "$QUANTITY" != "1" ] then - echo 'should get quantity 1. got:' $QUANTITY #`jq .contract_terms.products[0] < $LAST_RESPONSE` - exit 1 + exit_fail "Expected quantity 1. got: $QUANTITY" fi echo "OK" @@ -261,8 +262,7 @@ STATUS=$(curl 'http://localhost:9966/instances/default/private/products' \ if [ "$STATUS" != "400" ] then - echo 'should respond bad request, product price is in another currency. got:' $STATUS - exit 1 + exit_fail "Expected 400 bad request, product price is in another currency. got: $STATUS" fi # @@ -272,72 +272,76 @@ fi echo -n "Creating order to be paid..." STATUS=$(curl 'http://localhost:9966/instances/default/private/orders' \ -d '{"order":{"amount":"TESTKUDOS:1","summary":"payme"},"inventory_products":[{"product_id":"2","quantity":1}]}' \ - -w "%{http_code}" -s -o $LAST_RESPONSE) + -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then - echo 'should response ok, order created. got:' $STATUS `cat $LAST_RESPONSE` - exit 1 + jq . < "$LAST_RESPONSE" + exit_fail "Expected 200, order created. got: $STATUS" fi -ORDER_ID=`jq -e -r .order_id < $LAST_RESPONSE` -TOKEN=`jq -e -r .token < $LAST_RESPONSE` +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) + -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then - echo 'should response ok, getting order info before claming it. got:' $STATUS `cat $LAST_RESPONSE` - exit 1 + jq . < "$LAST_RESPONSE" + exit_fail "Expected 200, getting order info before claming it. got: $STATUS" fi -PAY_URL=`jq -e -r .taler_pay_uri < $LAST_RESPONSE` +PAY_URL=$(jq -e -r .taler_pay_uri < "$LAST_RESPONSE") echo "OK" -NOW=`date +%s` +NOW=$(date +%s) echo -n "Pay first order ${PAY_URL} ..." -taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB handle-uri "${PAY_URL}" -y 2> wallet-pay1.err > wallet-pay1.log -taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB run-until-done 2> wallet-finish-pay1.err > wallet-finish-pay1.log -NOW2=`date +%s` -echo " OK (took $( echo -n $(($NOW2 - $NOW)) ) secs )" +taler-wallet-cli --no-throttle --wallet-db="$WALLET_DB" handle-uri "${PAY_URL}" -y 2> wallet-pay1.err > wallet-pay1.log +taler-wallet-cli --no-throttle --wallet-db="$WALLET_DB" run-until-done 2> wallet-finish-pay1.err > wallet-finish-pay1.log +NOW2=$(date +%s) +echo " OK (took $(( NOW2 - NOW )) secs )" STATUS=$(curl "http://localhost:9966/instances/default/private/orders/${ORDER_ID}" \ - -w "%{http_code}" -s -o $LAST_RESPONSE) + -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then - echo 'should response ok, after pay. got:' $STATUS `cat $LAST_RESPONSE` - exit 1 + jq . < "$LAST_RESPONSE" + exit_fail "Expected 200, after pay. got: $STATUS" fi -ORDER_STATUS=`jq -r .order_status < $LAST_RESPONSE` +ORDER_STATUS=$(jq -r .order_status < "$LAST_RESPONSE") if [ "$ORDER_STATUS" != "paid" ] then - echo "Order status should be 'paid'. got:" $ORDER_STATUS `cat $LAST_RESPONSE` - exit 1 + jq . < "$LAST_RESPONSE" + exit_fail "Order status should be 'paid'. got: $ORDER_STATUS" fi # # WIRE TRANSFER TO MERCHANT AND NOTIFY BACKEND # -PAY_DEADLINE=`jq -r .contract_terms.pay_deadline.t_s < $LAST_RESPONSE` -WIRE_DEADLINE=`jq -r .contract_terms.wire_transfer_deadline.t_s < $LAST_RESPONSE` +# PAY_DEADLINE=$(jq -r .contract_terms.pay_deadline.t_s < "$LAST_RESPONSE") +WIRE_DEADLINE=$(jq -r .contract_terms.wire_transfer_deadline.t_s < "$LAST_RESPONSE") -NOW=`date +%s` +NOW=$(date +%s) -TO_SLEEP=`echo $(( $WIRE_DEADLINE - $NOW ))` +TO_SLEEP=$(( WIRE_DEADLINE - NOW )) echo "Waiting $TO_SLEEP secs for wire transfer" echo -n "Perform wire transfers ..." -taler-exchange-aggregator -y -c $CONF -T ${TO_SLEEP}000000 -t -L INFO &> aggregator.log -taler-exchange-transfer -c $CONF -t -L INFO &> transfer.log +taler-exchange-aggregator -y -c "$CONF" -T "${TO_SLEEP}"000000 -t -L INFO &> aggregator.log +taler-exchange-transfer -c "$CONF" -t -L INFO &> transfer.log echo " DONE" echo -n "Give time to Nexus to route the payment to Sandbox..." +# FIXME-MS: trigger immediate update at nexus +# NOTE: once libeufin can do long-polling, we should +# be able to reduce the delay here and run aggregator/transfer +# always in the background via setup sleep 3 echo " DONE" @@ -346,12 +350,12 @@ echo -n "Obtaining wire transfer details from bank..." # the wire transfer information _via the exchange_ bank # account. NOTE: grabbing tx == 0, since the latest # transaction appear first in the bank's history. -BANKDATA=`get_bankaccount_transactions exchange x | jq '.transactions[0]'` -SUBJECT=`echo $BANKDATA | jq -r .subject` -WTID=`echo $SUBJECT | awk '{print $1}'` -WURL=`echo $SUBJECT | awk '{print $2}'` -CREDIT_AMOUNT="`echo $BANKDATA | jq -r .currency`:`echo $BANKDATA | jq -r .amount`" -TARGET=`echo $BANKDATA | jq -r .creditorIban` +BANKDATA=$(get_bankaccount_transactions exchange x | jq '.transactions[0]') +SUBJECT=$(echo "$BANKDATA" | jq -r .subject) +WTID=$(echo "$SUBJECT" | awk '{print $1}') +WURL=$(echo "$SUBJECT" | awk '{print $2}') +CREDIT_AMOUNT="$(echo "$BANKDATA" | jq -r .currency):$(echo "$BANKDATA" | jq -r .amount)" +TARGET=$(echo "$BANKDATA" | jq -r .creditorIban) # 'TARGET' is now the IBAN. TARGET_PAYTO="payto://iban/SANDBOXX/$TARGET?receiver-name=Forty+Three" @@ -373,13 +377,13 @@ export LAST_RESPONSE echo -n "Notifying merchant of bogus wire transfer ..." STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \ - -d '{"credit_amount":"'$CREDIT_AMOUNT'1","wtid":"'$WTID'","payto_uri":"'$TARGET_PAYTO'","exchange_url":"'$WURL'"}' \ + -d '{"credit_amount":"'"$CREDIT_AMOUNT"'1","wtid":"'"$WTID"'","payto_uri":"'"$TARGET_PAYTO"'","exchange_url":"'"$WURL"'"}' \ -m 3 \ - -w "%{http_code}" -s -o $LAST_RESPONSE) + -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "204" ] then - jq . < $LAST_RESPONSE + jq . < "$LAST_RESPONSE" exit_fail "Expected to fail since the amount is not valid. got: $STATUS" fi @@ -388,13 +392,13 @@ echo "OK" echo -n "Notifying merchant of correct wire transfer (conflicting with old data)..." STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \ - -d '{"credit_amount":"'$CREDIT_AMOUNT'","wtid":"'$WTID'","payto_uri":"'$TARGET_PAYTO'","exchange_url":"'$WURL'"}' \ + -d '{"credit_amount":"'"$CREDIT_AMOUNT"'","wtid":"'"$WTID"'","payto_uri":"'"$TARGET_PAYTO"'","exchange_url":"'"$WURL"'"}' \ -m 3 \ - -w "%{http_code}" -s -o $LAST_RESPONSE) + -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "409" ] then - jq . < $LAST_RESPONSE + jq . < "$LAST_RESPONSE" exit_fail "Expected response conflict, after providing conflicting transfer data. got: $STATUS" fi @@ -402,23 +406,23 @@ echo " OK" echo -n "Deleting bogus wire transfer ..." -TID=`curl -s http://localhost:9966/instances/default/private/transfers | jq -r .transfers[0].transfer_serial_id` +TID=$(curl -s http://localhost:9966/instances/default/private/transfers | jq -r .transfers[0].transfer_serial_id) STATUS=$(curl -H "Content-Type: application/json" -X DELETE \ "http://localhost:9966/instances/default/private/transfers/$TID" \ - -w "%{http_code}" -s -o $LAST_RESPONSE) + -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "204" ] then - jq . < $LAST_RESPONSE + jq . < "$LAST_RESPONSE" exit_fail "Expected response 204 No Content, after deleting valid TID. got: $STATUS" fi STATUS=$(curl -H "Content-Type: application/json" -X DELETE \ "http://localhost:9966/instances/default/private/transfers/$TID" \ - -w "%{http_code}" -s -o $LAST_RESPONSE) + -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "404" ] then - jq . < $LAST_RESPONSE + jq . < "$LAST_RESPONSE" exit_fail "Expected response 404 Not found, after deleting TID again. got: $STATUS" fi @@ -427,13 +431,13 @@ echo " OK" echo -n "Notifying merchant of correct wire transfer (now working)..." STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \ - -d '{"credit_amount":"'$CREDIT_AMOUNT'","wtid":"'$WTID'","payto_uri":"'$TARGET_PAYTO'","exchange_url":"'$WURL'"}' \ + -d '{"credit_amount":"'"$CREDIT_AMOUNT"'","wtid":"'"$WTID"'","payto_uri":"'"$TARGET_PAYTO"'","exchange_url":"'"$WURL"'"}' \ -m 3 \ - -w "%{http_code}" -s -o $LAST_RESPONSE) + -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "204" ] then - jq . < $LAST_RESPONSE + jq . < "$LAST_RESPONSE" exit_fail "Expected response 204 No content, after providing transfer data. got: $STATUS" fi @@ -446,65 +450,57 @@ set -e # Test idempotence: do it again! STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \ - -d '{"credit_amount":"'$CREDIT_AMOUNT'","wtid":"'$WTID'","payto_uri":"'$TARGET_PAYTO'","exchange_url":"'$WURL'"}' \ - -w "%{http_code}" -s -o $LAST_RESPONSE) + -d '{"credit_amount":"'"$CREDIT_AMOUNT"'","wtid":"'"$WTID"'","payto_uri":"'"$TARGET_PAYTO"'","exchange_url":"'"$WURL"'"}' \ + -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "204" ] then - jq . < $LAST_RESPONSE + jq . < "$LAST_RESPONSE" exit_fail "Expected response No Content, after providing transfer data. got: $STATUS" fi echo " OK" echo -n "Testing taler-merchant-exchange ..." set -e -taler-merchant-exchange -L INFO -c $CONF -t &> taler-merchant-exchange.log +taler-merchant-exchange -L INFO -c "$CONF" -t &> taler-merchant-exchange.log echo " OK" echo -n "Fetching wire transfers ..." STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \ - -w "%{http_code}" -s -o $LAST_RESPONSE) + -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then - jq . < $LAST_RESPONSE + jq . < "$LAST_RESPONSE" exit_fail "Expected response 200 Ok. got: $STATUS" fi -TRANSFERS_LIST_SIZE=`jq -r '.transfers | length' < $LAST_RESPONSE` +TRANSFERS_LIST_SIZE=$(jq -r '.transfers | length' < "$LAST_RESPONSE") if [ "$TRANSFERS_LIST_SIZE" != "1" ] then - jq . < $LAST_RESPONSE + jq . < "$LAST_RESPONSE" exit_fail "Expected 1 entry in transfer list. Got: $TRANSFERS_LIST_SIZE" fi echo "OK" echo -n "Checking order status ..." - STATUS=$(curl "http://localhost:9966/instances/default/private/orders/${ORDER_ID}?transfer=YES" \ - -w "%{http_code}" -s -o $LAST_RESPONSE) - - - + -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then - jq . < $LAST_RESPONSE - exit_fail 'should respond 200 ok, after order inquiry. got:' $STATUS `cat $LAST_RESPONSE` - exit 1 + jq . < "$LAST_RESPONSE" + exit_fail "Expected 200, after order inquiry. got: $STATUS" fi - -DEPOSIT_TOTAL=`jq -r .deposit_total < $LAST_RESPONSE` - +DEPOSIT_TOTAL=$(jq -r .deposit_total < "$LAST_RESPONSE") if [ "$DEPOSIT_TOTAL" == "TESTKUDOS:0" ] then - echo 'deposit total is zero, expected greater than zero. got:' $DEPOSIT_TOTAL `cat $LAST_RESPONSE` - exit 1 + jq . < "$LAST_RESPONSE" + exit_fail "Expected non-zero deposit total. got: $DEPOSIT_TOTAL" fi - echo " OK" ACCOUNT_PASSWORD="fortythree:x" @@ -512,39 +508,29 @@ BANK_HOST="localhost:18082" # Can be replaced by the libeufin-cli way. STATUS=$(curl "http://$ACCOUNT_PASSWORD@$BANK_HOST/demobanks/default/access-api/accounts/fortythree" \ - -w "%{http_code}" -s -o $LAST_RESPONSE) - + -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then - jq . < $LAST_RESPONSE - echo "Expected response 200 Ok, getting account status. Got: $STATUS" - exit 1 + jq . < "$LAST_RESPONSE" + exit_fail "Expected response 200 Ok, getting account status. Got: $STATUS" fi - -BALANCE=`jq -r .balance.amount < $LAST_RESPONSE` - +BALANCE=$(jq -r .balance.amount < "$LAST_RESPONSE") if [ "$BALANCE" == "TESTKUDOS:0" ] then - jq . < $LAST_RESPONSE - echo "Wire transfer did not happen. Got: $BALANCE" - exit 1 + jq . < "$LAST_RESPONSE" + exit_fail "Wire transfer did not happen. Got: $BALANCE" fi - echo " OK" echo -n "Getting information about kyc ..." - STATUS=$(curl -H "Content-Type: application/json" -X GET \ http://localhost:9966/instances/default/private/kyc \ -w "%{http_code}" -s -o /dev/null) - if [ "$STATUS" != "204" ] then - echo 'should respond ok, instance created. got:' $STATUS - exit 1 + exit_fail "Expected 204. Got: $STATUS" fi - echo " OK" exit 0 |