def extend_genesis_util(self, overrides):
     print
     vnm = None
     try:
         vnm = get_default_vnm(2, overrides=overrides)
         # Test genesis util
         cfg = vnm.get_configuration(0)
         ledger_type = cfg['LedgerType']
         gblock_file = genesis_info_file_name(cfg['DataDirectory'])
         self.assertFalse(os.path.exists(gblock_file))
         vnm.do_genesis()
         self.assertTrue(os.path.exists(gblock_file))
         genesis_dat = None
         with open(gblock_file, 'r') as f:
             genesis_dat = json.load(f)
         self.assertTrue('GenesisId' in genesis_dat.keys())
         head = genesis_dat['GenesisId']
         # Verify genesis tool efficacy on a minimal network
         vnm.launch()
         # ...verify validator is extending tgt_block
         to = TimeOut(64)
         blk_lists = None
         prog_str = 'testing root extension (expect root: %s)' % head
         with Progress(prog_str) as p:
             print
             while not to.is_timed_out() and blk_lists is None:
                 try:
                     blk_lists = get_blocklists(['http://localhost:8800'])
                     print 'block_lists: %s' % blk_lists
                     if len(blk_lists) < 1 or len(blk_lists[0]) < 2:
                         blk_lists = None
                 except MessageException as e:
                     pass
                 time.sleep(2)
                 p.step()
         self.assertIsNotNone(blk_lists)
         root = blk_lists[0][0]
         self.assertEqual(head, root)
         # ...verify general convergence
         to = TimeOut(32)
         with Progress('testing root convergence') as p:
             print
             while (is_convergent(vnm.urls(), tolerance=1, standard=1) is
                    False and not to.is_timed_out()):
                 time.sleep(2)
                 p.step()
         # ...verify convergence on the genesis block
         blk_lists = get_blocklists(['http://localhost:8800'])
         root = blk_lists[0][0]
         self.assertEqual(head, root)
         print 'network converged on root: %s' % root
     finally:
         if vnm is not None:
             archive_name = 'Test%sGenesisResults' % ledger_type.upper()
             vnm.shutdown(archive_name=archive_name)
Exemplo n.º 2
0
 def extend_genesis_util(self, ledger_type, pre_overrides, post_overrides):
     print
     top = None
     try:
         # Get configs and resources for a ValidatorManager compliant nodes
         top = get_default_sim_controller(2, ledger_type=ledger_type)
         # Set up validator-0
         cfg = top.get_configuration(0)
         cfg.update(pre_overrides)
         top.set_configuration(0, cfg)
         config_file = top.write_configuration(0)
         # Test genesis tool
         print 'testing genesis util...'
         gblock_file = genesis_info_file_name(cfg['DataDirectory'])
         self.assertFalse(os.path.exists(gblock_file))
         cli_args = 'admin %s-genesis --config %s' % (ledger_type,
                                                      config_file)
         sawtooth_cli_intercept(cli_args)
         # Get genesis block id
         self.assertTrue(os.path.exists(gblock_file))
         genesis_dat = None
         with open(gblock_file, 'r') as f:
             genesis_dat = json.load(f)
         self.assertTrue('GenesisId' in genesis_dat.keys())
         head = genesis_dat['GenesisId']
         # Verify genesis tool efficacy on a minimal network
         print 'testing efficacy...'
         # ...apply validator-related overrides to validator-0
         cfg = top.get_configuration(0)
         cfg.update(post_overrides)
         top.set_configuration(0, cfg)
         # ...launch entire network
         top.launch(probe_seconds=0, reg_seconds=0)
         # ...verify validator is extending tgt_block
         to = TimeOut(64)
         blk_lists = None
         prog_str = 'testing root extension (expect root: %s)' % head
         with Progress(prog_str) as p:
             print
             while not to.is_timed_out() and blk_lists is None:
                 try:
                     blk_lists = get_blocklists(['http://localhost:8800'])
                     print 'block_lists: %s' % blk_lists
                     if len(blk_lists) < 1 or len(blk_lists[0]) < 2:
                         blk_lists = None
                 except MessageException as e:
                     pass
                 time.sleep(2)
                 p.step()
         self.assertIsNotNone(blk_lists)
         root = blk_lists[0][0]
         self.assertEqual(head, root)
         # ...verify general convergence
         to = TimeOut(32)
         with Progress('testing root convergence') as p:
             print
             while (is_convergent(top.urls(), tolerance=1, standard=1) is
                    False and not to.is_timed_out()):
                 time.sleep(2)
                 p.step()
         # ...verify convergence on the genesis block
         blk_lists = get_blocklists(['http://localhost:8800'])
         root = blk_lists[0][0]
         self.assertEqual(head, root)
         print 'network converged on root: %s' % root
     finally:
         if top is not None:
             archive_name = 'Test%sGenesisResults' % ledger_type.upper()
             top.shutdown(archive_name=archive_name)
