summaryrefslogtreecommitdiff
path: root/src/testing/test_merchant_order_creation.sh
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-04-19 15:49:06 +0200
committerChristian Grothoff <christian@grothoff.org>2021-04-19 15:49:06 +0200
commit0c8b2ddbaa4a93f1192e949181a4818f800d23d3 (patch)
tree830c9352b9922eed8a836e1f9aca6546b262eae5 /src/testing/test_merchant_order_creation.sh
parent760c4183ea4c64495fb5048cd760a330a2edc9b2 (diff)
downloadmerchant-0c8b2ddbaa4a93f1192e949181a4818f800d23d3.tar.gz
merchant-0c8b2ddbaa4a93f1192e949181a4818f800d23d3.tar.bz2
merchant-0c8b2ddbaa4a93f1192e949181a4818f800d23d3.zip
-fix test
Diffstat (limited to 'src/testing/test_merchant_order_creation.sh')
-rwxr-xr-xsrc/testing/test_merchant_order_creation.sh70
1 files changed, 64 insertions, 6 deletions
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