-
Notifications
You must be signed in to change notification settings - Fork 169
/
Copy pathtpsLoad.py
107 lines (88 loc) · 2.5 KB
/
tpsLoad.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
#!/usr/bin/env python3
# -*- coding: utf_8 -*-l
import time
from mypylib.mypylib import MyPyClass
from mytoncore import MyTonCore, Sleep
local = MyPyClass('./tests')
local.db["config"]["logLevel"] = "info"
load = 100
ton = MyTonCore(local)
def Init():
wallets = list()
local.buffer["wallets"] = wallets
walletsNameList = ton.GetWalletsNameList()
# Create tests wallet
testsWalletName = "tests_hwallet"
testsWallet = ton.CreateHighWallet(testsWalletName)
# Check tests wallet balance
account = ton.GetAccount(testsWallet.addr)
local.AddLog("wallet: {addr}, status: {status}, balance: {balance}".format(addr=testsWallet.addr, status=account.status, balance=account.balance))
if account.balance == 0:
raise Exception(testsWallet.name + " wallet balance is empty.")
if account.status == "uninit":
ton.SendFile(testsWallet.bocFilePath, testsWallet)
# Create wallets
for i in range(load):
walletName = "w_" + str(i)
if walletName not in walletsNameList:
wallet = ton.CreateWallet(walletName)
else:
wallet = ton.GetLocalWallet(walletName)
wallets.append(wallet)
#end for
# Fill up wallets
buff_wallet = None
buff_seqno = None
destList = list()
for wallet in wallets:
wallet.account = ton.GetAccount(wallet.addr)
need = 20 - wallet.account.balance
if need > 10:
destList.append([wallet.addr_init, need])
elif need < -10:
need = need * -1
buff_wallet = wallet
buff_wallet.oldseqno = ton.GetSeqno(wallet)
ton.MoveGrams(wallet, testsWallet.addr, need, wait=False)
local.AddLog(testsWallet.name + " <<< " + wallet.name)
if buff_wallet:
ton.WaitTransaction(buff_wallet, False)
#end for
# Move grams from highload wallet
ton.MoveGramsFromHW(testsWallet, destList)
# Activate wallets
for wallet in wallets:
if wallet.account.status == "uninit":
wallet.oldseqno = ton.GetSeqno(wallet)
ton.SendFile(wallet.bocFilePath)
local.AddLog(str(wallet.subwallet) + " - OK")
ton.WaitTransaction(wallets[-1])
#end define
def Work():
wallets = local.buffer["wallets"]
for i in range(load):
if i + 1 == load:
i = -1
#end if
wallet1 = wallets[i]
wallet2 = wallets[i+1]
wallet1.oldseqno = ton.GetSeqno(wallet1)
ton.MoveGrams(wallet1, wallet2.addr, 3.14, wait=False)
local.AddLog(wallet1.name + " >>> " + wallet2.name)
ton.WaitTransaction(wallets[-1])
#end define
def General():
Init()
while True:
time.sleep(1)
Work()
local.AddLog("Work - OK")
#end while
#end define
###
### Start test
###
local.Run()
load = 100
local.StartCycle(General, sec=1)
Sleep()