Added heavy logging to the chat identity builder

This commit is contained in:
Samuel Hawksby-Robinson 2020-12-02 14:00:28 +00:00 committed by Andrea Maria Piana
parent fe9e04ca13
commit 279c395f23
2 changed files with 39 additions and 0 deletions

View File

@ -6,6 +6,8 @@ import (
"crypto/sha256" "crypto/sha256"
"database/sql" "database/sql"
"encoding/hex" "encoding/hex"
"encoding/json"
"fmt"
"io/ioutil" "io/ioutil"
"math" "math"
"math/rand" "math/rand"
@ -17,6 +19,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"go.uber.org/zap" "go.uber.org/zap"
"github.com/davecgh/go-spew/spew"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
gethcrypto "github.com/ethereum/go-ethereum/crypto" 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)) keyUIDBytes := sha256.Sum256(gethcrypto.FromECDSAPub(&m.identity.PublicKey))
keyUID := types.EncodeHex(keyUIDBytes[:]) 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{ ci := &protobuf.ChatIdentity{
Clock: m.transport.GetCurrentTime(), Clock: m.transport.GetCurrentTime(),
EnsName: "", // TODO add ENS name handling to dedicate PR EnsName: "", // TODO add ENS name handling to dedicate PR
@ -582,23 +588,34 @@ func (m *Messenger) createChatIdentity(context string) (*protobuf.ChatIdentity,
switch context { switch context {
case "public-chat": case "public-chat":
m.logger.Info(fmt.Sprintf("handling public-chat ChatIdentity"))
img, err := m.multiAccounts.GetIdentityImage(keyUID, userimage.SmallDimName) img, err := m.multiAccounts.GetIdentityImage(keyUID, userimage.SmallDimName)
if err != nil { if err != nil {
return nil, err 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) ciis[userimage.SmallDimName] = m.adaptIdentityImageToProtobuf(img)
m.logger.Info(fmt.Sprintf("public-chat protobuf.IdentityImage '%s'", spew.Sdump(ciis)))
ci.Images = ciis ci.Images = ciis
case "private-chat": case "private-chat":
m.logger.Info(fmt.Sprintf("handling private-chat ChatIdentity"))
imgs, err := m.multiAccounts.GetIdentityImages(keyUID) imgs, err := m.multiAccounts.GetIdentityImages(keyUID)
if err != nil { if err != nil {
return nil, err 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 { for _, img := range imgs {
ciis[img.Name] = m.adaptIdentityImageToProtobuf(img) ciis[img.Name] = m.adaptIdentityImageToProtobuf(img)
} }
m.logger.Info(fmt.Sprintf("private-chat protobuf.IdentityImage '%s'", spew.Sdump(ciis)))
ci.Images = ciis ci.Images = ciis
} }

View File

@ -3,6 +3,7 @@ package protocol
import ( import (
"context" "context"
"crypto/ecdsa" "crypto/ecdsa"
"crypto/sha256"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"errors" "errors"
@ -13,16 +14,19 @@ import (
"testing" "testing"
"time" "time"
"github.com/davecgh/go-spew/spew"
"github.com/google/uuid" "github.com/google/uuid"
_ "github.com/mutecomm/go-sqlcipher" // require go-sqlcipher that overrides default implementation _ "github.com/mutecomm/go-sqlcipher" // require go-sqlcipher that overrides default implementation
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"go.uber.org/zap" "go.uber.org/zap"
gethcrypto "github.com/ethereum/go-ethereum/crypto"
gethbridge "github.com/status-im/status-go/eth-node/bridge/geth" gethbridge "github.com/status-im/status-go/eth-node/bridge/geth"
coretypes "github.com/status-im/status-go/eth-node/core/types" 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/crypto"
"github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/eth-node/types"
enstypes "github.com/status-im/status-go/eth-node/types/ens" 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/multiaccounts"
"github.com/status-im/status-go/protocol/common" "github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/protobuf" "github.com/status-im/status-go/protocol/protobuf"
@ -2519,3 +2523,21 @@ func WaitOnMessengerResponse(m *Messenger, condition func(*MessengerResponse) bo
return err 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))
}