Esempio n. 1
0
    def run(cls, eth_passphrase, eth_auth_token, sol_file):
        """
        Runs the backend
        """
        # Note: except for stream_logger, every other import
        # to a subpackage of qsp_prototol_node must be
        # performed at this point

        from audit import QSPAuditNode
        from config import ConfigFactory
        from utils.stop import Stop

        cfg = ConfigFactory.create_from_dictionary(
            Program.__yaml_config,
            Program.__env,
            account_passwd=eth_passphrase,
            auth_token=eth_auth_token,
        )

        logger.info("Initializing QSP Audit Node")
        logger.debug("account: {0}".format(cfg.account))
        logger.debug("analyzers: {0}".format(cfg.analyzers))
        logger.debug("audit contract address: {0}".format(
            cfg.audit_contract_address))

        logger.debug("min_price_in_qsp: {0}".format(cfg.min_price_in_qsp))
        logger.debug("evt_polling: {0}".format(cfg.evt_polling))
        logger.debug("audit contract address: {0}".format(
            cfg.audit_contract_address))

        # Based on the provided configuration, instantiates a new
        # QSP audit node
        audit_node = QSPAuditNode(cfg)
        Stop.register(audit_node)

        if QSPAuditNode.is_police_officer(cfg):
            logger.info("Running QSP node (performs audits and police checks)")
        else:
            logger.info("Running QSP node (performs audits only)")

        # If a sol file is given, produce the audit report for that file and exit
        if sol_file:
            _, audit_report = audit_node.get_full_report(requestor=cfg.account,
                                                         uri=sol_file,
                                                         request_id=1)
            pprint(audit_report)
        # Runs the QSP audit node in a busy loop fashion
        else:
            try:
                audit_node.start()
            except Exception as error:
                if audit_node is not None:
                    audit_node.stop()
                    raise error
Esempio n. 2
0
    def test_stop_all(self):
        stoppables = [Stoppable(), Stoppable(), Stoppable(), Stoppable()]
        Stop.register(stoppables[0])
        Stop.register(stoppables[1])
        Stop.register(stoppables[2])
        Stop.register(stoppables[3])
        Stop.stop_all()

        self.assertTrue(stoppables[0].is_stopped)
        self.assertTrue(stoppables[1].is_stopped)
        self.assertTrue(stoppables[2].is_stopped)
        self.assertTrue(stoppables[3].is_stopped)
Esempio n. 3
0
 def test_normal(self):
     with patch('sys.exit') as exit_mock:
         stoppables = [Stoppable(), Stoppable(), Stoppable(), Stoppable()]
         Stop.register(stoppables[0])
         Stop.register(stoppables[1])
         Stop.register(stoppables[2])
         Stop.register(stoppables[3])
         Stop.normal()
         exit_mock.assert_called_once_with(0)
         self.assertTrue(stoppables[0].is_stopped)
         self.assertTrue(stoppables[1].is_stopped)
         self.assertTrue(stoppables[2].is_stopped)
         self.assertTrue(stoppables[3].is_stopped)
Esempio n. 4
0
 def test_error(self):
     with patch('sys.exit') as exit_mock:
         stoppables = [Stoppable(), Stoppable(), Stoppable(), Stoppable()]
         Stop.register(stoppables[0])
         Stop.register(stoppables[1])
         Stop.register(stoppables[2])
         Stop.register(stoppables[3])
         error_code = 17
         Stop.error("Some error", error_code)
         self.assertTrue(stoppables[0].is_stopped)
         self.assertTrue(stoppables[1].is_stopped)
         self.assertTrue(stoppables[2].is_stopped)
         self.assertTrue(stoppables[3].is_stopped)
         exit_mock.assert_called_once_with(error_code)
Esempio n. 5
0
 def test_handle_sigkill_signal(self):
     with patch('sys.exit') as exit_mock:
         stoppables = [Stoppable(), Stoppable(), Stoppable(), Stoppable()]
         Stop.register(stoppables[0])
         Stop.register(stoppables[1])
         Stop.register(stoppables[2])
         Stop.register(stoppables[3])
         handle(15, 0)
         self.assertTrue(handle.stopping)
         exit_mock.assert_called_once_with(0)
         self.assertTrue(stoppables[0].is_stopped)
         self.assertTrue(stoppables[1].is_stopped)
         self.assertTrue(stoppables[2].is_stopped)
         self.assertTrue(stoppables[3].is_stopped)
         # this should just return now
         self.assertIsNone(handle(15, 0))
         exit_mock.assert_called_once_with(0)
         handle.stopping = False
Esempio n. 6
0
 def test_sigkill(self):
     with patch('sys.exit') as exit_mock:
         Stop.sigkill()
     exit_mock.assert_called_once_with(0)
Esempio n. 7
0
 def test_deregister(self):
     stoppable = Stoppable()
     Stop.register(stoppable)
     number_of_registered_objects = len(Stop.objects())
     Stop.deregister(stoppable)
     self.assertEqual(len(Stop.objects()), number_of_registered_objects - 1)
Esempio n. 8
0
 def test_register(self):
     number_of_registered_objects = len(Stop.objects())
     Stop.register(Stoppable())
     self.assertEqual(len(Stop.objects()), number_of_registered_objects + 1)