summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2021-06-16 00:42:13 -0300
committerSebastian <sebasjm@gmail.com>2021-06-16 00:42:16 -0300
commit1fa773793b24285205818c21c70fb72cd63fe6ba (patch)
treec6887412c0819fd8422419b6e5b8f3ddc9ce2332
parent9b2eae57e379402c05c5bce4db7d2cb7405dfbf9 (diff)
downloadmerchant-1fa773793b24285205818c21c70fb72cd63fe6ba.tar.gz
merchant-1fa773793b24285205818c21c70fb72cd63fe6ba.tar.bz2
merchant-1fa773793b24285205818c21c70fb72cd63fe6ba.zip
issue #6903
-rwxr-xr-xsrc/testing/test_merchant_order_creation.sh110
1 files changed, 70 insertions, 40 deletions
diff --git a/src/testing/test_merchant_order_creation.sh b/src/testing/test_merchant_order_creation.sh
index be2d0b81..bbababf0 100755
--- a/src/testing/test_merchant_order_creation.sh
+++ b/src/testing/test_merchant_order_creation.sh
@@ -3,6 +3,25 @@
. initialize_taler_system.sh
+echo -n "First prepare wallet with coins..."
+rm $WALLET_DB
+taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB api 'withdrawTestBalance' \
+ "$(jq -n '
+ {
+ amount: "TESTKUDOS:99",
+ 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"
+
+#
+# CREATE INSTANCE FOR TESTING
+#
+
echo -n "Configuring merchant instance ..."
# create with 2 address
@@ -36,17 +55,10 @@ fi
echo OK
RANDOM_IMG='data:image/png;base64,abcdefg'
-echo -n "Creating product..."
-STATUS=$(curl 'http://localhost:9966/instances/default/private/products' \
- -d '{"product_id":"2","description":"product with id 2 and price :15","price":"TESTKUDOS:15","total_stock":2,"description_i18n":{},"unit":"","image":"'$RANDOM_IMG'","taxes":[],"address":{},"next_restock":{"t_ms":"never"}}' \
- -w "%{http_code}" -s -o /dev/null)
-if [ "$STATUS" != "204" ]
-then
- echo 'should respond ok, product created. got:' $STATUS
- exit 1
-fi
-echo OK
+#
+# CREATE ORDER WITH NON-INVENTORY AND CHECK
+#
echo -n "Creating order with non-inventory products..."
STATUS=$(curl 'http://localhost:9966/instances/default/private/orders' \
@@ -87,6 +99,23 @@ then
fi
echo OK
+
+#
+# CREATE INVENTORY PRODUCT AND CLAIM IT
+#
+
+echo -n "Creating product..."
+STATUS=$(curl 'http://localhost:9966/instances/default/private/products' \
+ -d '{"product_id":"2","description":"product with id 2 and price :15","price":"TESTKUDOS:15","total_stock":2,"description_i18n":{},"unit":"","image":"'$RANDOM_IMG'","taxes":[],"address":{},"next_restock":{"t_ms":"never"}}' \
+ -w "%{http_code}" -s -o /dev/null)
+
+if [ "$STATUS" != "204" ]
+then
+ echo 'should respond ok, product created. got:' $STATUS
+ exit 1
+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}]}' \
@@ -122,6 +151,11 @@ fi
echo "OK"
+#
+# CREATE INVALID ORDER
+#
+
+
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)
@@ -132,6 +166,10 @@ then
exit 1
fi
+#
+# CREATE ORDER AND SELL IT
+#
+
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}]}' \
@@ -157,34 +195,8 @@ 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
-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 ..."
@@ -192,7 +204,6 @@ taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB handle-uri "${PAY_URL}" -y
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)
@@ -210,6 +221,10 @@ then
exit 1
fi
+#
+# WIRE TRANSFER TO MERCHANT AND NOTIFY BACKEND
+#
+
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`
@@ -217,8 +232,6 @@ NOW=`date +%s`
TO_SLEEP=`echo $(( ($WIRE_DEADLINE /1000) - $NOW ))`
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
@@ -247,8 +260,23 @@ then
exit_fail "Wrong exchange URL in subject '$SUBJECT', expected $EXCHANGE_URL"
fi
+set +e
+
+STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \
+ -d '{"credit_amount":"'$CREDIT_AMOUNT'1","wtid":"'$WTID'","payto_uri":"'$TARGET_PAYTO'","exchange_url":"'$WURL'"}' \
+ -m 3 \
+ -w "%{http_code}" -s -o $LAST_RESPONSE)
+
+set -e
+
+if [ "$STATUS" != "000" ]
+then
+ exit_fail "Expected to fail since the amount is not valid. got: $STATUS"
+fi
+
STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \
-d '{"credit_amount":"'$CREDIT_AMOUNT'","wtid":"'$WTID'","payto_uri":"'$TARGET_PAYTO'","exchange_url":"'$WURL'"}' \
+ -m 3 \
-w "%{http_code}" -s -o $LAST_RESPONSE)
if [ "$STATUS" != "200" ]
@@ -269,6 +297,9 @@ then
exit_fail "Expected response ok, after providing transfer data. got: $STATUS"
fi
+#
+# CHECK TRANSFER API
+#
STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \
-d '{"credit_amount":"'$CREDIT_AMOUNT'","wtid":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","payto_uri":"'$TARGET_PAYTO'","exchange_url":"'$WURL'"}' \
@@ -328,7 +359,6 @@ then
exit 1
fi
-
DEPOSIT_TOTAL=`jq -r .deposit_total < $LAST_RESPONSE`
if [ "$DEPOSIT_TOTAL" == "TESTKUDOS:0" ]