“5f1bcf7827f501f7502432a1a478bac86db72153”上不存在“tests/nodeos_run_test.py”
nodeos_run_test.py 28.0 KB
Newer Older
1
#!/usr/bin/env python3
2 3 4

import testUtils

K
Kevin Heifner 已提交
5
import decimal
6
import argparse
7
import re
8 9

###############################################################
10
# nodeos_run_test
11 12
# --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>
13 14 15
###############################################################

Print=testUtils.Utils.Print
16
errorExit=testUtils.Utils.errorExit
17 18


19 20
def cmdError(name, cmdCode=0, exitNow=False):
    msg="FAILURE - %s%s" % (name, ("" if cmdCode == 0 else (" returned error code %d" % cmdCode)))
21 22 23 24 25 26 27 28 29 30 31 32 33 34
    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)
35 36 37 38
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)
39
parser.add_argument("-c", "--prod-count", type=int, help="Per node producer count", default=1)
40 41
parser.add_argument("--inita_prvt_key", type=str, help="Inita private key.")
parser.add_argument("--initb_prvt_key", type=str, help="Initb private key.")
42 43
parser.add_argument("--mongodb", help="Configure a MongoDb instance", action='store_true')
parser.add_argument("--dump-error-details",
44
                    help="Upon error print etc/eosio/node_*/config.ini and var/lib/node_*/stderr.log to stdout",
45
                    action='store_true')
46 47
parser.add_argument("--dont-launch", help="Don't launch own node. Assume node is already running.",
                    action='store_true')
48
parser.add_argument("--keep-logs", help="Don't delete var/lib/node_* folders upon test completion",
49 50
                    action='store_true')
parser.add_argument("-v", help="verbose logging", action='store_true')
51
parser.add_argument("--dont-kill", help="Leave cluster running after test finishes", action='store_true')
52
parser.add_argument("--only-bios", help="Limit testing to bios node.", action='store_true')
53

54 55 56 57
args = parser.parse_args()
testOutputFile=args.output
server=args.host
port=args.port
58
debug=args.v
59
enableMongo=args.mongodb
60 61
initaPrvtKey=args.inita_prvt_key
initbPrvtKey=args.initb_prvt_key
62 63 64
dumpErrorDetails=args.dump_error_details
keepLogs=args.keep_logs
dontLaunch=args.dont_launch
65
dontKill=args.dont_kill
66
prodCount=args.prod_count
67
onlyBios=args.only_bios
68

69 70
testUtils.Utils.Debug=debug
localTest=True if server == LOCAL_HOST else False
71
cluster=testUtils.Cluster(walletd=True, enableMongo=enableMongo, initaPrvtKey=initaPrvtKey, initbPrvtKey=initbPrvtKey)
72
walletMgr=testUtils.WalletMgr(True)
73
testSuccessful=False
74 75
killEosInstances=not dontKill
killWallet=not dontKill
76

77 78 79
WalletdName="keosd"
ClientName="cleos"
# testUtils.Utils.setMongoSyncTime(50)
80

81 82 83 84 85
try:
    Print("BEGIN")
    print("TEST_OUTPUT: %s" % (testOutputFile))
    print("SERVER: %s" % (server))
    print("PORT: %d" % (port))
86

87 88 89
    if enableMongo and not cluster.isMongodDbRunning():
        errorExit("MongoDb doesn't seem to be running.")

90 91 92
    walletMgr.killall()
    walletMgr.cleanup()

93 94 95
    if localTest and not dontLaunch:
        cluster.killall()
        cluster.cleanup()
96
        Print("Stand up cluster")
97
        if cluster.launch(prodCount=prodCount, onlyBios=onlyBios, dontKill=dontKill) is False:
98 99
            cmdError("launcher")
            errorExit("Failed to stand up eos cluster.")
100
    else:
101
        cluster.initializeNodes(initaPrvtKey=initaPrvtKey, initbPrvtKey=initbPrvtKey)
102 103
        killEosInstances=False

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    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
120

121 122 123 124 125
    testeraAccount.activePrivateKey=currencyAccount.activePrivateKey=PRV_KEY3
    testeraAccount.activePublicKey=currencyAccount.activePublicKey=PUB_KEY3

    exchangeAccount.ownerPrivateKey=PRV_KEY2
    exchangeAccount.ownerPublicKey=PUB_KEY2
126

127 128
    Print("Stand up walletd")
    if walletMgr.launch() is False:
129
        cmdError("%s" % (WalletdName))
