forked from eos-amsterdam-rnd/wax2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistributed-transactions-test.py
executable file
·124 lines (99 loc) · 4.02 KB
/
distributed-transactions-test.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
#!/usr/bin/env python3
from testUtils import Utils
from Cluster import Cluster
from WalletMgr import WalletMgr
from TestHelper import TestHelper
import random
###############################################################
# distributed-transactions-test
#
# Performs currency transfers between N accounts sent to http endpoints of
# N nodes and verifies, after a steady state is reached, that the accounts
# balances are correct
# if called with --nodes-file it will will load a json description of nodes
# that are already running and run distributed test against them (not
# currently testing this feature)
#
###############################################################
Print=Utils.Print
errorExit=Utils.errorExit
args=TestHelper.parse_args({"-p","-n","-d","-s","--nodes-file","--seed"
,"--dump-error-details","-v","--leave-running","--clean-run","--keep-logs"})
pnodes=args.p
topo=args.s
delay=args.d
total_nodes = pnodes if args.n < pnodes else args.n
debug=args.v
nodesFile=args.nodes_file
dontLaunch=nodesFile is not None
seed=args.seed
dontKill=args.leave_running
dumpErrorDetails=args.dump_error_details
killAll=args.clean_run
keepLogs=args.keep_logs
killWallet=not dontKill
killEosInstances=not dontKill
if nodesFile is not None:
killEosInstances=False
Utils.Debug=debug
testSuccessful=False
random.seed(seed) # Use a fixed seed for repeatability.
cluster=Cluster(walletd=True)
walletMgr=WalletMgr(True)
try:
cluster.setWalletMgr(walletMgr)
if dontLaunch: # run test against remote cluster
jsonStr=None
with open(nodesFile, "r") as f:
jsonStr=f.read()
if not cluster.initializeNodesFromJson(jsonStr):
errorExit("Failed to initilize nodes from Json string.")
total_nodes=len(cluster.getNodes())
walletMgr.killall(allInstances=killAll)
walletMgr.cleanup()
print("Stand up walletd")
if walletMgr.launch() is False:
errorExit("Failed to stand up keosd.")
else:
cluster.killall(allInstances=killAll)
cluster.cleanup()
Print ("producing nodes: %s, non-producing nodes: %d, topology: %s, delay between nodes launch(seconds): %d" %
(pnodes, total_nodes-pnodes, topo, delay))
Print("Stand up cluster")
if cluster.launch(pnodes=pnodes, totalNodes=total_nodes, topo=topo, delay=delay) is False:
errorExit("Failed to stand up eos cluster.")
Print ("Wait for Cluster stabilization")
# wait for cluster to start producing blocks
if not cluster.waitOnClusterBlockNumSync(3):
errorExit("Cluster never stabilized")
accountsCount=total_nodes
walletName="MyWallet-%d" % (random.randrange(10000))
Print("Creating wallet %s if one doesn't already exist." % walletName)
walletAccounts=[cluster.defproduceraAccount,cluster.defproducerbAccount]
if not dontLaunch:
walletAccounts.append(cluster.eosioAccount)
wallet=walletMgr.create(walletName, walletAccounts)
if wallet is None:
errorExit("Failed to create wallet %s" % (walletName))
Print ("Populate wallet with %d accounts." % (accountsCount))
if not cluster.populateWallet(accountsCount, wallet):
errorExit("Wallet initialization failed.")
defproduceraAccount=cluster.defproduceraAccount
defproducerbAccount=cluster.defproducerbAccount
eosioAccount=cluster.eosioAccount
Print("Create accounts.")
if not cluster.createAccounts(eosioAccount):
errorExit("Accounts creation failed.")
Print("Spread funds and validate")
if not cluster.spreadFundsAndValidate(10):
errorExit("Failed to spread and validate funds.")
print("Funds spread validated")
if not dontKill:
cluster.killall(allInstances=killAll)
else:
print("NOTE: Skip killing nodes, block log verification will be limited")
cluster.compareBlockLogs()
testSuccessful=True
finally:
TestHelper.shutdown(cluster, walletMgr, testSuccessful, killEosInstances, killWallet, keepLogs, killAll, dumpErrorDetails)
exit(0)