Exemplo n.º 1
0
    def test_add_subscriber(self):
        """Tests that the handler for adding the subscriptions will properly
        add a subscriber.
        """
        block_tree_manager = BlockTreeManager()
        delta_processor = StateDeltaProcessor(
            service=Mock(),
            state_delta_store=Mock(),
            block_store=block_tree_manager.block_store)

        handler = StateDeltaAddSubscriberHandler(delta_processor)

        request = RegisterStateDeltaSubscriberRequest(
            last_known_block_ids=[block_tree_manager.chain_head.identifier],
            address_prefixes=['0123456']).SerializeToString()

        response = handler.handle('test_conn_id', request)
        self.assertEqual(HandlerStatus.PASS, response.status)

        self.assertEqual(['test_conn_id'], delta_processor.subscriber_ids)
Exemplo n.º 2
0
    def test_register_with_unknown_block_ids(self):
        """Tests that the handler will respond with a DROP
        when a subscriber does not supply a known block id in
        last_known_block_ids, but the subscriber is added.  It passed
        validation, but a fork may have occured between validation and now.
        """
        block_tree_manager = BlockTreeManager()

        delta_processor = StateDeltaProcessor(
            service=Mock(),
            state_delta_store=Mock(),
            block_store=block_tree_manager.block_store)

        handler = StateDeltaAddSubscriberHandler(delta_processor)

        request = RegisterStateDeltaSubscriberRequest(
            last_known_block_ids=['a'],
            address_prefixes=['000000']).SerializeToString()

        response = handler.handle('test_conn_id', request)

        self.assertEqual(HandlerStatus.DROP, response.status)

        self.assertEqual(['test_conn_id'], delta_processor.subscriber_ids)