-
Notifications
You must be signed in to change notification settings - Fork 1
/
locastfile.py
139 lines (126 loc) · 6.01 KB
/
locastfile.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
import datetime
from locust import HttpLocust, TaskSet, task
from libs import actions, tools, api
from genesis_blockchain_tools.contract import Contract
class WebsiteTasks(TaskSet):
def on_start(self):
self.config = tools.read_config('nodes')
self.url = self.client.base_url
self.pause = tools.read_config('test')['wait_tx_status']
self.pr_key = self.config[0]['private_key']
self.data = actions.login(self.url, self.pr_key, 0)
self.token = self.data['jwtToken']
keys = tools.read_fixtures('keys')
self.ldata = actions.login(self.config[1]['url'], keys['key2'], 0)
self.before_time = datetime.datetime.now()
self.before_trs = api.metrics(self.url, self.token, 'transactions')['count']
def on_stop(self):
after_time = datetime.datetime.now()
after_trs = api.metrics(self.url, self.token, 'transactions')['count']
trs = int(after_trs) - int(self.before_trs)
dur = after_time - self.before_time
speed = trs/dur
data = {"speed": speed}
print("Speed: ", str(speed), " in second")
file = os.path.join(os.getcwd(), 'speed.txt')
with open(file, 'w') as f:
f.write(data)
@task
def NewContract(self):
contract_name = 'NewContract'
code, name = tools.generate_name_and_code('')
data = {'Value': code, 'ApplicationId': 1, 'Conditions': 'true'}
schema = api.contract(self.url, self.token, contract_name)
contract = Contract(schema=schema, private_key=self.pr_key,
params=data)
tx_bin_data = contract.concat()
self.client.post('/sendTx', files={'call1': tx_bin_data},
headers={'Authorization': self.token}, name=contract_name)
def TokensSend(self):
contract_name = 'TokensSend'
data = {'Recipient': self.ldata['address'],
'Amount': '1000'}
schema = api.contract(self.url, self.token, contract_name)
contract = Contract(schema=schema, private_key=self.pr_key,
params=data)
tx_bin_data = contract.concat()
self.client.post('/sendTx', files={'call1': tx_bin_data},
headers={'Authorization': self.token}, name=contract_name)
@task
def NewParameter(self):
contract_name = 'NewParameter'
name = 'Par_' + tools.generate_random_name()
data = {'Name': name, 'Value': 'test', 'Conditions': 'true'}
schema = api.contract(self.url, self.token, contract_name)
contract = Contract(schema=schema, private_key=self.pr_key,
params=data)
tx_bin_data = contract.concat()
self.client.post('/sendTx', files={'call1': tx_bin_data},
headers={'Authorization': self.token}, name=contract_name)
@task
def NewMenu(self):
contract_name = 'NewMenu'
name = 'Menu_' + tools.generate_random_name()
data = {'Name': name, 'Value': 'Item1',
'Conditions': 'true'}
schema = api.contract(self.url, self.token, contract_name)
contract = Contract(schema=schema, private_key=self.pr_key,
params=data)
tx_bin_data = contract.concat()
self.client.post('/sendTx', files={'call1': tx_bin_data},
headers={'Authorization': self.token}, name=contract_name)
@task
def NewPage(self):
contract_name = 'NewPage'
name = 'Page_' + tools.generate_random_name()
data = {'Name': name, 'Value': 'Hello page!', 'ApplicationId': 1,
'Conditions': 'true', 'Menu': 'default_menu'}
schema = api.contract(self.url, self.token, contract_name)
contract = Contract(schema=schema, private_key=self.pr_key,
params=data)
tx_bin_data = contract.concat()
self.client.post('/sendTx', files={'call1': tx_bin_data},
headers={'Authorization': self.token}, name=contract_name)
@task
def NewBlock(self):
contract_name = 'NewBlock'
name = 'Block_' + tools.generate_random_name()
data = {'Name': name, 'Value': 'Hello page!', 'ApplicationId': 1,
'Conditions': 'true'}
schema = api.contract(self.url, self.token, contract_name)
contract = Contract(schema=schema, private_key=self.pr_key,
params=data)
tx_bin_data = contract.concat()
self.client.post('/sendTx', files={'call1': tx_bin_data},
headers={'Authorization': self.token}, name=contract_name)
@task
def NewTable(self):
contract_name = 'NewTable'
column = '''[{"name":"MyName","type":"varchar",
"index": "1", "conditions":"true"}]'''
permission = '''{"insert": "false",
"update" : "true","new_column": "true"}'''
data = {'Name': 'Tab_' + tools.generate_random_name(),
'Columns': column, 'ApplicationId': 1,
'Permissions': permission}
schema = api.contract(self.url, self.token, contract_name)
contract = Contract(schema=schema, private_key=self.pr_key,
params=data)
tx_bin_data = contract.concat()
self.client.post('/sendTx', files={'call1': tx_bin_data},
headers={'Authorization': self.token}, name=contract_name)
@task
def NewLang(self):
contract_name = 'NewLang'
data = {'Name': 'Lang_' + tools.generate_random_name(),
'Trans': '{"en": "false", "ru" : "true"}'}
schema = api.contract(self.url, self.token, contract_name)
contract = Contract(schema=schema, private_key=self.pr_key,
params=data)
tx_bin_data = contract.concat()
self.client.post('/sendTx', files={'call1': tx_bin_data},
headers={'Authorization': self.token}, name=contract_name)
class WebsiteUser(HttpLocust):
task_set = WebsiteTasks
min_wait = 5000
max_wait = 15000