-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_system_contracts.py
897 lines (800 loc) · 45.4 KB
/
test_system_contracts.py
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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
import unittest
import os
import time
from libs import actions, tools, db, contract, check
class TestSystemContracts():
config = tools.read_config('nodes')
url = config[2]['url']
db = config[0]['db']
wait = tools.read_config('test')['wait_tx_status']
pr_key = config[0]['private_key']
data = actions.login(url, pr_key, 0)
token = data['jwtToken']
keys = tools.read_fixtures('keys')
@classmethod
def setup_class(self):
self.unit = unittest.TestCase()
def callMulti(self, name, data, sleep):
resp = actions.call_multi_contract(self.url, self.pr_key, name, data, self.token)
time.sleep(sleep)
if 'hashes' in resp:
result = actions.tx_status_multi(self.url, self.wait, resp['hashes'], self.token)
for status in result.values():
self.unit.assertNotIn('errmsg', status)
self.unit.assertGreater(int(status['blockid']), 0,
'BlockID not generated')
def wait_block_id(self, old_block_id, limit):
while True:
# add contract, which get block_id
body = '''
{
data{}
conditions{}
action
{
$result = $block
}
}
'''
tx = contract.new_contract(self.url, self.pr_key, self.token, source=body)
currrent_block_id = check.is_tx_in_block(self.url, self.wait, tx, self.token)
expected_block_id = old_block_id + limit + 1 # +1 spare block
if currrent_block_id == expected_block_id:
break
def test_create_ecosystem(self):
tx = contract.new_ecosystem(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
def test_create_new_user(self):
tx = contract.new_user(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
def test_edit_application(self):
tx = contract.new_application(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
id = actions.get_object_id(self.url, tx['name'], 'applications', self.token)
tx = contract.edit_application(self.url, self.pr_key, self.token, id)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
def test_activate_application(self):
tx = contract.new_application(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
id = actions.get_object_id(self.url, tx['name'], 'applications', self.token)
tx_del0 = contract.del_application(self.url, self.pr_key, self.token, id, 0)
check.is_tx_in_block(self.url, self.wait, tx_del0, self.token)
tx_del1 = contract.del_application(self.url, self.pr_key, self.token, id, 1)
check.is_tx_in_block(self.url, self.wait, tx_del1, self.token)
def test_edit_ecosystem_name(self):
tx = contract.edit_ecosystem_name(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
def test_edit_ecosystem_name_incorrect_id(self):
id = 500
tx = contract.edit_ecosystem_name(self.url, self.pr_key, self.token, id=id)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'The ecosystem {id} does not exist'.format(id=id)
self.unit.assertIn(msg, status['error'], 'Is not equals')
def tokens_send(self):
ldata = actions.login(self.url, self.keys['key2'])
print(ldata)
sum = '1000'
tx = contract.tokens_send(self.url, self.pr_key, self.token, ldata['account'], sum)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
is_commission_in_history = actions.is_commission_in_history(
self.url, self.token,
self.config[0]['keyID'],
ldata['key_id'], sum
)
self.unit.assertTrue(is_commission_in_history, 'No TokensSend resord in history')
def tokens_send_incorrect_wallet(self):
wallet = '0005-2070-2000-0006'
msg = 'The recipient 0005-2070-2000-0006 is not valid'
tx = contract.tokens_send(self.url, self.pr_key, self.token, wallet, '1000')
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
self.unit.assertIn(msg, status['error'], 'Incorrect message' + msg)
def tokens_send_incorrect_keyid(self):
wallet = '-3449126383880043801'
msg = 'The recipient {wallet} is not valid'.format(wallet=wallet)
tx = contract.tokens_send(self.url, self.pr_key, self.token, wallet, '1000')
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
self.unit.assertIn(msg, status['error'], 'Incorrect message' + msg)
def tokens_send_zero_amount(self):
ldata = actions.login(self.url, self.keys['key2'], 0)
tx = contract.tokens_send(self.url, self.pr_key, self.token, ldata['address'], '0')
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'The specified amount is zero'
self.unit.assertIn(msg, status['error'], 'Incorrect message' + str(status))
def tokens_send_negative_amount(self):
ldata = actions.login(self.url, self.keys['key2'], 0)
msg = 'The specified amount is less than zero'
tx = contract.tokens_send(self.url, self.pr_key, self.token, ldata['address'], '-1000')
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
self.unit.assertIn(msg, status['error'], 'Incorrect message' + msg)
def tokens_send_amount_as_string(self):
amount = 'tttt'
ldata = actions.login(self.url, self.keys['key2'], 0)
msg = "Invalid param 'Amount': can't convert {amount} to decimal".format(amount=amount)
tx = contract.tokens_send(self.url, self.pr_key, self.token, ldata['address'], amount)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
self.unit.assertIn(msg, status['error'], 'Incorrect message' + msg)
def test_new_contract(self):
tx = contract.new_contract(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
def test_new_contract_exists_name(self):
tx1 = contract.new_contract(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx1, self.token)
tx2 = contract.new_contract(self.url, self.pr_key, self.token, name=tx1['name'])
status = actions.tx_status(self.url, self.wait, tx2['hash'], self.token)
msg = 'Contract ' + tx1['name'] + ' already exists'
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_new_contract_without_name(self):
tx = contract.new_contract(self.url, self.pr_key, self.token, name=' ')
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'The contract name is missing'
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_new_contract_incorrect_condition(self):
cond = 'condition'
tx = contract.new_contract(self.url, self.pr_key, self.token, condition=cond)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'Condition {cond} is not allowed'.format(cond=cond)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_edit_contract_incorrect_condition(self):
tx = contract.new_contract(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
cond = 'tryam'
id = actions.get_contract_id(self.url, tx['name'], self.token)
tx2 = contract.edit_contract(self.url, self.pr_key, self.token,
id, new_source=tx['code'], condition=cond)
status = actions.tx_status(self.url, self.wait, tx2['hash'], self.token)
msg = 'Condition {cond} is not allowed'.format(cond=cond)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_edit_contract(self):
tx = contract.new_contract(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
id = actions.get_contract_id(self.url, tx['name'], self.token)
print(tx['code'])
tx2 = contract.edit_contract(self.url, self.pr_key, self.token,
id, new_source=tx['code'], condition='false')
check.is_tx_in_block(self.url, self.wait, tx2, self.token)
def test_edit_name_of_contract(self):
tx = contract.new_contract(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
code1, name1 = tools.generate_name_and_code('')
id = actions.get_contract_id(self.url, tx['name'], self.token)
tx2 = contract.edit_contract(self.url, self.pr_key, self.token,
id, new_source=code1)
status = actions.tx_status(self.url, self.wait, tx2['hash'], self.token)
msg = 'Contracts or functions names cannot be changed'
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_edit_incorrect_contract(self):
id = '9999'
tx2 = contract.edit_contract(self.url, self.pr_key, self.token, id, name='gggggggg')
status = actions.tx_status(self.url, self.wait, tx2['hash'], self.token)
msg = 'Item {id} has not been found'.format(id=id)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def bind_wallet(self):
tx = contract.new_contract(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
id = actions.get_contract_id(self.url, tx['name'], self.token)
tx = contract.bind_wallet(self.url, self.pr_key, self.token, id)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
def bind_wallet_incorrect_contract(self):
id = '99999'
tx = contract.bind_wallet(self.url, self.pr_key, self.token, id)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'Contract {id} does not exist'.format(id=id)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def bind_wallet_incorrect_wallet(self):
tx = contract.new_contract(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
id = actions.get_contract_id(self.url, tx['name'], self.token)
wallet = '0005-2070-2000-0006-0200'
tx = contract.bind_wallet(self.url, self.pr_key, self.token, id, wallet = wallet)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'The key ID is not found'
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def unbind_wallet(self):
tx = contract.new_contract(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
id = actions.get_contract_id(self.url, tx['name'], self.token)
tx = contract.bind_wallet(self.url, self.pr_key, self.token, id)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
tx = contract.unbind_wallet(self.url, self.pr_key, self.token, id)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
def unbind_wallet_incorrect_wallet(self):
id = '99999'
tx = contract.unbind_wallet(self.url, self.pr_key, self.token, id)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'Contract {id} does not exist'.format(id=id)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_new_parameter(self):
tx = contract.new_parameter(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
def test_new_parameter_exist_name(self):
tx = contract.new_parameter(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
tx2 = contract.new_parameter(self.url, self.pr_key, self.token, name=tx['name'])
status = actions.tx_status(self.url, self.wait, tx2['hash'], self.token)
msg = 'The {name} parameter already exists'.format(name=tx['name'])
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_new_parameter_incorrect_condition(self):
condition = 'tryam'
tx = contract.new_parameter(self.url, self.pr_key, self.token, condition=condition)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'Condition {cond} is not allowed'.format(cond=condition)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_edit_parameter(self):
tx = contract.new_parameter(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
id = actions.get_parameter_id(self.url, tx['name'], self.token)
value = 'test_edited'
res = contract.edit_parameter(self.url,
self.pr_key,
self.token,
id,
value)
check.is_tx_in_block(self.url, self.wait, res, self.token)
def test_edit_incorrect_parameter(self):
id = '99999'
tx = contract.edit_parameter(self.url, self.pr_key, self.token, id)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'Item {id} has not been found'.format(id=id)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_edit_parameter_incorrect_condition(self):
tx = contract.new_parameter(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
id = actions.get_parameter_id(self.url, tx['name'], self.token)
condition = 'tryam'
tx = contract.edit_parameter(self.url, self.pr_key, self.token,
id, condition=condition)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'Condition {cond} is not allowed'.format(cond=condition)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_new_menu(self):
tx = contract.new_menu(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
content = {'tree': [{'tag': 'text', 'text': 'Item1'}]}
m_content = actions.get_content(self.url, 'menu', tx['name'], '', 1, self.token)
self.unit.assertEqual(m_content, content)
def test_new_menu_exist_name(self):
tx = contract.new_menu(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
tx = contract.new_menu(self.url, self.pr_key, self.token, name=tx['name'])
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'The {name} menu already exists'.format(name=tx['name'])
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_new_menu_incorrect_condition(self):
condition = 'tryam'
tx = contract.new_menu(self.url, self.pr_key, self.token, condition=condition)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'Condition {cond} is not allowed'.format(cond=condition)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_edit_menu(self):
tx = contract.new_menu(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
id = actions.get_object_id(self.url, tx['name'], 'menu', self.token)
tx2 = contract.edit_menu(self.url, self.pr_key, self.token, id)
check.is_tx_in_block(self.url, self.wait, tx2, self.token)
content = {'title': 'true', 'tree': [{'tag': 'text', 'text': 'ItemEdited'}]}
m_content = actions.get_content(self.url, 'menu', tx['name'], '', 1, self.token)
self.unit.assertEqual(m_content, content)
def test_edit_incorrect_menu(self):
id = '99999'
tx = contract.edit_menu(self.url, self.pr_key, self.token, id)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'The item is not found'
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_edit_menu_incorrect_condition(self):
condition = 'tryam'
tx = contract.new_menu(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
id = actions.get_object_id(self.url, tx['name'], 'menu', self.token)
tx2 = contract.edit_menu(self.url, self.pr_key, self.token, id, condition=condition)
status = actions.tx_status(self.url, self.wait, tx2['hash'], self.token)
msg = 'Condition {condition} is not allowed'.format(condition=condition)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_append_menu(self):
tx = contract.new_menu(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
id = actions.get_object_id(self.url, tx['name'], 'menu', self.token)
tx = contract.append_item(self.url, self.pr_key, self.token, id)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
def test_append_incorrect_menu(self):
id = '999'
tx = contract.append_item(self.url, self.pr_key, self.token, id)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'Item {id} has not been found'.format(id=id)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_new_page(self):
tx = contract.new_page(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
content = [{'tag': 'text', 'text': 'Hello page!'}]
cont = actions.get_content(self.url, 'page', tx['name'], '', 1, self.token)
self.unit.assertEqual(cont['tree'], content)
def test_new_page_exist_name(self):
tx = contract.new_page(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
tx2 = contract.new_page(self.url, self.pr_key, self.token, name=tx['name'])
status = actions.tx_status(self.url, self.wait, tx2['hash'], self.token)
msg = 'The {name} page already exists'.format(name=tx['name'])
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_new_page_incorrect_condition(self):
condition = 'tryam'
tx = contract.new_page(self.url, self.pr_key, self.token, condition=condition)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'Condition {cond} is not allowed'.format(cond=condition)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_edit_page(self):
tx = contract.new_page(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
id = actions.get_object_id(self.url, tx['name'], 'pages', self.token)
new_val = 'Good by page!'
tx2 = contract.edit_page(self.url, self.pr_key, self.token, id)
check.is_tx_in_block(self.url, self.wait, tx2, self.token)
content = [{'tag': 'text', 'text': new_val}]
p_content = actions.get_content(self.url, 'page', tx['name'], '', 1, self.token)
self.unit.assertEqual(p_content['tree'], content)
def test_edit_page_with_validate_count(self):
tx = contract.new_page(self.url, self.pr_key, self.token, validate_count=6)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
id = actions.get_object_id(self.url, tx['name'], 'pages', self.token)
tx2 = contract.edit_page(self.url, self.pr_key, self.token, id, validate_count=1)
check.is_tx_in_block(self.url, self.wait, tx2, self.token)
content = [{'tag': 'text', 'text': 'Good by page!'}]
p_content = actions.get_content(self.url, 'page', tx['name'], '', 1, self.token)
self.unit.assertEqual(p_content['tree'], content)
def test_edit_incorrect_page(self):
id = '99999'
tx = contract.edit_page(self.url, self.pr_key, self.token, id)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'The item is not found'
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_edit_page_incorrect_condition(self):
tx = contract.new_page(self.url, self.pr_key, self.token, validate_count=6)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
condition = 'Tryam'
id = actions.get_object_id(self.url, tx['name'], 'pages', self.token)
tx2 = contract.edit_page(self.url, self.pr_key, self.token, id, condition=condition)
status = actions.tx_status(self.url, self.wait, tx2['hash'], self.token)
msg = 'Condition {cond} is not allowed'.format(cond=condition)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_append_page(self):
tx = contract.new_page(self.url, self.pr_key, self.token, validate_count=6)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
id = actions.get_object_id(self.url, tx['name'], 'pages', self.token)
tx2 = contract.append_page(self.url, self.pr_key, self.token, id)
check.is_tx_in_block(self.url, self.wait, tx2, self.token)
content = [{'tag': 'text', 'text': 'Hello page!\r\nGood by!'}]
p_content = actions.get_content(self.url, 'page', tx['name'], '', 1, self.token)
self.unit.assertEqual(p_content['tree'], content)
def test_append_page_incorrect_id(self):
id = '9999'
tx = contract.append_page(self.url, self.pr_key, self.token, id)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'Item {id} has not been found'.format(id=id)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_new_block(self):
tx = contract.new_block(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
def test_new_block_exist_name(self):
tx = contract.new_block(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
tx2 = contract.new_block(self.url, self.pr_key, self.token, name=tx['name'])
status = actions.tx_status(self.url, self.wait, tx2['hash'], self.token)
msg = "The '{name}' block already exists".format(name=tx['name'])
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_new_block_incorrect_condition(self):
condition = 'tryam'
tx = contract.new_block(self.url, self.pr_key, self.token, condition=condition)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'Condition {cond} is not allowed'.format(cond=condition)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_edit_block_incorrect_id(self):
id = '9999'
tx = contract.edit_block(self.url, self.pr_key, self.token, id)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'The item is not found'
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_edit_block(self):
tx = contract.new_block(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
id = actions.get_object_id(self.url, tx['name'], 'blocks', self.token)
tx2 = contract.edit_block(self.url, self.pr_key, self.token, id)
check.is_tx_in_block(self.url, self.wait, tx2, self.token)
def test_edit_block_incorrect_condition(self):
tx = contract.new_block(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
id = actions.get_object_id(self.url, tx['name'], 'blocks', self.token)
condition = 'tryam'
tx2 = contract.edit_block(self.url, self.pr_key, self.token, id, condition=condition)
status = actions.tx_status(self.url, self.wait, tx2['hash'], self.token)
msg = 'Condition {condition} is not allowed'.format(condition=condition)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_new_table(self):
# create new table
tx = contract.new_table(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
# create new page
val = 'DBFind("' + tx['name'] + '",src)'
tx_page = contract.new_page(self.url, self.pr_key, self.token, value=val)
check.is_tx_in_block(self.url, self.wait, tx_page, self.token)
# test
content = [{'attr': {'columns': ['id', 'myname'], 'data': [],
'name': tx['name'],
'source': 'src', 'types': []},
'tag': 'dbfind'}]
cont = actions.get_content(self.url, 'page', tx_page['name'], '', 1, self.token)
self.unit.assertEqual(cont['tree'], content)
def test_new_table_not_readable(self):
# create new table
column = '''[
{"name": "Text","type": "varchar", "index": "1", "conditions": {"update": "true", "read": "false"}},
{"name": "num","type": "varchar", "index": "0", "conditions": {"update": "true", "read": "true"}}
]'''
tx = contract.new_table(self.url, self.pr_key, self.token, columns=column)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
# create new contract, which added record in table
code = '''{
data {}
conditions {}
action {
DBInsert("%s", {text: "text1", num: "num1"})
}
}''' % tx['name']
tx_cont = contract.new_contract(self.url, self.pr_key, self.token, source=code)
check.is_tx_in_block(self.url, self.wait, tx_cont, self.token)
# call contract
tx_call = actions.call_contract(self.url, self.pr_key, tx_cont['name'], {}, self.token)
status = actions.tx_status(self.url, self.wait, tx_call, self.token)
# create new page
val = 'DBFind("{}",src)'.format(tx['name'])
tx_page = contract.new_page(self.url, self.pr_key, self.token, value=val)
check.is_tx_in_block(self.url, self.wait, tx_page, self.token)
# test
content = [['num1', '1']]
cont = actions.get_content(self.url, 'page', tx_page['name'], '', 1, self.token)
self.unit.assertEqual(cont['tree'][0]['attr']['data'], content)
def test_new_table_not_readable_all_columns(self):
# create new table
column = '''[
{"name": "Text", "type": "varchar", "index": "1", "conditions": {"update": "true", "read": "false"}},
{"name": "num", "type": "varchar", "index": "0", "conditions": {"update": "true", "read": "false"}}
]'''
tx = contract.new_table(self.url, self.pr_key, self.token, columns=column)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
# create new page
val = 'DBFind("{}",src)'.format(tx['name'])
tx_page = contract.new_page(self.url, self.pr_key, self.token, value=val)
check.is_tx_in_block(self.url, self.wait, tx_page, self.token)
# test
content = [{'tag': 'text', 'text': 'Access denied'}]
cont = actions.get_content(self.url, 'page', tx_page['name'], '', 1, self.token)
self.unit.assertEqual(cont['tree'], content)
def test_new_table_not_readable_one_column(self):
# create new table
column = '''[
{"name": "Text", "type": "varchar", "index": "1", "conditions": {"update": "true", "read": "false"}},
{"name": "num", "type": "varchar", "index": "0", "conditions": {"update": "true", "read": "true"}}
]'''
tx = contract.new_table(self.url, self.pr_key, self.token, columns=column)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
# create new contract, which added record in table
code = '''{
data {}
conditions {}
action {
DBInsert("%s", {text: "text1", num: "num1"})
}
}''' % tx['name']
tx_cont = contract.new_contract(self.url, self.pr_key, self.token, source=code)
check.is_tx_in_block(self.url, self.wait, tx_cont, self.token)
# call contract
tx_call = actions.call_contract(self.url, self.pr_key, tx_cont['name'], {}, self.token)
status = actions.tx_status(self.url, self.wait, tx_call, self.token)
# create new page
val = 'DBFind("{}",src)'.format(tx['name'])
tx_page = contract.new_page(self.url, self.pr_key, self.token, value=val)
check.is_tx_in_block(self.url, self.wait, tx_page, self.token)
# test
content = [['num1', '1']]
cont = actions.get_content(self.url, 'page', tx_page['name'], '', 1, self.token)
self.unit.assertEqual(cont['tree'][0]['attr']['data'], content)
def test_new_table_incorrect_column_name_digit(self):
column = '''[{"name":"123","type":"varchar",
"index": "1", "conditions":"true"}]'''
tx = contract.new_table(self.url, self.pr_key, self.token, columns=column)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'Column name cannot begin with digit'
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_new_table_incorrect_column_name_cyrillic(self):
word = 'привет'
column = '''[{"name":"%s","type":"varchar",
"index": "1", "conditions":"true"}]''' % word
tx = contract.new_table(self.url, self.pr_key, self.token, columns=column)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = "Name {word} must only contain latin, digit and '_', '-' characters".format(word=word)
self.unit.assertIn(msg, status["error"], "Incorrect message: " + str(status))
def test_new_table_incorrect_condition1(self):
condition = 'tryam'
permissions = "{\"insert\": \"" + condition + \
"\", \"update\" : \"true\", \"new_column\": \"true\"}"
tx = contract.new_table(self.url, self.pr_key, self.token, perms=permissions)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'Condition {condition} is not allowed'.format(condition=condition)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_new_table_incorrect_condition2(self):
condition = 'tryam'
permissions = "{\"insert\": \"true\", \"update\" : \"" + \
condition + "\", \"new_column\": \"true\"}"
tx = contract.new_table(self.url, self.pr_key, self.token, perms=permissions)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'Condition {condition} is not allowed'.format(condition=condition)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_new_table_incorrect_condition3(self):
condition = 'tryam'
permissions = "{\"insert\": \"true\", \"update\" : \"true\"," + \
" \"new_column\": \"" + condition + "\"}"
tx = contract.new_table(self.url, self.pr_key, self.token, perms=permissions)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = 'Condition {condition} is not allowed'.format(condition=condition)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_new_table_exist_name(self):
tx = contract.new_table(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
tx2 = contract.new_table(self.url, self.pr_key, self.token, name=tx['name'])
status = actions.tx_status(self.url, self.wait, tx2['hash'], self.token)
msg = 'table {name} exists'.format(name=tx['name'])
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_new_table_incorrect_name_cyrillic(self):
name = 'таблица'
tx = contract.new_table(self.url, self.pr_key, self.token, name=name)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = "Name {name} must only contain latin, digit and '_', '-' characters".format(name=name)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_new_table_identical_columns(self):
columns = "[{\"name\":\"MyName\",\"type\":\"varchar\"," + \
"\"index\": \"1\", \"conditions\":\"true\"}," + \
"{\"name\":\"MyName\",\"type\":\"varchar\"," + \
"\"index\": \"1\", \"conditions\":\"true\"}]"
tx = contract.new_table(self.url, self.pr_key, self.token, columns=columns)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
self.unit.assertIn('There are the same columns', status['error'],
'Incorrect message: ' + str(status))
def test_edit_table(self):
tx = contract.new_table(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
tx2 = contract.edit_table(self.url, self.pr_key, self.token, tx['name'])
check.is_tx_in_block(self.url, self.wait, tx2, self.token)
def test_new_column(self):
tx = contract.new_table(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
tx2 = contract.new_column(self.url, self.pr_key, self.token,
tx['name'], type='varchar')
check.is_tx_in_block(self.url, self.wait, tx2, self.token)
tx3 = contract.new_column(self.url, self.pr_key, self.token,
tx['name'], type='json')
check.is_tx_in_block(self.url, self.wait, tx3, self.token)
tx4 = contract.new_column(self.url, self.pr_key, self.token,
tx['name'], type='number')
check.is_tx_in_block(self.url, self.wait, tx4, self.token)
tx5 = contract.new_column(self.url, self.pr_key, self.token,
tx['name'], type='datetime')
check.is_tx_in_block(self.url, self.wait, tx5, self.token)
tx6 = contract.new_column(self.url, self.pr_key, self.token,
tx['name'], type='money')
check.is_tx_in_block(self.url, self.wait, tx6, self.token)
tx7 = contract.new_column(self.url, self.pr_key, self.token,
tx['name'], type='text')
check.is_tx_in_block(self.url, self.wait, tx7, self.token)
tx8 = contract.new_column(self.url, self.pr_key, self.token,
tx['name'], type='double')
check.is_tx_in_block(self.url, self.wait, tx8, self.token)
tx9 = contract.new_column(self.url, self.pr_key, self.token,
tx['name'], type='character')
check.is_tx_in_block(self.url, self.wait, tx9, self.token)
def test_edit_column(self):
tx = contract.new_table(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
tx2 = contract.new_column(self.url, self.pr_key, self.token, tx['name'])
check.is_tx_in_block(self.url, self.wait, tx2, self.token)
tx3 = contract.edit_column(self.url, self.pr_key, self.token,
tx['name'], tx2['name'])
check.is_tx_in_block(self.url, self.wait, tx3, self.token)
def test_new_lang(self):
tx = contract.new_lang(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
def test_new_lang_joint(self):
tx = contract.new_lang_joint(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
def test_edit_lang_joint(self):
tx = contract.new_lang_joint(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
id = actions.get_count(self.url, 'languages', self.token)
tx2 = contract.edit_lang_joint(self.url, self.pr_key, self.token, id)
check.is_tx_in_block(self.url, self.wait, tx2, self.token)
def test_edit_lang(self):
tx = contract.new_lang(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
id = actions.get_count(self.url, 'languages', self.token)
tx2 = contract.edit_lang(self.url, self.pr_key, self.token, id)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
def test_new_app_param(self):
tx = contract.new_app_param(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
def test_edit_app_param(self):
tx = contract.new_app_param(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
tx2 = contract.edit_app_param(self.url, self.pr_key, self.token, 1)
check.is_tx_in_block(self.url, self.wait, tx2, self.token)
def test_delayed_contracts(self):
# add table for test
column = '''[{"name":"id_block","type":"number", "index": "1", "conditions":"true"}]'''
tx = contract.new_table(self.url, self.pr_key, self.token, columns=column)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
# add contract which insert records in table in progress CallDelayedContract
body = '''
{
data{}
conditions{}
action {
DBInsert("%s", {id_block: $block})
}
}
''' % tx['name']
tx_cont = contract.new_contract(self.url, self.pr_key, self.token, source=body)
check.is_tx_in_block(self.url, self.wait, tx_cont, self.token)
# NewDelayedContract
new_limit = 3
tx2 = contract.new_delayed_contract(self.url, self.pr_key, self.token,
name=tx_cont['name'], limit=new_limit)
old_block_id = check.is_tx_in_block(self.url, self.wait, tx2, self.token)
# get record id of 'delayed_contracts' table for run EditDelayedContract
id = actions.get_count(self.url, 'delayed_contracts', self.token)
# wait block_id until run CallDelayedContract
self.wait_block_id(old_block_id, new_limit)
# EditDelayedContract
editLimit = 2
tx3 = contract.edit_delayed_contract(self.url, self.pr_key, self.token, id,
tx2['name'], limit=editLimit)
old_block_id = check.is_tx_in_block(self.url, self.wait, tx3, self.token)
# wait block_id until run CallDelayedContract
self.wait_block_id(old_block_id, editLimit)
# verify records count in table
count = actions.get_count(self.url, tx['name'], self.token)
self.unit.assertEqual(int(count), new_limit + editLimit)
def test_upload_binary(self):
path = os.path.join(os.getcwd(), 'fixtures', 'image2.jpg')
tx = contract.upload_binary(self.url, self.pr_key, self.token, path)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
def test_contract_recursive_call_by_name_action(self):
contract_name = 'recur_' + tools.generate_random_name()
body = '''
{
data { }
conditions { }
action {
Println("hello1")
%s()
}
}
''' % contract_name
tx = contract.new_contract(self.url, self.pr_key, self.token,
name=contract_name, source=body)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = "The contract can't call itself recursively"
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_contract_recursive_call_by_name_conditions(self):
contract_name = 'recur_' + tools.generate_random_name()
body = '''
{
data { }
conditions {
Println("hello1")
%s()
}
action { }
}
''' % contract_name
tx = contract.new_contract(self.url, self.pr_key, self.token,
name=contract_name, source=body)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = "The contract can't call itself recursively"
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_contract_recursive_call_by_name_func_action(self):
contract_name = 'recur_' + tools.generate_random_name()
body = '''
{
func runContract() int {
%s()
}
data { }
conditions { }
action {
runContract()
}
}
''' % contract_name
tx = contract.new_contract(self.url, self.pr_key, self.token,
name=contract_name, source=body)
status = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
msg = "The contract can't call itself recursively"
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_contract_recursive_call_contract_action(self):
contract_name = 'recur_' + tools.generate_random_name()
body = '''
{
data { }
conditions { }
action {
Println("hello1")
var par map
CallContract("%s", par)
}
}
''' % contract_name
tx = contract.new_contract(self.url, self.pr_key, self.token,
name=contract_name, source=body)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
res = actions.call_contract(self.url, self.pr_key, contract_name, {}, self.token)
status = actions.tx_status(self.url, self.wait, res, self.token)
msg = 'There is loop in @1{con} contract'.format(con=contract_name)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_functions_recursive_limit(self):
# add contract with recursive
body = '''
{
func myfunc(num int) int {
num = num + 1
myfunc(num)
}
data{}
conditions{}
action {
$a = 0
myfunc($a)
}
}
'''
tx = contract.new_contract(self.url, self.pr_key, self.token, source=body)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
# test
msg = 'max call depth'
tx_call = actions.call_contract(self.url, self.pr_key, tx['name'], {}, self.token)
status = actions.tx_status(self.url, self.wait, tx_call, self.token)
self.unit.assertIn(msg, status['error'], 'Incorrect message: ' + str(status))
def test_import_export(self):
#changing limits
data = {'Name': 'max_block_generation_time', 'Value': '10000'}
res = actions.call_contract(self.url, self.pr_key, 'UpdateSysParam', data, self.token)
check.is_tx_in_block(self.url, self.wait, {'hash': res}, self.token)
# Export
tx_ex = contract.export_new_app(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx_ex, self.token)
data = {}
res_export = actions.call_contract(self.url, self.pr_key, 'Export', data, self.token)
res = check.is_tx_in_block(self.url, self.wait, {'hash': res_export}, self.token)
#founder_id = actions.get_parameter_value(self.url, 'founder_account', self.token)
app_id = 1
export_app_data = actions.get_export_app_data(self.url, self.token, app_id, self.data['account'])
path = os.path.join(os.getcwd(), 'fixtures', 'exportApp1.json')
with open(path, 'w', encoding='UTF-8') as f:
f.write(export_app_data)
if os.path.exists(path):
file_exist = True
else:
file_exist = False
must_be = dict(resultExport=True,
resultFile=True)
actual = dict(resultExport=int(res) > 0,
resultFile=file_exist)
self.unit.assertDictEqual(must_be, actual, 'test_Export is failed!')
# Import
path = os.path.join(os.getcwd(), 'fixtures', 'exportApp1.json')
tx = contract.import_upload(self.url, self.pr_key, self.token, path)
tx0 = check.is_tx_in_block(self.url, self.wait, tx, self.token)
import_app_data = db.get_import_app_data(self.db, self.data['account'])
import_app_data = import_app_data['data']
contract_name = 'Import'
data = [{'contract': contract_name,
'params': import_app_data[i]} for i in range(len(import_app_data))]
self.callMulti(contract_name, data, 3000)
#limits
data = {'Name': 'max_block_generation_time', 'Value': '2000'}
res = actions.call_contract(self.url, self.pr_key, 'UpdateSysParam', data, self.token)
check.is_tx_in_block(self.url, self.wait, {'hash': res}, self.token)