130 131 132 133 134 135 136 137 138
        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))

139 140
    Print("Wallet \"%s\" password=%s." % (testWalletName, testWallet.password.encode("utf-8")))

141 142 143
    for account in accounts:
        Print("Importing keys for account %s into wallet %s." % (account.name, testWallet.name))
        if not walletMgr.importKey(account, testWallet):
144
            cmdError("%s wallet import" % (ClientName))
145 146 147 148 149 150 151 152
            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))
153

154 155
    initaAccount=cluster.initaAccount
    initbAccount=cluster.initbAccount
156 157 158

    Print("Importing keys for account %s into wallet %s." % (initaAccount.name, initaWallet.name))
    if not walletMgr.importKey(initaAccount, initaWallet):
159
        cmdError("%s wallet import" % (ClientName))
160 161 162 163
        errorExit("Failed to import key for account %s" % (initaAccount.name))

    Print("Locking wallet \"%s\"." % (testWallet.name))
    if not walletMgr.lockWallet(testWallet):
164
        cmdError("%s wallet lock" % (ClientName))
165 166 167 168
        errorExit("Failed to lock wallet %s" % (testWallet.name))

    Print("Unlocking wallet \"%s\"." % (testWallet.name))
    if not walletMgr.unlockWallet(testWallet):
169
        cmdError("%s wallet unlock" % (ClientName))
170 171 172 173
        errorExit("Failed to unlock wallet %s" % (testWallet.name))

    Print("Locking all wallets.")
    if not walletMgr.lockAllWallets():
174
        cmdError("%s wallet lock_all" % (ClientName))
175 176 177 178
        errorExit("Failed to lock all wallets")

    Print("Unlocking wallet \"%s\"." % (testWallet.name))
    if not walletMgr.unlockWallet(testWallet):
179
        cmdError("%s wallet unlock" % (ClientName))
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
        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:
196
        errorExit("FAILURE - wallet keys did not include %s" % (noMatch), raw=True)
197 198 199

    Print("Locking all wallets.")
    if not walletMgr.lockAllWallets():
200
        cmdError("%s wallet lock_all" % (ClientName))
201 202 203 204
        errorExit("Failed to lock all wallets")

    Print("Unlocking wallet \"%s\"." % (initaWallet.name))
    if not walletMgr.unlockWallet(initaWallet):
205 206 207 208 209
        cmdError("%s wallet unlock" % (ClientName))
        errorExit("Failed to unlock wallet %s" % (initaWallet.name))

    Print("Unlocking wallet \"%s\"." % (testWallet.name))
    if not walletMgr.unlockWallet(testWallet):
210
        cmdError("%s wallet unlock" % (ClientName))
211 212 213 214 215 216 217
        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:
218
        errorExit("FAILURE - wallet keys did not include %s" % (noMatch), raw=True)
219

220 221 222 223 224
    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))
225
    transId=node.createInitializeAccount(testeraAccount, initaAccount, stakedDeposit=0, waitForTransBlock=False)
226
    if transId is None:
227
        cmdError("%s create account" % (ClientName))
228 229 230 231 232 233
        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)

234 235
    transferAmount="97.5321 EOS"
    Print("Transfer funds %s from account %s to %s" % (transferAmount, initaAccount.name, testeraAccount.name))
236
    if node.transferFunds(initaAccount, testeraAccount, transferAmount, "test transfer") is None:
237
        cmdError("%s transfer" % (ClientName))
238 239 240
        errorExit("Failed to transfer funds %d from account %s to %s" % (
            transferAmount, initaAccount.name, testeraAccount.name))

241 242 243 244 245 246
    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))
247

248 249
    transferAmount="0.0100 EOS"
    Print("Force transfer funds %s from account %s to %s" % (
250 251
        transferAmount, initaAccount.name, testeraAccount.name))
    if node.transferFunds(initaAccount, testeraAccount, transferAmount, "test transfer", force=True) is None:
252
        cmdError("%s transfer" % (ClientName))
253 254 255
        errorExit("Failed to force transfer funds %d from account %s to %s" % (
            transferAmount, initaAccount.name, testeraAccount.name))

256 257 258 259 260 261
    expectedAmount="97.5421 EOS"
    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))
262 263

    Print("Create new account %s via %s" % (currencyAccount.name, initbAccount.name))
264
    transId=node.createInitializeAccount(currencyAccount, initbAccount, stakedDeposit=5000)
265
    if transId is None:
266
        cmdError("%s create account" % (ClientName))