Exemplo n.º 3
0
    def extend_genesis_util(self, overrides):
        print()
        vnm = None
        try:
            self._node_ctrl = None
            print('creating', str(self.__class__.__name__))
            # set up our nodes (suite-internal interface)
            self._node_ctrl = WrappedNodeController(SubprocessNodeController())
            cfg = overrides
            temp_dir = self._node_ctrl.get_data_dir()
            file_name = os.path.join(temp_dir, "config.js")
            with open(file_name, 'w') as config:
                config.write(json.dumps(cfg))
            data_dir = os.path.join(temp_dir, "data")
            gblock_file = genesis_info_file_name(data_dir)

            self._nodes = [
                NodeArguments('v%s' % i, 8800 + i, 9000 + i,
                              config_files=[file_name],
                              ledger_type=overrides["LedgerType"])
                for i in range(2)]
            # set up our urls (external interface)
            self.urls = [
                'http://localhost:%s' % x.http_port for x in self._nodes]
            # Make genesis block
            print('creating genesis block...')
            self.assertFalse(os.path.exists(gblock_file))
            self._nodes[0].genesis = True
            self._node_ctrl.create_genesis_block(self._nodes[0])

            # Test genesis util
            self.assertTrue(os.path.exists(gblock_file))
            genesis_dat = None
            with open(gblock_file, 'r') as f:
                genesis_dat = json.load(f)
            self.assertTrue('GenesisId' in genesis_dat.keys())
            head = genesis_dat['GenesisId']
            # Verify genesis tool efficacy on a minimal network
            # Launch network (node zero will trigger bootstrapping)
            print('launching network...')
            for x in self._nodes:
                self._node_ctrl.start(x)

            # ...verify validator is extending tgt_block
            to = TimeOut(64)
            blk_lists = None
            prog_str = 'testing root extension (expect root: %s)' % head
            with Progress(prog_str) as p:
                print()
                while not to.is_timed_out() and blk_lists is None:
                    try:
                        blk_lists = get_blocklists(['http://localhost:8800'])
                        print('block_lists: %s' % blk_lists)
                        if len(blk_lists) < 1 or len(blk_lists[0]) < 2:
                            blk_lists = None
                    except MessageException as e:
                        pass
                    time.sleep(2)
                    p.step()
            self.assertIsNotNone(blk_lists)
            root = blk_lists[0][0]
            self.assertEqual(head, root)
            # ...verify general convergence
            to = TimeOut(32)
            with Progress('testing root convergence') as p:
                print()
                while (is_convergent(self.urls, tolerance=1, standard=1)
                       is False and not to.is_timed_out()):
                    time.sleep(2)
                    p.step()
            # ...verify convergence on the genesis block
            blk_lists = get_blocklists(['http://localhost:8800'])
            root = blk_lists[0][0]
            self.assertEqual(head, root)
            print('network converged on root: %s' % root)
        finally:
            print('destroying', str(self.__class__.__name__))
            if hasattr(self, '_node_ctrl') and self._node_ctrl is not None:
                # Shut down the network
                with Progress("terminating network") as p:
                    for node_name in self._node_ctrl.get_node_names():
                        self._node_ctrl.stop(node_name)
                    to = TimeOut(16)
                    while len(self._node_ctrl.get_node_names()) > 0:
                        if to.is_timed_out():
                            break
                        time.sleep(1)
                        p.step()
                # force kill anything left over
                for node_name in self._node_ctrl.get_node_names():
                    try:
                        print("%s still 'up'; sending kill..." % node_name)
                        self._node_ctrl.kill(node_name)
                    except Exception as e:
                        print(e.message)
                self._node_ctrl.archive(self.__class__.__name__)
                self._node_ctrl.clean()
 def extend_genesis_util(self, ledger_type, pre_overrides, post_overrides):
     print
     top = None
     try:
         # Get configs and resources for a ValidatorManager compliant nodes
         top = get_default_sim_controller(2, ledger_type=ledger_type)
         # Set up validator-0
         cfg = top.get_configuration(0)
         cfg.update(pre_overrides)
         top.set_configuration(0, cfg)
         config_file = top.write_configuration(0)
         # Test genesis tool
         print 'testing genesis util...'
         gblock_file = genesis_info_file_name(cfg['DataDirectory'])
         self.assertFalse(os.path.exists(gblock_file))
         cli_args = 'admin %s-genesis --config %s' % (ledger_type,
                                                      config_file)
         sawtooth_cli_intercept(cli_args)
         # Get genesis block id
         self.assertTrue(os.path.exists(gblock_file))
         genesis_dat = None
         with open(gblock_file, 'r') as f:
             genesis_dat = json.load(f)
         self.assertTrue('GenesisId' in genesis_dat.keys())
         head = genesis_dat['GenesisId']
         # Verify genesis tool efficacy on a minimal network
         print 'testing efficacy...'
         # ...apply validator-related overrides to validator-0
         cfg = top.get_configuration(0)
         cfg.update(post_overrides)
         top.set_configuration(0, cfg)
         # ...launch entire network
         top.launch(probe_seconds=0, reg_seconds=0)
         # ...verify validator is extending tgt_block
         to = TimeOut(64)
         blk_lists = None
         prog_str = 'testing root extension (expect root: %s)' % head
         with Progress(prog_str) as p:
             print
             while not to.is_timed_out() and blk_lists is None:
                 try:
                     blk_lists = get_blocklists(['http://localhost:8800'])
                     print 'block_lists: %s' % blk_lists
                     if len(blk_lists) < 1 or len(blk_lists[0]) < 2:
                         blk_lists = None
                 except MessageException as e:
                     pass
                 time.sleep(2)
                 p.step()
         self.assertIsNotNone(blk_lists)
         root = blk_lists[0][0]
         self.assertEqual(head, root)
         # ...verify general convergence
         to = TimeOut(32)
         with Progress('testing root convergence') as p:
             print
             while (is_convergent(top.urls(), tolerance=1, standard=1)
                    is False and not to.is_timed_out()):
                 time.sleep(2)
                 p.step()
         # ...verify convergence on the genesis block
         blk_lists = get_blocklists(['http://localhost:8800'])
         root = blk_lists[0][0]
         self.assertEqual(head, root)
         print 'network converged on root: %s' % root
     finally:
         if top is not None:
             archive_name = 'Test%sGenesisResults' % ledger_type.upper()
             top.shutdown(archive_name=archive_name)
