mirror of
https://github.com/status-im/status-go.git
synced 2025-02-06 11:56:01 +00:00
chore_: refactor TestMessengerCollapsedComunityCategoriesSuite
(#5790)
* chore_: improve readability of `TestE2eSendingReceivingProfilePicture` * chore_: cleanup logs * chore_: remove generateKeyUID * chore_: cleanup logs * chore_: move chat message sending to switch case * chore_: remove redundant args * chore_: simplify images check * chore(testMesengerConfig)_: add createSettings option * chore_: move TestMessengerCollapsedCommunityCategoriesSuite * chore(MessengerProfilePictureHandlerSuite)_: simpler messenger creation * chore_: MessengerProfilePictureHandlerSuite test cases * chore_: lint fix * chore_: address pr comments
This commit is contained in:
parent
717814e83f
commit
4083aae162
@ -2,7 +2,6 @@ package protocol
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
@ -19,10 +18,6 @@ import (
|
|||||||
|
|
||||||
const DefaultProfileDisplayName = ""
|
const DefaultProfileDisplayName = ""
|
||||||
|
|
||||||
func TestMessengerCollapsedComunityCategoriesSuite(t *testing.T) {
|
|
||||||
suite.Run(t, new(MessengerCollapsedCommunityCategoriesSuite))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *MessengerBaseTestSuite) SetupTest() {
|
func (s *MessengerBaseTestSuite) SetupTest() {
|
||||||
s.logger = tt.MustCreateTestLogger()
|
s.logger = tt.MustCreateTestLogger()
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/status-im/status-go/eth-node/crypto"
|
"github.com/status-im/status-go/eth-node/crypto"
|
||||||
"github.com/status-im/status-go/eth-node/types"
|
"github.com/status-im/status-go/eth-node/types"
|
||||||
"github.com/status-im/status-go/multiaccounts"
|
"github.com/status-im/status-go/multiaccounts"
|
||||||
|
"github.com/status-im/status-go/multiaccounts/settings"
|
||||||
"github.com/status-im/status-go/protocol/protobuf"
|
"github.com/status-im/status-go/protocol/protobuf"
|
||||||
"github.com/status-im/status-go/protocol/tt"
|
"github.com/status-im/status-go/protocol/tt"
|
||||||
v1protocol "github.com/status-im/status-go/protocol/v1"
|
v1protocol "github.com/status-im/status-go/protocol/v1"
|
||||||
@ -142,3 +143,12 @@ func (u *unhandledMessagesTracker) addMessage(msg *v1protocol.StatusMessage, err
|
|||||||
}
|
}
|
||||||
u.messages[msgType] = append(u.messages[msgType], newMessage)
|
u.messages[msgType] = append(u.messages[msgType], newMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newTestSettings() settings.Settings {
|
||||||
|
return settings.Settings{
|
||||||
|
DisplayName: DefaultProfileDisplayName,
|
||||||
|
ProfilePicturesShowTo: 1,
|
||||||
|
ProfilePicturesVisibility: 1,
|
||||||
|
URLUnfurlingMode: settings.URLUnfurlingAlwaysAsk,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,9 +1,17 @@
|
|||||||
package protocol
|
package protocol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/status-im/status-go/protocol/requests"
|
"github.com/status-im/status-go/protocol/requests"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestMessengerCollapsedCommunityCategoriesSuite(t *testing.T) {
|
||||||
|
suite.Run(t, new(MessengerCollapsedCommunityCategoriesSuite))
|
||||||
|
}
|
||||||
|
|
||||||
type MessengerCollapsedCommunityCategoriesSuite struct {
|
type MessengerCollapsedCommunityCategoriesSuite struct {
|
||||||
MessengerBaseTestSuite
|
MessengerBaseTestSuite
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,12 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cenkalti/backoff/v3"
|
"github.com/cenkalti/backoff/v3"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
||||||
@ -17,6 +19,7 @@ import (
|
|||||||
"github.com/status-im/status-go/images"
|
"github.com/status-im/status-go/images"
|
||||||
"github.com/status-im/status-go/multiaccounts"
|
"github.com/status-im/status-go/multiaccounts"
|
||||||
"github.com/status-im/status-go/multiaccounts/settings"
|
"github.com/status-im/status-go/multiaccounts/settings"
|
||||||
|
"github.com/status-im/status-go/params"
|
||||||
"github.com/status-im/status-go/protocol/protobuf"
|
"github.com/status-im/status-go/protocol/protobuf"
|
||||||
"github.com/status-im/status-go/protocol/requests"
|
"github.com/status-im/status-go/protocol/requests"
|
||||||
"github.com/status-im/status-go/protocol/tt"
|
"github.com/status-im/status-go/protocol/tt"
|
||||||
@ -32,9 +35,6 @@ type MessengerProfilePictureHandlerSuite struct {
|
|||||||
alice *Messenger // client instance of Messenger
|
alice *Messenger // client instance of Messenger
|
||||||
bob *Messenger // server instance of Messenger
|
bob *Messenger // server instance of Messenger
|
||||||
|
|
||||||
aliceKey *ecdsa.PrivateKey // private key for the alice instance of Messenger
|
|
||||||
bobKey *ecdsa.PrivateKey // private key for the bob instance of Messenger
|
|
||||||
|
|
||||||
// If one wants to send messages between different instances of Messenger,
|
// If one wants to send messages between different instances of Messenger,
|
||||||
// a single Waku service should be shared.
|
// a single Waku service should be shared.
|
||||||
shh types.Waku
|
shh types.Waku
|
||||||
@ -43,10 +43,6 @@ type MessengerProfilePictureHandlerSuite struct {
|
|||||||
|
|
||||||
func (s *MessengerProfilePictureHandlerSuite) SetupSuite() {
|
func (s *MessengerProfilePictureHandlerSuite) SetupSuite() {
|
||||||
s.logger = tt.MustCreateTestLogger()
|
s.logger = tt.MustCreateTestLogger()
|
||||||
}
|
|
||||||
|
|
||||||
func (s *MessengerProfilePictureHandlerSuite) SetupTest() {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
// Setup Waku things
|
// Setup Waku things
|
||||||
config := waku.DefaultConfig
|
config := waku.DefaultConfig
|
||||||
@ -55,29 +51,36 @@ func (s *MessengerProfilePictureHandlerSuite) SetupTest() {
|
|||||||
shh := waku.New(&config, wakuLogger)
|
shh := waku.New(&config, wakuLogger)
|
||||||
s.shh = gethbridge.NewGethWakuWrapper(shh)
|
s.shh = gethbridge.NewGethWakuWrapper(shh)
|
||||||
s.Require().NoError(shh.Start())
|
s.Require().NoError(shh.Start())
|
||||||
|
}
|
||||||
|
|
||||||
// Generate private keys for Alice and Bob
|
func (s *MessengerProfilePictureHandlerSuite) TearDownSuite() {
|
||||||
s.aliceKey, err = crypto.GenerateKey()
|
_ = gethbridge.GetGethWakuFrom(s.shh).Stop()
|
||||||
s.Require().NoError(err)
|
_ = s.logger.Sync()
|
||||||
s.bobKey, err = crypto.GenerateKey()
|
}
|
||||||
|
|
||||||
|
func (s *MessengerProfilePictureHandlerSuite) newMessenger(name string) *Messenger {
|
||||||
|
m, err := newTestMessenger(s.shh, testMessengerConfig{
|
||||||
|
logger: s.logger.Named(fmt.Sprintf("messenger-%s", name)),
|
||||||
|
name: name,
|
||||||
|
extraOptions: []Option{
|
||||||
|
WithAppSettings(newTestSettings(), params.NodeConfig{}),
|
||||||
|
},
|
||||||
|
})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
_, err = m.Start()
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MessengerProfilePictureHandlerSuite) SetupTest() {
|
||||||
// Generate Alice Messenger
|
// Generate Alice Messenger
|
||||||
aliceLogger := s.logger.Named("Alice messenger")
|
s.alice = s.newMessenger("Alice")
|
||||||
s.alice, err = newMessengerWithKey(s.shh, s.aliceKey, aliceLogger, []Option{})
|
s.bob = s.newMessenger("Bobby")
|
||||||
s.Require().NoError(err)
|
|
||||||
s.logger.Debug("alice messenger created")
|
|
||||||
|
|
||||||
// Generate Bob Messenger
|
|
||||||
bobLogger := s.logger.Named("Bob messenger")
|
|
||||||
s.bob, err = newMessengerWithKey(s.shh, s.bobKey, bobLogger, []Option{})
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.logger.Debug("bob messenger created")
|
|
||||||
|
|
||||||
// Setup MultiAccount for Alice Messenger
|
// Setup MultiAccount for Alice Messenger
|
||||||
s.logger.Debug("alice setupMultiAccount before")
|
|
||||||
s.setupMultiAccount(s.alice)
|
s.setupMultiAccount(s.alice)
|
||||||
s.logger.Debug("alice setupMultiAccount after")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerProfilePictureHandlerSuite) TearDownTest() {
|
func (s *MessengerProfilePictureHandlerSuite) TearDownTest() {
|
||||||
@ -89,24 +92,37 @@ func (s *MessengerProfilePictureHandlerSuite) TearDownTest() {
|
|||||||
_ = s.logger.Sync()
|
_ = s.logger.Sync()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerProfilePictureHandlerSuite) generateKeyUID(publicKey *ecdsa.PublicKey) string {
|
|
||||||
return types.EncodeHex(crypto.FromECDSAPub(publicKey))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *MessengerProfilePictureHandlerSuite) setupMultiAccount(m *Messenger) {
|
func (s *MessengerProfilePictureHandlerSuite) setupMultiAccount(m *Messenger) {
|
||||||
keyUID := s.generateKeyUID(&m.identity.PublicKey)
|
name, err := m.settings.DisplayName()
|
||||||
m.account = &multiaccounts.Account{KeyUID: keyUID}
|
s.Require().NoError(err)
|
||||||
|
|
||||||
err := m.multiAccounts.SaveAccount(multiaccounts.Account{Name: "string", KeyUID: keyUID})
|
keyUID := m.IdentityPublicKeyString()
|
||||||
|
m.account = &multiaccounts.Account{
|
||||||
|
Name: name,
|
||||||
|
KeyUID: keyUID,
|
||||||
|
}
|
||||||
|
|
||||||
|
err = m.multiAccounts.SaveAccount(*m.account)
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerProfilePictureHandlerSuite) generateAndStoreIdentityImages(m *Messenger) []images.IdentityImage {
|
func (s *MessengerProfilePictureHandlerSuite) generateAndStoreIdentityImages(m *Messenger) map[string]images.IdentityImage {
|
||||||
keyUID := s.generateKeyUID(&m.identity.PublicKey)
|
keyUID := m.IdentityPublicKeyString()
|
||||||
iis := images.SampleIdentityImages()
|
iis := images.SampleIdentityImages()
|
||||||
s.Require().NoError(m.multiAccounts.StoreIdentityImages(keyUID, iis, false))
|
|
||||||
|
|
||||||
return iis
|
err := m.multiAccounts.StoreIdentityImages(keyUID, iis, false)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
out := make(map[string]images.IdentityImage)
|
||||||
|
|
||||||
|
for _, ii := range iis {
|
||||||
|
out[ii.Name] = ii
|
||||||
|
}
|
||||||
|
|
||||||
|
s.Require().Contains(out, images.SmallDimName)
|
||||||
|
s.Require().Contains(out, images.LargeDimName)
|
||||||
|
|
||||||
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerProfilePictureHandlerSuite) TestChatIdentity() {
|
func (s *MessengerProfilePictureHandlerSuite) TestChatIdentity() {
|
||||||
@ -202,7 +218,7 @@ func (s *MessengerProfilePictureHandlerSuite) TestPictureInPrivateChatOneSided()
|
|||||||
err = s.alice.settings.SaveSettingField(settings.ProfilePicturesVisibility, settings.ProfilePicturesShowToEveryone)
|
err = s.alice.settings.SaveSettingField(settings.ProfilePicturesVisibility, settings.ProfilePicturesShowToEveryone)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
bChat := CreateOneToOneChat(s.generateKeyUID(&s.aliceKey.PublicKey), &s.aliceKey.PublicKey, s.alice.transport)
|
bChat := CreateOneToOneChat(s.alice.IdentityPublicKeyString(), s.alice.IdentityPublicKey(), s.alice.transport)
|
||||||
err = s.bob.SaveChat(bChat)
|
err = s.bob.SaveChat(bChat)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
@ -240,16 +256,16 @@ func (s *MessengerProfilePictureHandlerSuite) TestPictureInPrivateChatOneSided()
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerProfilePictureHandlerSuite) TestE2eSendingReceivingProfilePicture() {
|
func (s *MessengerProfilePictureHandlerSuite) TestE2eSendingReceivingProfilePicture() {
|
||||||
profilePicShowSettings := map[string]settings.ProfilePicturesShowToType{
|
profilePicShowSettings := []settings.ProfilePicturesShowToType{
|
||||||
"ShowToContactsOnly": settings.ProfilePicturesShowToContactsOnly,
|
settings.ProfilePicturesShowToContactsOnly,
|
||||||
"ShowToEveryone": settings.ProfilePicturesShowToEveryone,
|
settings.ProfilePicturesShowToEveryone,
|
||||||
"ShowToNone": settings.ProfilePicturesShowToNone,
|
settings.ProfilePicturesShowToNone,
|
||||||
}
|
}
|
||||||
|
|
||||||
profilePicViewSettings := map[string]settings.ProfilePicturesVisibilityType{
|
profilePicViewSettings := []settings.ProfilePicturesVisibilityType{
|
||||||
"ViewFromContactsOnly": settings.ProfilePicturesVisibilityContactsOnly,
|
settings.ProfilePicturesVisibilityContactsOnly,
|
||||||
"ViewFromEveryone": settings.ProfilePicturesVisibilityEveryone,
|
settings.ProfilePicturesVisibilityEveryone,
|
||||||
"ViewFromNone": settings.ProfilePicturesVisibilityNone,
|
settings.ProfilePicturesVisibilityNone,
|
||||||
}
|
}
|
||||||
|
|
||||||
isContactFor := map[string][]bool{
|
isContactFor := map[string][]bool{
|
||||||
@ -264,243 +280,20 @@ func (s *MessengerProfilePictureHandlerSuite) TestE2eSendingReceivingProfilePict
|
|||||||
|
|
||||||
// TODO see if possible to push each test scenario into a go routine
|
// TODO see if possible to push each test scenario into a go routine
|
||||||
for _, cc := range chatContexts {
|
for _, cc := range chatContexts {
|
||||||
for sn, ss := range profilePicShowSettings {
|
for _, ss := range profilePicShowSettings {
|
||||||
for vn, vs := range profilePicViewSettings {
|
for _, vs := range profilePicViewSettings {
|
||||||
for _, ac := range isContactFor["alice"] {
|
for _, ac := range isContactFor["alice"] {
|
||||||
for _, bc := range isContactFor["bob"] {
|
for _, bc := range isContactFor["bob"] {
|
||||||
s.logger.Debug("top of the loop")
|
args := &e2eArgs{
|
||||||
s.SetupTest()
|
chatContext: cc,
|
||||||
s.logger.Info("testing with criteria:",
|
showToType: ss,
|
||||||
zap.String("chat context type", string(cc)),
|
visibilityType: vs,
|
||||||
zap.String("profile picture Show Settings", sn),
|
aliceContact: ac,
|
||||||
zap.String("profile picture View Settings", vn),
|
bobContact: bc,
|
||||||
zap.Bool("bob in Alice's Contacts", ac),
|
|
||||||
zap.Bool("alice in Bob's Contacts", bc),
|
|
||||||
)
|
|
||||||
|
|
||||||
expectPicture, err := resultExpected(ss, vs, ac, bc)
|
|
||||||
s.logger.Debug("expect to receive a profile pic?",
|
|
||||||
zap.Bool("result", expectPicture),
|
|
||||||
zap.Error(err))
|
|
||||||
|
|
||||||
// Setting up Bob
|
|
||||||
s.logger.Debug("Setting up test criteria for Bob")
|
|
||||||
|
|
||||||
s.logger.Debug("Save bob profile-pictures-visibility setting before")
|
|
||||||
err = s.bob.settings.SaveSettingField(settings.ProfilePicturesVisibility, vs)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.logger.Debug("Save bob profile-pictures-visibility setting after")
|
|
||||||
|
|
||||||
s.logger.Debug("bob add contact before")
|
|
||||||
if bc {
|
|
||||||
s.logger.Debug("bob has contact to add")
|
|
||||||
_, err = s.bob.AddContact(context.Background(), &requests.AddContact{ID: s.generateKeyUID(&s.alice.identity.PublicKey)})
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.logger.Debug("bob add contact after")
|
|
||||||
}
|
}
|
||||||
s.logger.Debug("bob add contact after after")
|
s.Run(args.TestCaseName(s.T()), func() {
|
||||||
|
s.testE2eSendingReceivingProfilePicture(args)
|
||||||
// Create Bob's chats
|
})
|
||||||
switch cc {
|
|
||||||
case publicChat:
|
|
||||||
s.logger.Debug("making publicChats for bob")
|
|
||||||
|
|
||||||
// Bob opens up the public chat and joins it
|
|
||||||
bChat := CreatePublicChat("status", s.alice.transport)
|
|
||||||
err = s.bob.SaveChat(bChat)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
_, err = s.bob.Join(bChat)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
case privateChat:
|
|
||||||
s.logger.Debug("making privateChats for bob")
|
|
||||||
|
|
||||||
s.logger.Debug("Bob making one to one chat with alice")
|
|
||||||
bChat := CreateOneToOneChat(s.generateKeyUID(&s.aliceKey.PublicKey), &s.aliceKey.PublicKey, s.alice.transport)
|
|
||||||
s.logger.Debug("Bob saving one to one chat with alice")
|
|
||||||
err = s.bob.SaveChat(bChat)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.logger.Debug("Bob saved one to one chat with alice")
|
|
||||||
|
|
||||||
s.logger.Debug("Bob joining one to one chat with alice")
|
|
||||||
_, err = s.bob.Join(bChat)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.logger.Debug("Bob joined one to one chat with alice")
|
|
||||||
default:
|
|
||||||
s.Failf("unexpected chat context type", "%s", string(cc))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setting up Alice
|
|
||||||
s.logger.Debug("Setting up test criteria for Alice")
|
|
||||||
|
|
||||||
s.logger.Debug("Save alice profile-pictures-show-to setting before")
|
|
||||||
err = s.alice.settings.SaveSettingField(settings.ProfilePicturesShowTo, ss)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.logger.Debug("Save alice profile-pictures-show-to setting after")
|
|
||||||
|
|
||||||
s.logger.Debug("alice add contact before")
|
|
||||||
if ac {
|
|
||||||
s.logger.Debug("alice has contact to add")
|
|
||||||
_, err = s.alice.AddContact(context.Background(), &requests.AddContact{ID: s.generateKeyUID(&s.bob.identity.PublicKey)})
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.logger.Debug("alice add contact after")
|
|
||||||
}
|
|
||||||
s.logger.Debug("alice add contact after after")
|
|
||||||
|
|
||||||
s.logger.Debug("generateAndStoreIdentityImages before")
|
|
||||||
iis := s.generateAndStoreIdentityImages(s.alice)
|
|
||||||
s.logger.Debug("generateAndStoreIdentityImages after")
|
|
||||||
|
|
||||||
s.logger.Debug("Before making chat for alice")
|
|
||||||
// Create chats
|
|
||||||
var aChat *Chat
|
|
||||||
switch cc {
|
|
||||||
case publicChat:
|
|
||||||
s.logger.Debug("making publicChats for alice")
|
|
||||||
|
|
||||||
// Alice opens creates a public chat
|
|
||||||
aChat = CreatePublicChat("status", s.alice.transport)
|
|
||||||
err = s.alice.SaveChat(aChat)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
case privateChat:
|
|
||||||
s.logger.Debug("making privateChats for alice")
|
|
||||||
|
|
||||||
s.logger.Debug("Alice making one to one chat with bob")
|
|
||||||
aChat = CreateOneToOneChat(s.generateKeyUID(&s.bobKey.PublicKey), &s.bobKey.PublicKey, s.bob.transport)
|
|
||||||
s.logger.Debug("Alice saving one to one chat with bob")
|
|
||||||
err = s.alice.SaveChat(aChat)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.logger.Debug("Alice saved one to one chat with bob")
|
|
||||||
|
|
||||||
s.logger.Debug("Alice joining one to one chat with bob")
|
|
||||||
_, err = s.alice.Join(aChat)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.logger.Debug("Alice joined one to one chat with bob")
|
|
||||||
|
|
||||||
s.logger.Debug("alice before manually triggering publishContactCode")
|
|
||||||
err = s.alice.publishContactCode()
|
|
||||||
s.logger.Debug("alice after manually triggering publishContactCode",
|
|
||||||
zap.Error(err))
|
|
||||||
s.Require().NoError(err)
|
|
||||||
default:
|
|
||||||
s.Failf("unexpected chat context type", "%s", string(cc))
|
|
||||||
}
|
|
||||||
|
|
||||||
s.logger.Debug("Build and send a chat from alice")
|
|
||||||
|
|
||||||
// Alice sends a message to the public chat
|
|
||||||
message := buildTestMessage(*aChat)
|
|
||||||
response, err := s.alice.SendChatMessage(context.Background(), message)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().NotNil(response)
|
|
||||||
|
|
||||||
// Poll bob to see if he got the chatIdentity
|
|
||||||
// Retrieve ChatIdentity
|
|
||||||
var contacts []*Contact
|
|
||||||
|
|
||||||
s.logger.Debug("Checking Bob to see if he got the chatIdentity")
|
|
||||||
options := func(b *backoff.ExponentialBackOff) {
|
|
||||||
b.MaxElapsedTime = 2 * time.Second
|
|
||||||
}
|
|
||||||
err = tt.RetryWithBackOff(func() error {
|
|
||||||
|
|
||||||
response, err = s.bob.RetrieveAll()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
contacts = response.Contacts
|
|
||||||
s.logger.Debug("RetryWithBackOff contact data", zap.Any("contacts", contacts))
|
|
||||||
|
|
||||||
if len(contacts) > 0 && len(contacts[0].Images) > 0 {
|
|
||||||
s.logger.Debug("", zap.Any("contacts", contacts))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return errors.New("no new contacts with images received")
|
|
||||||
}, options)
|
|
||||||
|
|
||||||
s.logger.Debug("Finished RetryWithBackOff got Bob",
|
|
||||||
zap.Any("contacts", contacts),
|
|
||||||
zap.Error(err))
|
|
||||||
|
|
||||||
if expectPicture {
|
|
||||||
s.logger.Debug("expecting a contact with images")
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().NotNil(contacts)
|
|
||||||
} else {
|
|
||||||
s.logger.Debug("expecting no contacts with images")
|
|
||||||
s.Require().EqualError(err, "no new contacts with images received")
|
|
||||||
s.logger.Info("Completed testing with criteria:",
|
|
||||||
zap.String("chat context type", string(cc)),
|
|
||||||
zap.String("profile picture Show Settings", sn),
|
|
||||||
zap.String("profile picture View Settings", vn),
|
|
||||||
zap.Bool("bob in Alice's Contacts", ac),
|
|
||||||
zap.Bool("alice in Bob's Contacts", bc),
|
|
||||||
)
|
|
||||||
s.TearDownTest()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
s.logger.Debug("checking alice's contact")
|
|
||||||
|
|
||||||
// Check if alice's contact data with profile picture is there
|
|
||||||
var contact *Contact
|
|
||||||
for _, c := range contacts {
|
|
||||||
if c.ID == s.generateKeyUID(&s.alice.identity.PublicKey) {
|
|
||||||
contact = c
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s.Require().NotNil(contact)
|
|
||||||
|
|
||||||
s.logger.Debug("checked alice's contact info all good")
|
|
||||||
|
|
||||||
// Check that Bob now has Alice's profile picture(s)
|
|
||||||
switch cc {
|
|
||||||
case publicChat:
|
|
||||||
// In public chat context we only need the images.SmallDimName, but also may have the large
|
|
||||||
s.Require().GreaterOrEqual(len(contact.Images), 1)
|
|
||||||
|
|
||||||
// Check if the result matches expectation
|
|
||||||
smImg, ok := contact.Images[images.SmallDimName]
|
|
||||||
s.Require().True(ok, "contact images must contain the images.SmallDimName")
|
|
||||||
|
|
||||||
for _, ii := range iis {
|
|
||||||
if ii.Name == images.SmallDimName {
|
|
||||||
s.Require().Equal(ii.Payload, smImg.Payload)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case privateChat:
|
|
||||||
s.Require().Equal(len(contact.Images), 2)
|
|
||||||
s.logger.Info("private chat chat images", zap.Any("iis", iis))
|
|
||||||
|
|
||||||
// Check if the result matches expectation
|
|
||||||
smImg, ok := contact.Images[images.SmallDimName]
|
|
||||||
s.Require().True(ok, "contact images must contain the images.SmallDimName")
|
|
||||||
|
|
||||||
lgImg, ok := contact.Images[images.LargeDimName]
|
|
||||||
s.Require().True(ok, "contact images must contain the images.LargeDimName")
|
|
||||||
|
|
||||||
for _, ii := range iis {
|
|
||||||
switch ii.Name {
|
|
||||||
case images.SmallDimName:
|
|
||||||
s.Require().Equal(ii.Payload, smImg.Payload)
|
|
||||||
case images.LargeDimName:
|
|
||||||
s.Require().Equal(ii.Payload, lgImg.Payload)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
s.logger.Info("Completed testing with criteria:",
|
|
||||||
zap.String("chat context type", string(cc)),
|
|
||||||
zap.String("profile picture Show Settings", sn),
|
|
||||||
zap.String("profile picture View Settings", vn),
|
|
||||||
zap.Bool("bob in Alice's Contacts", ac),
|
|
||||||
zap.Bool("alice in Bob's Contacts", bc),
|
|
||||||
)
|
|
||||||
s.TearDownTest()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -510,15 +303,201 @@ func (s *MessengerProfilePictureHandlerSuite) TestE2eSendingReceivingProfilePict
|
|||||||
s.SetupTest()
|
s.SetupTest()
|
||||||
}
|
}
|
||||||
|
|
||||||
func resultExpected(ss settings.ProfilePicturesShowToType, vs settings.ProfilePicturesVisibilityType, ac, bc bool) (bool, error) {
|
func (s *MessengerProfilePictureHandlerSuite) testE2eSendingReceivingProfilePicture(args *e2eArgs) {
|
||||||
switch ss {
|
// Generate Alice Messenger
|
||||||
|
alice := s.newMessenger("Alice")
|
||||||
|
bob := s.newMessenger("Bobby")
|
||||||
|
|
||||||
|
// Setup MultiAccount for Alice Messenger
|
||||||
|
s.setupMultiAccount(alice)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
TearDownMessenger(&s.Suite, alice)
|
||||||
|
alice = nil
|
||||||
|
TearDownMessenger(&s.Suite, bob)
|
||||||
|
bob = nil
|
||||||
|
_ = s.logger.Sync()
|
||||||
|
}()
|
||||||
|
|
||||||
|
s.logger.Info("testing with criteria:", zap.Any("args", args))
|
||||||
|
defer s.logger.Info("Completed testing with criteria:", zap.Any("args", args))
|
||||||
|
|
||||||
|
expectPicture, err := args.resultExpected()
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
s.logger.Debug("expect to receive a profile pic?",
|
||||||
|
zap.Bool("result", expectPicture),
|
||||||
|
zap.Error(err))
|
||||||
|
|
||||||
|
// Setting up Bob
|
||||||
|
err = bob.settings.SaveSettingField(settings.ProfilePicturesVisibility, args.visibilityType)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
if args.bobContact {
|
||||||
|
_, err = bob.AddContact(context.Background(), &requests.AddContact{ID: alice.IdentityPublicKeyString()})
|
||||||
|
s.Require().NoError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create Bob's chats
|
||||||
|
switch args.chatContext {
|
||||||
|
case publicChat:
|
||||||
|
// Bob opens up the public chat and joins it
|
||||||
|
bChat := CreatePublicChat("status", alice.transport)
|
||||||
|
err = bob.SaveChat(bChat)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
_, err = bob.Join(bChat)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
case privateChat:
|
||||||
|
bChat := CreateOneToOneChat(alice.IdentityPublicKeyString(), alice.IdentityPublicKey(), alice.transport)
|
||||||
|
err = bob.SaveChat(bChat)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
_, err = bob.Join(bChat)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
default:
|
||||||
|
s.Failf("unexpected chat context type", "%s", string(args.chatContext))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setting up Alice
|
||||||
|
err = alice.settings.SaveSettingField(settings.ProfilePicturesShowTo, args.showToType)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
if args.aliceContact {
|
||||||
|
_, err = alice.AddContact(context.Background(), &requests.AddContact{ID: bob.IdentityPublicKeyString()})
|
||||||
|
s.Require().NoError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
iis := s.generateAndStoreIdentityImages(alice)
|
||||||
|
|
||||||
|
// Create chats
|
||||||
|
var aChat *Chat
|
||||||
|
switch args.chatContext {
|
||||||
|
case publicChat:
|
||||||
|
// Alice opens creates a public chat
|
||||||
|
aChat = CreatePublicChat("status", alice.transport)
|
||||||
|
err = alice.SaveChat(aChat)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
// Alice sends a message to the public chat
|
||||||
|
message := buildTestMessage(*aChat)
|
||||||
|
response, err := alice.SendChatMessage(context.Background(), message)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().NotNil(response)
|
||||||
|
s.Require().Len(response.messages, 1)
|
||||||
|
|
||||||
|
case privateChat:
|
||||||
|
aChat = CreateOneToOneChat(bob.IdentityPublicKeyString(), bob.IdentityPublicKey(), bob.transport)
|
||||||
|
err = alice.SaveChat(aChat)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
_, err = alice.Join(aChat)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
err = alice.publishContactCode()
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
default:
|
||||||
|
s.Failf("unexpected chat context type", "%s", string(args.chatContext))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Poll bob to see if he got the chatIdentity
|
||||||
|
// Retrieve ChatIdentity
|
||||||
|
var contacts []*Contact
|
||||||
|
|
||||||
|
options := func(b *backoff.ExponentialBackOff) {
|
||||||
|
b.MaxElapsedTime = 2 * time.Second
|
||||||
|
}
|
||||||
|
|
||||||
|
err = tt.RetryWithBackOff(func() error {
|
||||||
|
response, err := bob.RetrieveAll()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
contacts = response.Contacts
|
||||||
|
if len(contacts) > 0 && len(contacts[0].Images) > 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors.New("no new contacts with images received")
|
||||||
|
}, options)
|
||||||
|
|
||||||
|
if !expectPicture {
|
||||||
|
s.Require().EqualError(err, "no new contacts with images received")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().NotNil(contacts)
|
||||||
|
|
||||||
|
// Check if alice's contact data with profile picture is there
|
||||||
|
var contact *Contact
|
||||||
|
for _, c := range contacts {
|
||||||
|
if c.ID == alice.IdentityPublicKeyString() {
|
||||||
|
contact = c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s.Require().NotNil(contact)
|
||||||
|
|
||||||
|
// Check that Bob now has Alice's profile picture(s)
|
||||||
|
switch args.chatContext {
|
||||||
|
case publicChat:
|
||||||
|
// In public chat context we only need the images.SmallDimName, but also may have the large
|
||||||
|
s.Require().GreaterOrEqual(len(contact.Images), 1)
|
||||||
|
s.Require().Contains(contact.Images, images.SmallDimName)
|
||||||
|
s.Require().Equal(iis[images.SmallDimName].Payload, contact.Images[images.SmallDimName].Payload)
|
||||||
|
|
||||||
|
case privateChat:
|
||||||
|
s.Require().Equal(len(contact.Images), 2)
|
||||||
|
s.Require().Contains(contact.Images, images.SmallDimName)
|
||||||
|
s.Require().Contains(contact.Images, images.LargeDimName)
|
||||||
|
s.Require().Equal(iis[images.SmallDimName].Payload, contact.Images[images.SmallDimName].Payload)
|
||||||
|
s.Require().Equal(iis[images.LargeDimName].Payload, contact.Images[images.LargeDimName].Payload)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type e2eArgs struct {
|
||||||
|
chatContext ChatContext
|
||||||
|
showToType settings.ProfilePicturesShowToType
|
||||||
|
visibilityType settings.ProfilePicturesVisibilityType
|
||||||
|
aliceContact bool
|
||||||
|
bobContact bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (args *e2eArgs) String() string {
|
||||||
|
return fmt.Sprintf("ChatContext: %s, ShowTo: %s, Visibility: %s, AliceContact: %t, BobContact: %t",
|
||||||
|
string(args.chatContext),
|
||||||
|
profilePicShowSettingsMap[args.showToType],
|
||||||
|
profilePicViewSettingsMap[args.visibilityType],
|
||||||
|
args.aliceContact,
|
||||||
|
args.bobContact,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (args *e2eArgs) TestCaseName(t *testing.T) string {
|
||||||
|
expected, err := args.resultExpected()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s-%s-%s-ac.%t-bc.%t-exp.%t",
|
||||||
|
string(args.chatContext),
|
||||||
|
profilePicShowSettingsMap[args.showToType],
|
||||||
|
profilePicViewSettingsMap[args.visibilityType],
|
||||||
|
args.aliceContact,
|
||||||
|
args.bobContact,
|
||||||
|
expected,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (args *e2eArgs) resultExpected() (bool, error) {
|
||||||
|
switch args.showToType {
|
||||||
case settings.ProfilePicturesShowToContactsOnly:
|
case settings.ProfilePicturesShowToContactsOnly:
|
||||||
if ac {
|
if args.aliceContact {
|
||||||
return resultExpectedVS(vs, bc)
|
return args.resultExpectedVS()
|
||||||
}
|
}
|
||||||
return false, nil
|
return false, nil
|
||||||
case settings.ProfilePicturesShowToEveryone:
|
case settings.ProfilePicturesShowToEveryone:
|
||||||
return resultExpectedVS(vs, bc)
|
return args.resultExpectedVS()
|
||||||
case settings.ProfilePicturesShowToNone:
|
case settings.ProfilePicturesShowToNone:
|
||||||
return false, nil
|
return false, nil
|
||||||
default:
|
default:
|
||||||
@ -526,16 +505,28 @@ func resultExpected(ss settings.ProfilePicturesShowToType, vs settings.ProfilePi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func resultExpectedVS(vs settings.ProfilePicturesVisibilityType, bc bool) (bool, error) {
|
func (args *e2eArgs) resultExpectedVS() (bool, error) {
|
||||||
switch vs {
|
switch args.visibilityType {
|
||||||
case settings.ProfilePicturesVisibilityContactsOnly:
|
case settings.ProfilePicturesVisibilityContactsOnly:
|
||||||
return true, nil
|
return true, nil
|
||||||
case settings.ProfilePicturesVisibilityEveryone:
|
case settings.ProfilePicturesVisibilityEveryone:
|
||||||
return true, nil
|
return true, nil
|
||||||
case settings.ProfilePicturesVisibilityNone:
|
case settings.ProfilePicturesVisibilityNone:
|
||||||
// If we are contacts, we save the image regardless
|
// If we are contacts, we save the image regardless
|
||||||
return bc, nil
|
return args.bobContact, nil
|
||||||
default:
|
default:
|
||||||
return false, errors.New("unknown ProfilePicturesVisibilityType")
|
return false, errors.New("unknown ProfilePicturesVisibilityType")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var profilePicShowSettingsMap = map[settings.ProfilePicturesShowToType]string{
|
||||||
|
settings.ProfilePicturesShowToContactsOnly: "ShowToContactsOnly",
|
||||||
|
settings.ProfilePicturesShowToEveryone: "ShowToEveryone",
|
||||||
|
settings.ProfilePicturesShowToNone: "ShowToNone",
|
||||||
|
}
|
||||||
|
|
||||||
|
var profilePicViewSettingsMap = map[settings.ProfilePicturesVisibilityType]string{
|
||||||
|
settings.ProfilePicturesVisibilityContactsOnly: "ViewFromContactsOnly",
|
||||||
|
settings.ProfilePicturesVisibilityEveryone: "ViewFromEveryone",
|
||||||
|
settings.ProfilePicturesVisibilityNone: "ViewFromNone",
|
||||||
|
}
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
|
|
||||||
|
"github.com/waku-org/go-waku/waku/v2/api/publish"
|
||||||
v2protocol "github.com/waku-org/go-waku/waku/v2/protocol"
|
v2protocol "github.com/waku-org/go-waku/waku/v2/protocol"
|
||||||
"github.com/waku-org/go-waku/waku/v2/protocol/pb"
|
"github.com/waku-org/go-waku/waku/v2/protocol/pb"
|
||||||
|
|
||||||
@ -25,7 +26,6 @@ import (
|
|||||||
"github.com/status-im/status-go/protocol/tt"
|
"github.com/status-im/status-go/protocol/tt"
|
||||||
v1protocol "github.com/status-im/status-go/protocol/v1"
|
v1protocol "github.com/status-im/status-go/protocol/v1"
|
||||||
"github.com/status-im/status-go/wakuv2"
|
"github.com/status-im/status-go/wakuv2"
|
||||||
"github.com/waku-org/go-waku/waku/v2/api/publish"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -11,11 +11,12 @@ import (
|
|||||||
"golang.org/x/exp/maps"
|
"golang.org/x/exp/maps"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
|
||||||
"github.com/waku-org/go-waku/waku/v2/payload"
|
"github.com/waku-org/go-waku/waku/v2/payload"
|
||||||
"github.com/waku-org/go-waku/waku/v2/protocol"
|
"github.com/waku-org/go-waku/waku/v2/protocol"
|
||||||
"github.com/waku-org/go-waku/waku/v2/protocol/pb"
|
"github.com/waku-org/go-waku/waku/v2/protocol/pb"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
const testShard = "/waku/2/rs/16/32"
|
const testShard = "/waku/2/rs/16/32"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user