Skip to content

Commit

Permalink
drop unused sync_device_test code
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-sirotin committed Jul 31, 2023
1 parent 2a7ca36 commit e734349
Showing 1 changed file with 0 additions and 222 deletions.
222 changes: 0 additions & 222 deletions server/pairing/sync_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pairing
import (
"context"
"encoding/json"
"github.com/status-im/status-go/signal"
"path/filepath"
"testing"
"time"
Expand Down Expand Up @@ -69,25 +68,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()
Expand Down Expand Up @@ -205,57 +185,11 @@ func (s *SyncDeviceSuite) pairAccounts(serverBackend *api.GethStatusBackend, ser
clientConfigBytes, err := json.Marshal(clientPayloadSourceConfig)
require.NoError(s.T(), err)

var accountData AccountData

signalHandler := signal.MobileSignalHandler(func(data []byte) {

s.logger.Info("signal catch", zap.ByteString("data", data))

var envelope signal.Envelope
err := json.Unmarshal(data, &envelope)
if err != nil {
return
}

if envelope.Type != signal.LocalPairingEvent {
return
}

eventJson, err := json.Marshal(envelope.Event)
s.Require().NoError(err)

var event Event
err = json.Unmarshal(eventJson, &event)
s.Require().NoError(err)

s.logger.Info("local pairing event", zap.Any("event", event))

if event.Type == EventReceivedAccount {

accountDataJson, err := json.Marshal(event.Data)
s.Require().NoError(err)

err = json.Unmarshal(accountDataJson, &accountData)
s.Require().NoError(err)
}

})

signal.SetMobileSignalHandler(signalHandler)

err = StartUpReceivingClient(clientBackend, connectionString, string(clientConfigBytes))
require.NoError(s.T(), err)

require.True(s.T(), serverBackend.Messenger().HasPairedDevices())
require.True(s.T(), clientBackend.Messenger().HasPairedDevices())

s.Require().NotNil(accountData)

//err = clientBackend.Logout()
//s.Require().NoError(err)
//
//err = clientBackend.StartNodeWithAccount(*accountData.Account, accountData.Password, clientNodeConfig)
//s.Require().NoError(err)
}

func (s *SyncDeviceSuite) sendContactRequest(request *requests.SendContactRequest, messenger *protocol.Messenger) {
Expand Down Expand Up @@ -319,28 +253,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)
Expand Down Expand Up @@ -654,140 +566,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)
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

Expand Down

0 comments on commit e734349

Please sign in to comment.