Exemplo n.º 5
0
    def test_genesis_util(self):
        print
        old_home = os.getenv('CURRENCYHOME')
        tmp_home = tempfile.mkdtemp()
        vcc = None
        try:
            # Set up env and config
            v_file = find_txn_validator()
            os.environ['CURRENCYHOME'] = tmp_home
            cfg = get_validator_configuration([], {})
            # ...rewire for ValidatorManager compatibility
            cfg['KeyDirectory'] = tmp_home
            cfg['DataDirectory'] = tmp_home
            cfg['LogDirectory'] = tmp_home

            # En route, test keygen client via main
            key_name = cfg['NodeName']
            key_dir = cfg['KeyDirectory']
            cmd = 'keygen %s --key-dir %s' % (key_name, key_dir)
            entry_point(args=cmd.split(), with_loggers=False)
            base_name = key_dir + os.path.sep + key_name
            self.assertTrue(os.path.exists('%s.wif' % base_name))
            self.assertTrue(os.path.exists('%s.addr' % base_name))
            cfg['KeyFile'] = '%s.wif' % base_name

            # Test admin poet0-genesis tool
            fname = get_genesis_block_id_file_name(cfg['DataDirectory'])
            self.assertFalse(os.path.exists(fname))
            config_file = tmp_home + os.path.sep + 'cfg.json'
            with open(config_file, 'w') as f:
                f.write(json.dumps(cfg, indent=4) + '\n')
            cmd = 'admin poet0-genesis --config %s' % config_file
            entry_point(args=cmd.split(), with_loggers=False)
            self.assertTrue(os.path.exists(fname))
            dat = None
            with open(fname, 'r') as f:
                dat = json.load(f)
            self.assertTrue('GenesisId' in dat.keys())
            tgt_block = dat['GenesisId']

            # Verify genesis tool (also tests blockchain restoration)
            # ...initial connectivity must be zero for the initial validator
            cfg['InitialConnectivity'] = 0
            # ...launch validator
            net_cfg = NetworkConfig.from_config_list([cfg])
            vcc = ValidatorCollectionController(net_cfg,
                                                data_dir=tmp_home,
                                                txnvalidator=v_file)
            vcc.activate(0, probe_seconds=120)
            # ...verify validator is extending tgt_block
            to = TimeOut(64)
            blk_lists = None
            prog_str = 'TEST ROOT RESTORATION (expect %s)' % tgt_block
            with Progress(prog_str) as p:
                print
                while not to.is_timed_out() and blk_lists is None:
                    try:
                        blk_lists = get_blocklists(['http://localhost:8800'])
                        print 'block_lists: %s' % blk_lists
                        if len(blk_lists) < 1 or len(blk_lists[0]) < 2:
                            blk_lists = None
                    except MessageException as e:
                        pass
                    time.sleep(1)
                    p.step()
            self.assertIsNotNone(blk_lists)
            root = blk_lists[0][0]
            self.assertEqual(tgt_block, root)

        finally:
            # Shut down validator
            if vcc is not None:
                vcc.shutdown()
            # Restore environmental vars
            if old_home is None:
                os.unsetenv('CURRENCYHOME')
            else:
                os.environ['CURRENCYHOME'] = old_home
            # Delete temp dir
            if os.path.exists(tmp_home):
                shutil.rmtree(tmp_home)
