diff options
Diffstat (limited to 'src/testing/test_merchant_transfer_tracking.sh')
-rwxr-xr-x | src/testing/test_merchant_transfer_tracking.sh | 255 |
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 | |||
23 | echo -n "First prepare wallet with coins..." | ||
24 | rm $WALLET_DB | ||
25 | taler-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 | ||
35 | taler-wallet-cli --wallet-db=$WALLET_DB run-until-done 2>wallet-withdraw-finish-1.err >wallet-withdraw-finish-1.out | ||
36 | echo " OK" | ||
37 | |||
38 | # | ||
39 | # CREATE INSTANCE FOR TESTING | ||
40 | # | ||
41 | |||
42 | echo -n "Configuring merchant default instance ..." | ||
43 | |||
44 | # create with 2 address | ||
45 | STATUS=$(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 | |||
51 | if [ "$STATUS" != "204" ] | ||
52 | then | ||
53 | echo 'should respond ok, instance created. got:' $STATUS | ||
54 | exit 1 | ||
55 | fi | ||
56 | |||
57 | echo OK | ||
58 | |||
59 | |||
60 | echo -n "Configuring merchant test instance ..." | ||
61 | |||
62 | # create with 2 address | ||
63 | STATUS=$(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 | |||
69 | if [ "$STATUS" != "204" ] | ||
70 | then | ||
71 | echo 'should respond ok, instance created. got:' $STATUS | ||
72 | exit 1 | ||
73 | fi | ||
74 | echo OK | ||
75 | |||
76 | RANDOM_IMG='data:image/png;base64,abcdefg' | ||
77 | |||
78 | # CREATE ORDER AND SELL IT | ||
79 | echo -n "Creating order to be paid..." | ||
80 | STATUS=$(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 | |||
84 | if [ "$STATUS" != "200" ] | ||
85 | then | ||
86 | echo 'should respond ok, order created. got:' $STATUS `cat $LAST_RESPONSE` | ||
87 | exit 1 | ||
88 | fi | ||
89 | |||
90 | ORDER_ID=`jq -e -r .order_id < $LAST_RESPONSE` | ||
91 | TOKEN=`jq -e -r .token < $LAST_RESPONSE` | ||
92 | |||
93 | STATUS=$(curl "http://localhost:9966/instances/test/private/orders/${ORDER_ID}" \ | ||
94 | -w "%{http_code}" -s -o $LAST_RESPONSE) | ||
95 | |||
96 | if [ "$STATUS" != "200" ] | ||
97 | then | ||
98 | echo 'should respond ok, getting order info before claming it. got:' $STATUS `cat $LAST_RESPONSE` | ||
99 | exit 1 | ||
100 | fi | ||
101 | PAY_URL=`jq -e -r .taler_pay_uri < $LAST_RESPONSE` | ||
102 | echo OK | ||
103 | |||
104 | NOW=`date +%s` | ||
105 | echo -n "Pay first order ..." | ||
106 | taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB handle-uri "${PAY_URL}" -y 2> wallet-pay1.err > wallet-pay1.log | ||
107 | NOW2=`date +%s` | ||
108 | echo " OK (took $( echo -n $(($NOW2 - $NOW))) secs)" | ||
109 | |||
110 | STATUS=$(curl "http://localhost:9966/instances/test/private/orders/${ORDER_ID}" \ | ||
111 | -w "%{http_code}" -s -o $LAST_RESPONSE) | ||
112 | |||
113 | if [ "$STATUS" != "200" ] | ||
114 | then | ||
115 | echo 'should respond ok, after pay. got:' $STATUS `cat $LAST_RESPONSE` | ||
116 | exit 1 | ||
117 | fi | ||
118 | |||
119 | ORDER_STATUS=`jq -r .order_status < $LAST_RESPONSE` | ||
120 | |||
121 | if [ "$ORDER_STATUS" != "paid" ] | ||
122 | then | ||
123 | echo 'order should be paid. got:' $ORDER_STATUS `cat $LAST_RESPONSE` | ||
124 | exit 1 | ||
125 | fi | ||
126 | |||
127 | # | ||
128 | # WIRE TRANSFER TO MERCHANT AND NOTIFY BACKEND | ||
129 | # | ||
130 | |||
131 | PAY_DEADLINE=`jq -r .contract_terms.pay_deadline.t_ms < $LAST_RESPONSE` | ||
132 | WIRE_DEADLINE=`jq -r .contract_terms.wire_transfer_deadline.t_ms < $LAST_RESPONSE` | ||
133 | |||
134 | NOW=`date +%s` | ||
135 | |||
136 | TO_SLEEP=`echo $(( ($WIRE_DEADLINE /1000) - $NOW ))` | ||
137 | echo "waiting $TO_SLEEP secs for wire transfer" | ||
138 | |||
139 | echo -n "Perform wire transfers ..." | ||
140 | taler-exchange-aggregator -c $CONF -T ${TO_SLEEP}000000 -t -L INFO &> aggregator.log | ||
141 | taler-exchange-transfer -c $CONF -t -L INFO &> transfer.log | ||
142 | echo " DONE" | ||
143 | |||
144 | echo -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). | ||
150 | export BANKDATA=`taler-bank-manage -c $CONF django dumpdata 2>/dev/null | tail -n1 | jq '.[] | select(.model=="app.banktransaction")' | jq 'select(.fields.debit_account==2)'` | ||
151 | export SUBJECT=`echo $BANKDATA | jq -r .fields.subject` | ||
152 | export WTID=`echo $SUBJECT | awk '{print $1}'` | ||
153 | export WURL=`echo $SUBJECT | awk '{print $2}'` | ||
154 | export CREDIT_AMOUNT=`echo $BANKDATA | jq -r .fields.amount` | ||
155 | export 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*: | ||
157 | BANKADATA=`taler-bank-manage -c $CONF django dumpdata 2>/dev/null | tail -n1 | jq '.[] | select(.model=="auth.user")' | jq 'select(.pk=='$TARGET')'` | ||
158 | ACCOUNT_NAME=`echo $BANKADATA | jq -r .fields.username` | ||
159 | TARGET_PAYTO="payto://x-taler-bank/localhost:8082/$ACCOUNT_NAME" | ||
160 | |||
161 | if [ "$EXCHANGE_URL" != "$WURL" ] | ||
162 | then | ||
163 | exit_fail "Wrong exchange URL in subject '$SUBJECT', expected $EXCHANGE_URL" | ||
164 | fi | ||
165 | |||
166 | echo " OK" | ||
167 | |||
168 | set +e | ||
169 | |||
170 | export TARGET_PAYTO | ||
171 | export WURL | ||
172 | export WTID | ||
173 | export CREDIT_AMOUNT | ||
174 | export LAST_RESPONSE | ||
175 | |||
176 | echo -n "Notifying merchant of correct wire transfer, but on wrong instance..." | ||
177 | |||
178 | STATUS=$(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 | |||
183 | if [ "$STATUS" != "404" ] | ||
184 | then | ||
185 | jq . < $LAST_RESPONSE | ||
186 | exit_fail "Expected response ok, after providing transfer data. got: $STATUS" | ||
187 | fi | ||
188 | echo " OK" | ||
189 | |||
190 | |||
191 | echo -n "Fetching wire transfers of DEFAULT instance ..." | ||
192 | |||
193 | STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \ | ||
194 | -w "%{http_code}" -s -o $LAST_RESPONSE) | ||
195 | |||
196 | if [ "$STATUS" != "200" ] | ||
197 | then | ||
198 | jq . < $LAST_RESPONSE | ||
199 | exit_fail "Expected response 200 Ok. got: $STATUS" | ||
200 | fi | ||
201 | |||
202 | TRANSFERS_LIST_SIZE=`jq -r '.transfers | length' < $LAST_RESPONSE` | ||
203 | |||
204 | if [ "$TRANSFERS_LIST_SIZE" != "0" ] | ||
205 | then | ||
206 | jq . < $LAST_RESPONSE | ||
207 | exit_fail "Expected response ok. got: $STATUS" | ||
208 | fi | ||
209 | |||
210 | echo "OK" | ||
211 | |||
212 | echo -n "Fetching wire transfers of 'test' instance ..." | ||
213 | |||
214 | STATUS=$(curl 'http://localhost:9966/instances/test/private/transfers' \ | ||
215 | -w "%{http_code}" -s -o $LAST_RESPONSE) | ||
216 | |||
217 | if [ "$STATUS" != "200" ] | ||
218 | then | ||
219 | jq . < $LAST_RESPONSE | ||
220 | exit_fail "Expected response 200 Ok. got: $STATUS" | ||
221 | fi | ||
222 | |||
223 | TRANSFERS_LIST_SIZE=`jq -r '.transfers | length' < $LAST_RESPONSE` | ||
224 | |||
225 | if [ "$TRANSFERS_LIST_SIZE" != "0" ] | ||
226 | then | ||
227 | jq . < $LAST_RESPONSE | ||
228 | exit_fail "Expected response ok. got: $STATUS" | ||
229 | fi | ||
230 | |||
231 | echo "OK" | ||
232 | |||
233 | |||
234 | echo -n "Checking order status ..." | ||
235 | STATUS=$(curl "http://localhost:9966/instances/test/private/orders/${ORDER_ID}?transfer=YES" \ | ||
236 | -w "%{http_code}" -s -o $LAST_RESPONSE) | ||
237 | |||
238 | if [ "$STATUS" != "200" ] | ||
239 | then | ||
240 | jq . < $LAST_RESPONSE | ||
241 | exit_fail 'should response ok, after order inquiry. got:' $STATUS `cat $LAST_RESPONSE` | ||
242 | exit 1 | ||
243 | fi | ||
244 | |||
245 | WAS_WIRED=`jq -r .wired < $LAST_RESPONSE` | ||
246 | |||
247 | if [ "$WAS_WIRED" == "true" ] | ||
248 | then | ||
249 | echo '.wired true, expected false' | ||
250 | exit 1 | ||
251 | fi | ||
252 | |||
253 | echo " OK" | ||
254 | |||
255 | exit 0 | ||