errorExit = Utils.errorExit args = TestHelper.parse_args({ "--dump-error-details", "--keep-logs", "-v", "--leave-running", "--clean-run", "--wallet-port" }) Utils.Debug = args.v totalNodes = 4 cluster = Cluster(walletd=True) dumpErrorDetails = args.dump_error_details keepLogs = args.keep_logs dontKill = args.leave_running killAll = args.clean_run walletPort = args.wallet_port walletMgr = WalletMgr(True, port=walletPort) testSuccessful = False killEosInstances = not dontKill killWallet = not dontKill WalletdName = Utils.EosWalletName ClientName = "cleos" try: TestHelper.printSystemInfo("BEGIN") cluster.setWalletMgr(walletMgr) cluster.killall(allInstances=killAll) cluster.cleanup() Print("Stand up cluster") minRAMFlag = "--chain-state-db-guard-size-mb"
# --dump-error-details <Upon error print etc/ETAio/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 args = TestHelper.parse_args({"--dump-error-details","--keep-logs","-v","--leave-running","--clean-run"}) Utils.Debug=args.v totalNodes=4 cluster=Cluster(walletd=True) dumpErrorDetails=args.dump_error_details keepLogs=args.keep_logs dontKill=args.leave_running killAll=args.clean_run walletMgr=WalletMgr(True) testSuccessful=False killETAInstances=not dontKill killWallet=not dontKill WalletdName="kETAd" ClientName="clETA" try: TestHelper.printSystemInfo("BEGIN") cluster.killall(allInstances=killAll) cluster.cleanup() Print("Stand up cluster") minRAMFlag="--chain-state-db-guard-size-mb" minRAMValue=1002
"--leave-running", "--clean-run", "--wallet-port" }) Utils.Debug = args.v totalProducerNodes = 2 totalNonProducerNodes = 1 totalNodes = totalProducerNodes + totalNonProducerNodes maxActiveProducers = 3 totalProducers = maxActiveProducers cluster = Cluster(walletd=True) dumpErrorDetails = args.dump_error_details keepLogs = args.keep_logs dontKill = args.leave_running killAll = args.clean_run walletPort = args.wallet_port walletMgr = WalletMgr(True, port=walletPort) testSuccessful = False killBitconchInstances = not dontKill killWallet = not dontKill WalletdName = Utils.BitconchWalletName ClientName = "clbitconch" try: TestHelper.printSystemInfo("BEGIN") cluster.setWalletMgr(walletMgr) cluster.killall(allInstances=killAll) cluster.cleanup() Print("Stand up cluster") specificExtraNodebitconchArgs = {}
def bootstrap(totalNodes, prodCount, biosHost, biosPort, dontKill=False, onlyBios=False): """Create 'prodCount' init accounts and deposits 10000000000 SYS in each. If prodCount is -1 will initialize all possible producers. Ensure nodes are inter-connected prior to this call. One way to validate this will be to check if every node has block 1.""" Utils.Print("Starting cluster bootstrap.") biosNode=Node(biosHost, biosPort) if not biosNode.checkPulse(): Utils.Print("ERROR: Bios node doesn't appear to be running...") return None producerKeys=Cluster.parseClusterKeys(totalNodes) # should have totalNodes node plus bios node if producerKeys is None or len(producerKeys) < (totalNodes+1): Utils.Print("ERROR: Failed to parse private keys from cluster config files.") return None walletMgr=WalletMgr(True) walletMgr.killall() walletMgr.cleanup() if not walletMgr.launch(): Utils.Print("ERROR: Failed to launch bootstrap wallet.") return None biosNode.setWalletEndpointArgs(walletMgr.walletEndpointArgs) try: ignWallet=walletMgr.create("ignition") eosioName="eosio" eosioKeys=producerKeys[eosioName] eosioAccount=Account(eosioName) eosioAccount.ownerPrivateKey=eosioKeys["private"] eosioAccount.ownerPublicKey=eosioKeys["public"] eosioAccount.activePrivateKey=eosioKeys["private"] eosioAccount.activePublicKey=eosioKeys["public"] if not walletMgr.importKey(eosioAccount, ignWallet): Utils.Print("ERROR: Failed to import %s account keys into ignition wallet." % (eosioName)) return None contract="eosio.bios" contractDir="contracts/%s" % (contract) wasmFile="%s.wasm" % (contract) abiFile="%s.abi" % (contract) Utils.Print("Publish %s contract" % (contract)) trans=biosNode.publishContract(eosioAccount.name, contractDir, wasmFile, abiFile, waitForTransBlock=True) if trans is None: Utils.Print("ERROR: Failed to publish contract %s." % (contract)) return None Node.validateTransaction(trans) Utils.Print("Creating accounts: %s " % ", ".join(producerKeys.keys())) producerKeys.pop(eosioName) accounts=[] for name, keys in producerKeys.items(): initx = None initx = Account(name) initx.ownerPrivateKey=keys["private"] initx.ownerPublicKey=keys["public"] initx.activePrivateKey=keys["private"] initx.activePublicKey=keys["public"] trans=biosNode.createAccount(initx, eosioAccount, 0) if trans is None: Utils.Print("ERROR: Failed to create account %s" % (name)) return None Node.validateTransaction(trans) accounts.append(initx) transId=Node.getTransId(trans) if not biosNode.waitForTransInBlock(transId): Utils.Print("ERROR: Failed to validate transaction %s got rolled into a block on server port %d." % (transId, biosNode.port)) return None Utils.Print("Validating system accounts within bootstrap") biosNode.validateAccounts(accounts) if not onlyBios: if prodCount == -1: setProdsFile="setprods.json" if Utils.Debug: Utils.Print("Reading in setprods file %s." % (setProdsFile)) with open(setProdsFile, "r") as f: setProdsStr=f.read() Utils.Print("Setting producers.") opts="--permission eosio@active" myTrans=biosNode.pushMessage("eosio", "setprods", setProdsStr, opts) if myTrans is None or not myTrans[0]: Utils.Print("ERROR: Failed to set producers.") return None else: counts=dict.fromkeys(range(totalNodes), 0) #initialize node prods count to 0 setProdsStr='{"schedule": [' firstTime=True prodNames=[] for name, keys in producerKeys.items(): if counts[keys["node"]] >= prodCount: continue if firstTime: firstTime = False else: setProdsStr += ',' setProdsStr += ' { "producer_name": "%s", "block_signing_key": "%s" }' % (keys["name"], keys["public"]) prodNames.append(keys["name"]) counts[keys["node"]] += 1 setProdsStr += ' ] }' if Utils.Debug: Utils.Print("setprods: %s" % (setProdsStr)) Utils.Print("Setting producers: %s." % (", ".join(prodNames))) opts="--permission eosio@active" # pylint: disable=redefined-variable-type trans=biosNode.pushMessage("eosio", "setprods", setProdsStr, opts) if trans is None or not trans[0]: Utils.Print("ERROR: Failed to set producer %s." % (keys["name"])) return None trans=trans[1] transId=Node.getTransId(trans) if not biosNode.waitForTransInBlock(transId): Utils.Print("ERROR: Failed to validate transaction %s got rolled into a block on server port %d." % (transId, biosNode.port)) return None # wait for block production handover (essentially a block produced by anyone but eosio). lam = lambda: biosNode.getInfo(exitOnError=True)["head_block_producer"] != "eosio" ret=Utils.waitForBool(lam) if not ret: Utils.Print("ERROR: Block production handover failed.") return None eosioTokenAccount=copy.deepcopy(eosioAccount) eosioTokenAccount.name="eosio.token" trans=biosNode.createAccount(eosioTokenAccount, eosioAccount, 0) if trans is None: Utils.Print("ERROR: Failed to create account %s" % (eosioTokenAccount.name)) return None eosioRamAccount=copy.deepcopy(eosioAccount) eosioRamAccount.name="eosio.ram" trans=biosNode.createAccount(eosioRamAccount, eosioAccount, 0) if trans is None: Utils.Print("ERROR: Failed to create account %s" % (eosioRamAccount.name)) return None eosioRamfeeAccount=copy.deepcopy(eosioAccount) eosioRamfeeAccount.name="eosio.ramfee" trans=biosNode.createAccount(eosioRamfeeAccount, eosioAccount, 0) if trans is None: Utils.Print("ERROR: Failed to create account %s" % (eosioRamfeeAccount.name)) return None eosioStakeAccount=copy.deepcopy(eosioAccount) eosioStakeAccount.name="eosio.stake" trans=biosNode.createAccount(eosioStakeAccount, eosioAccount, 0) if trans is None: Utils.Print("ERROR: Failed to create account %s" % (eosioStakeAccount.name)) return None Node.validateTransaction(trans) transId=Node.getTransId(trans) if not biosNode.waitForTransInBlock(transId): Utils.Print("ERROR: Failed to validate transaction %s got rolled into a block on server port %d." % (transId, biosNode.port)) return None contract="eosio.token" contractDir="contracts/%s" % (contract) wasmFile="%s.wasm" % (contract) abiFile="%s.abi" % (contract) Utils.Print("Publish %s contract" % (contract)) trans=biosNode.publishContract(eosioTokenAccount.name, contractDir, wasmFile, abiFile, waitForTransBlock=True) if trans is None: Utils.Print("ERROR: Failed to publish contract %s." % (contract)) return None # Create currency0000, followed by issue currency0000 contract=eosioTokenAccount.name Utils.Print("push create action to %s contract" % (contract)) action="create" data="{\"issuer\":\"%s\",\"maximum_supply\":\"1000000000.0000 %s\",\"can_freeze\":\"0\",\"can_recall\":\"0\",\"can_whitelist\":\"0\"}" % (eosioTokenAccount.name, CORE_SYMBOL) opts="--permission %s@active" % (contract) trans=biosNode.pushMessage(contract, action, data, opts) if trans is None or not trans[0]: Utils.Print("ERROR: Failed to push create action to eosio contract.") return None Node.validateTransaction(trans[1]) transId=Node.getTransId(trans[1]) if not biosNode.waitForTransInBlock(transId): Utils.Print("ERROR: Failed to validate transaction %s got rolled into a block on server port %d." % (transId, biosNode.port)) return None contract=eosioTokenAccount.name Utils.Print("push issue action to %s contract" % (contract)) action="issue" data="{\"to\":\"%s\",\"quantity\":\"1000000000.0000 %s\",\"memo\":\"initial issue\"}" % (eosioAccount.name, CORE_SYMBOL) opts="--permission %s@active" % (contract) trans=biosNode.pushMessage(contract, action, data, opts) if trans is None or not trans[0]: Utils.Print("ERROR: Failed to push issue action to eosio contract.") return None Node.validateTransaction(trans[1]) Utils.Print("Wait for issue action transaction to become finalized.") transId=Node.getTransId(trans[1]) # biosNode.waitForTransInBlock(transId) # guesstimating block finalization timeout. Two production rounds of 12 blocks per node, plus 60 seconds buffer timeout = .5 * 12 * 2 * len(producerKeys) + 60 if not biosNode.waitForTransFinalization(transId, timeout=timeout): Utils.Print("ERROR: Failed to validate transaction %s got rolled into a finalized block on server port %d." % (transId, biosNode.port)) return None expectedAmount="1000000000.0000 {0}".format(CORE_SYMBOL) Utils.Print("Verify eosio issue, Expected: %s" % (expectedAmount)) actualAmount=biosNode.getAccountEosBalanceStr(eosioAccount.name) if expectedAmount != actualAmount: Utils.Print("ERROR: Issue verification failed. Excepted %s, actual: %s" % (expectedAmount, actualAmount)) return None contract="eosio.system" contractDir="contracts/%s" % (contract) wasmFile="%s.wasm" % (contract) abiFile="%s.abi" % (contract) Utils.Print("Publish %s contract" % (contract)) trans=biosNode.publishContract(eosioAccount.name, contractDir, wasmFile, abiFile, waitForTransBlock=True) if trans is None: Utils.Print("ERROR: Failed to publish contract %s." % (contract)) return None Node.validateTransaction(trans) initialFunds="1000000.0000 {0}".format(CORE_SYMBOL) Utils.Print("Transfer initial fund %s to individual accounts." % (initialFunds)) trans=None contract=eosioTokenAccount.name action="transfer" for name, keys in producerKeys.items(): data="{\"from\":\"%s\",\"to\":\"%s\",\"quantity\":\"%s\",\"memo\":\"%s\"}" % (eosioAccount.name, name, initialFunds, "init transfer") opts="--permission %s@active" % (eosioAccount.name) trans=biosNode.pushMessage(contract, action, data, opts) if trans is None or not trans[0]: Utils.Print("ERROR: Failed to transfer funds from %s to %s." % (eosioTokenAccount.name, name)) return None Node.validateTransaction(trans[1]) Utils.Print("Wait for last transfer transaction to become finalized.") transId=Node.getTransId(trans[1]) if not biosNode.waitForTransInBlock(transId): Utils.Print("ERROR: Failed to validate transaction %s got rolled into a block on server port %d." % (transId, biosNode.port)) return None Utils.Print("Cluster bootstrap done.") finally: if not dontKill: walletMgr.killall() walletMgr.cleanup() return biosNode
# Parse command line arguments args = TestHelper.parse_args({ "-v", "--clean-run", "--dump-error-details", "--leave-running", "--keep-logs", "--alternate-version-labels-file" }) Utils.Debug = args.v killAll = args.clean_run dumpErrorDetails = args.dump_error_details dontKill = args.leave_running killRoxeInstances = not dontKill killWallet = not dontKill keepLogs = args.keep_logs alternateVersionLabelsFile = args.alternate_version_labels_file walletMgr = WalletMgr(True) cluster = Cluster(walletd=True) cluster.setWalletMgr(walletMgr) def restartNode(node: Node, nodeId, chainArg=None, addOrSwapFlags=None, nodroxePath=None): if not node.killed: node.kill(signal.SIGTERM) isRelaunchSuccess = node.relaunch(nodeId, chainArg, addOrSwapFlags=addOrSwapFlags, timeout=5,
class TraceApiPluginTest(unittest.TestCase): sleep_s = 1 cluster=Cluster(walletd=True, defproduceraPrvtKey=None) walletMgr=WalletMgr(True) accounts = [] cluster.setWalletMgr(walletMgr) # kill nodeos and keosd and clean up dir def cleanEnv(self, shouldCleanup: bool) : self.cluster.killall(allInstances=True) if shouldCleanup: self.cluster.cleanup() self.walletMgr.killall(allInstances=True) if shouldCleanup: self.walletMgr.cleanup() # start keosd and nodeos def startEnv(self) : account_names = ["alice", "bob", "charlie"] traceNodeosArgs = " --plugin eosio::trace_api_plugin --trace-no-abis --trace-dir=." self.cluster.launch(totalNodes=1, extraNodeosArgs=traceNodeosArgs) self.walletMgr.launch() testWalletName="testwallet" testWallet=self.walletMgr.create(testWalletName, [self.cluster.eosioAccount, self.cluster.defproduceraAccount]) self.cluster.validateAccounts(None) self.accounts=Cluster.createAccountKeys(len(account_names)) node = self.cluster.getNode(0) for idx in range(len(account_names)): self.accounts[idx].name = account_names[idx] self.walletMgr.importKey(self.accounts[idx], testWallet) for account in self.accounts: node.createInitializeAccount(account, self.cluster.eosioAccount, buyRAM=1000000, stakedDeposit=5000000, waitForTransBlock=True, exitOnError=True) time.sleep(self.sleep_s) def get_block(self, params: str, node: Node) -> json: base_cmd_str = ("curl http://%s:%s/v1/") % (TestHelper.LOCAL_HOST, node.port) cmd_str = base_cmd_str + "trace_api/get_block -X POST -d " + ("'{\"block_num\":%s}'") % params return Utils.runCmdReturnJson(cmd_str) def test_TraceApi(self) : node = self.cluster.getNode(0) for account in self.accounts: self.assertIsNotNone(node.verifyAccount(account)) expectedAmount = Node.currencyIntToStr(5000000, CORE_SYMBOL) account_balances = [] for account in self.accounts: amount = node.getAccountEosBalanceStr(account.name) self.assertEqual(amount, expectedAmount) account_balances.append(amount) xferAmount = Node.currencyIntToStr(123456, CORE_SYMBOL) trans = node.transferFunds(self.accounts[0], self.accounts[1], xferAmount, "test transfer a->b") transId = Node.getTransId(trans) blockNum = Node.getTransBlockNum(trans) self.assertEqual(node.getAccountEosBalanceStr(self.accounts[0].name), Utils.deduceAmount(expectedAmount, xferAmount)) self.assertEqual(node.getAccountEosBalanceStr(self.accounts[1].name), Utils.addAmount(expectedAmount, xferAmount)) time.sleep(self.sleep_s) # verify trans via node api before calling trace_api RPC blockFromNode = node.getBlock(blockNum) self.assertIn("transactions", blockFromNode) isTrxInBlockFromNode = False for trx in blockFromNode["transactions"]: self.assertIn("trx", trx) self.assertIn("id", trx["trx"]) if (trx["trx"]["id"] == transId) : isTrxInBlockFromNode = True break self.assertTrue(isTrxInBlockFromNode) # verify trans via trace_api by calling get_block RPC blockFromTraceApi = self.get_block(blockNum, node) self.assertIn("transactions", blockFromTraceApi) isTrxInBlockFromTraceApi = False for trx in blockFromTraceApi["transactions"]: self.assertIn("id", trx) if (trx["id"] == transId) : isTrxInBlockFromTraceApi = True break self.assertTrue(isTrxInBlockFromTraceApi) @classmethod def setUpClass(self): self.cleanEnv(self, shouldCleanup=True) self.startEnv(self) @classmethod def tearDownClass(self): self.cleanEnv(self, shouldCleanup=False) # not cleanup to save log in case for further investigation
total_nodes = pnodes killCount = args.kill_count if args.kill_count > 0 else 1 killSignal = args.kill_sig killVestInstances = not args.leave_running dumpErrorDetails = args.dump_error_details keepLogs = args.keep_logs killAll = args.clean_run p2pPlugin = args.p2p_plugin seed = 1 Utils.Debug = debug testSuccessful = False random.seed(seed) # Use a fixed seed for repeatability. cluster = Cluster(walletd=True) walletMgr = WalletMgr(True) try: TestHelper.printSystemInfo("BEGIN") cluster.setChainStrategy(chainSyncStrategyStr) cluster.setWalletMgr(walletMgr) cluster.killall(allInstances=killAll) cluster.cleanup() walletMgr.killall(allInstances=killAll) walletMgr.cleanup() Print( "producing nodes: %d, topology: %s, delay between nodes launch(seconds): %d, chain sync strategy: %s" % (pnodes, topo, delay, chainSyncStrategyStr))
args = TestHelper.parse_args({ "--prod-count", "--dump-error-details", "--keep-logs", "-v", "--leave-running", "--clean-run", "--wallet-port" }) Utils.Debug = args.v totalNodes = 4 cluster = Cluster(walletd=True) dumpErrorDetails = args.dump_error_details keepLogs = args.keep_logs dontKill = args.leave_running prodCount = args.prod_count killAll = args.clean_run walletPort = args.wallet_port walletMgr = WalletMgr(True, port=walletPort) testSuccessful = False killInstances = not dontKill killWallet = not dontKill WalletdName = Utils.WalletName CliName = "vectrum-cli" try: TestHelper.printSystemInfo("BEGIN") cluster.setWalletMgr(walletMgr) cluster.killall(allInstances=killAll) cluster.cleanup() Print("Stand up cluster") if cluster.launch(prodCount=prodCount,
total_nodes = pnodes killCount = args.kill_count if args.kill_count > 0 else 1 killSignal = args.kill_sig killEosInstances = not args.leave_running dumpErrorDetails = args.dump_error_details keepLogs = args.keep_logs killAll = args.clean_run terminate = args.terminate_at_block seed = 1 Utils.Debug = debug testSuccessful = False random.seed(seed) # Use a fixed seed for repeatability. cluster = Cluster(walletd=True) walletMgr = WalletMgr(True) try: TestHelper.printSystemInfo("BEGIN") cluster.setWalletMgr(walletMgr) cluster.setChainStrategy(chainSyncStrategyStr) cluster.setWalletMgr(walletMgr) cluster.killall(allInstances=killAll) cluster.cleanup() walletMgr.killall(allInstances=killAll) walletMgr.cleanup() Print( "producing nodes: %d, topology: %s, delay between nodes launch(seconds): %d, chain sync strategy: %s"
def bootstrap(totalNodes, prodCount, biosHost, biosPort, dontKill=False, onlyBios=False): """Create 'prodCount' init accounts and deposits 10000000000 SYS in each. If prodCount is -1 will initialize all possible producers. Ensure nodes are inter-connected prior to this call. One way to validate this will be to check if every node has block 1.""" Utils.Print("Starting cluster bootstrap.") biosNode=Node(biosHost, biosPort) if not biosNode.checkPulse(): Utils.Print("ERROR: Bios node doesn't appear to be running...") return False producerKeys=Cluster.parseClusterKeys(totalNodes) # should have totalNodes node plus bios node if producerKeys is None or len(producerKeys) < (totalNodes+1): Utils.Print("ERROR: Failed to parse private keys from cluster config files.") return False walletMgr=WalletMgr(True) walletMgr.killall() walletMgr.cleanup() if not walletMgr.launch(): Utils.Print("ERROR: Failed to launch bootstrap wallet.") return False biosNode.setWalletEndpointArgs(walletMgr.walletEndpointArgs) try: ignWallet=walletMgr.create("ignition") if ignWallet is None: Utils.Print("ERROR: Failed to create ignition wallet.") return False eosioName="eosio" eosioKeys=producerKeys[eosioName] eosioAccount=Account(eosioName) eosioAccount.ownerPrivateKey=eosioKeys["private"] eosioAccount.ownerPublicKey=eosioKeys["public"] eosioAccount.activePrivateKey=eosioKeys["private"] eosioAccount.activePublicKey=eosioKeys["public"] if not walletMgr.importKey(eosioAccount, ignWallet): Utils.Print("ERROR: Failed to import %s account keys into ignition wallet." % (eosioName)) return False contract="eosio.bios" contractDir="contracts/%s" % (contract) wastFile="contracts/%s/%s.wast" % (contract, contract) abiFile="contracts/%s/%s.abi" % (contract, contract) Utils.Print("Publish %s contract" % (contract)) trans=biosNode.publishContract(eosioAccount.name, contractDir, wastFile, abiFile, waitForTransBlock=True) if trans is None: Utils.Print("ERROR: Failed to publish contract %s." % (contract)) return False Node.validateTransaction(trans) Utils.Print("Creating accounts: %s " % ", ".join(producerKeys.keys())) producerKeys.pop(eosioName) accounts=[] for name, keys in producerKeys.items(): initx = None initx = Account(name) initx.ownerPrivateKey=keys["private"] initx.ownerPublicKey=keys["public"] initx.activePrivateKey=keys["private"] initx.activePublicKey=keys["public"] trans=biosNode.createAccount(initx, eosioAccount, 0) if trans is None: Utils.Print("ERROR: Failed to create account %s" % (name)) return False Node.validateTransaction(trans) accounts.append(initx) transId=Node.getTransId(trans) if not biosNode.waitForTransInBlock(transId): Utils.Print("ERROR: Failed to validate transaction %s got rolled into a block on server port %d." % (transId, biosNode.port)) return False Utils.Print("Validating system accounts within bootstrap") biosNode.validateAccounts(accounts) if not onlyBios: if prodCount == -1: setProdsFile="setprods.json" if Utils.Debug: Utils.Print("Reading in setprods file %s." % (setProdsFile)) with open(setProdsFile, "r") as f: setProdsStr=f.read() Utils.Print("Setting producers.") opts="--permission eosio@active" myTrans=biosNode.pushMessage("eosio", "setprods", setProdsStr, opts) if myTrans is None or not myTrans[0]: Utils.Print("ERROR: Failed to set producers.") return False else: counts=dict.fromkeys(range(totalNodes), 0) #initialize node prods count to 0 setProdsStr='{"schedule": [' firstTime=True prodNames=[] for name, keys in producerKeys.items(): if counts[keys["node"]] >= prodCount: continue if firstTime: firstTime = False else: setProdsStr += ',' setProdsStr += ' { "producer_name": "%s", "block_signing_key": "%s" }' % (keys["name"], keys["public"]) prodNames.append(keys["name"]) counts[keys["node"]] += 1 setProdsStr += ' ] }' if Utils.Debug: Utils.Print("setprods: %s" % (setProdsStr)) Utils.Print("Setting producers: %s." % (", ".join(prodNames))) opts="--permission eosio@active" # pylint: disable=redefined-variable-type trans=biosNode.pushMessage("eosio", "setprods", setProdsStr, opts) if trans is None or not trans[0]: Utils.Print("ERROR: Failed to set producer %s." % (keys["name"])) return False trans=trans[1] transId=Node.getTransId(trans) if not biosNode.waitForTransInBlock(transId): Utils.Print("ERROR: Failed to validate transaction %s got rolled into a block on server port %d." % (transId, biosNode.port)) return False # wait for block production handover (essentially a block produced by anyone but eosio). lam = lambda: biosNode.getInfo()["head_block_producer"] != "eosio" ret=Utils.waitForBool(lam) if not ret: Utils.Print("ERROR: Block production handover failed.") return False eosioTokenAccount=copy.deepcopy(eosioAccount) eosioTokenAccount.name="eosio.token" trans=biosNode.createAccount(eosioTokenAccount, eosioAccount, 0) if trans is None: Utils.Print("ERROR: Failed to create account %s" % (eosioTokenAccount.name)) return False eosioRamAccount=copy.deepcopy(eosioAccount) eosioRamAccount.name="eosio.ram" trans=biosNode.createAccount(eosioRamAccount, eosioAccount, 0) if trans is None: Utils.Print("ERROR: Failed to create account %s" % (eosioRamAccount.name)) return False eosioRamfeeAccount=copy.deepcopy(eosioAccount) eosioRamfeeAccount.name="eosio.ramfee" trans=biosNode.createAccount(eosioRamfeeAccount, eosioAccount, 0) if trans is None: Utils.Print("ERROR: Failed to create account %s" % (eosioRamfeeAccount.name)) return False eosioStakeAccount=copy.deepcopy(eosioAccount) eosioStakeAccount.name="eosio.stake" trans=biosNode.createAccount(eosioStakeAccount, eosioAccount, 0) if trans is None: Utils.Print("ERROR: Failed to create account %s" % (eosioStakeAccount.name)) return False Node.validateTransaction(trans) transId=Node.getTransId(trans) if not biosNode.waitForTransInBlock(transId): Utils.Print("ERROR: Failed to validate transaction %s got rolled into a block on server port %d." % (transId, biosNode.port)) return False contract="eosio.token" contractDir="contracts/%s" % (contract) wastFile="contracts/%s/%s.wast" % (contract, contract) abiFile="contracts/%s/%s.abi" % (contract, contract) Utils.Print("Publish %s contract" % (contract)) trans=biosNode.publishContract(eosioTokenAccount.name, contractDir, wastFile, abiFile, waitForTransBlock=True) if trans is None: Utils.Print("ERROR: Failed to publish contract %s." % (contract)) return False # Create currency0000, followed by issue currency0000 contract=eosioTokenAccount.name Utils.Print("push create action to %s contract" % (contract)) action="create" data="{\"issuer\":\"%s\",\"maximum_supply\":\"1000000000.0000 %s\",\"can_freeze\":\"0\",\"can_recall\":\"0\",\"can_whitelist\":\"0\"}" % (eosioTokenAccount.name, CORE_SYMBOL) opts="--permission %s@active" % (contract) trans=biosNode.pushMessage(contract, action, data, opts) if trans is None or not trans[0]: Utils.Print("ERROR: Failed to push create action to eosio contract.") return False Node.validateTransaction(trans[1]) transId=Node.getTransId(trans[1]) if not biosNode.waitForTransInBlock(transId): Utils.Print("ERROR: Failed to validate transaction %s got rolled into a block on server port %d." % (transId, biosNode.port)) return False contract=eosioTokenAccount.name Utils.Print("push issue action to %s contract" % (contract)) action="issue" data="{\"to\":\"%s\",\"quantity\":\"1000000000.0000 %s\",\"memo\":\"initial issue\"}" % (eosioAccount.name, CORE_SYMBOL) opts="--permission %s@active" % (contract) trans=biosNode.pushMessage(contract, action, data, opts) if trans is None or not trans[0]: Utils.Print("ERROR: Failed to push issue action to eosio contract.") return False Node.validateTransaction(trans[1]) Utils.Print("Wait for issue action transaction to become finalized.") transId=Node.getTransId(trans[1]) # biosNode.waitForTransInBlock(transId) # guesstimating block finalization timeout. Two production rounds of 12 blocks per node, plus 60 seconds buffer timeout = .5 * 12 * 2 * len(producerKeys) + 60 if not biosNode.waitForTransFinalization(transId, timeout=timeout): Utils.Print("ERROR: Failed to validate transaction %s got rolled into a finalized block on server port %d." % (transId, biosNode.port)) return False expectedAmount="1000000000.0000 {0}".format(CORE_SYMBOL) Utils.Print("Verify eosio issue, Expected: %s" % (expectedAmount)) actualAmount=biosNode.getAccountEosBalanceStr(eosioAccount.name) if expectedAmount != actualAmount: Utils.Print("ERROR: Issue verification failed. Excepted %s, actual: %s" % (expectedAmount, actualAmount)) return False contract="eosio.system" contractDir="contracts/%s" % (contract) wastFile="contracts/%s/%s.wast" % (contract, contract) abiFile="contracts/%s/%s.abi" % (contract, contract) Utils.Print("Publish %s contract" % (contract)) trans=biosNode.publishContract(eosioAccount.name, contractDir, wastFile, abiFile, waitForTransBlock=True) if trans is None: Utils.Print("ERROR: Failed to publish contract %s." % (contract)) return False Node.validateTransaction(trans) initialFunds="1000000.0000 {0}".format(CORE_SYMBOL) Utils.Print("Transfer initial fund %s to individual accounts." % (initialFunds)) trans=None contract=eosioTokenAccount.name action="transfer" for name, keys in producerKeys.items(): data="{\"from\":\"%s\",\"to\":\"%s\",\"quantity\":\"%s\",\"memo\":\"%s\"}" % (eosioAccount.name, name, initialFunds, "init transfer") opts="--permission %s@active" % (eosioAccount.name) trans=biosNode.pushMessage(contract, action, data, opts) if trans is None or not trans[0]: Utils.Print("ERROR: Failed to transfer funds from %s to %s." % (eosioTokenAccount.name, name)) return False Node.validateTransaction(trans[1]) Utils.Print("Wait for last transfer transaction to become finalized.") transId=Node.getTransId(trans[1]) if not biosNode.waitForTransInBlock(transId): Utils.Print("ERROR: Failed to validate transaction %s got rolled into a block on server port %d." % (transId, biosNode.port)) return False Utils.Print("Cluster bootstrap done.") finally: if not dontKill: walletMgr.killall() walletMgr.cleanup() return True
transBlocksBehind = args.transaction_time_delta * blocksPerSec numTransactions = args.num_transactions maxTransactionsPerSecond = args.max_transactions_per_second assert args.total_accounts >= minTotalAccounts, Print( "ERROR: Only %d was selected for --total-accounts, must have at least %d" % (args.total_accounts, minTotalAccounts)) if numTransactions % args.total_accounts > 0: oldNumTransactions = numTransactions numTransactions = int((oldNumTransactions + args.total_accounts - 1) / args.total_accounts) * args.total_accounts Print( "NOTE: --num-transactions passed as %d, but rounding to %d so each of the %d accounts gets the same number of transactions" % (oldNumTransactions, numTransactions, args.total_accounts)) numRounds = int(numTransactions / args.total_accounts) walletMgr = WalletMgr(True, port=walletPort) testSuccessful = False killEosInstances = not dontKill killWallet = not dontKill WalletdName = Utils.EosWalletName ClientName = "cleos" maxTransactionAttempts = 2 # max number of attempts to try to send a transaction maxTransactionAttemptsNoSend = 1 # max number of attempts to try to create a transaction to be sent as a duplicate try: TestHelper.printSystemInfo("BEGIN") cluster.setWalletMgr(walletMgr) cluster.killall(allInstances=killAll)
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 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) testSuccessful=False killEosInstances=not dontKill killWallet=not dontKill dontBootstrap=sanityTest WalletdName="keosd" ClientName="cleos" timeout = .5 * 12 * 2 + 60 # time for finalization with 1 producer + 60 seconds padding Utils.setIrreversibleTimeout(timeout) try: TestHelper.printSystemInfo("BEGIN") Print("SERVER: %s" % (server)) Print("PORT: %d" % (port))
# kill the producing node. Then we flood hundreds transactions to the bridge node. At the end, we # kill the bridge. It tests that no crashes happen when the nodes are killed. # ############################################################### errorExit = Utils.errorExit args = TestHelper.parse_args({"--wallet-port", "-v"}) cluster = Cluster(walletd=True) killAll = True totalProducerNodes = 1 totalNonProducerNodes = 1 totalNodes = totalProducerNodes + totalNonProducerNodes walletPort = args.wallet_port walletMgr = WalletMgr(True, port=walletPort) producerEndpoint = '127.0.0.1:8888' httpServerAddress = '127.0.0.1:8889' try: TestHelper.printSystemInfo("BEGIN") cluster.setWalletMgr(walletMgr) cluster.killall(allInstances=killAll) cluster.cleanup() specificExtraNodeosArgs = {} specificExtraNodeosArgs[ 0] = "--plugin eosio::producer_plugin --plugin eosio::chain_api_plugin --plugin eosio::http_plugin " "--plugin eosio::txn_test_gen_plugin --plugin eosio::producer_api_plugin " # producer nodes will be mapped to 0 through totalProducerNodes-1, so the number totalProducerNodes will be the non-producing node specificExtraNodeosArgs[
args = TestHelper.parse_args({ "--defproducera_prvt_key", "--dump-error-details", "--dont-launch", "--keep-logs", "-v", "--leave-running", "--clean-run" }) debug = args.v defproduceraPrvtKey = args.defproducera_prvt_key dumpErrorDetails = args.dump_error_details keepLogs = args.keep_logs dontLaunch = args.dont_launch dontKill = args.leave_running killAll = args.clean_run Utils.Debug = debug cluster = Cluster(walletd=True, defproduceraPrvtKey=defproduceraPrvtKey) walletMgr = WalletMgr(True) testSuccessful = False killEosInstances = not dontKill killWallet = not dontKill 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) if not dontLaunch:
dumpErrorDetails=args.dump_error_details killAll=args.clean_run keepLogs=args.keep_logs p2pPlugin=args.p2p_plugin killWallet=not dontKill killEosInstances=not dontKill if nodesFile is not None: killEosInstances=False Utils.Debug=debug testSuccessful=False random.seed(seed) # Use a fixed seed for repeatability. cluster=Cluster(walletd=True) walletMgr=WalletMgr(True) try: cluster.setWalletMgr(walletMgr) if dontLaunch: # run test against remote cluster jsonStr=None with open(nodesFile, "r") as f: jsonStr=f.read() if not cluster.initializeNodesFromJson(jsonStr): errorExit("Failed to initilize nodes from Json string.") total_nodes=len(cluster.getNodes()) walletMgr.killall(allInstances=killAll) walletMgr.cleanup() print("Stand up walletd")
seed = args.seed dontKill = args.leave_running dumpErrorDetails = args.dump_error_details killAll = args.clean_run killWallet = not dontKill killBesInstances = not dontKill if nodesFile is not None: killBesInstances = False Utils.Debug = debug testSuccessful = False random.seed(seed) # Use a fixed seed for repeatability. cluster = Cluster(walletd=True) walletMgr = WalletMgr(True) try: cluster.setWalletMgr(walletMgr) if nodesFile is not None: jsonStr = None with open(nodesFile, "r") as f: jsonStr = f.read() if not cluster.initializeNodesFromJson(jsonStr): errorExit("Failed to initilize nodes from Json string.") total_nodes = len(cluster.getNodes()) else: cluster.killall(allInstances=killAll) cluster.cleanup() walletMgr.killall(allInstances=killAll)
seed=args.seed dontKill=args.leave_running dumpErrorDetails=args.dump_error_details killAll=args.clean_run killWallet=not dontKill killEosInstances=not dontKill if nodesFile is not None: killEosInstances=False Utils.Debug=debug testSuccessful=False random.seed(seed) # Use a fixed seed for repeatability. cluster=Cluster(walletd=True) walletMgr=WalletMgr(True) try: cluster.setWalletMgr(walletMgr) if nodesFile is not None: jsonStr=None with open(nodesFile, "r") as f: jsonStr=f.read() if not cluster.initializeNodesFromJson(jsonStr): errorExit("Failed to initilize nodes from Json string.") total_nodes=len(cluster.getNodes()) else: cluster.killall(allInstances=killAll) cluster.cleanup() walletMgr.killall(allInstances=killAll)
dontKill = args.leave_running prodCount = args.prod_count onlyBios = args.only_bios killAll = args.clean_run sanityTest = args.sanity_test walletPort = args.wallet_port Utils.Debug = debug localTest = True if server == TestHelper.LOCAL_HOST else False cluster = Cluster(host=server, port=port, walletd=True, enableMongo=enableMongo, defproduceraPrvtKey=defproduceraPrvtKey, defproducerbPrvtKey=defproducerbPrvtKey) walletMgr = WalletMgr(True, port=walletPort) testSuccessful = False killrsnInstances = 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.rsnWalletName ClientName = "arisecli" 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))
debug = args.v total_nodes = pnodes killCount = args.kill_count if args.kill_count > 0 else 1 killSignal = args.kill_sig killRoxeInstances = not args.leave_running dumpErrorDetails = args.dump_error_details keepLogs = args.keep_logs killAll = args.clean_run seed = 1 Utils.Debug = debug testSuccessful = False random.seed(seed) # Use a fixed seed for repeatability. cluster = Cluster(walletd=True) walletMgr = WalletMgr(True) try: TestHelper.printSystemInfo("BEGIN") cluster.setWalletMgr(walletMgr) cluster.setChainStrategy(chainSyncStrategyStr) cluster.setWalletMgr(walletMgr) cluster.killall(allInstances=killAll) cluster.cleanup() walletMgr.killall(allInstances=killAll) walletMgr.cleanup() Print( "producing nodes: %d, topology: %s, delay between nodes launch(seconds): %d, chain sync strategy: %s"
args = TestHelper.parse_args({ "--prod-count", "--dump-error-details", "--keep-logs", "-v", "--leave-running", "--clean-run", "--p2p-plugin" }) Utils.Debug = args.v totalNodes = 4 cluster = Cluster(walletd=True) dumpErrorDetails = args.dump_error_details keepLogs = args.keep_logs dontKill = args.leave_running prodCount = args.prod_count killAll = args.clean_run p2pPlugin = args.p2p_plugin walletMgr = WalletMgr(True) testSuccessful = False killEnuInstances = not dontKill killWallet = not dontKill WalletdName = "enuwallet" ClientName = "enucli" try: TestHelper.printSystemInfo("BEGIN") cluster.killall(allInstances=killAll) cluster.cleanup() Print("Stand up cluster") if cluster.launch(prodCount=prodCount, onlyBios=False,
Print=Utils.Print errorExit=Utils.errorExit from core_symbol import CORE_SYMBOL args = TestHelper.parse_args({"--prod-count","--dump-error-details","--keep-logs","-v","--leave-running","--clean-run"}) Utils.Debug=args.v totalNodes=4 cluster=Cluster(walletd=True) dumpErrorDetails=args.dump_error_details keepLogs=args.keep_logs dontKill=args.leave_running prodCount=args.prod_count killAll=args.clean_run walletMgr=WalletMgr(True) testSuccessful=False killEosInstances=not dontKill killWallet=not dontKill WalletdName="keosd" ClientName="cleos" try: TestHelper.printSystemInfo("BEGIN") cluster.killall(allInstances=killAll) cluster.cleanup() Print("Stand up cluster") if cluster.launch(prodCount=prodCount, onlyBios=False, dontKill=dontKill, pnodes=totalNodes, totalNodes=totalNodes, totalProducers=totalNodes*21) is False: Utils.cmdError("launcher")