-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_block_chain.py
71 lines (64 loc) · 2.99 KB
/
test_block_chain.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
import unittest
import time
from builtins import sum
from libs import actions, tools, check, contract
class TestBlockChain():
full_config = tools.read_config('nodes')
nodes = len(full_config)
config1 = full_config[0]
config2 = full_config[1]
wait = tools.read_config('test')['wait_tx_status']
def setup_class(self):
self.uni = unittest.TestCase()
data = actions.login(
self.config1['url'], self.config1['private_key'], 0)
self.token = data['jwtToken']
def test_block_chain(self):
ts_count = 30
i = 1
amounts_b = actions.get_user_token_amounts(
self.config1['url'], self.token)
sum_amounts_before = sum(amounts_b)
while i < ts_count:
tx_cont = contract.new_contract(self.config1['url'],
self.config1['private_key'],
self.token)
check.is_tx_in_block(self.config1['url'], self.wait, tx_cont, self.token)
i = i + 1
# time.sleep(1)
amounts_after = actions.get_user_token_amounts(
self.config1['url'], self.token)
expect = {'isTheSameNodes': True, 'isTheSameDB': True,
'sumAmounts': sum_amounts_before}
dict = {'isTheSameNodes': check.compare_nodes(self.full_config),
'isTheSameDB': check.compare_db(self.full_config, self.config1['url'],
self.token),
'sumAmounts': sum(amounts_after)}
self.uni.assertDictEqual(expect, dict, 'Error in test_block_chain')
def test_block_chain_edit(self):
ts_count = 30
tx = contract.new_menu(
self.config1['url'], self.config1['private_key'], self.token)
check.is_tx_in_block(self.config1['url'], self.wait, tx, self.token)
id = actions.get_object_id(
self.config1['url'], tx['name'], 'menu', self.token)
i = 1
amounts_b = actions.get_user_token_amounts(
self.config1['url'], self.token)
sum_amounts_before = sum(amounts_b)
while i < ts_count:
tx_edit = contract.edit_menu(self.config1['url'],
self.config1['private_key'],
self.token, id)
check.is_tx_in_block(self.config1['url'], self.wait, tx_edit, self.token)
i = i + 1
amounts_after = actions.get_user_token_amounts(
self.config1['url'], self.token)
expect = {'isTheSameNodes': True, 'isTheSameDB': True,
'sumAmounts': sum_amounts_before}
dict = {'isTheSameNodes': check.compare_nodes(self.full_config),
'isTheSameDB': check.compare_db(self.full_config, self.config1['url'],
self.token),
'sumAmounts': sum(amounts_after)}
self.uni.assertDictEqual(
expect, dict, 'Error in test_block_chain_edit')