Files
status-go/internal/protocol/messenger_chat_context_test.go
Igor Sirotin f3e4363808 refactor: move protocol to internal/protocol
Part of the Go project layout migration, item 27.

Pure move plus import-path rewrite across 502 files. No API or behaviour
change. `internal/` keeps the messaging application logic unimportable
from outside the module, which is what the issue asks for -- status-go is
consumed through the C-bindings in mobile/, not as a Go library.

Things that had to follow the move, beyond the Go imports:

- tools/generate-handlers/template.txt. messenger_handlers.go is
  generated, and the template hard-codes the imports it emits, so the
  generated file kept importing protocol/common and failed typecheck.
- .gitignore. The ignore rule for that generated file was pinned to the
  old path; without moving it, a 1486-line generated file starts being
  tracked.
- Makefile: the logosstorage and torrent test targets (both the archive
  packages and ./protocol itself), the archive README, migration-protocol.
- scripts/run_unit_tests.sh, which names the protocol package explicitly
  to shard its tests.
- scripts/cleanup_generated_files.sh and .golangci.yml.

scripts/migration_check.sh also needed a fix that is not specific to this
move: it validated every file the branch touched under a migration dir
against the timestamp naming rule, and a directory rename makes every
migration in it look newly added. It now excludes renames, so moving a
migration is not mistaken for adding one.

refs #7067
2026-08-21 10:11:05 +02:00

78 lines
2.6 KiB
Go

package protocol
import (
_ "github.com/mutecomm/go-sqlcipher/v4" // require go-sqlcipher that overrides default implementation
"github.com/status-im/status-go/internal/crypto"
"github.com/status-im/status-go/internal/crypto/types"
"github.com/status-im/status-go/internal/db/multiaccounts/settings"
"github.com/status-im/status-go/internal/images"
"github.com/status-im/status-go/internal/protocol/protobuf"
"github.com/status-im/status-go/internal/testutils/fake"
)
func isImageWithNamePresent(imgs map[string]*protobuf.IdentityImage, name string) bool {
for k, v := range imgs {
if k == name && len(v.Payload) > 0 {
return true
}
}
return false
}
func (s *MessengerSuite) retrieveIdentityImages(alice, bob *Messenger, chat *Chat) map[string]*protobuf.IdentityImage {
s.Require().NoError(alice.settings.SaveSettingField(settings.DisplayName, "alice"))
identityImages := fake.IdentityImages()
identityImagesMap := make(map[string]images.IdentityImage)
for _, img := range identityImages {
img.KeyUID = s.m.account.KeyUID
identityImagesMap[img.Name] = img
}
err := s.m.multiAccounts.StoreIdentityImages(s.m.account.KeyUID, identityImages, true)
s.Require().NoError(err)
s.Require().NoError(alice.SaveChat(chat))
s.Require().NoError(bob.settings.SaveSettingField(settings.DisplayName, "bob"))
s.Require().NoError(bob.SaveChat(chat))
chatContext := GetChatContextFromChatType(chat.ChatType)
chatIdentity, err := alice.createChatIdentity(chatContext)
s.Require().NoError(err)
imgs := chatIdentity.Images
s.Require().NoError(err)
return imgs
}
func (s *MessengerSuite) TestTwoImagesAreAddedToChatIdentityForPrivateChat() {
alice := s.m
bob := s.newMessenger()
bobPkString := types.EncodeHex(crypto.FromECDSAPub(&bob.identity.PublicKey))
chat := CreateOneToOneChat(bobPkString, &bob.identity.PublicKey, alice.getTimesource())
s.Require().Equal(privateChat, GetChatContextFromChatType(chat.ChatType))
imgs := s.retrieveIdentityImages(alice, bob, chat)
s.Require().Len(imgs, 2)
s.Require().Equal(true, isImageWithNamePresent(imgs, "thumbnail"))
s.Require().Equal(true, isImageWithNamePresent(imgs, "large"))
}
func (s *MessengerSuite) TestOneImageIsAddedToChatIdentityForPublicChat() {
alice := s.m
bob := s.newMessenger()
chat := CreatePublicChat("alic-and-bob-chat", &testTimeSource{})
s.Require().Equal(publicChat, GetChatContextFromChatType(chat.ChatType))
imgs := s.retrieveIdentityImages(alice, bob, chat)
s.Require().Len(imgs, 1)
s.Require().Equal(true, isImageWithNamePresent(imgs, "thumbnail"))
s.Require().Equal(false, isImageWithNamePresent(imgs, "large"))
}