-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodeos_run_test.py
executable file
·694 lines (586 loc) · 29.9 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
683
684
685
686
687
688
689
690
691
692
693
694
#!/usr/bin/env python3
from testUtils import Utils
from Cluster import Cluster
from WalletMgr import WalletMgr
from Node import Node
from TestHelper import TestHelper
import decimal
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=Utils.Print
errorExit=Utils.errorExit
cmdError=Utils.cmdError
from core_symbol import CORE_SYMBOL
args = TestHelper.parse_args({"--host","--port","--prod-count","--defproducera_prvt_key","--defproducerb_prvt_key","--mongodb"
,"--dump-error-details","--dont-launch","--keep-logs","-v","--leave-running","--only-bios","--clean-run"
,"--sanity-test","--p2p-plugin","--wallet-port"})
server=args.host
port=args.port
debug=args.v
enableMongo=args.mongodb
defproduceraPrvtKey=args.defproducera_prvt_key
defproducerbPrvtKey=args.defproducerb_prvt_key
dumpErrorDetails=args.dump_error_details
keepLogs=args.keep_logs
dontLaunch=args.dont_launch
dontKill=args.leave_running
prodCount=args.prod_count
onlyBios=args.only_bios
killAll=args.clean_run
sanityTest=args.sanity_test
p2pPlugin=args.p2p_plugin
walletPort=args.wallet_port
Utils.Debug=debug
localTest=True if server == TestHelper.LOCAL_HOST else False
cluster=Cluster(walletd=True, enableMongo=enableMongo, defproduceraPrvtKey=defproduceraPrvtKey, defproducerbPrvtKey=defproducerbPrvtKey)
walletMgr=WalletMgr(True, port=walletPort)
testSuccessful=False
killEosInstances=not dontKill
killWallet=not dontKill
dontBootstrap=sanityTest # intent is to limit the scope of the sanity test to just verifying that nodes can be started
WalletdName=Utils.EosWalletName
ClientName="cleos"
timeout = .5 * 12 * 2 + 60 # time for finalization with 1 producer + 60 seconds padding
Utils.setIrreversibleTimeout(timeout)
try:
TestHelper.printSystemInfo("BEGIN")
cluster.setWalletMgr(walletMgr)
Print("SERVER: %s" % (server))
Print("PORT: %d" % (port))
if enableMongo and not cluster.isMongodDbRunning():
errorExit("MongoDb doesn't seem to be running.")
if localTest and not dontLaunch:
cluster.killall(allInstances=killAll)
cluster.cleanup()
Print("Stand up cluster")
if cluster.launch(prodCount=prodCount, onlyBios=onlyBios, dontBootstrap=dontBootstrap, p2pPlugin=p2pPlugin) is False:
cmdError("launcher")
errorExit("Failed to stand up eos cluster.")
else:
Print("Collecting cluster info.")
cluster.initializeNodes(defproduceraPrvtKey=defproduceraPrvtKey, defproducerbPrvtKey=defproducerbPrvtKey)
killEosInstances=False
Print("Stand up %s" % (WalletdName))
walletMgr.killall(allInstances=killAll)
walletMgr.cleanup()
print("Stand up walletd")
if walletMgr.launch() is False:
cmdError("%s" % (WalletdName))
errorExit("Failed to stand up eos walletd.")
if sanityTest:
testSuccessful=True
exit(0)
Print("Validating system accounts after bootstrap")
cluster.validateAccounts(None)
accounts=Cluster.createAccountKeys(3)
if accounts is None:
errorExit("FAILURE - create keys")
testeraAccount=accounts[0]
testeraAccount.name="testera11111"
currencyAccount=accounts[1]
currencyAccount.name="currency1111"
exchangeAccount=accounts[2]
exchangeAccount.name="exchange1111"
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
testWalletName="test"
Print("Creating wallet \"%s\"." % (testWalletName))
walletAccounts=[cluster.defproduceraAccount,cluster.defproducerbAccount]
if not dontLaunch:
walletAccounts.append(cluster.eosioAccount)
testWallet=walletMgr.create(testWalletName, walletAccounts)
Print("Wallet \"%s\" password=%s." % (testWalletName, testWallet.password.encode("utf-8")))
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))
defproduceraWalletName="defproducera"
Print("Creating wallet \"%s\"." % (defproduceraWalletName))
defproduceraWallet=walletMgr.create(defproduceraWalletName)
Print("Wallet \"%s\" password=%s." % (defproduceraWalletName, defproduceraWallet.password.encode("utf-8")))
defproduceraAccount=cluster.defproduceraAccount
defproducerbAccount=cluster.defproducerbAccount
Print("Importing keys for account %s into wallet %s." % (defproduceraAccount.name, defproduceraWallet.name))
if not walletMgr.importKey(defproduceraAccount, defproduceraWallet):
cmdError("%s wallet import" % (ClientName))
errorExit("Failed to import key for account %s" % (defproduceraAccount.name))
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(testWallet)
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\"." % (defproduceraWallet.name))
if not walletMgr.unlockWallet(defproduceraWallet):
cmdError("%s wallet unlock" % (ClientName))
errorExit("Failed to unlock wallet %s" % (defproduceraWallet.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(defproduceraWallet)
expectedkeys=[defproduceraAccount.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)
Print("Validating accounts before user accounts creation")
cluster.validateAccounts(None)
Print("Create new account %s via %s" % (testeraAccount.name, cluster.defproduceraAccount.name))
transId=node.createInitializeAccount(testeraAccount, cluster.defproduceraAccount, stakedDeposit=0, waitForTransBlock=False, exitOnError=True)
Print("Create new account %s via %s" % (currencyAccount.name, cluster.defproduceraAccount.name))
transId=node.createInitializeAccount(currencyAccount, cluster.defproduceraAccount, buyRAM=200000, stakedDeposit=5000, exitOnError=True)
Print("Create new account %s via %s" % (exchangeAccount.name, cluster.defproduceraAccount.name))
transId=node.createInitializeAccount(exchangeAccount, cluster.defproduceraAccount, buyRAM=200000, waitForTransBlock=True, exitOnError=True)
Print("Validating accounts after user accounts creation")
accounts=[testeraAccount, currencyAccount, exchangeAccount]
cluster.validateAccounts(accounts)
Print("Verify account %s" % (testeraAccount))
if not node.verifyAccount(testeraAccount):
errorExit("FAILURE - account creation failed.", raw=True)
transferAmount="97.5321 {0}".format(CORE_SYMBOL)
Print("Transfer funds %s from account %s to %s" % (transferAmount, defproduceraAccount.name, testeraAccount.name))
node.transferFunds(defproduceraAccount, testeraAccount, transferAmount, "test transfer")
expectedAmount=transferAmount
Print("Verify transfer, Expected: %s" % (expectedAmount))
actualAmount=node.getAccountEosBalanceStr(testeraAccount.name)
if expectedAmount != actualAmount:
cmdError("FAILURE - transfer failed")
errorExit("Transfer verification failed. Excepted %s, actual: %s" % (expectedAmount, actualAmount))
transferAmount="0.0100 {0}".format(CORE_SYMBOL)
Print("Force transfer funds %s from account %s to %s" % (
transferAmount, defproduceraAccount.name, testeraAccount.name))
node.transferFunds(defproduceraAccount, testeraAccount, transferAmount, "test transfer", force=True)
expectedAmount="97.5421 {0}".format(CORE_SYMBOL)
Print("Verify transfer, Expected: %s" % (expectedAmount))
actualAmount=node.getAccountEosBalanceStr(testeraAccount.name)
if expectedAmount != actualAmount:
cmdError("FAILURE - transfer failed")
errorExit("Transfer verification failed. Excepted %s, actual: %s" % (expectedAmount, actualAmount))
Print("Validating accounts after some user trasactions")
accounts=[testeraAccount, currencyAccount, exchangeAccount]
cluster.validateAccounts(accounts)
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="97.5311 {0}".format(CORE_SYMBOL)
Print("Transfer funds %s from account %s to %s" % (
transferAmount, testeraAccount.name, currencyAccount.name))
trans=node.transferFunds(testeraAccount, currencyAccount, transferAmount, "test transfer a->b")
transId=Node.getTransId(trans)
expectedAmount="98.0311 {0}".format(CORE_SYMBOL) # 5000 initial deposit
Print("Verify transfer, Expected: %s" % (expectedAmount))
actualAmount=node.getAccountEosBalanceStr(currencyAccount.name)
if expectedAmount != actualAmount:
cmdError("FAILURE - transfer failed")
errorExit("Transfer verification failed. Excepted %s, actual: %s" % (expectedAmount, actualAmount))
Print("Validate last action for account %s" % (testeraAccount.name))
actions=node.getActions(testeraAccount, -1, -1, exitOnError=True)
try:
if not enableMongo:
assert(actions["actions"][0]["action_trace"]["act"]["name"] == "transfer")
else:
assert(actions["act"]["name"] == "transfer")
except (AssertionError, TypeError, KeyError) as _:
Print("Action validation failed. Actions: %s" % (actions))
raise
node.waitForTransInBlock(transId)
transaction=node.getTransaction(transId, exitOnError=True, delayedRetry=False)
typeVal=None
amountVal=None
key=""
try:
if not enableMongo:
key="[traces][0][act][name]"
typeVal= transaction["traces"][0]["act"]["name"]
key="[traces][0][act][data][quantity]"
amountVal=transaction["traces"][0]["act"]["data"]["quantity"]
amountVal=int(decimal.Decimal(amountVal.split()[0])*10000)
else:
key="[actions][0][name]"
typeVal= transaction["actions"][0]["name"]
key="[actions][0][data][quantity]"
amountVal=transaction["actions"][0]["data"]["quantity"]
amountVal=int(decimal.Decimal(amountVal.split()[0])*10000)
except (TypeError, KeyError) as e:
Print("transaction%s not found. Transaction: %s" % (key, transaction))
raise
if typeVal != "transfer" or amountVal != 975311:
errorExit("FAILURE - get transaction trans_id failed: %s %s %s" % (transId, typeVal, amountVal), 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 currency1111" % (ClientName))
errorExit("Failed to get code hash for account %s" % (currencyAccount.name))
hashNum=int(codeHash, 16)
if hashNum != 0:
errorExit("FAILURE - get code currency1111 failed", raw=True)
contractDir="contracts/eosio.token"
wasmFile="eosio.token.wasm"
abiFile="eosio.token.abi"
Print("Publish contract")
trans=node.publishContract(currencyAccount.name, contractDir, wasmFile, abiFile, waitForTransBlock=True)
if trans is None:
cmdError("%s set contract currency1111" % (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 currency1111" % (ClientName))
errorExit("Failed to get code hash for account %s" % (currencyAccount.name))
hashNum=int(codeHash, 16)
if hashNum == 0:
errorExit("FAILURE - get code currency1111 failed", raw=True)
else:
Print("verify abi is set")
account=node.getEosAccountFromDb(currencyAccount.name)
abiName=account["abi"]["structs"][0]["name"]
abiActionName=account["abi"]["actions"][0]["name"]
abiType=account["abi"]["actions"][0]["type"]
if abiName != "transfer" or abiActionName != "transfer" or abiType != "transfer":
errorExit("FAILURE - get EOS account failed", raw=True)
Print("push create action to currency1111 contract")
contract="currency1111"
action="create"
data="{\"issuer\":\"currency1111\",\"maximum_supply\":\"100000.0000 CUR\",\"can_freeze\":\"0\",\"can_recall\":\"0\",\"can_whitelist\":\"0\"}"
opts="--permission currency1111@active"
trans=node.pushMessage(contract, action, data, opts)
try:
assert(trans)
assert(trans[0])
except (AssertionError, KeyError) as _:
Print("ERROR: Failed push create action to currency1111 contract assertion. %s" % (trans))
raise
Print("push issue action to currency1111 contract")
action="issue"
data="{\"to\":\"currency1111\",\"quantity\":\"100000.0000 CUR\",\"memo\":\"issue\"}"
opts="--permission currency1111@active"
trans=node.pushMessage(contract, action, data, opts)
try:
assert(trans)
assert(trans[0])
except (AssertionError, KeyError) as _:
Print("ERROR: Failed push issue action to currency1111 contract assertion. %s" % (trans))
raise
Print("Verify currency1111 contract has proper initial balance (via get table)")
contract="currency1111"
table="accounts"
row0=node.getTableRow(contract, currencyAccount.name, table, 0)
try:
assert(row0)
assert(row0["balance"] == "100000.0000 CUR")
except (AssertionError, KeyError) as _:
Print("ERROR: Failed get table row assertion. %s" % (row0))
raise
Print("Verify currency1111 contract has proper initial balance (via get currency1111 balance)")
amountStr=node.getTableAccountBalance("currency1111", currencyAccount.name)
expected="100000.0000 CUR"
actual=amountStr
if actual != expected:
errorExit("FAILURE - currency1111 balance check failed. Expected: %s, Recieved %s" % (expected, actual), raw=True)
Print("Verify currency1111 contract has proper total supply of CUR (via get currency1111 stats)")
res=node.getCurrencyStats(contract, "CUR", exitOnError=True)
try:
assert(res["CUR"]["supply"] == "100000.0000 CUR")
except (AssertionError, KeyError) as _:
Print("ERROR: Failed get currecy stats assertion. %s" % (res))
raise
dupRejected=False
dupTransAmount=10
totalTransfer=dupTransAmount
contract="currency1111"
action="transfer"
for _ in range(5):
Print("push transfer action to currency1111 contract")
data="{\"from\":\"currency1111\",\"to\":\"defproducera\",\"quantity\":"
data +="\"00.00%s CUR\",\"memo\":\"test\"}" % (dupTransAmount)
opts="--permission currency1111@active"
trans=node.pushMessage(contract, action, data, opts)
if trans is None or not trans[0]:
cmdError("%s push message currency1111 transfer" % (ClientName))
errorExit("Failed to push message to currency1111 contract")
transId=Node.getTransId(trans[1])
Print("push duplicate transfer action to currency1111 contract")
transDuplicate=node.pushMessage(contract, action, data, opts, True)
if transDuplicate is not None and transDuplicate[0]:
transDuplicateId=Node.getTransId(transDuplicate[1])
if transId != transDuplicateId:
Print("%s push message currency1111 duplicate transfer incorrectly accepted, but they were generated with different transaction ids, this is a timing setup issue, trying again" % (ClientName))
# add the transfer that wasn't supposed to work
totalTransfer+=dupTransAmount
dupTransAmount+=1
# add the new first transfer that is expected to work
totalTransfer+=dupTransAmount
continue
else:
cmdError("%s push message currency1111 transfer, \norig: %s \ndup: %s" % (ClientName, trans, transDuplicate))
errorExit("Failed to reject duplicate message for currency1111 contract")
else:
dupRejected=True
break
if not dupRejected:
errorExit("Failed to reject duplicate message for currency1111 contract")
Print("verify transaction exists")
if not node.waitForTransInBlock(transId):
cmdError("%s get transaction trans_id" % (ClientName))
errorExit("Failed to verify push message transaction id.")
Print("read current contract balance")
amountStr=node.getTableAccountBalance("currency1111", defproduceraAccount.name)
expectedDefproduceraBalance="0.00%s CUR" % (totalTransfer)
actual=amountStr
if actual != expectedDefproduceraBalance:
errorExit("FAILURE - Wrong currency1111 balance (expected=%s, actual=%s)" % (expectedDefproduceraBalance, actual), raw=True)
amountStr=node.getTableAccountBalance("currency1111", currencyAccount.name)
expExtension=100-totalTransfer
expectedCurrency1111Balance="99999.99%s CUR" % (expExtension)
actual=amountStr
if actual != expectedCurrency1111Balance:
errorExit("FAILURE - Wrong currency1111 balance (expected=%s, actual=%s)" % (expectedCurrency1111Balance, actual), raw=True)
amountStr=node.getCurrencyBalance("currency1111", currencyAccount.name, "CUR")
try:
assert(actual)
assert(isinstance(actual, str))
actual=amountStr.strip()
assert(expectedCurrency1111Balance == actual)
except (AssertionError, KeyError) as _:
Print("ERROR: Failed get currecy balance assertion. (expected=<%s>, actual=<%s>)" % (expectedCurrency1111Balance, actual))
raise
Print("Test for block decoded packed transaction (issue 2932)")
blockId=node.getBlockIdByTransId(transId)
assert(blockId)
block=node.getBlock(blockId, exitOnError=True)
transactions=None
try:
if not enableMongo:
transactions=block["transactions"]
else:
transactions=block["block"]["transactions"]
assert(transactions)
except (AssertionError, TypeError, KeyError) as _:
Print("FAILURE - Failed to parse block. %s" % (block))
raise
myTrans=None
for trans in transactions:
assert(trans)
try:
myTransId=trans["trx"]["id"]
if transId == myTransId:
myTrans=trans["trx"]["transaction"]
assert(myTrans)
break
except (AssertionError, TypeError, KeyError) as _:
Print("FAILURE - Failed to parse block transactions. %s" % (trans))
raise
assert(myTrans)
try:
assert(myTrans["actions"][0]["name"] == "transfer")
assert(myTrans["actions"][0]["account"] == "currency1111")
assert(myTrans["actions"][0]["authorization"][0]["actor"] == "currency1111")
assert(myTrans["actions"][0]["authorization"][0]["permission"] == "active")
assert(myTrans["actions"][0]["data"]["from"] == "currency1111")
assert(myTrans["actions"][0]["data"]["to"] == "defproducera")
assert(myTrans["actions"][0]["data"]["quantity"] == "0.00%s CUR" % (dupTransAmount))
assert(myTrans["actions"][0]["data"]["memo"] == "test")
except (AssertionError, TypeError, KeyError) as _:
Print("FAILURE - Failed to parse block transaction. %s" % (myTrans))
raise
Print("Unlocking wallet \"%s\"." % (defproduceraWallet.name))
if not walletMgr.unlockWallet(defproduceraWallet):
cmdError("%s wallet unlock" % (ClientName))
errorExit("Failed to unlock wallet %s" % (defproduceraWallet.name))
Print("push transfer action to currency1111 contract that would go negative")
contract="currency1111"
action="transfer"
data="{\"from\":\"defproducera\",\"to\":\"currency1111\",\"quantity\":"
data +="\"00.0051 CUR\",\"memo\":\"test\"}"
opts="--permission defproducera@active"
trans=node.pushMessage(contract, action, data, opts, True)
if trans is None or trans[0]:
cmdError("%s push message currency1111 transfer should have failed" % (ClientName))
errorExit("Failed to reject invalid transfer message to currency1111 contract")
Print("read current contract balance")
amountStr=node.getTableAccountBalance("currency1111", defproduceraAccount.name)
actual=amountStr
if actual != expectedDefproduceraBalance:
errorExit("FAILURE - Wrong currency1111 balance (expected=%s, actual=%s)" % (expectedDefproduceraBalance, actual), raw=True)
amountStr=node.getTableAccountBalance("currency1111", currencyAccount.name)
actual=amountStr
if actual != expectedCurrency1111Balance:
errorExit("FAILURE - Wrong currency1111 balance (expected=%s, actual=%s)" % (expectedCurrency1111Balance, actual), raw=True)
Print("push another transfer action to currency1111 contract")
contract="currency1111"
action="transfer"
data="{\"from\":\"defproducera\",\"to\":\"currency1111\",\"quantity\":"
data +="\"00.00%s CUR\",\"memo\":\"test\"}" % (totalTransfer)
opts="--permission defproducera@active"
trans=node.pushMessage(contract, action, data, opts)
if trans is None or not trans[0]:
cmdError("%s push message currency1111 transfer" % (ClientName))
errorExit("Failed to push message to currency1111 contract")
transId=Node.getTransId(trans[1])
Print("read current contract balance")
amountStr=node.getCurrencyBalance("currency1111", defproduceraAccount.name, "CUR")
expected="0.0000 CUR"
try:
actual=amountStr.strip()
assert(expected == actual or not actual)
except (AssertionError, KeyError) as _:
Print("ERROR: Failed get currecy balance assertion. (expected=<%s>, actual=<%s>)" % (str(expected), str(actual)))
raise
amountStr=node.getTableAccountBalance("currency1111", currencyAccount.name)
expected="100000.0000 CUR"
actual=amountStr
if actual != expected:
errorExit("FAILURE - Wrong currency1111 balance (expected=%s, actual=%s)" % (str(expected), str(actual)), raw=True)
Print("push transfer action to currency1111 contract that would go negative")
contract="currency1111"
action="transfer"
data="{\"from\":\"defproducera\",\"to\":\"currency1111\",\"quantity\":"
data +="\"00.0025 CUR\",\"memo\":\"test\"}"
opts="--permission defproducera@active"
trans=node.pushMessage(contract, action, data, opts, True)
if trans is None or trans[0]:
cmdError("%s push message currency1111 transfer should have failed" % (ClientName))
errorExit("Failed to reject invalid transfer message to currency1111 contract")
Print("read current contract balance")
amountStr=node.getCurrencyBalance("currency1111", defproduceraAccount.name, "CUR")
expected="0.0000 CUR"
try:
actual=amountStr.strip()
assert(expected == actual or not actual)
except (AssertionError, KeyError) as _:
Print("ERROR: Failed get currecy balance assertion. (expected=<%s>, actual=<%s>)" % (str(expected), str(actual)))
raise
amountStr=node.getTableAccountBalance("currency1111", currencyAccount.name)
expected="100000.0000 CUR"
actual=amountStr
if actual != expected:
errorExit("FAILURE - Wrong currency1111 balance (expected=%s, actual=%s)" % (str(expected), str(actual)), raw=True)
Print("Locking wallet \"%s\"." % (defproduceraWallet.name))
if not walletMgr.lockWallet(defproduceraWallet):
cmdError("%s wallet lock" % (ClientName))
errorExit("Failed to lock wallet %s" % (defproduceraWallet.name))
contractDir="contracts/simpledb"
wasmFile="simpledb.wasm"
abiFile="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", contractDir, wasmFile, 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 simpledb failed", raw=True)
else:
Print("Test successful, %s returned error code: %d" % (ClientName, retMap["returncode"]))
Print("set permission")
code="currency1111"
pType="transfer"
requirement="active"
trans=node.setPermission(testeraAccount.name, code, pType, requirement, waitForTransBlock=True, exitOnError=True)
Print("remove permission")
requirement="null"
trans=node.setPermission(testeraAccount.name, code, pType, requirement, waitForTransBlock=True, exitOnError=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\"." % (defproduceraWallet.name))
if not walletMgr.unlockWallet(defproduceraWallet):
cmdError("%s wallet unlock defproducera" % (ClientName))
errorExit("Failed to unlock wallet %s" % (defproduceraWallet.name))
Print("Get account defproducera")
account=node.getEosAccount(defproduceraAccount.name, exitOnError=True)
Print("Unlocking wallet \"%s\"." % (defproduceraWallet.name))
if not walletMgr.unlockWallet(testWallet):
cmdError("%s wallet unlock test" % (ClientName))
errorExit("Failed to unlock wallet %s" % (testWallet.name))
Print("Get head block num.")
currentBlockNum=node.getHeadBlockNum()
Print("CurrentBlockNum: %d" % (currentBlockNum))
Print("Request blocks 1-%d" % (currentBlockNum))
start=1
if enableMongo:
start=2 # block 1 (genesis block) is not signaled to the plugins, so not available in DB
for blockNum in range(start, currentBlockNum+1):
block=node.getBlock(blockNum, silentErrors=False, exitOnError=True)
if enableMongo:
blockId=block["block_id"]
block2=node.getBlockByIdMdb(blockId)
if block2 is None:
errorExit("mongo get block by id %s" % blockId)
Print("Request invalid block numbered %d. This will generate an expected error message." % (currentBlockNum+1000))
block=node.getBlock(currentBlockNum+1000, silentErrors=True)
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"
assertionsFound=False
with open(errFileName) as errFile:
for line in errFile:
if p.search(line):
assertionsFound=True
if assertionsFound:
# Too many assertion logs, hard to validate how many are genuine. Make this a warning
# for now, hopefully the logs will get cleaned up in future.
Print("WARNING: Asserts in var/lib/node_00/stderr.txt")
#errorExit("FAILURE - Assert in var/lib/node_00/stderr.txt")
Print("Validating accounts at end of test")
accounts=[testeraAccount, currencyAccount, exchangeAccount]
cluster.validateAccounts(accounts)
testSuccessful=True
finally:
TestHelper.shutdown(cluster, walletMgr, testSuccessful, killEosInstances, killWallet, keepLogs, killAll, dumpErrorDetails)
exit(0)