summaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2021-04-19 02:53:08 -0300
committerSebastian <sebasjm@gmail.com>2021-04-19 02:53:34 -0300
commit03084c1c1e14f1b97d069fe6b76f73fbcffc6031 (patch)
treec7615c6d258d6642922c1c410f236882eb42add0 /src/testing
parent0e86010f0e15070fcb4cbd588a53a9573d6935a4 (diff)
downloadmerchant-03084c1c1e14f1b97d069fe6b76f73fbcffc6031.tar.gz
merchant-03084c1c1e14f1b97d069fe6b76f73fbcffc6031.tar.bz2
merchant-03084c1c1e14f1b97d069fe6b76f73fbcffc6031.zip
no balance after paying
Diffstat (limited to 'src/testing')
-rwxr-xr-xsrc/testing/test_merchant_order_creation.sh144
1 files changed, 142 insertions, 2 deletions
diff --git a/src/testing/test_merchant_order_creation.sh b/src/testing/test_merchant_order_creation.sh
index c865b98c..58d8e332 100755
--- a/src/testing/test_merchant_order_creation.sh
+++ b/src/testing/test_merchant_order_creation.sh
@@ -7,7 +7,7 @@ echo -n "Configuring merchant instance ..."
STATUS=$(curl -H "Content-Type: application/json" -X POST \
-H 'Authorization: Bearer secret-token:super_secret' \
http://localhost:9966/private/instances \
- -d '{"auth":{"method":"external"},"payto_uris":["payto://x-taler-bank/localhost/43"],"id":"default","name":"default","address":{},"jurisdiction":{},"default_max_wire_fee":"TESTKUDOS:1", "default_max_deposit_fee":"TESTKUDOS:1","default_wire_fee_amortization":1,"default_wire_transfer_delay":{"d_ms" : 3600000},"default_pay_delay":{"d_ms": 3600000}}' \
+ -d '{"auth":{"method":"external"},"payto_uris":["payto://x-taler-bank/localhost:8082/43"],"id":"default","name":"default","address":{},"jurisdiction":{},"default_max_wire_fee":"TESTKUDOS:1", "default_max_deposit_fee":"TESTKUDOS:1","default_wire_fee_amortization":1,"default_wire_transfer_delay":{"d_ms" : 50000},"default_pay_delay":{"d_ms": 60000}}' \
-w "%{http_code}" -s -o /dev/null)
if [ "$STATUS" != "204" ]
@@ -104,7 +104,6 @@ fi
echo "OK"
-
STATUS=$(curl 'http://localhost:9966/instances/default/private/products' \
-d '{"product_id":"1","description":"product with id 1 and price :15","price":"USD:15","total_stock":1,"description_i18n":{},"unit":"","image":"","taxes":[],"address":{},"next_restock":{"t_ms":"never"}}' \
-w "%{http_code}" -s -o /dev/null)
@@ -115,4 +114,145 @@ then
exit 1
fi
+echo -n "Creating order to be pay..."
+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)
+
+if [ "$STATUS" != "200" ]
+then
+ echo 'should response ok, order created. got:' $STATUS `cat $LAST_RESPONSE`
+ exit 1
+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
+ echo 'should response ok, getting order info before claming it. got:' $STATUS `cat $LAST_RESPONSE`
+ exit 1
+fi
+
+PAY_URL=`jq -e -r .taler_pay_uri < $LAST_RESPONSE`
+
+#FIXME cannot claim here because will be unable to pay
+
+# 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
+# fi
+echo OK
+
+# PAY_DEADLINE=`jq -r .contract_terms.pay_deadline.t_ms < $LAST_RESPONSE`
+# WIRE_DEADLINE=`jq -r .contract_terms.wire_transfer_deadline.t_ms < $LAST_RESPONSE`
+
+echo -n "First withdraw wallet"
+rm $WALLET_DB
+taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB api 'withdrawTestBalance' \
+ "$(jq -n '
+ {
+ amount: "TESTKUDOS:5",
+ bankBaseUrl: $BANK_URL,
+ exchangeBaseUrl: $EXCHANGE_URL
+ }' \
+ --arg BANK_URL "$BANK_URL" \
+ --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
+echo " OK"
+
+NOW=`date +%s`
+
+echo -n "Pay first order ..."
+taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB handle-uri "${PAY_URL}" -y 2> wallet-pay1.err > wallet-pay1.log
+NOW2=`date +%s`
+echo " OK (took $( echo -n $(($NOW2 - $NOW)) ) secs )"
+
+
+STATUS=$(curl "http://localhost:9966/instances/default/private/orders/${ORDER_ID}" \
+ -w "%{http_code}" -s -o $LAST_RESPONSE)
+
+if [ "$STATUS" != "200" ]
+then
+ echo 'should response ok, after pay. got:' $STATUS `cat $LAST_RESPONSE`
+ exit 1
+fi
+
+ORDER_STATUS=`jq -r .order_status < $LAST_RESPONSE`
+
+if [ "$ORDER_STATUS" != "paid" ]
+then
+ echo 'order should be paid. got:' $ORDER_STATUS `cat $LAST_RESPONSE`
+ exit 1
+fi
+
+PAY_DEADLINE=`jq -r .contract_terms.pay_deadline.t_ms < $LAST_RESPONSE`
+WIRE_DEADLINE=`jq -r .contract_terms.wire_transfer_deadline.t_ms < $LAST_RESPONSE`
+
+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
+
+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 1
+fi
+
+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
+
+ACCOUNT_PASSWORD="43:x"
+BANK_HOST="localhost:8082"
+
+STATUS=$(curl "http://$ACCOUNT_PASSWORD@$BANK_HOST/accounts/43" \
+ -w "%{http_code}" -s -o $LAST_RESPONSE)
+
+if [ "$STATUS" != "200" ]
+then
+ echo 'should response ok, getting account status. got:' $STATUS `cat $LAST_RESPONSE`
+ exit 1
+fi
+
+BALANCE=`jq -r .balance.amount < $LAST_RESPONSE`
+
+if [ "$BALANCE" == "TESTKUDOS:0" ]
+then
+ echo 'wire transfer did not happend. got:' $BALANCE
+ echo 'going to sleep more, just in case...'
+ sleep 62
+
+ STATUS=$(curl "http://$ACCOUNT_PASSWORD@$BANK_HOST/accounts/43" \
+ -w "%{http_code}" -s -o $LAST_RESPONSE)
+
+ if [ "$STATUS" != "200" ]
+ then
+ echo 'should response ok, getting account status. got:' $STATUS `cat $LAST_RESPONSE`
+ exit 1
+ fi
+
+ BALANCE=`jq -r .balance.amount < $LAST_RESPONSE`
+
+ if [ "$BALANCE" == "TESTKUDOS:0" ]
+ then
+ echo 'wire transfer did not happend. got:' $BALANCE `cat $LAST_RESPONSE`
+ exit 1
+ fi
+fi
+
exit 0