def compare_notify_old_to_current(
     self,
     converted_current_message: NotificationMessage,
     original_current_message: NotificationMessage,
 ):
     self.assertEqual(
         original_current_message.rawbytes(),
         converted_current_message.rawbytes(),
     )
Esempio n. 2
0
 def test_msg_notification(self, log):
     args_list = ["10", str(TransactionFlag.NO_FLAGS.value), str(EntityType.TRANSACTION.value), "100"]
     args = ",".join(args_list)
     notification_msg = NotificationMessage(NotificationCode.QUOTA_FILL_STATUS, args)
     log.assert_not_called()
     self.connection.msg_notify(notification_msg)
     log.assert_called_once()
Esempio n. 3
0
    def test_msg_notification_assigning_short_ids(self):
        # set test connection to be transaction relay connection
        relay_id = str(uuid.uuid4())
        peer_model = OutboundPeerModel(constants.LOCALHOST, 12345, relay_id)
        self.node.peer_transaction_relays = {peer_model}
        self.connection.peer_id = relay_id
        self.connection.peer_model = peer_model

        self.assertEqual(1, len(self.node.peer_transaction_relays))
        self.connection.msg_notify(NotificationMessage(NotificationCode.ASSIGNING_SHORT_IDS))

        relay_peer = next(iter(self.node.peer_transaction_relays))
        self.assertTrue(relay_peer.assigning_short_ids)

        self.connection.msg_notify(NotificationMessage(NotificationCode.NOT_ASSIGNING_SHORT_IDS))
        relay_peer = next(iter(self.node.peer_transaction_relays))
        self.assertFalse(relay_peer.assigning_short_ids)
Esempio n. 4
0
    def test_expiration_notification_message(self):
        notification_code = NotificationCode.ACCOUNT_EXPIRED_NOTIFICATION

        notification_message = self.create_message_successfully(
            NotificationMessage(notification_code), NotificationMessage)

        self.assertEqual(notification_code,
                         notification_message.notification_code())
        self.assertEqual(
            notification_message.formatted_message(),
            "The account associated with this gateway has expired. "
            "Please visit https://portal.bloxroute.com to renew your subscription."
        )
Esempio n. 5
0
    def test_quota_notification_message(self):
        notification_code = NotificationCode.QUOTA_FILL_STATUS
        args_list = ["10", str(EntityType.TRANSACTION.value), "100"]
        raw_message = ",".join(args_list)

        notification_message = self.create_message_successfully(
            NotificationMessage(notification_code, raw_message),
            NotificationMessage)

        self.assertEqual(notification_code,
                         notification_message.notification_code())
        self.assertEqual(raw_message, notification_message.raw_message())
        self.assertEqual(
            notification_message.formatted_message(),
            "10% of daily transaction quota with limit of 100 transactions per day is depleted."
        )
    def msg_notify(self, msg: NotificationMessage) -> None:
        if msg.notification_code() == NotificationCode.QUOTA_FILL_STATUS:
            args_list = msg.raw_message().split(",")
            entity_type = EntityType(int(args_list[1]))
            quota_level = int(args_list[0])
            if entity_type == EntityType.TRANSACTION and self.node.quota_level != quota_level:
                self.node.quota_level = quota_level
                self.node.alarm_queue.register_approx_alarm(
                    2 * constants.MIN_SLEEP_TIMEOUT,
                    constants.MIN_SLEEP_TIMEOUT,
                    status_log.update_alarm_callback,
                    self.node.connection_pool, self.node.opts.use_extensions,
                    self.node.opts.source_version, self.node.opts.external_ip,
                    self.node.opts.continent, self.node.opts.country,
                    self.node.opts.should_update_source_version,
                    self.node.account_id, self.node.quota_level)

        if msg.level() == LogLevel.WARNING or msg.level() == LogLevel.ERROR:
            self.log(msg.level(), log_messages.NOTIFICATION_FROM_RELAY,
                     msg.formatted_message())
        else:
            self.log(msg.level(), "Notification from Relay: {}",
                     msg.formatted_message())
 def notify_message(self) -> NotificationMessage:
     return NotificationMessage(NotificationCode.QUOTA_FILL_STATUS,
                                str(helpers.generate_bytes(100)))
    def msg_notify(self, msg: NotificationMessage) -> None:
        if msg.notification_code() == NotificationCode.QUOTA_FILL_STATUS:
            args_list = msg.raw_message().split(",")
            entity_type = EntityType(int(args_list[1]))
            quota_level = int(args_list[0])
            if entity_type == EntityType.TRANSACTION and self.node.quota_level != quota_level:
                self.node.quota_level = quota_level
                self.node.alarm_queue.register_approx_alarm(
                    2 * constants.MIN_SLEEP_TIMEOUT,
                    constants.MIN_SLEEP_TIMEOUT,
                    status_log.update_alarm_callback,
                    self.node.connection_pool, self.node.opts.use_extensions,
                    self.node.opts.source_version, self.node.opts.external_ip,
                    self.node.opts.continent, self.node.opts.country,
                    self.node.opts.should_update_source_version,
                    self.node.blockchain_peers, self.node.account_id,
                    self.node.quota_level)
        elif (msg.notification_code() == NotificationCode.ASSIGNING_SHORT_IDS
              or msg.notification_code()
              == NotificationCode.NOT_ASSIGNING_SHORT_IDS):
            is_assigning = msg.notification_code(
            ) == NotificationCode.ASSIGNING_SHORT_IDS
            peer_model = self.peer_model
            if peer_model is not None:
                peer_model.assigning_short_ids = is_assigning
            if self.node.opts.split_relays:
                for peer_model in self.node.peer_transaction_relays:
                    if peer_model.ip == self.peer_ip and peer_model.node_id == self.peer_id:
                        peer_model.assigning_short_ids = is_assigning

        if msg.level() == LogLevel.WARNING or msg.level() == LogLevel.ERROR:
            self.log(msg.level(), log_messages.NOTIFICATION_FROM_RELAY,
                     msg.formatted_message())
        else:
            self.log(msg.level(), "Notification from Relay: {}",
                     msg.formatted_message())