-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodeos_run_test.py
executable file
·682 lines (593 loc) · 28.8 KB
/
nodeos_run_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
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
#!/usr/bin/env python3
import testUtils
import decimal
import argparse
import random
import re
###############################################################
# nodeos_run_test
# --dump-error-details <Upon error print etc/eosio/node_*/config.ini and var/lib/node_*/stderr.log to stdout>
# --keep-logs <Don't delete var/lib/node_* folders upon test completion>
###############################################################
Print=testUtils.Utils.Print
errorExit=testUtils.Utils.errorExit
def cmdError(name, code=0, exitNow=False):
msg="FAILURE - %s%s" % (name, ("" if code == 0 else (" returned error code %d" % code)))
if exitNow:
errorExit(msg, True)
else:
Print(msg)
TEST_OUTPUT_DEFAULT="test_output_0.txt"
LOCAL_HOST="localhost"
DEFAULT_PORT=8888
parser = argparse.ArgumentParser(add_help=False)
# Override default help argument so that only --help (and not -h) can call help
parser.add_argument('-?', action='help', default=argparse.SUPPRESS,
help=argparse._('show this help message and exit'))
parser.add_argument("-o", "--output", type=str, help="output file", default=TEST_OUTPUT_DEFAULT)
parser.add_argument("-h", "--host", type=str, help="%s host name" % (testUtils.Utils.EosServerName),
default=LOCAL_HOST)
parser.add_argument("-p", "--port", type=int, help="%s host port" % testUtils.Utils.EosServerName,
default=DEFAULT_PORT)
parser.add_argument("--inita_prvt_key", type=str, help="Inita private key.")
parser.add_argument("--initb_prvt_key", type=str, help="Initb private key.")
parser.add_argument("--mongodb", help="Configure a MongoDb instance", action='store_true')
parser.add_argument("--dump-error-details",
help="Upon error print etc/eosio/node_*/config.ini and var/lib/node_*/stderr.log to stdout",
action='store_true')
parser.add_argument("--dont-launch", help="Don't launch own node. Assume node is already running.",
action='store_true')
parser.add_argument("--keep-logs", help="Don't delete var/lib/node_* folders upon test completion",
action='store_true')
parser.add_argument("-v", help="verbose logging", action='store_true')
parser.add_argument("--not-noon", help="This is not the Noon branch.", action='store_true')
parser.add_argument("--dont-kill", help="Leave cluster running after test finishes", action='store_true')
args = parser.parse_args()
testOutputFile=args.output
server=args.host
port=args.port
debug=args.v
enableMongo=args.mongodb
amINoon=not args.not_noon
initaPrvtKey=args.inita_prvt_key
initbPrvtKey=args.initb_prvt_key
dumpErrorDetails=args.dump_error_details
keepLogs=args.keep_logs
dontLaunch=args.dont_launch
dontKill=args.dont_kill
testUtils.Utils.Debug=debug
localTest=True if server == LOCAL_HOST else False
# launcher launched bios node listens on port DEFAULT_PORT-100
cluster=testUtils.Cluster(walletd=True, enableMongo=enableMongo, initaPrvtKey=initaPrvtKey, initbPrvtKey=initbPrvtKey, port=DEFAULT_PORT-100)
walletMgr=testUtils.WalletMgr(True, nodeosPort=DEFAULT_PORT-100)
testSuccessful=False
killEosInstances=not dontKill
killWallet=not dontKill
WalletdName="eos-walletd"
ClientName="eosc"
if amINoon:
WalletdName="keosd"
ClientName="cleos"
# noon branch requires longer mongo sync time.
testUtils.Utils.setMongoSyncTime(50)
else:
testUtils.Utils.iAmNotNoon()
try:
Print("BEGIN")
print("TEST_OUTPUT: %s" % (testOutputFile))
print("SERVER: %s" % (server))
print("PORT: %d" % (port))
if localTest and not dontLaunch:
cluster.killall()
cluster.cleanup()
Print("Stand up cluster")
if cluster.launch() is False:
cmdError("launcher")
errorExit("Failed to stand up eos cluster.")
else:
cluster.initializeNodes()
killEosInstances=False
walletMgr.killall()
walletMgr.cleanup()
accounts=testUtils.Cluster.createAccountKeys(3)
if accounts is None:
errorExit("FAILURE - create keys")
testeraAccount=accounts[0]
testeraAccount.name="testera"
currencyAccount=accounts[1]
currencyAccount.name="currency"
exchangeAccount=accounts[2]
exchangeAccount.name="exchange"
PRV_KEY1=testeraAccount.ownerPrivateKey
PUB_KEY1=testeraAccount.ownerPublicKey
PRV_KEY2=currencyAccount.ownerPrivateKey
PUB_KEY2=currencyAccount.ownerPublicKey
PRV_KEY3=exchangeAccount.activePrivateKey
PUB_KEY3=exchangeAccount.activePublicKey
testeraAccount.activePrivateKey=currencyAccount.activePrivateKey=PRV_KEY3
testeraAccount.activePublicKey=currencyAccount.activePublicKey=PUB_KEY3
exchangeAccount.ownerPrivateKey=PRV_KEY2
exchangeAccount.ownerPublicKey=PUB_KEY2
Print("Stand up walletd")
if walletMgr.launch() is False:
cmdError("%s" % (WalletdName))
errorExit("Failed to stand up eos walletd.")
testWalletName="test"
Print("Creating wallet \"%s\"." % (testWalletName))
testWallet=walletMgr.create(testWalletName)
if testWallet is None:
cmdError("eos wallet create")
errorExit("Failed to create wallet %s." % (testWalletName))
for account in accounts:
Print("Importing keys for account %s into wallet %s." % (account.name, testWallet.name))
if not walletMgr.importKey(account, testWallet):
cmdError("%s wallet import" % (ClientName))
errorExit("Failed to import key for account %s" % (account.name))
initaWalletName="inita"
Print("Creating wallet \"%s\"." % (initaWalletName))
initaWallet=walletMgr.create(initaWalletName)
if initaWallet is None:
cmdError("eos wallet create")
errorExit("Failed to create wallet %s." % (initaWalletName))
initaAccount=cluster.initaAccount
initbAccount=cluster.initbAccount
Print("Importing keys for account %s into wallet %s." % (initaAccount.name, initaWallet.name))
if not walletMgr.importKey(initaAccount, initaWallet):
cmdError("%s wallet import" % (ClientName))
errorExit("Failed to import key for account %s" % (initaAccount.name))
producerKeys=cluster.producerKeys;
for name, keys in producerKeys.items():
Print("name: %s, keys: %s" % (name, str(keys)))
account=None
account=testUtils.Account(name)
account.ownerPrivateKey=keys[1]
account.ownerPublicKey=keys[0]
account.activePrivateKey=keys[1]
account.activePublicKey=keys[0]
walletMgr.importKey(account, initaWallet)
cluster.nodes[0].createInitAccounts(cluster.producerKeys)
Print("Locking wallet \"%s\"." % (testWallet.name))
if not walletMgr.lockWallet(testWallet):
cmdError("%s wallet lock" % (ClientName))
errorExit("Failed to lock wallet %s" % (testWallet.name))
Print("Unlocking wallet \"%s\"." % (testWallet.name))
if not walletMgr.unlockWallet(testWallet):
cmdError("%s wallet unlock" % (ClientName))
errorExit("Failed to unlock wallet %s" % (testWallet.name))
Print("Locking all wallets.")
if not walletMgr.lockAllWallets():
cmdError("%s wallet lock_all" % (ClientName))
errorExit("Failed to lock all wallets")
Print("Unlocking wallet \"%s\"." % (testWallet.name))
if not walletMgr.unlockWallet(testWallet):
cmdError("%s wallet unlock" % (ClientName))
errorExit("Failed to unlock wallet %s" % (testWallet.name))
Print("Getting open wallet list.")
wallets=walletMgr.getOpenWallets()
if len(wallets) == 0 or wallets[0] != testWallet.name or len(wallets) > 1:
Print("FAILURE - wallet list did not include %s" % (testWallet.name))
errorExit("Unexpected wallet list: %s" % (wallets))
Print("Getting wallet keys.")
actualKeys=walletMgr.getKeys()
expectedkeys=[]
for account in accounts:
expectedkeys.append(account.ownerPrivateKey)
expectedkeys.append(account.activePrivateKey)
noMatch=list(set(expectedkeys) - set(actualKeys))
if len(noMatch) > 0:
errorExit("FAILURE - wallet keys did not include %s" % (noMatch), raw=true)
Print("Locking all wallets.")
if not walletMgr.lockAllWallets():
cmdError("%s wallet lock_all" % (ClientName))
errorExit("Failed to lock all wallets")
Print("Unlocking wallet \"%s\"." % (initaWallet.name))
if not walletMgr.unlockWallet(initaWallet):
cmdError("%s wallet unlock" % (ClientName))
errorExit("Failed to unlock wallet %s" % (initaWallet.name))
Print("Unlocking wallet \"%s\"." % (testWallet.name))
if not walletMgr.unlockWallet(testWallet):
cmdError("%s wallet unlock" % (ClientName))
errorExit("Failed to unlock wallet %s" % (testWallet.name))
Print("Getting wallet keys.")
actualKeys=walletMgr.getKeys()
expectedkeys=[initaAccount.ownerPrivateKey]
noMatch=list(set(expectedkeys) - set(actualKeys))
if len(noMatch) > 0:
errorExit("FAILURE - wallet keys did not include %s" % (noMatch), raw=true)
node=cluster.getNode(0)
if node is None:
errorExit("Cluster in bad state, received None node")
Print("Create new account %s via %s" % (testeraAccount.name, initaAccount.name))
transId=node.createAccount(testeraAccount, initaAccount, stakedDeposit=0, waitForTransBlock=True)
if transId is None:
cmdError("%s create account" % (ClientName))
errorExit("Failed to create account %s" % (testeraAccount.name))
Print("Verify account %s" % (testeraAccount))
if not node.verifyAccount(testeraAccount):
errorExit("FAILURE - account creation failed.", raw=True)
transferAmount=975321
Print("Transfer funds %d from account %s to %s" % (transferAmount, initaAccount.name, testeraAccount.name))
if node.transferFunds(initaAccount, testeraAccount, transferAmount, "test transfer") is None:
cmdError("%s transfer" % (ClientName))
errorExit("Failed to transfer funds %d from account %s to %s" % (
transferAmount, initaAccount.name, testeraAccount.name))
expectedAmount=transferAmount
Print("Verify transfer, Expected: %d" % (expectedAmount))
actualAmount=node.getAccountBalance(testeraAccount.name)
if expectedAmount != actualAmount:
cmdError("FAILURE - transfer failed")
errorExit("Transfer verification failed. Excepted %d, actual: %d" % (expectedAmount, actualAmount))
transferAmount=100
Print("Force transfer funds %d from account %s to %s" % (
transferAmount, initaAccount.name, testeraAccount.name))
if node.transferFunds(initaAccount, testeraAccount, transferAmount, "test transfer", force=True) is None:
cmdError("%s transfer" % (ClientName))
errorExit("Failed to force transfer funds %d from account %s to %s" % (
transferAmount, initaAccount.name, testeraAccount.name))
expectedAmount=975421
Print("Verify transfer, Expected: %d" % (expectedAmount))
actualAmount=node.getAccountBalance(testeraAccount.name)
if expectedAmount != actualAmount:
cmdError("FAILURE - transfer failed")
errorExit("Transfer verification failed. Excepted %d, actual: %d" % (expectedAmount, actualAmount))
Print("Create new account %s via %s" % (currencyAccount.name, initbAccount.name))
transId=node.createAccount(currencyAccount, initbAccount, stakedDeposit=5000)
if transId is None:
cmdError("%s create account" % (ClientName))
errorExit("Failed to create account %s" % (currencyAccount.name))
Print("Create new account %s via %s" % (exchangeAccount.name, initaAccount.name))
transId=node.createAccount(exchangeAccount, initaAccount, waitForTransBlock=True)
if transId is None:
cmdError("%s create account" % (ClientName))
errorExit("Failed to create account %s" % (exchangeAccount.name))
Print("Locking all wallets.")
if not walletMgr.lockAllWallets():
cmdError("%s wallet lock_all" % (ClientName))
errorExit("Failed to lock all wallets")
Print("Unlocking wallet \"%s\"." % (testWallet.name))
if not walletMgr.unlockWallet(testWallet):
cmdError("%s wallet unlock" % (ClientName))
errorExit("Failed to unlock wallet %s" % (testWallet.name))
transferAmount=975311
Print("Transfer funds %d from account %s to %s" % (
transferAmount, testeraAccount.name, currencyAccount.name))
trans=node.transferFunds(testeraAccount, currencyAccount, transferAmount, "test transfer a->b")
if trans is None:
cmdError("%s transfer" % (ClientName))
errorExit("Failed to transfer funds %d from account %s to %s" % (
transferAmount, initaAccount.name, testeraAccount.name))
transId=testUtils.Node.getTransId(trans)
expectedAmount=975311+5000 # 5000 initial deposit
Print("Verify transfer, Expected: %d" % (expectedAmount))
actualAmount=node.getAccountBalance(currencyAccount.name)
if actualAmount is None:
cmdError("%s get account currency" % (ClientName))
errorExit("Failed to retrieve balance for account %s" % (currencyAccount.name))
if expectedAmount != actualAmount:
cmdError("FAILURE - transfer failed")
errorExit("Transfer verification failed. Excepted %d, actual: %d" % (expectedAmount, actualAmount))
expectedAccounts=[testeraAccount.name, currencyAccount.name, exchangeAccount.name]
Print("Get accounts by key %s, Expected: %s" % (PUB_KEY3, expectedAccounts))
actualAccounts=node.getAccountsArrByKey(PUB_KEY3)
if actualAccounts is None:
cmdError("%s get accounts pub_key3" % (ClientName))
errorExit("Failed to retrieve accounts by key %s" % (PUB_KEY3))
noMatch=list(set(expectedAccounts) - set(actualAccounts))
if len(noMatch) > 0:
errorExit("FAILURE - Accounts lookup by key %s. Expected: %s, Actual: %s" % (
PUB_KEY3, expectedAccounts, actualAccounts), raw=True)
expectedAccounts=[testeraAccount.name]
Print("Get accounts by key %s, Expected: %s" % (PUB_KEY1, expectedAccounts))
actualAccounts=node.getAccountsArrByKey(PUB_KEY1)
if actualAccounts is None:
cmdError("%s get accounts pub_key1" % (ClientName))
errorExit("Failed to retrieve accounts by key %s" % (PUB_KEY1))
noMatch=list(set(expectedAccounts) - set(actualAccounts))
if len(noMatch) > 0:
errorExit("FAILURE - Accounts lookup by key %s. Expected: %s, Actual: %s" % (
PUB_KEY1, expectedAccounts, actualAccounts), raw=True)
expectedServants=[testeraAccount.name, currencyAccount.name]
Print("Get %s servants, Expected: %s" % (initaAccount.name, expectedServants))
actualServants=node.getServantsArr(initaAccount.name)
if actualServants is None:
cmdError("%s get servants testera" % (ClientName))
errorExit("Failed to retrieve %s servants" % (initaAccount.name))
noMatch=list(set(expectedAccounts) - set(actualAccounts))
if len(noMatch) > 0:
errorExit("FAILURE - %s servants. Expected: %s, Actual: %s" % (
initaAccount.name, expectedServants, actualServants), raw=True)
Print("Get %s servants, Expected: []" % (testeraAccount.name))
actualServants=node.getServantsArr(testeraAccount.name)
if actualServants is None:
cmdError("%s get servants testera" % (ClientName))
errorExit("Failed to retrieve %s servants" % (testeraAccount.name))
if len(actualServants) > 0:
errorExit("FAILURE - %s servants. Expected: [], Actual: %s" % (
testeraAccount.name, actualServants), raw=True)
node.waitForTransIdOnNode(transId)
transaction=None
if not enableMongo:
transaction=node.getTransaction(transId)
else:
if amINoon:
transaction=node.getActionFromDb(transId)
else:
transaction=node.getMessageFromDb(transId)
if transaction is None:
cmdError("%s get transaction trans_id" % (ClientName))
errorExit("Failed to retrieve transaction details %s" % (transId))
typeVal=None
amountVal=None
if amINoon:
debug and Print("Transaction:", transaction)
if not enableMongo:
typeVal= transaction["transaction"]["data"]["actions"][0]["name"]
amountVal=transaction["transaction"]["data"]["actions"][0]["data"]["quantity"]
amountVal=int(decimal.Decimal(amountVal.split()[0])*10000)
else:
typeVal= transaction["name"]
amountVal=transaction["data"]["quantity"]
amountVal=int(decimal.Decimal(amountVal.split()[0])*10000)
else:
if not enableMongo:
typeVal= transaction["transaction"]["messages"][0]["type"]
amountVal=transaction["transaction"]["messages"][0]["data"]["amount"]
else:
typeVal= transaction["type"]
amountVal=transaction["data"]["amount"]
if typeVal!= "transfer" or amountVal != 975311:
errorExit("FAILURE - get transaction trans_id failed: %s %s %s" % (transId, typeVal, amountVal), raw=True)
Print("Get transactions for account %s" % (testeraAccount.name))
actualTransactions=node.getTransactionsArrByAccount(testeraAccount.name)
if actualTransactions is None:
cmdError("%s get transactions testera" % (ClientName))
errorExit("Failed to get transactions by account %s" % (testeraAccount.name))
if transId not in actualTransactions:
errorExit("FAILURE - get transactions testera failed", raw=True)
Print("Currency Contract Tests")
Print("verify no contract in place")
Print("Get code hash for account %s" % (currencyAccount.name))
codeHash=node.getAccountCodeHash(currencyAccount.name)
if codeHash is None:
cmdError("%s get code currency" % (ClientName))
errorExit("Failed to get code hash for account %s" % (currencyAccount.name))
hashNum=int(codeHash, 16)
if hashNum != 0:
errorExit("FAILURE - get code currency failed", raw=True)
wastFile="contracts/currency/currency.wast"
abiFile="contracts/currency/currency.abi"
Print("Publish contract")
trans=node.publishContract(currencyAccount.name, wastFile, abiFile, waitForTransBlock=True)
if trans is None:
cmdError("%s set contract currency" % (ClientName))
errorExit("Failed to publish contract.")
if not enableMongo:
Print("Get code hash for account %s" % (currencyAccount.name))
codeHash=node.getAccountCodeHash(currencyAccount.name)
if codeHash is None:
cmdError("%s get code currency" % (ClientName))
errorExit("Failed to get code hash for account %s" % (currencyAccount.name))
hashNum=int(codeHash, 16)
if hashNum == 0:
errorExit("FAILURE - get code currency failed", raw=True)
else:
Print("verify abi is set")
account=node.getEosAccountFromDb(currencyAccount.name)
abiName=account["abi"]["structs"][0]["name"]
abiActionName=None
if not amINoon:
abiActionName=account["abi"]["actions"][0]["action_name"]
else:
abiActionName=account["abi"]["actions"][0]["name"]
abiType=account["abi"]["actions"][0]["type"]
if abiName != "transfer" or abiActionName != "transfer" or abiType != "transfer":
errorExit("FAILURE - get table currency account failed", raw=True)
if amINoon:
Print("push create action to currency contract")
contract="currency"
action="create"
data="{\"issuer\":\"currency\",\"maximum_supply\":\"100000.0000 CUR\",\"can_freeze\":\"0\",\"can_recall\":\"0\",\"can_whitelist\":\"0\"}"
opts="--permission currency@active"
trans=node.pushMessage(contract, action, data, opts)
# Print("create action to currency contracttrans: %s" % str(trans))
if trans is None or not trans[0]:
errorExit("FAILURE - create action to currency contract failed", raw=True)
Print("push issue action to currency contract")
action="issue"
data="{\"to\":\"currency\",\"quantity\":\"100000.0000 CUR\",\"memo\":\"issue\"}"
opts="--permission currency@active"
trans=node.pushMessage(contract, action, data, opts)
if trans is None or not trans[0]:
errorExit("FAILURE - issue action to currency contract failed", raw=True)
# TODO need to update eosio.system contract to use new currency and update cleos and chain_plugin for interaction
# Print("Verify currency contract has proper initial balance (via get table)")
# contract="currency"
# table="accounts"
# row0=node.getTableRow(currencyAccount.name, contract, table, 0)
# if row0 is None:
# cmdError("%s get table currency account" % (ClientName))
# errorExit("Failed to retrieve contract %s table %s" % (contract, table))
#
# balanceKey="balance"
# keyKey="key"
# if row0[balanceKey] != 1000000000:
# errorExit("FAILURE - get table currency account failed", raw=True)
#
# Print("Verify currency contract has proper initial balance (via get currency balance)")
# res=node.getCurrencyBalance(contract, currencyAccount.name, "CUR")
# if res is None:
# cmdError("%s get currency balance" % (ClientName))
# errorExit("Failed to retrieve CUR balance from contract %s account %s" % (contract, currencyAccount.name))
#
# if res.strip()[1:-1] != "100000.0000 CUR":
# errorExit("FAILURE - get currency balance failed", raw=True)
#
# Print("Verify currency contract has proper total supply of CUR (via get currency stats)")
# res=node.getCurrencyStats(contract, "CUR")
# if res is None or not ("supply" in res):
# cmdError("%s get currency stats" % (ClientName))
# errorExit("Failed to retrieve CUR stats from contract" % (contract))
#
# if res["supply"] != "100000.0000 CUR":
# errorExit("FAILURE - get currency stats failed", raw=True)
Print("push transfer action to currency contract")
contract="currency"
action="transfer"
data="{\"from\":\"currency\",\"to\":\"inita\",\"quantity\":"
if amINoon:
data +="\"00.0050 CUR\",\"memo\":\"test\"}"
else:
data +="50}"
opts="--permission currency@active"
if not amINoon:
opts += " --scope currency,inita"
trans=node.pushMessage(contract, action, data, opts)
if trans is None or not trans[0]:
cmdError("%s push message currency transfer" % (ClientName))
errorExit("Failed to push message to currency contract")
transId=testUtils.Node.getTransId(trans[1])
Print("verify transaction exists")
if not node.waitForTransIdOnNode(transId):
cmdError("%s get transaction trans_id" % (ClientName))
errorExit("Failed to verify push message transaction id.")
# TODO need to update eosio.system contract to use new currency and update cleos and chain_plugin for interaction
# Print("read current contract balance")
# contract="currency"
# table="accounts"
# row0=node.getTableRow(initaAccount.name, contract, table, 0)
# if row0 is None:
# cmdError("%s get table currency account" % (ClientName))
# errorExit("Failed to retrieve contract %s table %s" % (contract, table))
#
# balanceKey="balance"
# keyKey="key"
# if row0[balanceKey] != 50:
# errorExit("FAILURE - get table currency account failed", raw=True)
#
# row0=node.getTableRow(currencyAccount.name, contract, table, 0)
# if row0 is None:
# cmdError("%s get table currency account" % (ClientName))
# errorExit("Failed to retrieve contract %s table %s" % (contract, table))
#
# if row0[balanceKey] != 999999950:
# errorExit("FAILURE - get table currency account failed", raw=True)
Print("Exchange Contract Tests")
Print("upload exchange contract")
wastFile="contracts/exchange/exchange.wast"
abiFile="contracts/exchange/exchange.abi"
Print("Publish exchange contract")
trans=node.publishContract(exchangeAccount.name, wastFile, abiFile, waitForTransBlock=True)
if trans is None:
cmdError("%s set contract exchange" % (ClientName))
errorExit("Failed to publish contract.")
wastFile="contracts/simpledb/simpledb.wast"
abiFile="contracts/simpledb/simpledb.abi"
Print("Setting simpledb contract without simpledb account was causing core dump in %s." % (ClientName))
Print("Verify %s generates an error, but does not core dump." % (ClientName))
retMap=node.publishContract("simpledb", wastFile, abiFile, shouldFail=True)
if retMap is None:
errorExit("Failed to publish, but should have returned a details map")
if retMap["returncode"] == 0 or retMap["returncode"] == 139: # 139 SIGSEGV
errorExit("FAILURE - set contract exchange failed", raw=True)
else:
Print("Test successful, %s returned error code: %d" % (ClientName, retMap["returncode"]))
# TODO Currently unable to set producer
if not amINoon:
Print("Producer tests")
trans=node.createProducer(testeraAccount.name, testeraAccount.ownerPublicKey, waitForTransBlock=False)
if trans is None:
cmdError("%s create producer" % (ClientName))
errorExit("Failed to create producer %s" % (testeraAccount.name))
Print("set permission")
code="currency"
pType="transfer"
requirement="active"
trans=node.setPermission(testeraAccount.name, code, pType, requirement, waitForTransBlock=True)
if trans is None:
cmdError("%s set action permission set" % (ClientName))
errorExit("Failed to set permission")
Print("remove permission")
requirement="null"
trans=node.setPermission(testeraAccount.name, code, pType, requirement, waitForTransBlock=True)
if trans is None:
cmdError("%s set action permission set" % (ClientName))
errorExit("Failed to remove permission")
Print("Locking all wallets.")
if not walletMgr.lockAllWallets():
cmdError("%s wallet lock_all" % (ClientName))
errorExit("Failed to lock all wallets")
Print("Unlocking wallet \"%s\"." % (initaWallet.name))
if not walletMgr.unlockWallet(initaWallet):
cmdError("%s wallet unlock inita" % (ClientName))
errorExit("Failed to unlock wallet %s" % (initaWallet.name))
# TODO: Approving producers currently not supported
# approve producer
# INFO="$(programs/cleos/cleos --host $SERVER --port $PORT --wallet-port 8899 set producer inita testera approve)"
# verifyErrorCode "cleos approve producer"
Print("Get account inita")
account=node.getEosAccount(initaAccount.name)
if account is None:
cmdError("%s get account" % (ClientName))
errorExit("Failed to get account %s" % (initaAccount.name))
# TODO: Unapproving producers currently not supported
# unapprove producer
# INFO="$(programs/cleos/cleos --host $SERVER --port $PORT --wallet-port 8899 set producer inita testera unapprove)"
# verifyErrorCode "cleos unapprove producer"
#
# Proxy
#
# not implemented
Print("Get head block num.")
currentBlockNum=node.getHeadBlockNum()
Print("CurrentBlockNum: %d" % (currentBlockNum))
Print("Request blocks 1-%d" % (currentBlockNum))
for blockNum in range(1, currentBlockNum+1):
block=node.getBlock(blockNum, retry=False)
if block is None:
cmdError("%s get block" % (ClientName))
errorExit("mongo get block by num %d" % blockNum)
if enableMongo:
blockId=block["block_id"]
block2=node.getBlockById(blockId, retry=False)
if block2 is None:
errorExit("mongo get block by id %s" % blockId)
# TBD: getTransByBlockId() needs to handle multiple returned transactions
# trans=node.getTransByBlockId(blockId, retry=False)
# if trans is not None:
# transId=testUtils.Node.getTransId(trans)
# trans2=node.getMessageFromDb(transId)
# if trans2 is None:
# errorExit("mongo get messages by transaction id %s" % (transId))
Print("Request invalid block numbered %d" % (currentBlockNum+1000))
block=node.getBlock(currentBlockNum+1000, silentErrors=True, retry=False)
if block is not None:
errorExit("ERROR: Received block where not expected")
else:
Print("Success: No such block found")
if localTest:
p = re.compile('Assert')
errFileName="var/lib/node_00/stderr.txt"
with open(errFileName) as errFile:
for line in errFile:
if p.search(line):
errorExit("FAILURE - Assert in var/lib/node_00/stderr.txt")
testSuccessful=True
Print("END")
finally:
if not testSuccessful and dumpErrorDetails:
cluster.dumpErrorDetails()
walletMgr.dumpErrorDetails()
Print("== Errors see above ==")
if killEosInstances:
Print("Shut down the cluster.")
cluster.killall()
if testSuccessful and not keepLogs:
Print("Cleanup cluster data.")
cluster.cleanup()
if killWallet:
Print("Shut down the wallet.")
walletMgr.killall()
if testSuccessful and not keepLogs:
Print("Cleanup wallet data.")
walletMgr.cleanup()
exit(0)