From 60fbb6df5ae4ae6791913dea8d70a23cf3360e86 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 30 Oct 2021 22:18:28 +0000 Subject: [PATCH] Add python test for gossip optimization --- python/tests/test_account.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 34e4732cb..e409e73a9 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -1221,6 +1221,40 @@ class TestOnlineAccount: assert not msg.is_encrypted() ac1._evtracker.get_matching("DC_EVENT_SMTP_MESSAGE_SENT") + def test_gossip_optimization(self, acfactory, lp): + """Test that gossip timestamp is updated when someone else sends gossip, + so we don't have to send gossip ourselves. + """ + ac1, ac2, ac3 = acfactory.get_many_online_accounts(3) + + acfactory.introduce_each_other([ac1, ac2]) + acfactory.introduce_each_other([ac2, ac3]) + + lp.sec("ac1 creates a group chat with ac2") + group_chat = ac1.create_group_chat("hello") + group_chat.add_contact(ac2) + msg = group_chat.send_text("hi") + + # No Autocrypt gossip was sent yet. + gossiped_timestamp = msg.chat.get_summary()["gossiped_timestamp"] + assert gossiped_timestamp == 0 + + msg = ac2._evtracker.wait_next_incoming_message() + assert msg.is_encrypted() + assert msg.text == "hi" + + lp.sec("ac2 adds ac3 to the group") + msg.chat.add_contact(ac3) + + lp.sec("ac1 receives message from ac2 and updates gossip timestamp") + msg = ac1._evtracker.wait_next_incoming_message() + assert msg.is_encrypted() + + # ac1 has updated the gossip timestamp even though no gossip was sent by ac1. + # ac1 does not need to send gossip because ac2 already did it. + gossiped_timestamp = msg.chat.get_summary()["gossiped_timestamp"] + assert gossiped_timestamp == int(msg.time_sent.timestamp()) + def test_gossip_encryption_preference(self, acfactory, lp): """Test that encryption preference of group members is gossiped to new members. This is a Delta Chat extension to Autocrypt 1.1.0, which Autocrypt-Gossip headers