aboutsummaryrefslogtreecommitdiff
path: root/src/testing/test_merchant_transfer_tracking.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/test_merchant_transfer_tracking.sh')
-rwxr-xr-xsrc/testing/test_merchant_transfer_tracking.sh255
1 files changed, 255 insertions, 0 deletions
diff --git a/src/testing/test_merchant_transfer_tracking.sh b/src/testing/test_merchant_transfer_tracking.sh
new file mode 100755
index 00000000..90696566
--- /dev/null
+++ b/src/testing/test_merchant_transfer_tracking.sh
@@ -0,0 +1,255 @@
1#!/bin/bash
2# This file is part of TALER
3# Copyright (C) 2014-2021 Taler Systems SA
4#
5# TALER is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as
7# published by the Free Software Foundation; either version 3, or
8# (at your option) any later version.
9#
10# TALER is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public
16# License along with TALER; see the file COPYING. If not, see
17# <http://www.gnu.org/licenses/>
18#
19# Testcase for #6912 (failed to reproduce so far)
20
21. initialize_taler_system.sh
22
23echo -n "First prepare wallet with coins..."
24rm $WALLET_DB
25taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB api 'withdrawTestBalance' \
26 "$(jq -n '
27 {
28 amount: "TESTKUDOS:99",
29 bankBaseUrl: $BANK_URL,
30 exchangeBaseUrl: $EXCHANGE_URL
31 }' \
32 --arg BANK_URL "$BANK_URL" \
33 --arg EXCHANGE_URL "$EXCHANGE_URL"
34 )" 2>wallet-withdraw-1.err >wallet-withdraw-1.out
35taler-wallet-cli --wallet-db=$WALLET_DB run-until-done 2>wallet-withdraw-finish-1.err >wallet-withdraw-finish-1.out
36echo " OK"
37
38#
39# CREATE INSTANCE FOR TESTING
40#
41
42echo -n "Configuring merchant default instance ..."
43
44# create with 2 address
45STATUS=$(curl -H "Content-Type: application/json" -X POST \
46 -H 'Authorization: Bearer secret-token:super_secret' \
47 http://localhost:9966/management/instances \
48 -d '{"auth":{"method":"external"},"payto_uris":["payto://x-taler-bank/localhost:8082/Tor","payto://x-taler-bank/localhost:8082/GNUnet"],"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}}' \
49 -w "%{http_code}" -s -o /dev/null)
50
51if [ "$STATUS" != "204" ]
52then
53 echo 'should respond ok, instance created. got:' $STATUS
54 exit 1
55fi
56
57echo OK
58
59
60echo -n "Configuring merchant test instance ..."
61
62# create with 2 address
63STATUS=$(curl -H "Content-Type: application/json" -X POST \
64 -H 'Authorization: Bearer secret-token:super_secret' \
65 http://localhost:9966/management/instances \
66 -d '{"auth":{"method":"external"},"payto_uris":["payto://x-taler-bank/localhost:8082/Survey","payto://x-taler-bank/localhost:8082/Tutorial"],"id":"test","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}}' \
67 -w "%{http_code}" -s -o /dev/null)
68
69if [ "$STATUS" != "204" ]
70then
71 echo 'should respond ok, instance created. got:' $STATUS
72 exit 1
73fi
74echo OK
75
76RANDOM_IMG='data:image/png;base64,abcdefg'
77
78# CREATE ORDER AND SELL IT
79echo -n "Creating order to be paid..."
80STATUS=$(curl 'http://localhost:9966/instances/test/private/orders' \
81 -d '{"order":{"amount":"TESTKUDOS:1","summary":"payme"}}' \
82 -w "%{http_code}" -s -o $LAST_RESPONSE)
83
84if [ "$STATUS" != "200" ]
85then
86 echo 'should respond ok, order created. got:' $STATUS `cat $LAST_RESPONSE`
87 exit 1
88fi
89
90ORDER_ID=`jq -e -r .order_id < $LAST_RESPONSE`
91TOKEN=`jq -e -r .token < $LAST_RESPONSE`
92
93STATUS=$(curl "http://localhost:9966/instances/test/private/orders/${ORDER_ID}" \
94 -w "%{http_code}" -s -o $LAST_RESPONSE)
95
96if [ "$STATUS" != "200" ]
97then
98 echo 'should respond ok, getting order info before claming it. got:' $STATUS `cat $LAST_RESPONSE`
99 exit 1
100fi
101PAY_URL=`jq -e -r .taler_pay_uri < $LAST_RESPONSE`
102echo OK
103
104NOW=`date +%s`
105echo -n "Pay first order ..."
106taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB handle-uri "${PAY_URL}" -y 2> wallet-pay1.err > wallet-pay1.log
107NOW2=`date +%s`
108echo " OK (took $( echo -n $(($NOW2 - $NOW))) secs)"
109
110STATUS=$(curl "http://localhost:9966/instances/test/private/orders/${ORDER_ID}" \
111 -w "%{http_code}" -s -o $LAST_RESPONSE)
112
113if [ "$STATUS" != "200" ]
114then
115 echo 'should respond ok, after pay. got:' $STATUS `cat $LAST_RESPONSE`
116 exit 1
117fi
118
119ORDER_STATUS=`jq -r .order_status < $LAST_RESPONSE`
120
121if [ "$ORDER_STATUS" != "paid" ]
122then
123 echo 'order should be paid. got:' $ORDER_STATUS `cat $LAST_RESPONSE`
124 exit 1
125fi
126
127#
128# WIRE TRANSFER TO MERCHANT AND NOTIFY BACKEND
129#
130
131PAY_DEADLINE=`jq -r .contract_terms.pay_deadline.t_ms < $LAST_RESPONSE`
132WIRE_DEADLINE=`jq -r .contract_terms.wire_transfer_deadline.t_ms < $LAST_RESPONSE`
133
134NOW=`date +%s`
135
136TO_SLEEP=`echo $(( ($WIRE_DEADLINE /1000) - $NOW ))`
137echo "waiting $TO_SLEEP secs for wire transfer"
138
139echo -n "Perform wire transfers ..."
140taler-exchange-aggregator -c $CONF -T ${TO_SLEEP}000000 -t -L INFO &> aggregator.log
141taler-exchange-transfer -c $CONF -t -L INFO &> transfer.log
142echo " DONE"
143
144echo -n "Obtaining wire transfer details from bank..."
145
146# First, extract the wire transfer data from the bank.
147# As there is no "nice" API, we do this by dumping the
148# bank database and grabbing the 'right' wire transfer,
149# which is the one outgoing from the exchange (account 2).
150export BANKDATA=`taler-bank-manage -c $CONF django dumpdata 2>/dev/null | tail -n1 | jq '.[] | select(.model=="app.banktransaction")' | jq 'select(.fields.debit_account==2)'`
151export SUBJECT=`echo $BANKDATA | jq -r .fields.subject`
152export WTID=`echo $SUBJECT | awk '{print $1}'`
153export WURL=`echo $SUBJECT | awk '{print $2}'`
154export CREDIT_AMOUNT=`echo $BANKDATA | jq -r .fields.amount`
155export TARGET=`echo $BANKDATA | jq -r .fields.credit_account`
156# 'TARGET' is now the numeric value of the account, we need to get the actual account *name*:
157BANKADATA=`taler-bank-manage -c $CONF django dumpdata 2>/dev/null | tail -n1 | jq '.[] | select(.model=="auth.user")' | jq 'select(.pk=='$TARGET')'`
158ACCOUNT_NAME=`echo $BANKADATA | jq -r .fields.username`
159TARGET_PAYTO="payto://x-taler-bank/localhost:8082/$ACCOUNT_NAME"
160
161if [ "$EXCHANGE_URL" != "$WURL" ]
162then
163 exit_fail "Wrong exchange URL in subject '$SUBJECT', expected $EXCHANGE_URL"
164fi
165
166echo " OK"
167
168set +e
169
170export TARGET_PAYTO
171export WURL
172export WTID
173export CREDIT_AMOUNT
174export LAST_RESPONSE
175
176echo -n "Notifying merchant of correct wire transfer, but on wrong instance..."
177
178STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \
179 -d '{"credit_amount":"'$CREDIT_AMOUNT'","wtid":"'$WTID'","payto_uri":"'$TARGET_PAYTO'","exchange_url":"'$WURL'"}' \
180 -m 3 \
181 -w "%{http_code}" -s -o $LAST_RESPONSE)
182
183if [ "$STATUS" != "404" ]
184then
185 jq . < $LAST_RESPONSE
186 exit_fail "Expected response ok, after providing transfer data. got: $STATUS"
187fi
188echo " OK"
189
190
191echo -n "Fetching wire transfers of DEFAULT instance ..."
192
193STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \
194 -w "%{http_code}" -s -o $LAST_RESPONSE)
195
196if [ "$STATUS" != "200" ]
197then
198 jq . < $LAST_RESPONSE
199 exit_fail "Expected response 200 Ok. got: $STATUS"
200fi
201
202TRANSFERS_LIST_SIZE=`jq -r '.transfers | length' < $LAST_RESPONSE`
203
204if [ "$TRANSFERS_LIST_SIZE" != "0" ]
205then
206 jq . < $LAST_RESPONSE
207 exit_fail "Expected response ok. got: $STATUS"
208fi
209
210echo "OK"
211
212echo -n "Fetching wire transfers of 'test' instance ..."
213
214STATUS=$(curl 'http://localhost:9966/instances/test/private/transfers' \
215 -w "%{http_code}" -s -o $LAST_RESPONSE)
216
217if [ "$STATUS" != "200" ]
218then
219 jq . < $LAST_RESPONSE
220 exit_fail "Expected response 200 Ok. got: $STATUS"
221fi
222
223TRANSFERS_LIST_SIZE=`jq -r '.transfers | length' < $LAST_RESPONSE`
224
225if [ "$TRANSFERS_LIST_SIZE" != "0" ]
226then
227 jq . < $LAST_RESPONSE
228 exit_fail "Expected response ok. got: $STATUS"
229fi
230
231echo "OK"
232
233
234echo -n "Checking order status ..."
235STATUS=$(curl "http://localhost:9966/instances/test/private/orders/${ORDER_ID}?transfer=YES" \
236 -w "%{http_code}" -s -o $LAST_RESPONSE)
237
238if [ "$STATUS" != "200" ]
239then
240 jq . < $LAST_RESPONSE
241 exit_fail 'should response ok, after order inquiry. got:' $STATUS `cat $LAST_RESPONSE`
242 exit 1
243fi
244
245WAS_WIRED=`jq -r .wired < $LAST_RESPONSE`
246
247if [ "$WAS_WIRED" == "true" ]
248then
249 echo '.wired true, expected false'
250 exit 1
251fi
252
253echo " OK"
254
255exit 0