def test_get_private_message(self): with open(TestMessageParsing.message_data_path + 'valid_private.txt', 'r') as data: message = parse_message(data.read()) key_manager = get_test_key_manager() msg_str = message.get_message(key_manager) self.assertIsNone(msg_str)
def test_decrypt_public_message(self): with open(TestMessageParsing.message_data_path + 'valid_public.txt', 'r') as data: message = parse_message(data.read()) key_manager = get_test_key_manager() msg_str = message.decrypt(key_manager.privatekey_main) self.assertIsNone(msg_str)
def test(self): with open(TestMessageParsing.message_data_path + file, 'r') as data: string = data.read() block = parse_message(string) if result: self.assertTrue(block) else: self.assertFalse(block)
def test_get_public_message(self): with open(TestMessageParsing.message_data_path + 'valid_public.txt', 'r') as data: message = parse_message(data.read()) key_manager = get_test_key_manager() msg_str = message.get_message(key_manager) self.assertEqual(" By sovereignty of nature. First he was", msg_str)
def test_parsing_data(self): with open(TestMessageParsing.message_data_path + 'valid_public.txt', 'r') as data: message = parse_message(data.read()) self.assertEqual(message.create_time, 1520174648.2770298) self.assertEqual(message.message, " By sovereignty of nature. First he was") self.assertEqual(message.recipient, None) self.assertIsNotNone(message.signature) with open( TestMessageParsing.message_data_path + "valid_public_sender_key.txt", 'r') as key: self.assertEqual(message.sender, key.read())
def add_message_str(self, msg_str): """ Verifies then adds incoming messages to the message queue. This method takes a string containing a message received by the server from a peer or a user. The message may be illformed, a duplicate, or invalid. It first verifies that this is not the case, then adds the message to the queue of messages to be processed into the blockchain, and returns True. If the message is invalid, this method returns False. This function is called by networking.py. """ message = parse_message(msg_str) # Make sure message string was properly formed if message is None: self.log.debug("Ill-formed message string") return False # Verify that the message is properly signed if not message.verify_signature(): self.log.debug("Invalidly signed message string") return False # Verify that the message is not a duplicate with self.lock: if message in self.message_queue: self.log.debug("Duplicate message rejected (already in message queue)") return False # This only checks if messages are in the current blockchain if self._is_duplicate_message(message): self.log.debug("Duplicate message rejected (already in blockchain)") return False # Add message to message queue self.log.debug("Adding message to message queue!") self.message_queue.append(message) return True
def test_wrong_signature(self): with open( TestMessageParsing.message_data_path + 'public_wrong_signature.txt', 'r') as data: message = parse_message(data.read()) self.assertFalse(message.verify_signature())
def test_private_correct_signature2(self): with open(TestMessageParsing.message_data_path + 'valid_private.txt', 'r') as data: message = parse_message(data.read()) self.assertTrue(message.verify_signature())
def test_to_string(self): with open(TestMessageParsing.message_data_path + 'valid_public.txt', 'r') as data: string = data.read() self.assertEqual(repr(parse_message(string)), string)