From 0c8b2ddbaa4a93f1192e949181a4818f800d23d3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 19 Apr 2021 15:49:06 +0200 Subject: -fix test --- src/testing/test_merchant_order_creation.sh | 70 ++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 6 deletions(-) (limited to 'src/testing/test_merchant_order_creation.sh') diff --git a/src/testing/test_merchant_order_creation.sh b/src/testing/test_merchant_order_creation.sh index 065c5274..5d856161 100755 --- a/src/testing/test_merchant_order_creation.sh +++ b/src/testing/test_merchant_order_creation.sh @@ -114,7 +114,7 @@ then exit 1 fi -echo -n "Creating order to be pay..." +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) @@ -198,27 +198,85 @@ WIRE_DEADLINE=`jq -r .contract_terms.wire_transfer_deadline.t_ms < $LAST_RESPONS NOW=`date +%s` TO_SLEEP=`echo $(( ($WIRE_DEADLINE /1000) - $NOW ))` -echo wating $TO_SLEEP secs for wire transfer -sleep $TO_SLEEP -sleep 2 # wait a little more +echo waiting $TO_SLEEP secs for wire transfer +# FIXME: we could do this with timetravel instead of sleeping! +# sleep $TO_SLEEP + +echo -n "Perform wire transfers ..." +taler-exchange-aggregator -c $CONF -T ${TO_SLEEP}000000 -t -L INFO +taler-exchange-transfer -c $CONF -t -L INFO +echo " DONE" + +echo -n "Notifying merchant of wire transfer ..." + +# First, extract the wire transfer data from the bank. +# As there is no "nice" API, we do this by dumping the +# bank database and grabbing the 'right' wire transfer, +# which is the one outgoing from the exchange (account 2). +BANKDATA=`taler-bank-manage -c $CONF django dumpdata 2>/dev/null | tail -n1 | jq '.[] | select(.model=="app.banktransaction")' | jq 'select(.fields.debit_account==2)'` +SUBJECT=`echo $BANKDATA | jq -r .fields.subject` +WTID=`echo $SUBJECT | awk '{print $1}'` +WURL=`echo $SUBJECT | awk '{print $2}'` +CREDIT_AMOUNT=`echo $BANKDATA | jq -r .fields.amount` +TARGET=`echo $BANKDATA | jq -r .fields.credit_account` +# 'TARGET' is now the numeric value of the account, we need to get the actual account *name*: +BANKADATA=`taler-bank-manage -c $CONF django dumpdata 2>/dev/null | tail -n1 | jq '.[] | select(.model=="auth.user")' | jq 'select(.pk=='$TARGET')'` +ACCOUNT_NAME=`echo $BANKADATA | jq -r .fields.username` +TARGET_PAYTO="payto://x-taler-bank/localhost:8082/$ACCOUNT_NAME" + +if [ "$EXCHANGE_URL" != "$WURL" ] +then + exit_fail "Wrong exchange URL in subject '$SUBJECT', expected $EXCHANGE_URL" +fi + +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) + +if [ "$STATUS" != "200" ] +then + echo `cat $LAST_RESPONSE` + bash + exit_fail "Expected response ok, after providing transfer data. got: $STATUS" +fi + +# 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) + +if [ "$STATUS" != "200" ] +then + echo `cat $LAST_RESPONSE` + exit_fail "Expected response ok, after providing transfer data. got: $STATUS" +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) if [ "$STATUS" != "200" ] then - echo 'should response ok, after pay. got:' $STATUS `cat $LAST_RESPONSE` + exit_fail 'should response ok, after order inquiry. got:' $STATUS `cat $LAST_RESPONSE` exit 1 fi + 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` + bash exit 1 fi +echo " OK" + echo Removing password from account 43 taler-bank-manage -c $CONF --with-db postgres:///$TALER_DB django changepassword_unsafe 43 x >/dev/null 2>/dev/null @@ -238,7 +296,7 @@ BALANCE=`jq -r .balance.amount < $LAST_RESPONSE` if [ "$BALANCE" == "TESTKUDOS:0" ] then - echo 'wire transfer did not happend. got:' $BALANCE + echo 'wire transfer did not happen. got:' $BALANCE echo 'going to sleep more, just in case...' sleep 62 -- cgit v1.2.3