Added heavy logging to the chat identity builder
This commit is contained in:
parent
fe9e04ca13
commit
279c395f23
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue