def main(): import optparse parser = optparse.OptionParser(usage="%prog [options]") parser.add_option( "--nocleanup", dest="nocleanup", default=False, action="store_true", help="Leave pastelds and test.* datadir on exit or error") parser.add_option( "--srcdir", dest="srcdir", default="../../src", help= "Source directory containing pasteld/pastel-cli (default: %default%)") parser.add_option("--tmpdir", dest="tmpdir", default=tempfile.mkdtemp(prefix="test"), help="Root directory for datadirs") (options, args) = parser.parse_args() os.environ['PATH'] = options.srcdir + ":" + os.environ['PATH'] check_json_precision() success = False try: print("Initializing test directory " + options.tmpdir) if not os.path.isdir(options.tmpdir): os.makedirs(options.tmpdir) initialize_chain(options.tmpdir) run_test(options.tmpdir) success = True except AssertionError as e: print("Assertion failed: " + e.message) except Exception as e: print("Unexpected exception caught during testing: " + str(e)) traceback.print_tb(sys.exc_info()[2]) if not options.nocleanup: print("Cleaning up") wait_bitcoinds() shutil.rmtree(options.tmpdir) if success: print("Tests successful") sys.exit(0) else: print("Failed") sys.exit(1)
def main(): import optparse parser = optparse.OptionParser(usage="%prog [options]") parser.add_option("--nocleanup", dest="nocleanup", default=False, action="store_true", help="Leave bitcoinds and test.* datadir on exit or error") # ZEN_MOD_START parser.add_option("--srcdir", dest="srcdir", default="../../src", help="Source directory containing zend/zen-cli (default: %default%)") # ZEN_MOD_END parser.add_option("--tmpdir", dest="tmpdir", default=tempfile.mkdtemp(prefix="test"), help="Root directory for datadirs") (options, args) = parser.parse_args() os.environ['PATH'] = options.srcdir+":"+os.environ['PATH'] check_json_precision() success = False nodes = [] try: print("Initializing test directory "+options.tmpdir) if not os.path.isdir(options.tmpdir): os.makedirs(options.tmpdir) initialize_chain(options.tmpdir) nodes = start_nodes(1, options.tmpdir, extra_args=[['-experimentalfeatures', '-developerencryptwallet']]) run_test(nodes, options.tmpdir) success = True except AssertionError as e: print("Assertion failed: "+e.message) except JSONRPCException as e: print("JSONRPC error: "+e.error['message']) traceback.print_tb(sys.exc_info()[2]) except Exception as e: print("Unexpected exception caught during testing: "+str(sys.exc_info()[0])) traceback.print_tb(sys.exc_info()[2]) if not options.nocleanup: print("Cleaning up") stop_nodes(nodes) wait_bitcoinds() shutil.rmtree(options.tmpdir) if success: print("Tests successful") sys.exit(0) else: print("Failed") sys.exit(1)
def main(): import optparse parser = optparse.OptionParser(usage="%prog [options]") parser.add_option("--nocleanup", dest="nocleanup", default=False, action="store_true", help="Leave bitcoinds and test.* datadir on exit or error") parser.add_option("--srcdir", dest="srcdir", default="../../src", help="Source directory containing bitcoind/bitcoin-cli (default: %default%)") parser.add_option("--tmpdir", dest="tmpdir", default=tempfile.mkdtemp(prefix="test"), help="Root directory for datadirs") (options, args) = parser.parse_args() os.environ['PATH'] = options.srcdir+":"+os.environ['PATH'] check_json_precision() success = False nodes = [] try: print("Initializing test directory "+options.tmpdir) if not os.path.isdir(options.tmpdir): os.makedirs(options.tmpdir) initialize_chain(options.tmpdir) nodes = start_nodes(1, options.tmpdir, extra_args=[['-experimentalfeatures', '-developerencryptwallet']]) run_test(nodes, options.tmpdir) success = True except AssertionError as e: print("Assertion failed: "+e.message) except JSONRPCException as e: print("JSONRPC error: "+e.error['message']) traceback.print_tb(sys.exc_info()[2]) except Exception as e: print("Unexpected exception caught during testing: "+str(sys.exc_info()[0])) traceback.print_tb(sys.exc_info()[2]) if not options.nocleanup: print("Cleaning up") stop_nodes(nodes) wait_bitcoinds() shutil.rmtree(options.tmpdir) if success: print("Tests successful") sys.exit(0) else: print("Failed") sys.exit(1)
def setup_test(self, srcdir): self.options = argparse.Namespace self.options.nocleanup=False self.options.noshutdown=False self.options.srcdir = srcdir self.options.cachedir = os.path.normpath(os.path.dirname(os.path.realpath(__file__)) + ".cache") self.options.loglevel = "INFO" self.options.trace_rpc = False self.options.coveragedir = None self.options.pdbonfailure = False PortSeed.n = os.getpid() os.environ['PATH'] = srcdir + ":" + os.environ['PATH'] check_json_precision() # Set up temp directory and start logging self.options.tmpdir = tempfile.mkdtemp(prefix="test") self._start_logging() self.setup_chain() self.setup_network()
def main(self): assert hasattr(self, "num_nodes") PortSeed.n = self.options.port_seed os.environ['PATH'] = self.options.srcdir + ":" + \ self.options.srcdir + "/qt:" + os.environ['PATH'] check_json_precision() self.options.cachedir = os.path.abspath(self.options.cachedir) # Set up temp directory and start logging self._start_logging() success = TestStatus.FAILED try: if self.options.usecli and not self.supports_cli: raise SkipTest( "--usecli specified but test does not support using CLI") self.setup_chain() self.setup_network() except JSONRPCException as e: self.log.exception("JSONRPC error") except SkipTest as e: self.log.warning("Test Skipped: {}".format(e.message)) success = TestStatus.SKIPPED except AssertionError as e: self.log.exception("Assertion failed") except KeyError as e: self.log.exception("Key error") except Exception as e: self.log.exception("Unexpected exception caught during testing") except KeyboardInterrupt as e: self.log.warning("Exiting after keyboard interrupt")
def main(self): import optparse parser = optparse.OptionParser(usage="%prog [options]") parser.add_option("--nocleanup", dest="nocleanup", default=False, action="store_true", help="Leave bitcoinds and test.* datadir on exit or error") parser.add_option("--noshutdown", dest="noshutdown", default=False, action="store_true", help="Don't stop bitcoinds after the test execution") parser.add_option("--zendir", dest="zendir", default="ZenCore/src", help="Source directory containing zend/zen-cli (default: %default)") parser.add_option("--scjarpath", dest="scjarpath", default="../examples/simpleapp/target/Sidechains-SDK-simpleapp-0.2.0.jar;../examples/simpleapp/target/lib/* com.horizen.examples.SimpleApp", #New option. Main class path won't be needed in future help="Directory containing .jar file for SC (default: %default)") parser.add_option("--tmpdir", dest="tmpdir", default="../examples/simpleapp/target/tmp", help="Root directory for datadirs") parser.add_option("--tracerpc", dest="trace_rpc", default=False, action="store_true", help="Print out all RPC calls as they are made") self.add_options(parser) self.sc_add_options(parser) (self.options, self.args) = parser.parse_args() if self.options.trace_rpc: import logging logging.basicConfig(level=logging.DEBUG) os.environ['PATH'] = self.options.zendir+":"+os.environ['PATH'] check_json_precision() success = False try: if not os.path.isdir(self.options.tmpdir): os.makedirs(self.options.tmpdir) print("Initializing test directory "+self.options.tmpdir) self.setup_chain() self.setup_network() self.sc_setup_chain() self.sc_setup_network() self.run_test() success = True except JSONRPCException as e: print("JSONRPC error: "+e.error['message']) traceback.print_tb(sys.exc_info()[2]) except SCAPIException as e: #New exception for SC API print("SCAPI error: "+e.error) traceback.print_tb(sys.exc_info()[2]) except TimeoutException as e: print("Timeout while: " + e.operation) #Timeout for SC Operations traceback.print_tb(sys.exc_info()[2]) except AssertionError as e: print("Assertion failed: "+e.message) traceback.print_tb(sys.exc_info()[2]) except Exception as e: print("Unexpected exception caught during testing: "+str(e)) traceback.print_tb(sys.exc_info()[2]) if not self.options.noshutdown: #Support for tests with MC only, SC only, MC/SC if hasattr(self,"sc_nodes"): print("Stopping SC nodes") stop_sc_nodes(self.sc_nodes) if hasattr(self, "nodes"): print("Stopping MC nodes") stop_nodes(self.nodes) wait_bitcoinds() else: print("Note: client processes were not stopped and may still be running") if not self.options.nocleanup and not self.options.noshutdown: print("Cleaning up") shutil.rmtree(self.options.tmpdir) if success: print("Test successful") sys.exit(0) else: print("Failed") sys.exit(1)
def main(): import optparse parser = optparse.OptionParser(usage="%prog [options]") parser.add_option( "--nocleanup", dest="nocleanup", default=False, action="store_true", help="Leave litecoinzds and test.* datadir on exit or error") parser.add_option( "--srcdir", dest="srcdir", default="../../src", help= "Source directory containing litecoinzd/litecoinz-cli (default: %default%)" ) parser.add_option("--tmpdir", dest="tmpdir", default=tempfile.mkdtemp(prefix="test"), help="Root directory for datadirs") (options, args) = parser.parse_args() os.environ['PATH'] = options.srcdir + ":" + os.environ['PATH'] check_json_precision() success = False nodes = [] try: print("Initializing test directory " + options.tmpdir) if not os.path.isdir(options.tmpdir): os.makedirs(options.tmpdir) initialize_chain(options.tmpdir) nodes = start_nodes( 1, options.tmpdir, extra_args=[['-experimentalfeatures', '-developerencryptwallet']]) run_test(nodes, options.tmpdir) success = True except AssertionError as e: print("Assertion failed: " + e.message) except JSONRPCException as e: print("JSONRPC error: " + e.error['message']) traceback.print_tb(sys.exc_info()[2]) except Exception as e: print("Unexpected exception caught during testing: " + str(sys.exc_info()[0])) traceback.print_tb(sys.exc_info()[2]) if not options.nocleanup: print("Cleaning up") stop_nodes(nodes) wait_litecoinzds() shutil.rmtree(options.tmpdir) if success: print("Tests successful") sys.exit(0) else: print("Failed") sys.exit(1) # refill keypool with three new addresses nodes[0].walletpassphrase('test', 12000) nodes[0].keypoolrefill(3) nodes[0].walletlock() # drain them by mining nodes[0].generate(1) nodes[0].generate(1) nodes[0].generate(1) nodes[0].generate(1) try: nodes[0].generate(1) raise AssertionError( 'Keypool should be exhausted after three addresses') except JSONRPCException, e: assert (e.error['code'] == -12)