From 705f7c4af49e8a9c0c5fee6dc5ff05ef6104a37a Mon Sep 17 00:00:00 2001 From: Igor Sirotin Date: Mon, 31 Jul 2023 13:50:16 +0300 Subject: [PATCH] drop unused sync_device_test code --- server/pairing/sync_device_test.go | 175 ----------------------------- 1 file changed, 175 deletions(-) diff --git a/server/pairing/sync_device_test.go b/server/pairing/sync_device_test.go index c9f9df875dd..2f836bdc942 100644 --- a/server/pairing/sync_device_test.go +++ b/server/pairing/sync_device_test.go @@ -69,25 +69,6 @@ func (s *SyncDeviceSuite) SetupTest() { s.pairThreeDevicesTmpdir = s.T().TempDir() } -//func (s *SyncDeviceSuite) startBackend(backend *api.GethStatusBackend) { -// -// account, err := backend.GetActiveAccount() -// s.Require().NoError(err) -// -// settings, err := defaultSettings() -// s.Require().NoError(err) -// -// nodeConfig, err := defaultNodeConfig() -// -// //accounts := []*accounts.Account{walletAccount, chatAccount} -// err = backend.StartNodeWithAccountAndInitialConfig(*account, s.password, *settings, nodeConfig, accounts) -// require.NoError(s.T(), err) -// multiaccounts, err := backend.GetAccounts() -// require.NoError(s.T(), err) -// require.NotEmpty(s.T(), multiaccounts[0].ColorHash) -// -//} - func (s *SyncDeviceSuite) prepareBackendWithAccount(tmpdir string) *api.GethStatusBackend { backend := s.prepareBackendWithoutAccount(tmpdir) accountManager := backend.AccountManager() @@ -319,28 +300,6 @@ func (s *SyncDeviceSuite) checkMutualContact(messenger *protocol.Messenger, cont s.Require().NotNil(contact.DisplayName) } -func (s *SyncDeviceSuite) syncInstallationContactV2FromContact(contact *protocol.Contact) protobuf.SyncInstallationContactV2 { - return protobuf.SyncInstallationContactV2{ - LastUpdatedLocally: contact.LastUpdatedLocally, - LastUpdated: contact.LastUpdated, - Id: contact.ID, - DisplayName: contact.DisplayName, - EnsName: contact.EnsName, - LocalNickname: contact.LocalNickname, - Added: contact.ContactRequestLocalState == protocol.ContactRequestStateSent, - Blocked: contact.Blocked, - Muted: false, - HasAddedUs: contact.ContactRequestRemoteState == protocol.ContactRequestStateReceived, - Removed: contact.Removed, - ContactRequestLocalState: int64(contact.ContactRequestLocalState), - ContactRequestRemoteState: int64(contact.ContactRequestRemoteState), - ContactRequestRemoteClock: int64(contact.ContactRequestRemoteClock), - ContactRequestLocalClock: int64(contact.ContactRequestLocalClock), - VerificationStatus: int64(contact.VerificationStatus), - TrustStatus: int64(contact.TrustStatus), - } -} - func (s *SyncDeviceSuite) TestPairingSyncDeviceClientAsSender() { clientTmpDir := filepath.Join(s.clientAsSenderTmpdir, "client") clientBackend := s.prepareBackendWithAccount(clientTmpDir) @@ -654,140 +613,6 @@ func (s *SyncDeviceSuite) TestPairingThreeDevices() { s.Require().Equal(1, len(alice3Backend.Messenger().Contacts())) } -func (s *SyncDeviceSuite) TestPairingBlockedContact() { - tmpdir := s.T().TempDir() - bobDisplayName := "bob-1" - - alice1TmpDir := filepath.Join(tmpdir, "alice1") - alice1Backend := s.prepareBackendWithAccount(alice1TmpDir) - alice1Messenger := alice1Backend.Messenger() - s.Require().NotNil(alice1Messenger) - _, err := alice1Messenger.Start() - s.Require().NoError(err) - - alice2TmpDir := filepath.Join(tmpdir, "alice2") - alice2Backend := s.prepareBackendWithoutAccount(alice2TmpDir) - - bobTmpDir := filepath.Join(tmpdir, "bob") - bobBackend := s.prepareBackendWithAccount(bobTmpDir) - bobMessenger := bobBackend.Messenger() - _, err = bobMessenger.Start() - s.Require().NoError(err) - err = bobMessenger.SetDisplayName(bobDisplayName) - s.Require().NoError(err) - - defer func() { - require.NoError(s.T(), bobBackend.Logout()) - require.NoError(s.T(), alice1Backend.Logout()) - }() - - // Make Alice and Bob mutual contacts - messageText := "hello!" - bobPublicKey := types.EncodeHex(crypto.FromECDSAPub(bobMessenger.IdentityPublicKey())) - request := &requests.SendContactRequest{ - ID: bobPublicKey, - Message: messageText, - } - s.sendContactRequest(request, alice1Messenger) - contactRequest := s.receiveContactRequest(messageText, bobMessenger) - s.acceptContactRequest(contactRequest, alice1Messenger, bobMessenger) - s.checkMutualContact(alice1Messenger, bobPublicKey) - - // Block Bob before pairing - _, err = alice1Messenger.BlockContact(bobPublicKey, false) - s.Require().NoError(err) - s.Require().Len(alice1Messenger.BlockedContacts(), 1) - s.Require().Equal(bobPublicKey, alice1Messenger.BlockedContacts()[0].ID) - - // Pair alice-1 <-> alice-2 - s.logger.Info("pairing Alice-1 and Alice-2") - s.pairAccounts(alice1Backend, alice1TmpDir, alice2Backend, alice2TmpDir) - - s.logger.Info("pairing finished") - - // Get alice-2 messenger - alice2Messenger := alice2Backend.Messenger() - s.Require().NotNil(alice2Messenger) - _, err = alice2Messenger.Start() - s.Require().NoError(err) - - // Check that Alice-2 has Bob as mutual contact - s.Require().Len(alice1Messenger.Contacts(), 1) - s.Require().Equal(bobPublicKey, alice1Messenger.Contacts()[0].ID) - - // Check that Bob contact is synced with correct display name and blocked - s.Require().Len(alice2Messenger.BlockedContacts(), 1) - s.Require().Equal(bobPublicKey, alice2Messenger.BlockedContacts()[0].ID) - s.Require().Equal(bobDisplayName, alice2Messenger.Contacts()[0].DisplayName) - - // Unblock after pairing - _, err = alice1Messenger.UnblockContact(bobPublicKey) - s.Require().NoError(err) - s.Require().Len(alice1Messenger.BlockedContacts(), 0) - - // For some reason after unblocking the real sync message doesn't arrive during tests. - // Therefor I manually push the update to Alice-2 handlers. - bobFromAlice1 := alice1Messenger.Contacts()[0] // Get bob perspective of alice for backup - contactSync := s.syncInstallationContactV2FromContact(bobFromAlice1) - alice2State := alice2Messenger.BuildMessageState() - err = alice2Messenger.HandleSyncInstallationContact(alice2State, contactSync) - s.Require().NoError(err) - - //// Wait for the 'unblock' state to sync - //resp, err := protocol.WaitOnMessengerResponse( - // alice2Messenger, - // func(r *protocol.MessengerResponse) bool { - // s.logger.Info("MessengerResponse", zap.Int("contacts", len(r.Contacts))) - // return len(r.Contacts) == 1 - // }, - // "synced contact not received", - //) - // - //s.Require().NoError(err) - //s.Require().NotNil(resp) - - // Check that Alice-2 has Bob unblocked and removed - s.Require().Len(alice2Messenger.BlockedContacts(), 0) - - // Wait for Bob to receive message that he was removed as contact - resp, err := protocol.WaitOnMessengerResponse( - bobMessenger, - func(r *protocol.MessengerResponse) bool { - s.logger.Info("MessengerResponse", zap.Int("contacts", len(r.Contacts))) - return len(r.Contacts) == 1 - }, - "synced contact not received", - ) - - s.Require().NoError(err) - s.Require().NotNil(resp) - - // 3. CR after unblocking - - // Send CR from Alice-1, accept on Bob - s.sendContactRequest(request, alice1Messenger) - contactRequest = s.receiveContactRequest(messageText, bobMessenger) - s.acceptContactRequest(contactRequest, alice1Messenger, bobMessenger) - s.checkMutualContact(alice1Messenger, bobPublicKey) - - // Wait for sync message to arrive at Alice-2 - resp, err = protocol.WaitOnMessengerResponse( - alice2Messenger, - func(r *protocol.MessengerResponse) bool { - s.logger.Info("MessengerResponse", zap.Int("contacts", len(r.Contacts))) - //return len(r.Contacts) == 1 && - return false - }, - "synced contact not received", - ) - - s.Require().NoError(err) - s.Require().NotNil(resp) - - // 4. block/unblock again - // 5. check chats list -} - func defaultSettings(generatedAccountInfo generator.GeneratedAccountInfo, derivedAddresses map[string]generator.AccountInfo, mnemonic *string) (*settings.Settings, error) { chatKeyString := derivedAddresses[pathDefaultChat].PublicKey