Пример #1
0
 def test_supported_messages(self, messages):
     data = protocol_options.encode_supported_messages(messages, ...)
     self.assertIsInstance(data, bytes)
     result, _ = protocol_options.decode_supported_messages(
         memoryview(data), 0, ...)
     self.assertIsInstance(result, set)
     self.assertEqual(messages, result)
Пример #2
0
 def test_supported_messages(self, messages):
     data = protocol_options.encode_supported_messages(messages, ...)
     self.assertIsInstance(data, bytes)
     result, _ = protocol_options.decode_supported_messages(
         memoryview(data), 0, ...)
     self.assertIsInstance(result, set)
     self.assertEqual(messages, result)
Пример #3
0
    def test_supported_messages_spec(self):
        # 7.10.  Supported Messages
        # An example of the first 16 bits of the compressed bitmap for a peer
        # supporting every message except ACKs and PEXs is 11011001 11110000.
        #
        data = b'\x02\xd9\xf0'
        offset = 0
        supported_messages, _ = protocol_options.decode_supported_messages(
            memoryview(data), offset, ...)
        self.assertIsInstance(supported_messages, set)
        not_supported = [MessageType.ACK, MessageType.PEX_REQ,
                         MessageType.PEX_REScert, MessageType.PEX_RESv4,
                         MessageType.PEX_RESv6]
        for msgtype in MessageType:
            if msgtype in not_supported:
                self.assertNotIn(msgtype, supported_messages)
            else:
                self.assertIn(msgtype, supported_messages)

        result = protocol_options.encode_supported_messages(
            supported_messages, ...)
        self.assertEqual(data, result)
Пример #4
0
    def test_supported_messages_spec(self):
        # 7.10.  Supported Messages
        # An example of the first 16 bits of the compressed bitmap for a peer
        # supporting every message except ACKs and PEXs is 11011001 11110000.
        #
        data = b'\x02\xd9\xf0'
        offset = 0
        supported_messages, _ = protocol_options.decode_supported_messages(
            memoryview(data), offset, ...)
        self.assertIsInstance(supported_messages, set)
        not_supported = [
            MessageType.ACK, MessageType.PEX_REQ, MessageType.PEX_REScert,
            MessageType.PEX_RESv4, MessageType.PEX_RESv6
        ]
        for msgtype in MessageType:
            if msgtype in not_supported:
                self.assertNotIn(msgtype, supported_messages)
            else:
                self.assertIn(msgtype, supported_messages)

        result = protocol_options.encode_supported_messages(
            supported_messages, ...)
        self.assertEqual(data, result)