267 268 269
        errorExit("Failed to create account %s" % (currencyAccount.name))

    Print("Create new account %s via %s" % (exchangeAccount.name, initaAccount.name))
270
    transId=node.createInitializeAccount(exchangeAccount, initaAccount, waitForTransBlock=True)
271
    if transId is None:
272
        cmdError("%s create account" % (ClientName))
273 274 275 276
        errorExit("Failed to create account %s" % (exchangeAccount.name))

    Print("Locking all wallets.")
    if not walletMgr.lockAllWallets():
277
        cmdError("%s wallet lock_all" % (ClientName))
278 279 280 281
        errorExit("Failed to lock all wallets")

    Print("Unlocking wallet \"%s\"." % (testWallet.name))
    if not walletMgr.unlockWallet(testWallet):
282
        cmdError("%s wallet unlock" % (ClientName))
283 284
        errorExit("Failed to unlock wallet %s" % (testWallet.name))

285 286
    transferAmount="97.5311 EOS"
    Print("Transfer funds %s from account %s to %s" % (
287
        transferAmount, testeraAccount.name, currencyAccount.name))
288 289
    trans=node.transferFunds(testeraAccount, currencyAccount, transferAmount, "test transfer a->b")
    if trans is None:
290
        cmdError("%s transfer" % (ClientName))
291
        errorExit("Failed to transfer funds %d from account %s to %s" % (
C
Ciju John 已提交
292
            transferAmount, testeraAccount.name, currencyAccount.name))
293
    transId=testUtils.Node.getTransId(trans)
294

295 296 297 298 299 300
    expectedAmount="98.0311 EOS" # 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))
301

C
Ciju John 已提交
302 303 304 305 306 307 308 309 310
    Print("Validate last action for account %s" % (testeraAccount.name))
    actions=node.getActions(testeraAccount, -1, -1)
    assert(actions)
    try:
        assert(actions["actions"][0]["action_trace"]["act"]["name"] == "transfer")
    except AssertionError as e:
        print("Last action validation failed. Actions: %s" % (actions))
        raise

311 312 313 314
    # Pre-mature exit on slim branch. This will pushed futher out as code stablizes.
    testSuccessful=True
    exit(0)

315 316
    expectedAccounts=[testeraAccount.name, currencyAccount.name, exchangeAccount.name]
    Print("Get accounts by key %s, Expected: %s" % (PUB_KEY3, expectedAccounts))
317
    actualAccounts=node.getAccountsArrByKey(PUB_KEY3)
318
    if actualAccounts is None:
319
        cmdError("%s get accounts pub_key3" % (ClientName))
320 321 322 323 324 325 326 327
        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))
328
    actualAccounts=node.getAccountsArrByKey(PUB_KEY1)
329
    if actualAccounts is None:
330
        cmdError("%s get accounts pub_key1" % (ClientName))
331 332 333 334 335 336 337 338
        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))
339
    actualServants=node.getServantsArr(initaAccount.name)
340
    if actualServants is None:
341
        cmdError("%s get servants testera" % (ClientName))
342 343 344 345 346 347 348
        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))
349
    actualServants=node.getServantsArr(testeraAccount.name)
350
    if actualServants is None:
351
        cmdError("%s get servants testera" % (ClientName))
352 353 354 355 356 357 358
        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)

359 360 361 362
    transaction=None
    if not enableMongo:
        transaction=node.getTransaction(transId)
    else:
363
        transaction=node.getActionFromDb(transId)
364
    if transaction is None:
365
        cmdError("%s get transaction trans_id" % (ClientName))
366 367
        errorExit("Failed to retrieve transaction details %s" % (transId))

368 369
    typeVal=None
    amountVal=None
370 371 372 373
    if not enableMongo:
        typeVal=  transaction["transaction"]["transaction"]["actions"][0]["name"]
        amountVal=transaction["transaction"]["transaction"]["actions"][0]["data"]["quantity"]
        amountVal=int(decimal.Decimal(amountVal.split()[0])*10000)
374
    else:
375 376 377 378 379
        typeVal=  transaction["name"]
        amountVal=transaction["data"]["quantity"]
        amountVal=int(decimal.Decimal(amountVal.split()[0])*10000)

    if typeVal != "transfer" or amountVal != 975311:
K
Kevin Heifner 已提交
380
        errorExit("FAILURE - get transaction trans_id failed: %s %s %s" % (transId, typeVal, amountVal), raw=True)
381 382

    Print("Get transactions for account %s" % (testeraAccount.name))
