nodeos_run_test.py 27.9 KB
Newer Older
1
#!/usr/bin/env python3
2 3 4

import testUtils

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

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

Print=testUtils.Utils.Print
17
errorExit=testUtils.Utils.errorExit
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35


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)
36 37 38 39
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)
40
parser.add_argument("-c", "--prod-count", type=int, help="Per node producer count", default=1)
41 42
parser.add_argument("--inita_prvt_key", type=str, help="Inita private key.")
parser.add_argument("--initb_prvt_key", type=str, help="Initb private key.")
43 44
parser.add_argument("--mongodb", help="Configure a MongoDb instance", action='store_true')
parser.add_argument("--dump-error-details",
45
                    help="Upon error print etc/eosio/node_*/config.ini and var/lib/node_*/stderr.log to stdout",
46
                    action='store_true')
47 48
parser.add_argument("--dont-launch", help="Don't launch own node. Assume node is already running.",
                    action='store_true')
49
parser.add_argument("--keep-logs", help="Don't delete var/lib/node_* folders upon test completion",
50 51
                    action='store_true')
parser.add_argument("-v", help="verbose logging", action='store_true')
52
parser.add_argument("--dont-kill", help="Leave cluster running after test finishes", 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

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

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

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

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

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

    walletMgr.killall()
    walletMgr.cleanup()
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118

    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
119

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

    exchangeAccount.ownerPrivateKey=PRV_KEY2
    exchangeAccount.ownerPublicKey=PUB_KEY2
125

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

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

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

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

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

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

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

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

    Print("Unlocking wallet \"%s\"." % (testWallet.name))
    if not walletMgr.unlockWallet(testWallet):
178
        cmdError("%s wallet unlock" % (ClientName))
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
        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():
199
        cmdError("%s wallet lock_all" % (ClientName))
200 201 202 203
        errorExit("Failed to lock all wallets")

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

    Print("Unlocking wallet \"%s\"." % (testWallet.name))
    if not walletMgr.unlockWallet(testWallet):
209
        cmdError("%s wallet unlock" % (ClientName))
210 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:
        errorExit("FAILURE - wallet keys did not include %s" % (noMatch), raw=true)
218

219 220 221 222 223
    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))
224
    transId=node.createAccount(testeraAccount, initaAccount, stakedDeposit=0, waitForTransBlock=False)
225
    if transId is None:
226
        cmdError("%s create account" % (ClientName))
227 228 229 230 231 232 233 234 235
        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:
236
        cmdError("%s transfer" % (ClientName))
237 238 239
        errorExit("Failed to transfer funds %d from account %s to %s" % (
            transferAmount, initaAccount.name, testeraAccount.name))

240
    # TBD: Known issue (Issue 2043) that 'get currency balance' doesn't return balance.
241
    #  Uncomment when functional
242 243 244 245 246 247
    # 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))
248 249 250 251 252

    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:
253
        cmdError("%s transfer" % (ClientName))
254 255 256
        errorExit("Failed to force transfer funds %d from account %s to %s" % (
            transferAmount, initaAccount.name, testeraAccount.name))

257
    # TBD: Known issue (Issue 2043) that 'get currency balance' doesn't return balance.
258
    #  Uncomment when functional
259 260 261 262 263 264
    # 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))
265 266

    Print("Create new account %s via %s" % (currencyAccount.name, initbAccount.name))
267
    transId=node.createAccount(currencyAccount, initbAccount, stakedDeposit=5000)
268
    if transId is None:
269
        cmdError("%s create account" % (ClientName))
270 271 272 273 274
        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:
275
        cmdError("%s create account" % (ClientName))
276 277 278 279
        errorExit("Failed to create account %s" % (exchangeAccount.name))

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

    Print("Unlocking wallet \"%s\"." % (testWallet.name))
    if not walletMgr.unlockWallet(testWallet):
285
        cmdError("%s wallet unlock" % (ClientName))
286 287 288 289 290
        errorExit("Failed to unlock wallet %s" % (testWallet.name))

    transferAmount=975311
    Print("Transfer funds %d from account %s to %s" % (
        transferAmount, testeraAccount.name, currencyAccount.name))
291 292
    trans=node.transferFunds(testeraAccount, currencyAccount, transferAmount, "test transfer a->b")
    if trans is None:
293
        cmdError("%s transfer" % (ClientName))
294 295
        errorExit("Failed to transfer funds %d from account %s to %s" % (
            transferAmount, initaAccount.name, testeraAccount.name))
296
    transId=testUtils.Node.getTransId(trans)
297

298
    # TBD: Known issue (Issue 2043) that 'get currency balance' doesn't return balance.
299
    #  Uncomment when functional
300 301 302 303 304 305 306 307 308
    # 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))
309 310 311

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

354 355 356 357
    transaction=None
    if not enableMongo:
        transaction=node.getTransaction(transId)
    else:
358
        transaction=node.getActionFromDb(transId)
359
    if transaction is None:
360
        cmdError("%s get transaction trans_id" % (ClientName))
361 362
        errorExit("Failed to retrieve transaction details %s" % (transId))

363 364
    typeVal=None
    amountVal=None
365 366 367 368
    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)
369
    else:
370 371 372 373 374
        typeVal=  transaction["name"]
        amountVal=transaction["data"]["quantity"]
        amountVal=int(decimal.Decimal(amountVal.split()[0])*10000)

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

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

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

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

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

423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
    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)
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
    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.
465 466 467 468
    # 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))
469 470
    #     errorExit("Failed to retrieve CUR stats from contract %s" % (contract))
    
471 472
    # if res["supply"] != "100000.0000 CUR":
    #     errorExit("FAILURE - get currency stats failed", raw=True)
473

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

    Print("verify transaction exists")
    if not node.waitForTransIdOnNode(transId):
488
        cmdError("%s get transaction trans_id" % (ClientName))
489
        errorExit("Failed to verify push message transaction id.")
490

491
    # TODO need to update eosio.system contract to use new currency and update cleos and chain_plugin for interaction
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
    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)
516 517 518 519

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

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

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

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

551 552 553 554 555 556
    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")
557

558 559
    Print("Locking all wallets.")
    if not walletMgr.lockAllWallets():
560
        cmdError("%s wallet lock_all" % (ClientName))
561 562 563 564
        errorExit("Failed to lock all wallets")

    Print("Unlocking wallet \"%s\"." % (initaWallet.name))
    if not walletMgr.unlockWallet(initaWallet):
565
        cmdError("%s wallet unlock inita" % (ClientName))
566 567 568 569 570
        errorExit("Failed to unlock wallet %s" % (initaWallet.name))

    Print("Get account inita")
    account=node.getEosAccount(initaAccount.name)
    if account is None:
571
        cmdError("%s get account" % (ClientName))
572 573 574 575 576 577 578 579 580 581 582 583
        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):
584
        block=node.getBlock(blockNum, retry=False, silentErrors=True)
585
        if block is None:
586
            # TBD: Known issue (Issue 2099) that the block containing setprods isn't retrievable.
587 588 589 590
            #  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)
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605

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

606

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

629 630 631 632 633
    testSuccessful=True
    Print("END")
finally:
    if not testSuccessful and dumpErrorDetails:
        cluster.dumpErrorDetails()
634 635
        walletMgr.dumpErrorDetails()
        Print("== Errors see above ==")
636 637

    if killEosInstances:
638
        Print("Shut down the cluster.")
639 640
        cluster.killall()
        if testSuccessful and not keepLogs:
641
            Print("Cleanup cluster data.")
642
            cluster.cleanup()
643 644 645 646 647 648

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

651
exit(0)