-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_simvolio.py
920 lines (811 loc) · 41 KB
/
test_simvolio.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
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
import hashlib
import unittest
import time
from libs import actions, db, tools, contract as contracts, check, api
class TestSimvolio():
contracts = tools.read_fixtures_yaml('simvolio')
wait = tools.read_config('test')['wait_tx_status']
config = tools.read_config('nodes')
unit = unittest.TestCase()
def setup(self):
print('setup class')
self.url = self.config[1]['url']
self.pr_key = self.config[0]['private_key']
self.db1 = self.config[0]['db']
data = actions.login(self.url, self.pr_key, 0)
self.token = data['jwtToken']
def check_contract(self, sourse, check_point, data={}):
tx = contracts.new_contract(
self.url, self.pr_key, self.token, source=sourse)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
res = actions.call_contract(
self.url, self.pr_key, tx['name'], data, self.token)
result = actions.tx_status(self.url, self.wait, res, self.token)
self.unit.assertIn(check_point, result['result'], 'ERROR: ' +
str(result))
def test_contract_dbFind(self):
contract = self.contracts['dbFind']
self.check_contract(contract['code'], contract['asert'])
def test_contract_toUpper(self):
contract = self.contracts['toUpper']
self.check_contract(contract['code'], contract['asert'])
def test_contract_elseif(self):
contract = self.contracts['elseif']
self.check_contract(contract['code'], contract['asert'])
def test_contract_blockTime(self):
contract = self.contracts['blockTime']
self.check_contract(contract['code'], contract['asert'])
def test_contract_ecosysParam(self):
contract = self.contracts['ecosysParam']
self.check_contract(contract['code'], contract['asert'])
def test_contract_ifMap(self):
contract = self.contracts['ifMap']
self.check_contract(contract['code'], contract['asert'])
def test_contract_dbRow(self):
contract = self.contracts['dbRow']
self.check_contract(contract['code'], contract['asert'])
def test_contract_evalCondition(self):
contract = self.contracts['evalCondition']
self.check_contract(contract['code'], contract['asert'])
def test_contract_validateCondition(self):
contract = self.contracts['validateCondition']
self.check_contract(contract['code'], contract['asert'])
def test_contract_addressToId(self):
contract = self.contracts['addressToId']
self.check_contract(contract['code'], contract['asert'])
def test_contract_idToAddress(self):
contract = self.contracts['idToAddress']
self.check_contract(contract['code'], contract['asert'])
def test_contract_one(self):
contract = self.contracts['one']
self.check_contract(contract['code'], contract['asert'])
def test_contract_row(self):
contract = self.contracts['row']
self.check_contract(contract['code'], contract['asert'])
def test_contract_contains(self):
contract = self.contracts['contains']
self.check_contract(contract['code'], contract['asert'])
def test_contract_float(self):
contract = self.contracts['float']
self.check_contract(contract['code'], contract['asert'])
def test_contract_hasPrefix(self):
contract = self.contracts['hasPrefix']
self.check_contract(contract['code'], contract['asert'])
def test_contract_hexToBytes(self):
contract = self.contracts['hexToBytes']
self.check_contract(contract['code'], contract['asert'])
def test_contract_int(self):
contract = self.contracts['int']
self.check_contract(contract['code'], contract['asert'])
def test_contract_join(self):
contract = self.contracts['join']
self.check_contract(contract['code'], contract['asert'])
def test_contract_split(self):
contract = self.contracts['split']
self.check_contract(contract['code'], contract['asert'])
def test_contract_len(self):
contract = self.contracts['len']
self.check_contract(contract['code'], contract['asert'])
def test_contract_pubToID(self):
contract = self.contracts['pubToID']
self.check_contract(contract['code'], contract['asert'])
def test_contract_replace(self):
contract = self.contracts['replace']
self.check_contract(contract['code'], contract['asert'])
def test_contract_size(self):
contract = self.contracts['size']
self.check_contract(contract['code'], contract['asert'])
def test_contract_sha256(self):
contract = self.contracts['sha256']
self.check_contract(contract['code'], contract['asert'])
def test_contract_sprintf(self):
contract = self.contracts['sprintf']
self.check_contract(contract['code'], contract['asert'])
def test_contract_str(self):
contract = self.contracts['str']
self.check_contract(contract['code'], contract['asert'])
def test_contract_substr(self):
contract = self.contracts['substr']
self.check_contract(contract['code'], contract['asert'])
def test_contract_sysParamString(self):
contract = self.contracts['sysParamString']
self.check_contract(contract['code'], contract['asert'])
def test_contract_sysParamInt(self):
contract = self.contracts['sysParamInt']
self.check_contract(contract['code'], contract['asert'])
def test_contract_getContractByName(self):
contract = self.contracts['getContractByName']
self.check_contract(contract['code'], contract['asert'])
def test_contract_random(self):
contract = self.contracts['random']
self.check_contract(contract['code'], contract['asert'])
def test_contract_getBlock(self):
contract = self.contracts['getBlock']
self.check_contract(contract['code'], contract['asert'])
def test_contract_type_bool(self):
contract = self.contracts['type_bool']
self.check_contract(contract['code'], contract['asert'])
def test_contract_type_bytes(self):
contract = self.contracts['type_bytes']
self.check_contract(contract['code'], contract['asert'])
def test_contract_type_int(self):
contract = self.contracts['type_int']
self.check_contract(contract['code'], contract['asert'])
def test_contract_type_address(self):
contract = self.contracts['type_address']
self.check_contract(contract['code'], contract['asert'])
def test_contract_type_array(self):
contract = self.contracts['type_array']
self.check_contract(contract['code'], contract['asert'])
def test_contract_type_map(self):
contract = self.contracts['type_map']
self.check_contract(contract['code'], contract['asert'])
def test_contract_type_money(self):
contract = self.contracts['type_money']
self.check_contract(contract['code'], contract['asert'])
def test_contract_date_time_location(self):
contract = self.contracts['DateTimeLocation']
self.check_contract(contract['code'], contract['asert'])
def test_contract_unix_date_time_location(self):
contract = self.contracts['UnixDateTimeLocation']
self.check_contract(contract['code'], contract['asert'])
def test_contract_type_float(self):
contract = self.contracts['type_float']
self.check_contract(contract['code'], contract['asert'])
def test_contract_type_string(self):
contract = self.contracts['type_string']
self.check_contract(contract['code'], contract['asert'])
def test_contract_getColumnType(self):
contract = self.contracts['getColumnType']
self.check_contract(contract['code'], contract['asert'])
def test_contract_decodeBase64(self):
contract = self.contracts['decodeBase64']
self.check_contract(contract['code'], contract['asert'])
def test_contract_encodeBase64(self):
contract = self.contracts['encodeBase64']
self.check_contract(contract['code'], contract['asert'])
def test_contract_jsonEncode(self):
contract = self.contracts['jsonEncode']
self.check_contract(contract['code'], contract['asert'])
def test_contract_jsonDecode(self):
contract = self.contracts['jsonDecode']
self.check_contract(contract['code'], contract['asert'])
def test_contract_bytesToString(self):
contract = self.contracts['bytesToString']
self.check_contract(contract['code'], contract['asert'])
def test_contract_stringToBytes(self):
contract = self.contracts['stringToBytes']
self.check_contract(contract['code'], contract['asert'])
def test_contract_append(self):
contract = self.contracts['append']
self.check_contract(contract['code'], contract['asert'])
def test_contract_getMapKeys(self):
contract = self.contracts['getMapKeys']
self.check_contract(contract['code'], contract['asert'])
def test_contract_sortedKeys(self):
contract = self.contracts['sortedKeys']
self.check_contract(contract['code'], contract['asert'])
def test_del_table_not_empty(self):
contractName = 'SimvolioDelTab'
if not actions.is_contract_present(self.url, self.token, contractName):
contract = self.contracts['del_table']
tx = contracts.new_contract(self.url, self.pr_key, self.token,
source=contract['code'], name = contractName)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
tab = 'contracts'
res = actions.call_contract(self.url, self.pr_key, contractName,
{"table": tab}, self.token)
result = actions.tx_status(self.url, self.wait, res, self.token)
self.unit.assertIn('Table 1_' + tab + ' is not empty', result['error'],
'Erorr in deleting tables by DelTab funtion')
def test_del_table_not_present(self):
contractName = 'SimvolioDelTab'
if not actions.is_contract_present(self.url, self.token, contractName):
contract = self.contracts['del_table']
tx = contracts.new_contract(self.url, self.pr_key, self.token,
source=contract['code'], name = contractName)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
tab = 'kjkb'
res = actions.call_contract(self.url, self.pr_key, contractName,
{"table": tab}, self.token)
result = actions.tx_status(self.url, self.wait, res, self.token)
self.unit.assertIn('Table 1_' + tab + ' has not been found', result['error'],
'Erorr in deleting tables by DelTab funtion' + result['error'])
def test_del_table_empty(self):
contractName = 'SimvolioDelTab'
if not actions.is_contract_present(self.url, self.token, contractName):
contract = self.contracts['del_table']
tx = contracts.new_contract(self.url, self.pr_key, self.token,
source=contract['code'], name = contractName)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
tx_tab = contracts.new_table(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx_tab, self.token)
res = actions.call_contract(self.url, self.pr_key, contractName,
{"table": tx_tab['name']}, self.token)
check.is_tx_in_block(self.url, self.wait, {'hash': res}, self.token)
def test_del_column_not_empty(self):
contractName = 'SimvolioDelColumn'
if not actions.is_contract_present(self.url, self.token, contractName):
contract = self.contracts['del_column']
tx = contracts.new_contract(self.url, self.pr_key, self.token,
source=contract['code'], name = contractName)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
tab = 'contracts'
res = actions.call_contract(self.url, self.pr_key, contractName,
{'table': tab, 'col': 'name'}, self.token)
result = actions.tx_status(self.url, self.wait, res, self.token)
self.unit.assertIn('Table 1_' + tab + ' is not empty', result['error'],
'Erorr in deleting tables by DelTab funtion' + result['error'])
def test_del_column_not_present_table(self):
contractName = 'SimvolioDelColumn'
if not actions.is_contract_present(self.url, self.token, contractName):
contract = self.contracts['del_column']
tx = contracts.new_contract(self.url, self.pr_key, self.token,
source=contract['code'], name = contractName)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
tab = 'notpresent'
res = actions.call_contract(self.url, self.pr_key, contractName,
{'table': tab, 'col': 'name'}, self.token)
result = actions.tx_status(self.url, self.wait, res, self.token)
self.unit.assertIn('Table 1_' + tab + ' has not been found', result['error'],
'Erorr in deleting tables by DelTab funtion' + result['error'])
def test_del_column_not_present_column(self):
contractName = 'SimvolioDelColumn'
if not actions.is_contract_present(self.url, self.token, contractName):
contract = self.contracts['del_column']
tx = contracts.new_contract(self.url, self.pr_key, self.token,
source=contract['code'], name = contractName)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
tx_tab = contracts.new_table(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx_tab, self.token)
col = "notpresent"
res = actions.call_contract(self.url, self.pr_key, contractName,
{'table': tx_tab['name'], 'col': col}, self.token)
result = actions.tx_status(self.url, self.wait, res, self.token)
self.unit.assertIn('column ' + col + " doesn't exist", result['error'],
'Erorr in deleting tables by DelTab funtion' + result['error'])
def test_del_column_not_empty(self):
contractName = 'SimvolioDelColumn'
if not actions.is_contract_present(self.url, self.token, contractName):
contract = self.contracts['del_column']
tx = contracts.new_contract(self.url, self.pr_key, self.token,
source=contract['code'], name = contractName)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
tx_tab = contracts.new_table(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx_tab, self.token)
tx2 = contracts.new_column(self.url, self.pr_key, self.token, tx_tab['name'])
check.is_tx_in_block(self.url, self.wait, tx2, self.token)
res = actions.call_contract(self.url, self.pr_key, contractName,
{'table': tx_tab['name'], 'col': tx2['name']}, self.token)
check.is_tx_in_block(self.url, self.wait, {'hash': res}, self.token)
def test_contract_langRes(self):
name = 'lang_' + tools.generate_random_name()
trans = '{"en": "test_en", "de": "test_de"}'
tx = contracts.new_lang(self.url, self.pr_key, self.token,
name=name, trans=trans)
check.is_tx_in_block(self.url, self.wait, tx, self.token,)
contract = self.contracts['langRes']
data = {'Name': name}
self.check_contract(contract['code'], contract['asert'], data)
def test_contract_dbInsert(self):
columns = '''[{"name":"name","type":"varchar",
"index": "1", "conditions":"true"},
{"name":"test","type":"varchar",
"index": "0", "conditions":"true"}]'''
tx = contracts.new_table(self.url, self.pr_key, self.token, columns=columns,
name='test')
actions.tx_status(self.url, self.wait, tx['hash'], self.token)
contract = self.contracts['dbInsert']
self.check_contract(contract['code'], contract['asert'])
def test_contract_dbUpdate(self):
columns = '''[{"name":"name","type":"varchar",
"index": "1", "conditions":"true"},
{"name":"test","type":"varchar",
"index": "0", "conditions":"true"}]'''
tx = contracts.new_table(self.url, self.pr_key, self.token, columns=columns,
name='test')
actions.tx_status(self.url, self.wait, tx['hash'], self.token)
contract = self.contracts['dbInsert']
self.check_contract(contract['code'], contract['asert'])
contract = self.contracts['dbUpdate']
self.check_contract(contract['code'], contract['asert'])
list = actions.get_list(self.url, 'test', self.token)['list']
for el in range(len(list)):
if int(list[el]['id']) == 1:
self.unit.assertEqual(
'updated', list[el]['test'], 'Failed. dbUpdate Error!')
break
def test_contracts_dbUpdateExt(self):
columns = '''[{"name":"name","type":"varchar",
"index": "1", "conditions":"true"},
{"name":"test","type":"varchar",
"index": "0", "conditions":"true"}]'''
tx = contracts.new_table(self.url, self.pr_key, self.token, columns=columns,
name='test')
actions.tx_status(self.url, self.wait, tx['hash'], self.token)
contract = self.contracts['dbInsert']
limit = 5
for i in range(limit):
self.check_contract(contract['code'], contract['asert'])
contract = self.contracts['dbUpdateExt']
self.check_contract(contract['code'], contract['asert'])
res = api.list(self.url, self.token, 'test', limit=limit)
expected = [
{'id': '1', 'name': 'block2', 'test': 'updatedById=1'},
{'id': '2', 'name': 'block2', 'test': 'updatedByName'},
{'id': '3', 'name': 'block2', 'test': 'updateIdBetween3-5'},
{'id': '4', 'name': 'block2', 'test': 'updateIdBetween3-5'},
{'id': '5', 'name': 'block2', 'test': 'updateIdBetween3-5'},
]
self.unit.assertEqual(res['list'], expected, 'Error in updated records')
def test_contract_callContract(self):
contract = self.contracts['myContract']
inner_contract_name = tools.generate_random_name()
tx = contracts.new_contract(self.url, self.pr_key, self.token,
source=contract['code'],
name=inner_contract_name)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
contract = self.contracts['callContract']
data = {'Name': inner_contract_name}
self.check_contract(contract['code'], contract['asert'], data)
def test_sys_vars_readonly(self):
var_list = [
'$time',
'$ecosystem_id',
'$block',
'$key_id',
'$block_key_id',
'$block_time',
'$original_contract',
'$this_contract',
'$guest_key',
'$stack',
]
expexted_dict = {}
actual_dict = {}
for i in range(len(var_list)):
code = ' { data{ } conditions{ } action{ ' + \
var_list[i] + ' = 5 } }'
tx = contracts.new_contract(
self.url, self.pr_key, self.token, source=code)
st = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
exp_result = 'system variable ' + \
var_list[i] + ' cannot be changed'
expexted_dict[i] = exp_result
actual_dict[i] = st['error']
self.unit.assertIn(exp_result, st['error'], 'Dictionaries is different')
def get_metrics(self, ecosystem_num, metric_name):
# get metrics count
res = actions.get_list(self.url, 'metrics', self.token)
i = 0
while i < len(res['list']):
if (int(res['list'][i]['key']) == int(ecosystem_num)) and (
str(res['list'][i]['metric']) == str(metric_name)):
return res['list'][i]['value']
i += 1
def test_z1_db_select_metrics_min(self):
# func generate contract which return block_id and increment count blocks
def wait_block_id(old_block_id, limit):
while True:
if old_block_id == limit:
break
code = ' {\n data{} \n conditions{} \n action { \n $result = $block \n } \n }'
tx = contracts.new_contract(
self.url, self.pr_key, self.token, source=code)
current_block_id = check.is_tx_in_block(
self.url, self.wait, tx, self.token)
old_block_id = current_block_id
# generate contract which return count blocks in blockchain
code2 = ' {\n data{} \n conditions{} \n action { \n $result = $block \n } \n }'
tx2 = contracts.new_contract(
self.url, self.pr_key, self.token, source=code2)
current_block_id = check.is_tx_in_block(
self.url, self.wait, tx2, self.token)
# wait until generated 100 blocks
if current_block_id < 100:
wait_block_id(current_block_id, 100)
# wait until generated multiples of 100 blocks
if (current_block_id % 100 >= 90):
count = current_block_id + (100 - (current_block_id % 100))
wait_block_id(current_block_id, count)
# test
ecosystem_tx = self.get_metrics(1, 'ecosystem_tx')
contract = self.contracts['dbSelectMetricsMin']
self.check_contract(contract['code'], str(ecosystem_tx))
def test_z2_db_select_metrics_max(self):
# Run test after test_z1_db_select_metrics_min
ecosystem_members = self.get_metrics(1, 'ecosystem_members')
contract = self.contracts['dbSelectMetricsMax']
self.check_contract(contract['code'], str(ecosystem_members))
def test_z3_db_select_metrics_max(self):
# Run test after test_z1_db_select_metrics_min
ecosystem_pages = self.get_metrics(1, 'ecosystem_pages')
contract = self.contracts['dbSelectMetricsAvg']
self.check_contract(contract['code'], str(ecosystem_pages))
def test_get_history_contract(self):
# create contract
replaced_string = 'old_var'
code = '''
{
data{}
conditions{}
action{ var %s int }
}
''' % replaced_string
tx = contracts.new_contract(
self.url, self.pr_key, self.token, source=code)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
# change contract
id = actions.get_object_id(
self.url, tx['name'], 'contracts', self.token)
new_code = code.replace(replaced_string, 'new_var')
tx = contracts.edit_contract(self.url, self.pr_key, self.token, id,
new_source=new_code)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
# test
data = {'Table': 'contracts', 'ID': id}
contract = self.contracts['getHistory']
self.check_contract(contract['code'], replaced_string, data)
def test_get_history_page(self):
# create page
page = 'Div(Body: Hello)'
tx_page = contracts.new_page(
self.url, self.pr_key, self.token, value=page)
check.is_tx_in_block(self.url, self.wait, tx_page, self.token)
# change page
id = actions.get_object_id(
self.url, tx_page['name'], 'pages', self.token)
new_value_page = page.replace('Hello', 'new_var')
tx = contracts.edit_page(
self.url, self.pr_key, self.token, id, value=new_value_page)
check.is_tx_in_block(self.url, self.wait, tx, self.token)
# test
data = {'Table': 'pages', 'ID': id}
contract = self.contracts['getHistory']
self.check_contract(contract['code'], page, data)
def test_sys_var_stack(self):
# This test has not a fixture
inner_name = tools.generate_random_name()
innerBody = '''
{
data{}
conditions{}
action {
$result = $stack
}
}
'''
inner_res = contracts.new_contract(self.url, self.pr_key, self.token,
source=innerBody, name=inner_name)
check.is_tx_in_block(self.url, self.wait, inner_res, self.token)
outer_name = tools.generate_random_name()
outer_body = '''
{
data{}
conditions{}
action {
var par map
var res string
res = CallContract("%s", par)
$result = res
}
}
''' % inner_name
outer_res = contracts.new_contract(self.url, self.pr_key, self.token,
source=outer_body, name=outer_name)
check.is_tx_in_block(self.url, self.wait, outer_res, self.token)
result = actions.call_contract(
self.url, self.pr_key, outer_name, {}, self.token)
res = actions.tx_status(self.url, self.wait, result, self.token)
must_be = '[@1' + outer_res['name'] + ' @1' + inner_res['name'] + ']'
self.unit.assertEqual(
must_be, res['result'], 'test_sys_var_stack is failed!')
def test_get_history_row_menu(self):
# create menu
rollc_before = db.get_max_id_from_table(self.db1, 'rollback_tx')
value = 'This is new menu'
menu = contracts.new_menu(
self.url, self.pr_key, self.token, value=value)
check.is_tx_in_block(self.url, self.wait, menu, self.token)
rollc_after = db.get_max_id_from_table(self.db1, 'rollback_tx')
# change menu
id = actions.get_object_id(self.url, menu['name'], 'menu', self.token)
new_value_menu = value.replace('new menu', 'new_var')
menu_e = contracts.edit_menu(self.url, self.pr_key, self.token,
id, value=new_value_menu)
check.is_tx_in_block(self.url, self.wait, menu_e, self.token)
# test
query = '''SELECT id FROM "rollback_tx" WHERE table_name = '1_menu' AND data='' AND id >= %s AND id <= %s''' % (
rollc_before, rollc_after)
rollback_id = db.submit_query(query, self.db1)[0][0]
data = {'Table': 'menu', 'ID': id, 'rID': rollback_id}
contract = self.contracts['getHistoryRow']
self.check_contract(contract['code'], value, data)
def test_get_history_row_block(self):
# create block
rollc_before = db.get_max_id_from_table(self.db1, 'rollback_tx')
value = 'Div(Body: Hello)'
block = contracts.new_block(
self.url, self.pr_key, self.token, value=value)
check.is_tx_in_block(self.url, self.wait, block, self.token)
rollc_after = db.get_max_id_from_table(self.db1, 'rollback_tx')
# change block
id = actions.get_object_id(
self.url, block['name'], 'blocks', self.token)
new_value_block = value.replace('Hello', 'new_var')
block_e = contracts.edit_block(self.url, self.pr_key, self.token, id,
value=new_value_block)
check.is_tx_in_block(self.url, self.wait, block_e, self.token)
# test
query = '''SELECT id FROM "rollback_tx" WHERE table_name = '1_blocks' AND data='' AND id >= %s AND id <= %s''' % (
rollc_before, rollc_after)
rollback_id = db.submit_query(query, self.db1)[0][0]
print(rollback_id)
data = {'Table': 'blocks', 'ID': id, 'rID': rollback_id}
contract = self.contracts['getHistoryRow']
self.check_contract(contract['code'], value, data)
def test_contract_hash(self):
my_string = 'Text message'
cont_value = '''
{
action {
$result = Hash("%s")
}
}
''' % my_string
res = contracts.new_contract(self.url,
self.pr_key,
self.token,
source=cont_value)
check.is_tx_in_block(self.url, self.wait, res, self.token)
res = actions.call_contract(self.url,
self.pr_key,
res['name'],
{},
self.token)
res = actions.tx_status(self.url, self.wait, res, self.token)
m = hashlib.sha256()
m.update(bytes(my_string, 'utf-8'))
sha = m.hexdigest()
self.unit.assertEqual(res['result'], sha, 'Hashes is not equals.')
def test_types_of_data(self):
data = {"B": "true",
"B2": "true",
"B3": "true"}
contract = self.contracts['types_of_data']
self.check_contract(contract['code'], contract['asert'], data)
def test_types_of_data_incorrect(self):
contract = self.contracts['types_of_data_incorrect']
tx = contracts.new_contract(
self.url, self.pr_key, self.token, source=contract['code'])
result = actions.tx_status(self.url, self.wait, tx['hash'], self.token)
self.unit.assertIn(contract['asert'],result['error'], 'Error messages is different')
def test_transactionInfo(self):
res = contracts.new_contract(self.url,
self.pr_key,
self.token)
data = {'Myhash': res['hash']}
contract = self.contracts['transactionInfo']
self.check_contract(contract['code'], contract['asert'], data)
def test_contract_PubToHex(self):
contract = self.contracts['PubToHex']
self.check_contract(contract['code'], contract['asert'])
def test_contract_HexToPub(self):
contract = self.contracts['HexToPub']
self.check_contract(contract['code'], contract['asert'])
def test_throw(self):
contract = self.contracts['Throw']
tx = contracts.new_contract(
self.url, self.pr_key, self.token, source=str(contract['code']))
check.is_tx_in_block(self.url, self.wait, tx, self.token)
res = actions.call_contract(
self.url, self.pr_key, tx['name'], {}, self.token)
resp = actions.tx_get_error(self.url, 30, res, self.token)
print("resp: ", resp)
self.unit.assertIn(contract['asert']['errmsg']['error'], resp['error'], resp)
def test_contract_UpdateNotifications(self):
contract = self.contracts['UpdateNotifications']
self.check_contract(contract['code'], contract['asert'])
def test_contract_UpdateRolesNotifications(self):
contract = self.contracts['UpdateRolesNotifications']
self.check_contract(contract['code'], contract['asert'])
def test_contract_Floor(self):
contract = self.contracts['Floor']
self.check_contract(contract['code'], contract['asert'])
def test_contract_Log(self):
contract = self.contracts['Log']
self.check_contract(contract['code'], contract['asert'])
def test_contract_LogNegative(self):
contract = self.contracts['LogNegative']
tx = contracts.new_contract(
self.url, self.pr_key, self.token, source=str(contract['code']))
check.is_tx_in_block(self.url, self.wait, tx, self.token)
res = actions.call_contract(
self.url, self.pr_key, tx['name'], {}, self.token)
resp = actions.tx_get_error(self.url, 30, res, self.token)
print(contract['asert'])
print(resp['error'])
self.unit.assertIn(contract['asert'], resp['error'], str(resp))
def test_contract_LogZero(self):
contract = self.contracts['LogZero']
tx = contracts.new_contract(
self.url, self.pr_key, self.token, source=str(contract['code']))
check.is_tx_in_block(self.url, self.wait, tx, self.token)
res = actions.call_contract(
self.url, self.pr_key, tx['name'], {}, self.token)
resp = actions.tx_get_error(self.url, 30, res, self.token)
self.unit.assertIn(contract['asert'], resp['error'], resp)
def test_contract_Log10(self):
contract = self.contracts['Log10']
self.check_contract(contract['code'], contract['asert'])
def test_contract_Log10Negative(self):
contract = self.contracts['Log10Negative']
tx = contracts.new_contract(
self.url, self.pr_key, self.token, source=str(contract['code']))
check.is_tx_in_block(self.url, self.wait, tx, self.token)
res = actions.call_contract(
self.url, self.pr_key, tx['name'], {}, self.token)
resp = actions.tx_get_error(self.url, 30, res, self.token)
self.unit.assertIn(contract['asert'], resp['error'], resp)
def test_contract_Log10Zero(self):
contract = self.contracts['Log10Zero']
tx = contracts.new_contract(
self.url, self.pr_key, self.token, source=str(contract['code']))
check.is_tx_in_block(self.url, self.wait, tx, self.token)
res = actions.call_contract(
self.url, self.pr_key, tx['name'], {}, self.token)
resp = actions.tx_get_error(self.url, 30, res, self.token)
self.unit.assertIn(contract['asert'], resp['error'], resp)
def test_contract_Pow(self):
contract = self.contracts['Pow']
self.check_contract(contract['code'], contract['asert'])
def test_contract_PowError(self):
contract = self.contracts['PowError']
tx = contracts.new_contract(
self.url, self.pr_key, self.token, source=str(contract['code']))
check.is_tx_in_block(self.url, self.wait, tx, self.token)
res = actions.call_contract(
self.url, self.pr_key, tx['name'], {}, self.token)
resp = actions.tx_get_error(self.url, 30, res, self.token)
self.unit.assertIn(contract['asert'], resp['error'], resp)
def test_contract_Round(self):
contract = self.contracts['Round']
self.check_contract(contract['code'], contract['asert'])
def test_contract_Sqrt(self):
contract = self.contracts['Sqrt']
self.check_contract(contract['code'], contract['asert'])
def test_contract_SqrtError(self):
contract = self.contracts['SqrtError']
tx = contracts.new_contract(
self.url, self.pr_key, self.token, source=str(contract['code']))
check.is_tx_in_block(self.url, self.wait, tx, self.token)
res = actions.call_contract(
self.url, self.pr_key, tx['name'], {}, self.token)
resp = actions.tx_get_error(self.url, 30, res, self.token)
self.unit.assertIn(contract['asert'], resp['error'], resp)
def test_contract_NotValidStringUTF8(self):
contract = self.contracts['NotValidStringUTF8']
tx = contracts.new_contract(self.url, self.pr_key, self.token, source=contract['code'])
check.is_tx_in_block(self.url, self.wait, tx, self.token)
msg = contract['asert']
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.assertEqual(msg, status['error'], 'Incorect messages: ' + str(status))
def test_dbfind_sorted_keys(self):
table = 'keys'
# create new ecosystem
tx_ecos = contracts.new_ecosystem(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx_ecos, self.token)
# create new contract for run it in loop
contract = self.contracts['DBFindSorted']
tx_cont = contracts.new_contract(
self.url, self.pr_key, self.token, source=str(contract['code']))
check.is_tx_in_block(self.url, self.wait, tx_cont, self.token)
# get result from db
db_res = db.get_all_sorted_records_from_table(self.db1, table)
expected_hash = tools.get_hash_sha256(str(db_res))
# test
expected_list = {}
actual_list = {}
i = 0
while i < 10:
expected_list[i] = expected_hash
# get result from contract
data = {"Table": table}
res = actions.call_contract(
self.url, self.pr_key, tx_cont['name'], data, self.token)
actual_hash = actions.tx_status(self.url, self.wait, res, self.token)['result']
actual_list[i] = actual_hash
i += 1
self.unit.assertDictEqual(expected_list, actual_list, 'Hashes is not equals')
def test_dbfind_sorted_members(self):
table = 'members'
# create new ecosystem
tx_ecos = contracts.new_ecosystem(self.url, self.pr_key, self.token)
check.is_tx_in_block(self.url, self.wait, tx_ecos, self.token)
# create new contract for run it in loop
contract = self.contracts['DBFindSorted']
tx_cont = contracts.new_contract(
self.url, self.pr_key, self.token, source=str(contract['code']))
check.is_tx_in_block(self.url, self.wait, tx_cont, self.token)
# get result from db
db_res = db.get_all_sorted_records_from_table(self.db1, table)
expected_hash = tools.get_hash_sha256(str(db_res))
# test
expected_list = {}
actual_list = {}
i = 0
while i < 10:
expected_list[i] = expected_hash
# get result from contract
data = {"Table": table}
res = actions.call_contract(
self.url, self.pr_key, tx_cont['name'], data, self.token)
actual_hash = actions.tx_status(self.url, self.wait, res, self.token)['result']
actual_list[i] = actual_hash
i += 1
self.unit.assertDictEqual(expected_list, actual_list, 'Hashes is not equals')
def test_dbfind_sorted_contracts(self):
table = 'contracts'
# create new contract for run it in loop
contract = self.contracts['DBFindSorted']
tx_cont = contracts.new_contract(
self.url, self.pr_key, self.token, source=str(contract['code']))
check.is_tx_in_block(self.url, self.wait, tx_cont, self.token)
# get result from db
db_res = db.get_all_sorted_records_from_table(self.db1, table)
expected_hash = tools.get_hash_sha256(str(db_res))
# test
expected_list = {}
actual_list = {}
i = 0
while i < 10:
expected_list[i] = expected_hash
# get result from contract
data = {"Table": table}
res = actions.call_contract(
self.url, self.pr_key, tx_cont['name'], data, self.token)
actual_hash = actions.tx_status(self.url, self.wait, res, self.token)['result']
actual_list[i] = actual_hash
i += 1
self.unit.assertDictEqual(expected_list, actual_list, 'Hashes is not equals')
def test_dbfind_sorted_user_table(self):
# create user table
table_name = tools.generate_random_name()
columns = '''[{"name":"name","type":"varchar",
"index": "1", "conditions":"true"}]'''
tx_cont = contracts.new_table(
self.url, self.pr_key, self.token, name=table_name, columns=columns )
check.is_tx_in_block(self.url, self.wait, tx_cont, self.token)
# create new contract for insert data in user table
contract = self.contracts['DBFindSortedUserTable']
tx_cont = contracts.new_contract(
self.url, self.pr_key, self.token, source=str(contract['code']))
check.is_tx_in_block(self.url, self.wait, tx_cont, self.token)
# call contract, which insert data in user table
data = {"TableName": table_name}
res = actions.call_contract(
self.url, self.pr_key, tx_cont['name'], data, self.token)
actions.tx_status(self.url, self.wait, res, self.token)['result']
# create new contract for run it in loop
contract = self.contracts['DBFindSorted']
tx_cont = contracts.new_contract(
self.url, self.pr_key, self.token, source=str(contract['code']))
check.is_tx_in_block(self.url, self.wait, tx_cont, self.token)
# get result from db
db_res = db.get_all_sorted_records_from_table(self.db1, table_name)
expected_hash = tools.get_hash_sha256(str(db_res))
# test
expected_list = {}
actual_list = {}
i = 0
while i < 10:
expected_list[i] = expected_hash
# get result from contract
data = {"Table": table_name}
res = actions.call_contract(
self.url, self.pr_key, tx_cont['name'], data, self.token)
actual_hash = actions.tx_status(self.url, self.wait, res, self.token)['result']
actual_list[i] = actual_hash
i += 1
self.unit.assertDictEqual(expected_list, actual_list, 'Hashes is not equals')