383
    actualTransactions=node.getTransactionsArrByAccount(testeraAccount.name)
384
    if actualTransactions is None:
385
        cmdError("%s get transactions testera" % (ClientName))
386
        errorExit("Failed to get transactions by account %s" % (testeraAccount.name))
387
    if transId not in actualTransactions:
388 389
        errorExit("FAILURE - get transactions testera failed", raw=True)

390 391
    Print("Currency Contract Tests")
    Print("verify no contract in place")
392 393 394
    Print("Get code hash for account %s" % (currencyAccount.name))
    codeHash=node.getAccountCodeHash(currencyAccount.name)
    if codeHash is None:
395
        cmdError("%s get code currency" % (ClientName))
396
        errorExit("Failed to get code hash for account %s" % (currencyAccount.name))
397 398 399 400
    hashNum=int(codeHash, 16)
    if hashNum != 0:
        errorExit("FAILURE - get code currency failed", raw=True)

401 402 403
    contractDir="contracts/eosio.token"
    wastFile="contracts/eosio.token/eosio.token.wast"
    abiFile="contracts/eosio.token/eosio.token.abi"
404
    Print("Publish contract")
405
    trans=node.publishContract(currencyAccount.name, contractDir, wastFile, abiFile, waitForTransBlock=True)
406
    if trans is None:
407
        cmdError("%s set contract currency" % (ClientName))
408
        errorExit("Failed to publish contract.")
409

410 411 412 413
    if not enableMongo:
        Print("Get code hash for account %s" % (currencyAccount.name))
        codeHash=node.getAccountCodeHash(currencyAccount.name)
        if codeHash is None:
414
            cmdError("%s get code currency" % (ClientName))
415 416 417 418 419 420 421 422
            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"]
423
        abiActionName=account["abi"]["actions"][0]["name"]
424 425
        abiType=account["abi"]["actions"][0]["type"]
        if abiName != "transfer" or abiActionName != "transfer" or abiType != "transfer":
426
            errorExit("FAILURE - get EOS account failed", raw=True)
427

428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
    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)
    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)
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
    Print("Verify currency contract has proper initial balance (via get table)")
    contract="currency"
    table="accounts"
    row0=node.getTableRow(contract, currencyAccount.name, table, 0)
    if row0 is None:
        cmdError("%s get currency table currency account" % (ClientName))
        errorExit("Failed to retrieve contract %s table %s" % (contract, table))

    balanceKey="balance"
    keyKey="key"
    if row0[balanceKey] != "100000.0000 CUR":
        errorExit("FAILURE - Wrong currency balance", 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))

    expected="100000.0000 CUR"
    actual=res.strip()
    if actual != expected:
        errorExit("FAILURE - get currency balance failed. Recieved response: <%s>" % (res), raw=True)

    # TBD: "get currency stats is still not working. Enable when ready.
470 471 472 473
    # 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))
474 475
    #     errorExit("Failed to retrieve CUR stats from contract %s" % (contract))
    
476 477
    # if res["supply"] != "100000.0000 CUR":
    #     errorExit("FAILURE - get currency stats failed", raw=True)
478

479
    Print("push transfer action to currency contract")
480 481
    contract="currency"
    action="transfer"
482
    data="{\"from\":\"currency\",\"to\":\"inita\",\"quantity\":"
483
    data +="\"00.0050 CUR\",\"memo\":\"test\"}"
484
    opts="--permission currency@active"
485
    trans=node.pushMessage(contract, action, data, opts)
486
    if trans is None or not trans[0]:
487
        cmdError("%s push message currency transfer" % (ClientName))
488
        errorExit("Failed to push message to currency contract")
489
    transId=testUtils.Node.getTransId(trans[1])
490 491 492

    Print("verify transaction exists")
    if not node.waitForTransIdOnNode(transId):
493
        cmdError("%s get transaction trans_id" % (ClientName))
494
        errorExit("Failed to verify push message transaction id.")
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
    Print("read current contract balance")
    contract="currency"
    table="accounts"
    row0=node.getTableRow(contract, initaAccount.name, table, 0)
    if row0 is None:
        cmdError("%s get currency table inita account" % (ClientName))
        errorExit("Failed to retrieve contract %s table %s" % (contract, table))

    balanceKey="balance"
    keyKey="key"
    expected="0.0050 CUR"
    actual=row0[balanceKey]
    if actual != expected:
        errorExit("FAILURE - Wrong currency balance (expected=%s, actual=%s)" % (str(expected), str(actual)), raw=True)

    row0=node.getTableRow(contract, currencyAccount.name, table, 0)
    if row0 is None:
        cmdError("%s get currency table currency account" % (ClientName))
        errorExit("Failed to retrieve contract %s table %s" % (contract, table))

    expected="99999.9950 CUR"
    actual=row0[balanceKey]
    if actual != expected:
        errorExit("FAILURE - Wrong currency balance (expected=%s, actual=%s)" % (str(expected), str(actual)), raw=True)
