status-go/protocol/messenger_base_test.go

91 lines
2.3 KiB
Go
Raw Normal View History

2023-03-08 17:47:09 +00:00
package protocol
import (
"crypto/ecdsa"
"testing"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"
gethbridge "github.com/status-im/status-go/eth-node/bridge/geth"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/multiaccounts/settings"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/protocol/tt"
"github.com/status-im/status-go/waku"
)
const DefaultProfileDisplayName = ""
2023-03-08 17:47:09 +00:00
func TestMessengerCollapsedComunityCategoriesSuite(t *testing.T) {
suite.Run(t, new(MessengerCollapsedCommunityCategoriesSuite))
}
func (s *MessengerBaseTestSuite) SetupTest() {
s.logger = tt.MustCreateTestLogger()
config := waku.DefaultConfig
config.MinimumAcceptedPoW = 0
shh := waku.New(&config, s.logger)
s.shh = gethbridge.NewGethWakuWrapper(shh)
s.Require().NoError(shh.Start())
s.m = s.newMessenger()
s.privateKey = s.m.identity
}
func (s *MessengerBaseTestSuite) TearDownTest() {
TearDownMessenger(&s.Suite, s.m)
2023-03-08 17:47:09 +00:00
_ = s.logger.Sync()
}
func (s *MessengerBaseTestSuite) newMessenger() *Messenger {
privateKey, err := crypto.GenerateKey()
s.Require().NoError(err)
messenger, err := newMessengerWithKey(s.shh, privateKey, s.logger, nil)
s.Require().NoError(err)
return messenger
}
type MessengerBaseTestSuite struct {
suite.Suite
m *Messenger // main instance of Messenger
privateKey *ecdsa.PrivateKey // private key for the main instance of Messenger
// If one wants to send messages between different instances of Messenger,
// a single waku service should be shared.
shh types.Waku
logger *zap.Logger
}
func newMessengerWithKey(shh types.Waku, privateKey *ecdsa.PrivateKey, logger *zap.Logger, extraOptions []Option) (*Messenger, error) {
options := []Option{
WithAppSettings(settings.Settings{
DisplayName: DefaultProfileDisplayName,
2023-03-08 17:47:09 +00:00
ProfilePicturesShowTo: 1,
ProfilePicturesVisibility: 1,
2023-10-13 14:31:56 +00:00
URLUnfurlingMode: settings.URLUnfurlingAlwaysAsk,
2023-03-08 17:47:09 +00:00
}, params.NodeConfig{}),
}
options = append(options, extraOptions...)
m, err := newTestMessenger(shh, testMessengerConfig{
privateKey: privateKey,
logger: logger,
}, options)
2023-03-08 17:47:09 +00:00
if err != nil {
return nil, err
}
m.EnableBackedupMessagesProcessing()
2023-03-08 17:47:09 +00:00
_, err = m.Start()
if err != nil {
return nil, err
}
return m, nil
}