Exemplo n.º 6
0
    def extend_genesis_util(self, overrides):
        print()
        vnm = None
        try:
            self._node_ctrl = None
            print('creating', str(self.__class__.__name__))
            # set up our nodes (suite-internal interface)
            self._node_ctrl = WrappedNodeController(
                SubprocessLegacyNodeController())
            cfg = overrides
            temp_dir = self._node_ctrl.get_data_dir()
            file_name = os.path.join(temp_dir, "config.js")
            with open(file_name, 'w') as config:
                config.write(json.dumps(cfg))
            data_dir = os.path.join(temp_dir, "data")
            gblock_file = genesis_info_file_name(data_dir)

            self._nodes = [
                NodeArguments('v%s' % i, 8800 + i, 9000 + i,
                              config_files=[file_name],
                              ledger_type=overrides["LedgerType"])
                for i in range(2)]
            # set up our urls (external interface)
            self.urls = [
                'http://localhost:%s' % x.http_port for x in self._nodes]
            # Make genesis block
            print('creating genesis block...')
            self.assertFalse(os.path.exists(gblock_file))
            self._nodes[0].genesis = True
            self._node_ctrl.create_genesis_block(self._nodes[0])

            # Test genesis util
            self.assertTrue(os.path.exists(gblock_file))
            genesis_dat = None
            with open(gblock_file, 'r') as f:
                genesis_dat = json.load(f)
            self.assertTrue('GenesisId' in genesis_dat.keys())
            head = genesis_dat['GenesisId']
            # Verify genesis tool efficacy on a minimal network
            # Launch network (node zero will trigger bootstrapping)
            print('launching network...')
            for x in self._nodes:
                self._node_ctrl.start(x)

            # ...verify validator is extending tgt_block
            to = TimeOut(64)
            blk_lists = None
            prog_str = 'testing root extension (expect root: %s)' % head
            with Progress(prog_str) as p:
                print()
                while not to.is_timed_out() and blk_lists is None:
                    try:
                        blk_lists = get_blocklists(['http://localhost:8800'])
                        print('block_lists: %s' % blk_lists)
                        if len(blk_lists) < 1 or len(blk_lists[0]) < 2:
                            blk_lists = None
                    except MessageException as e:
                        pass
                    time.sleep(2)
                    p.step()
            self.assertIsNotNone(blk_lists)
            root = blk_lists[0][0]
            self.assertEqual(head, root)
            # ...verify general convergence
            to = TimeOut(32)
            with Progress('testing root convergence') as p:
                print()
                while (is_convergent(self.urls, tolerance=1, standard=1)
                       is False and not to.is_timed_out()):
                    time.sleep(2)
                    p.step()
            # ...verify convergence on the genesis block
            blk_lists = get_blocklists(['http://localhost:8800'])
            root = blk_lists[0][0]
            self.assertEqual(head, root)
            print('network converged on root: %s' % root)
        finally:
            print('destroying', str(self.__class__.__name__))
            if hasattr(self, '_node_ctrl') and self._node_ctrl is not None:
                # Shut down the network
                with Progress("terminating network") as p:
                    for node_name in self._node_ctrl.get_node_names():
                        self._node_ctrl.stop(node_name)
                    to = TimeOut(16)
                    while len(self._node_ctrl.get_node_names()) > 0:
                        if to.is_timed_out():
                            break
                        time.sleep(1)
                        p.step()
                # force kill anything left over
                for node_name in self._node_ctrl.get_node_names():
                    try:
                        print("%s still 'up'; sending kill..." % node_name)
                        self._node_ctrl.kill(node_name)
                    except Exception as e:
                        print(e.message)
                self._node_ctrl.archive(self.__class__.__name__)
                self._node_ctrl.clean()