520 521 522 523

    Print("Exchange Contract Tests")
    Print("upload exchange contract")

524
    contractDir="contracts/exchange"
525 526 527
    wastFile="contracts/exchange/exchange.wast"
    abiFile="contracts/exchange/exchange.abi"
    Print("Publish exchange contract")
528
    trans=node.publishContract(exchangeAccount.name, contractDir, wastFile, abiFile, waitForTransBlock=True)
529 530 531
    if trans is None:
        cmdError("%s set contract exchange" % (ClientName))
        errorExit("Failed to publish contract.")
532

533
    contractDir="contracts/simpledb"
534 535
    wastFile="contracts/simpledb/simpledb.wast"
    abiFile="contracts/simpledb/simpledb.abi"
536 537
    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))
538
    retMap=node.publishContract("simpledb", contractDir, wastFile, abiFile, shouldFail=True)
539 540 541 542 543
    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:
544
        Print("Test successful, %s returned error code: %d" % (ClientName, retMap["returncode"]))
545 546 547 548 549 550 551

    Print("set permission")
    code="currency"
    pType="transfer"
    requirement="active"
    trans=node.setPermission(testeraAccount.name, code, pType, requirement, waitForTransBlock=True)
    if trans is None:
552
        cmdError("%s set action permission set" % (ClientName))
553 554
        errorExit("Failed to set permission")

555 556 557 558 559 560
    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")
561

562 563
    Print("Locking all wallets.")
    if not walletMgr.lockAllWallets():
564
        cmdError("%s wallet lock_all" % (ClientName))
565 566 567 568
        errorExit("Failed to lock all wallets")

    Print("Unlocking wallet \"%s\"." % (initaWallet.name))
    if not walletMgr.unlockWallet(initaWallet):
569
        cmdError("%s wallet unlock inita" % (ClientName))
570 571 572 573 574
        errorExit("Failed to unlock wallet %s" % (initaWallet.name))

    Print("Get account inita")
    account=node.getEosAccount(initaAccount.name)
    if account is None:
575
        cmdError("%s get account" % (ClientName))
576 577 578 579 580 581 582 583 584 585 586 587
        errorExit("Failed to get account %s" % (initaAccount.name))

    #
    # 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):
588
        block=node.getBlock(blockNum, retry=False, silentErrors=True)
589
        if block is None:
590
            # TBD: Known issue (Issue 2099) that the block containing setprods isn't retrievable.
591 592 593 594
            #  Enable errorExit() once that is resolved.
            Print("WARNING: Failed to get block %d (probably issue 2099). Report and keep going..." % (blockNum))
            # cmdError("%s get block" % (ClientName))
            # errorExit("get block by num %d" % blockNum)
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609

        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))

610

K
Kevin Heifner 已提交
611 612
    Print("Request invalid block numbered %d" % (currentBlockNum+1000))
    block=node.getBlock(currentBlockNum+1000, silentErrors=True, retry=False)
613 614 615 616 617 618 619
    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')
620
        errFileName="var/lib/node_00/stderr.txt"
621
        assertionsFound=False
622 623 624
        with open(errFileName) as errFile:
            for line in errFile:
                if p.search(line):
625 626 627 628 629 630 631
                    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")
632

633 634
    testSuccessful=True
finally:
635 636 637 638
    if testSuccessful:
        Print("Test succeeded.")
    else:
        Print("Test failed.")
639 640
    if not testSuccessful and dumpErrorDetails:
        cluster.dumpErrorDetails()
641 642
        walletMgr.dumpErrorDetails()
        Print("== Errors see above ==")
643 644

    if killEosInstances:
645
        Print("Shut down the cluster.")
646 647
        cluster.killall()
        if testSuccessful and not keepLogs:
648
            Print("Cleanup cluster data.")
649
            cluster.cleanup()
650 651 652 653 654 655

    if killWallet:
        Print("Shut down the wallet.")
        walletMgr.killall()
        if testSuccessful and not keepLogs:
            Print("Cleanup wallet data.")
656
            walletMgr.cleanup()
657

658
exit(0)