From 279c395f23f60e3b025eb5efe449f321842f8337 Mon Sep 17 00:00:00 2001 From: Samuel Hawksby-Robinson Date: Wed, 2 Dec 2020 14:00:28 +0000 Subject: [PATCH] Added heavy logging to the chat identity builder --- protocol/messenger.go | 17 +++++++++++++++++ protocol/messenger_test.go | 22 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/protocol/messenger.go b/protocol/messenger.go index a5ebbaa4c..b5943269e 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -6,6 +6,8 @@ import ( "crypto/sha256" "database/sql" "encoding/hex" + "encoding/json" + "fmt" "io/ioutil" "math" "math/rand" @@ -17,6 +19,7 @@ import ( "github.com/pkg/errors" "go.uber.org/zap" + "github.com/davecgh/go-spew/spew" "github.com/golang/protobuf/proto" gethcrypto "github.com/ethereum/go-ethereum/crypto" @@ -573,6 +576,9 @@ func (m *Messenger) createChatIdentity(context string) (*protobuf.ChatIdentity, keyUIDBytes := sha256.Sum256(gethcrypto.FromECDSAPub(&m.identity.PublicKey)) keyUID := types.EncodeHex(keyUIDBytes[:]) + m.logger.Info(fmt.Sprintf("generated keyUID '%s' from PublicKey", keyUID)) + m.logger.Info(fmt.Sprintf("context '%s'", context)) + ci := &protobuf.ChatIdentity{ Clock: m.transport.GetCurrentTime(), EnsName: "", // TODO add ENS name handling to dedicate PR @@ -582,23 +588,34 @@ func (m *Messenger) createChatIdentity(context string) (*protobuf.ChatIdentity, switch context { case "public-chat": + m.logger.Info(fmt.Sprintf("handling public-chat ChatIdentity")) + img, err := m.multiAccounts.GetIdentityImage(keyUID, userimage.SmallDimName) if err != nil { return nil, err } + imgJson, _ := json.Marshal(img) + m.logger.Info(fmt.Sprintf("public-chat images.IdentityImage '%s' '%s'", string(imgJson), spew.Sdump(img))) + ciis[userimage.SmallDimName] = m.adaptIdentityImageToProtobuf(img) + m.logger.Info(fmt.Sprintf("public-chat protobuf.IdentityImage '%s'", spew.Sdump(ciis))) ci.Images = ciis case "private-chat": + m.logger.Info(fmt.Sprintf("handling private-chat ChatIdentity")) imgs, err := m.multiAccounts.GetIdentityImages(keyUID) if err != nil { return nil, err } + imgsJson, _ := json.Marshal(imgs) + m.logger.Info(fmt.Sprintf("private-chat images.IdentityImage '%s' '%s'", string(imgsJson), spew.Sdump(imgs))) + for _, img := range imgs { ciis[img.Name] = m.adaptIdentityImageToProtobuf(img) } + m.logger.Info(fmt.Sprintf("private-chat protobuf.IdentityImage '%s'", spew.Sdump(ciis))) ci.Images = ciis } diff --git a/protocol/messenger_test.go b/protocol/messenger_test.go index 91f24d61b..29ccc2e78 100644 --- a/protocol/messenger_test.go +++ b/protocol/messenger_test.go @@ -3,6 +3,7 @@ package protocol import ( "context" "crypto/ecdsa" + "crypto/sha256" "encoding/hex" "encoding/json" "errors" @@ -13,16 +14,19 @@ import ( "testing" "time" + "github.com/davecgh/go-spew/spew" "github.com/google/uuid" _ "github.com/mutecomm/go-sqlcipher" // require go-sqlcipher that overrides default implementation "github.com/stretchr/testify/suite" "go.uber.org/zap" + gethcrypto "github.com/ethereum/go-ethereum/crypto" gethbridge "github.com/status-im/status-go/eth-node/bridge/geth" coretypes "github.com/status-im/status-go/eth-node/core/types" "github.com/status-im/status-go/eth-node/crypto" "github.com/status-im/status-go/eth-node/types" enstypes "github.com/status-im/status-go/eth-node/types/ens" + "github.com/status-im/status-go/images" "github.com/status-im/status-go/multiaccounts" "github.com/status-im/status-go/protocol/common" "github.com/status-im/status-go/protocol/protobuf" @@ -2519,3 +2523,21 @@ func WaitOnMessengerResponse(m *Messenger, condition func(*MessengerResponse) bo return err }) } + +func (s *MessengerSuite) TestChatIdentity() { + keyUIDBytes := sha256.Sum256(gethcrypto.FromECDSAPub(&s.m.identity.PublicKey)) + keyUID := types.EncodeHex(keyUIDBytes[:]) + + err := s.m.multiAccounts.SaveAccount(multiaccounts.Account{Name: "string", KeyUID: keyUID}) + s.Require().NoError(err) + + iis := images.SampleIdentityImages() + s.Require().NoError(s.m.multiAccounts.StoreIdentityImages(keyUID, iis)) + + ci, err := s.m.createChatIdentity("private-chat") + s.Require().NoError(err) + + s.Require().Exactly(len(iis), len(ci.Images)) + + spew.Dump(ci, len(ci.Images)) +}