diff options
Diffstat (limited to 'src/testing')
-rwxr-xr-x | src/testing/test_merchant_order_creation.sh | 144 |
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 |