def test_delivered_processed_message_cleanup(): recipient = factories.make_address() channel_identifier = 1 secret = factories.random_secret() first_message = events.SendSecretReveal(recipient, channel_identifier, random.randint(0, 2**16), secret) second_message = events.SendSecretReveal(recipient, channel_identifier, random.randint(0, 2**16), secret) message_queue = [first_message, second_message] fake_message_identifier = random.randint(0, 2**16) node.inplace_delete_message( message_queue, state_change.ReceiveDelivered(recipient, fake_message_identifier)) assert first_message in message_queue, "invalid message id must be ignored" assert second_message in message_queue, "invalid message id must be ignored" invalid_sender_address = factories.make_address() node.inplace_delete_message( message_queue, state_change.ReceiveDelivered(invalid_sender_address, first_message.message_identifier), ) assert first_message in message_queue, "invalid sender id must be ignored" assert second_message in message_queue, "invalid sender id must be ignored" node.inplace_delete_message( message_queue, state_change.ReceiveProcessed(recipient, first_message.message_identifier)) msg = "message must be cleared when a valid delivered is received" assert first_message not in message_queue, msg assert second_message in message_queue, msg
def test_delivered_processed_message_cleanup(): recipient = factories.make_address() channel_identifier = 1 secret = factories.random_secret() first_message = events.SendSecretReveal( recipient, channel_identifier, random.randint(0, 2 ** 16), secret, ) second_message = events.SendSecretReveal( recipient, channel_identifier, random.randint(0, 2 ** 16), secret, ) message_queue = [first_message, second_message] fake_message_identifier = random.randint(0, 2 ** 16) node.inplace_delete_message( message_queue, state_change.ReceiveDelivered(recipient, fake_message_identifier), ) assert first_message in message_queue, 'invalid message id must be ignored' assert second_message in message_queue, 'invalid message id must be ignored' invalid_sender_address = factories.make_address() node.inplace_delete_message( message_queue, state_change.ReceiveDelivered(invalid_sender_address, first_message.message_identifier), ) assert first_message in message_queue, 'invalid sender id must be ignored' assert second_message in message_queue, 'invalid sender id must be ignored' node.inplace_delete_message( message_queue, state_change.ReceiveProcessed(recipient, first_message.message_identifier), ) msg = 'message must be cleared when a valid delivered is received' assert first_message not in message_queue, msg assert second_message in message_queue, msg