forked from aws-samples/non-profit-blockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ngo-load-testapi.sh
executable file
·465 lines (462 loc) · 16.2 KB
/
ngo-load-testapi.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
#!/bin/bash
#
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
#
# Test script for testing the REST API
# Set the exports below to point to the REST API hostname/port and run the script
# The export statements below can be used to point to either localhost or to an ELB endpoint,
# depending on where the REST API server is running
export ENDPOINT=Fabric-ELB-205962472.us-west-2.elb.amazonaws.com
export PORT=80
#export ENDPOINT=localhost
#export PORT=3000
set +e
echo installing jq
sudo yum install jq
echo To test, run the API server as per the instructions in the README, then execute this script on the command line
echo 'NOTE: the logger for the REST API server (in app.js) should be running at INFO level, not DEBUG'
echo
RED='\033[0;31m'
RESTORE='\033[0m'
echo connecting to server: $ENDPOINT:$PORT
echo
echo '---------------------------------------'
echo Registering a user
echo '---------------------------------------'
echo 'Register User'
USERID=$(uuidgen)
echo
response=$(curl -s -X POST http://${ENDPOINT}:${PORT}/users -H 'content-type: application/x-www-form-urlencoded' -d "username=${USERID}&orgName=Org1")
echo $response
echo Response should be: {"success":true,"secret":"","message":"$USERID enrolled Successfully"}
echo
echo Checking response:
echo
ret=$(echo $response | jq '.message | contains("enrolled Successfully")')
if [ $ret ]; then
echo test case passed
else
echo -e ${RED} ERROR - test case failed - user was not enrolled ${RESTORE}
fi
echo $response | jq ".message" | grep "$USERID enrolled Successfully"
echo
echo '---------------------------------------'
echo Donors
echo '---------------------------------------'
echo 'Create Donor'
echo
DONOR1=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/donors -H 'content-type: application/json' -d '{
"donorUserName": "'"${DONOR1}"'",
"email": "[email protected]",
"registeredDate": "2018-10-22T11:52:20.182Z"
}')
echo "Transaction ID is $TRX_ID"
echo
DONOR2=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/donors -H 'content-type: application/json' -d '{
"donorUserName": "'"${DONOR2}"'",
"email": "[email protected]",
"registeredDate": "2018-10-22T11:52:20.182Z"
}')
echo "Transaction ID is $TRX_ID"
echo
echo 'Query all donors'
echo
curl -s -X GET http://${ENDPOINT}:${PORT}/donors -H 'content-type: application/json'
echo
echo 'Query specific donors'
echo
response=$(curl -s -X GET http://${ENDPOINT}:${PORT}/donors/${DONOR1} -H 'content-type: application/json')
echo $response
echo
ret=$(echo $response | jq '.[].docType' | jq 'contains("donor")')
echo $ret
if $ret ; then
echo test case passed
else
echo -e ${RED} ERROR - test case failed - query specific donors does not match expected result. Result is: $ret ${RESTORE}
fi
echo
echo '---------------------------------------'
echo NGO
echo '---------------------------------------'
echo 'Create NGO'
echo
NGO1=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/ngos -H 'content-type: application/json' -d '{
"ngoRegistrationNumber": "'"${NGO1}"'",
"ngoName": "Pets In Need",
"ngoDescription": "We help pets in need",
"address": "1 Pet street",
"contactNumber": "82372837",
"contactEmail": "[email protected]"
}')
echo "Transaction ID is $TRX_ID"
echo
echo 'Create NGO'
echo
NGO2=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/ngos -H 'content-type: application/json' -d '{
"ngoRegistrationNumber": "'"${NGO2}"'",
"ngoName": "Pets In Need",
"ngoDescription": "We help pets in need",
"address": "1 Pet street",
"contactNumber": "82372837",
"contactEmail": "[email protected]"
}')
echo "Transaction ID is $TRX_ID"
echo
echo 'Query all NGOs'
echo
curl -s -X GET http://${ENDPOINT}:${PORT}/ngos -H 'content-type: application/json'
echo
echo 'Query specific NGOs'
echo
response=$(curl -s -X GET http://${ENDPOINT}:${PORT}/ngos/${NGO1} -H 'content-type: application/json')
echo $response
echo
ret=$(echo $response | jq '.[].docType' | jq 'contains("ngo")')
echo $ret
if $ret ; then
echo test case passed
else
echo -e ${RED} ERROR - test case failed - query specific ngo does not match expected result. Result is: $response ${RESTORE}
fi
echo '---------------------------------------'
echo Rating
echo '---------------------------------------'
echo 'Create Rating'
echo
RATING1=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/ratings -H 'content-type: application/json' -d '{
"donorUserName": "'"${DONOR1}"'",
"ngoRegistrationNumber": "'"${NGO2}"'",
"rating": 1
}')
echo "Transaction ID is $TRX_ID"
echo
RATING2=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/ratings -H 'content-type: application/json' -d '{
"donorUserName": "'"${DONOR2}"'",
"ngoRegistrationNumber": "'"${NGO2}"'",
"rating": 3
}')
echo "Transaction ID is $TRX_ID"
echo
echo 'Query specific ratings'
echo
curl -s -X GET http://${ENDPOINT}:${PORT}/ratings/${NGO2}/${DONOR1}/ -H 'content-type: application/json'
echo
echo 'Query ratings for an NGO'
echo
response=$(curl -s -X GET http://${ENDPOINT}:${PORT}/ngos/${NGO2}/ratings -H 'content-type: application/json')
echo $response
echo
ret=$(echo $response | jq '.[].docType' | jq 'contains("rating")')
echo $ret
if $ret ; then
echo test case passed
else
echo -e ${RED} ERROR - test case failed - query specific rating does not match expected result. Result is: $response ${RESTORE}
fi
echo
echo '---------------------------------------'
echo Donation
echo '---------------------------------------'
echo
echo 'Create Donation'
echo
DONATION1=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/donations -H 'content-type: application/json' -d '{
"donationId": "'"${DONATION1}"'",
"donationAmount": 100,
"donationDate": "2018-09-20T12:41:59.582Z",
"donorUserName": "'"${DONOR1}"'",
"ngoRegistrationNumber": "'"${NGO1}"'"
}')
echo "Transaction ID is $TRX_ID"
echo
DONATION2=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/donations -H 'content-type: application/json' -d '{
"donationId": "'"${DONATION2}"'",
"donationAmount": 999,
"donationDate": "2018-09-20T12:41:59.582Z",
"donorUserName": "'"${DONOR2}"'",
"ngoRegistrationNumber": "'"${NGO1}"'"
}')
echo "Transaction ID is $TRX_ID"
echo
DONATION3=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/donations -H 'content-type: application/json' -d '{
"donationId": "'"${DONATION3}"'",
"donationAmount": 75,
"donationDate": "2018-09-20T12:41:59.582Z",
"donorUserName": "'"${DONOR1}"'",
"ngoRegistrationNumber": "'"${NGO2}"'"
}')
echo "Transaction ID is $TRX_ID"
echo
echo 'Query all Donations'
echo
curl -s -X GET http://${ENDPOINT}:${PORT}/donations -H 'content-type: application/json'
echo
echo 'Query specific Donations'
echo
curl -s -X GET http://${ENDPOINT}:${PORT}/donations/${DONATION2} -H 'content-type: application/json'
echo
echo 'Query Donations for a donor'
echo
curl -s -X GET http://${ENDPOINT}:${PORT}/donors/${DONOR1}/donations/ -H 'content-type: application/json'
echo
echo 'Query Donations for an NGO'
echo
response=$(curl -s -X GET http://${ENDPOINT}:${PORT}/ngos/${NGO1}/donations/ -H 'content-type: application/json')
echo $response
echo
ret=$(echo $response | jq '.[].docType' | jq 'contains("donation")')
echo $ret
if $ret ; then
echo test case passed
else
echo -e ${RED} ERROR - test case failed - query specific donation does not match expected result. Result is: $response ${RESTORE}
fi
echo
echo '---------------------------------------'
echo Spend
echo '---------------------------------------'
echo 'Create Spend'
echo
SPENDID=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/spend -H 'content-type: application/json' -d '{
"ngoRegistrationNumber": "'"${NGO1}"'",
"spendId": "'"${SPENDID}"'",
"spendDescription": "Peter Pipers Poulty Portions for Pets",
"spendDate": "2018-09-20T12:41:59.582Z",
"spendAmount": 33
}')
echo "Transaction ID is $TRX_ID"
echo
SPENDID=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/spend -H 'content-type: application/json' -d '{
"ngoRegistrationNumber": "'"${NGO2}"'",
"spendId": "'"${SPENDID}"'",
"spendDescription": "Peter Pipers Poulty Portions for Pets",
"spendDate": "2018-09-20T12:41:59.582Z",
"spendAmount": 100
}')
echo "Transaction ID is $TRX_ID"
echo
SPENDID=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/spend -H 'content-type: application/json' -d '{
"ngoRegistrationNumber": "'"${NGO1}"'",
"spendId": "'"${SPENDID}"'",
"spendDescription": "Peter Pipers Poulty Portions for Pets",
"spendDate": "2018-09-20T12:41:59.582Z",
"spendAmount": 123
}')
echo "Transaction ID is $TRX_ID"
echo
SPENDID=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/spend -H 'content-type: application/json' -d '{
"ngoRegistrationNumber": "'"${NGO1}"'",
"spendId": "'"${SPENDID}"'",
"spendDescription": "Peter Pipers Poulty Portions for Pets",
"spendDate": "2018-09-20T12:41:59.582Z",
"spendAmount": 1000
}')
echo "Transaction ID is $TRX_ID"
echo
SPENDID=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/spend -H 'content-type: application/json' -d '{
"ngoRegistrationNumber": "'"${NGO1}"'",
"spendId": "'"${SPENDID}"'",
"spendDescription": "Peter Pipers Poulty Portions for Pets",
"spendDate": "2018-09-20T12:41:59.582Z",
"spendAmount": 23
}')
echo "Transaction ID is $TRX_ID"
echo ${SPENDID}
echo
echo 'Query all Spends'
echo
curl -s -X GET http://${ENDPOINT}:${PORT}/spend -H 'content-type: application/json'
echo
echo 'Query specific Spends'
sleep 2
echo
curl -s -X GET http://${ENDPOINT}:${PORT}/spend/${SPENDID} -H 'content-type: application/json'
echo
echo 'Query Spend by NGO'
echo
response=$(curl -s -X GET http://${ENDPOINT}:${PORT}/ngos/${NGO1}/spend -H 'content-type: application/json')
echo $response
echo
ret=$(echo $response | jq '.[].docType' | jq 'contains("spend")')
echo $ret
if $ret ; then
echo test case passed
else
echo -e ${RED} ERROR - test case failed - query specific spend does not match expected result. Result is: $response ${RESTORE}
fi
echo
echo 'Query SpendAllocations by donation'
echo
echo
response=$(curl -s -X GET http://${ENDPOINT}:${PORT}/donations/${DONATION1}/spendallocations -H 'content-type: application/json')
echo $response
echo
ret=$(echo $response | jq '.[].docType' | jq 'contains("spendAllocation")')
echo $ret
if $ret ; then
echo test case passed
else
echo -e ${RED} ERROR - test case failed - query specific spendallocation does not match expected result. Result is: $response ${RESTORE}
fi
echo
echo 'Query SpendAllocations by spend'
echo
echo
response=$(curl -s -X GET http://${ENDPOINT}:${PORT}/spend/${SPENDID}/spendallocations -H 'content-type: application/json')
echo $response
echo
ret=$(echo $response | jq '.[].docType' | jq 'contains("spendAllocation")')
echo $ret
if $ret ; then
echo test case passed
else
echo -e ${RED} ERROR - test case failed - query specific spendallocation does not match expected result. Result is: $response ${RESTORE}
fi
echo
echo 'Query all SpendAllocations'
echo
curl -s -X GET http://${ENDPOINT}:${PORT}/spendallocations -H 'content-type: application/json'
echo
echo 'Send a mixture of donations and spends'
echo
echo 'Create Donations & Spends'
echo
DONATION1=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/donations -H 'content-type: application/json' -d '{
"donationId": "'"${DONATION1}"'",
"donationAmount": 111,
"donationDate": "2018-09-20T12:41:59.582Z",
"donorUserName": "'"${DONOR1}"'",
"ngoRegistrationNumber": "'"${NGO1}"'"
}')
echo "Transaction ID is $TRX_ID"
echo
DONATION1=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/donations -H 'content-type: application/json' -d '{
"donationId": "'"${DONATION1}"'",
"donationAmount": 222,
"donationDate": "2018-09-20T12:41:59.582Z",
"donorUserName": "'"${DONOR2}"'",
"ngoRegistrationNumber": "'"${NGO1}"'"
}')
echo "Transaction ID is $TRX_ID"
echo
DONATION1=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/donations -H 'content-type: application/json' -d '{
"donationId": "'"${DONATION1}"'",
"donationAmount": 222,
"donationDate": "2018-09-20T12:41:59.582Z",
"donorUserName": "'"${DONOR1}"'",
"ngoRegistrationNumber": "'"${NGO2}"'"
}')
echo "Transaction ID is $TRX_ID"
echo
SPENDID=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/spend -H 'content-type: application/json' -d '{
"ngoRegistrationNumber": "'"${NGO1}"'",
"spendId": "'"${SPENDID}"'",
"spendDescription": "Peter Pipers Poulty Portions for Pets",
"spendDate": "2018-09-20T12:41:59.582Z",
"spendAmount": 666
}')
echo "Transaction ID is $TRX_ID"
echo
SPENDID=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/spend -H 'content-type: application/json' -d '{
"ngoRegistrationNumber": "'"${NGO1}"'",
"spendId": "'"${SPENDID}"'",
"spendDescription": "Peter Pipers Poulty Portions for Pets",
"spendDate": "2018-09-20T12:41:59.582Z",
"spendAmount": 227
}')
echo "Transaction ID is $TRX_ID"
echo
SPENDID=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/spend -H 'content-type: application/json' -d '{
"ngoRegistrationNumber": "'"${NGO2}"'",
"spendId": "'"${SPENDID}"'",
"spendDescription": "Peter Pipers Poulty Portions for Pets",
"spendDate": "2018-09-20T12:41:59.582Z",
"spendAmount": 1
}')
echo "Transaction ID is $TRX_ID"
echo
SPENDID=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/spend -H 'content-type: application/json' -d '{
"ngoRegistrationNumber": "'"${NGO2}"'",
"spendId": "'"${SPENDID}"'",
"spendDescription": "Peter Pipers Poulty Portions for Pets",
"spendDate": "2018-09-20T12:41:59.582Z",
"spendAmount": 77
}')
echo "Transaction ID is $TRX_ID"
echo
DONATION1=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/donations -H 'content-type: application/json' -d '{
"donationId": "'"${DONATION1}"'",
"donationAmount": 875,
"donationDate": "2018-09-20T12:41:59.582Z",
"donorUserName": "'"${DONOR2}"'",
"ngoRegistrationNumber": "'"${NGO1}"'"
}')
echo "Transaction ID is $TRX_ID"
echo
DONATION1=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/donations -H 'content-type: application/json' -d '{
"donationId": "'"${DONATION1}"'",
"donationAmount": 1,
"donationDate": "2018-09-20T12:41:59.582Z",
"donorUserName": "'"${DONOR1}"'",
"ngoRegistrationNumber": "'"${NGO2}"'"
}')
echo "Transaction ID is $TRX_ID"
echo
SPENDID=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/spend -H 'content-type: application/json' -d '{
"ngoRegistrationNumber": "'"${NGO2}"'",
"spendId": "'"${SPENDID}"'",
"spendDescription": "Peter Pipers Poulty Portions for Pets",
"spendDate": "2018-09-20T12:41:59.582Z",
"spendAmount": 0
}')
echo "Transaction ID is $TRX_ID"
echo
DONATION1=$(uuidgen)
TRX_ID=$(curl -s -X POST http://${ENDPOINT}:${PORT}/donations -H 'content-type: application/json' -d '{
"donationId": "'"${DONATION1}"'",
"donationAmount": 0,
"donationDate": "2018-09-20T12:41:59.582Z",
"donorUserName": "'"${DONOR1}"'",
"ngoRegistrationNumber": "'"${NGO2}"'"
}')
echo "Transaction ID is $TRX_ID"
echo
echo 'Query Blockinfo for a record key'
echo
curl -s -X GET http://${ENDPOINT}:${PORT}/blockinfos/spendAllocation/keys/12345 -H 'content-type: application/json'