2023-03-08 17:47:09 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/account/generator"
|
2023-08-11 11:28:45 +00:00
|
|
|
"github.com/status-im/status-go/appdatabase"
|
2023-03-08 17:47:09 +00:00
|
|
|
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"
|
|
|
|
"github.com/status-im/status-go/multiaccounts/settings"
|
|
|
|
"github.com/status-im/status-go/params"
|
|
|
|
"github.com/status-im/status-go/protocol/tt"
|
2023-08-11 11:28:45 +00:00
|
|
|
"github.com/status-im/status-go/t/helpers"
|
2023-03-08 17:47:09 +00:00
|
|
|
"github.com/status-im/status-go/waku"
|
2023-08-11 11:28:45 +00:00
|
|
|
"github.com/status-im/status-go/walletdatabase"
|
2023-03-08 17:47:09 +00:00
|
|
|
)
|
|
|
|
|
2023-05-24 14:42:31 +00:00
|
|
|
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
|
|
|
|
_, err := s.m.Start()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerBaseTestSuite) TearDownTest() {
|
|
|
|
s.Require().NoError(s.m.Shutdown())
|
|
|
|
_ = 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) {
|
|
|
|
tmpfile, err := ioutil.TempFile("", "accounts-tests-")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
madb, err := multiaccounts.InitializeDB(tmpfile.Name())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
acc := generator.NewAccount(privateKey, nil)
|
|
|
|
iai := acc.ToIdentifiedAccountInfo("")
|
|
|
|
|
2023-08-11 11:28:45 +00:00
|
|
|
walletDb, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
appDb, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-03-08 17:47:09 +00:00
|
|
|
options := []Option{
|
|
|
|
WithCustomLogger(logger),
|
2023-08-11 11:28:45 +00:00
|
|
|
WithDatabase(appDb),
|
|
|
|
WithWalletDatabase(walletDb),
|
2023-03-08 17:47:09 +00:00
|
|
|
WithMultiAccounts(madb),
|
|
|
|
WithAccount(iai.ToMultiAccount()),
|
|
|
|
WithDatasync(),
|
|
|
|
WithToplevelDatabaseMigrations(),
|
|
|
|
WithAppSettings(settings.Settings{
|
2023-05-24 14:42:31 +00:00
|
|
|
DisplayName: DefaultProfileDisplayName,
|
2023-03-08 17:47:09 +00:00
|
|
|
ProfilePicturesShowTo: 1,
|
|
|
|
ProfilePicturesVisibility: 1,
|
|
|
|
}, params.NodeConfig{}),
|
|
|
|
WithBrowserDatabase(nil),
|
|
|
|
}
|
|
|
|
|
|
|
|
options = append(options, extraOptions...)
|
|
|
|
|
|
|
|
m, err := NewMessenger(
|
|
|
|
"Test",
|
|
|
|
privateKey,
|
|
|
|
&testNode{shh: shh},
|
|
|
|
uuid.New().String(),
|
|
|
|
nil,
|
2023-03-10 12:53:40 +00:00
|
|
|
nil,
|
2023-03-08 17:47:09 +00:00
|
|
|
options...,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = m.Init()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-07-20 10:08:57 +00:00
|
|
|
m.EnableBackedupMessagesProcessing()
|
|
|
|
|
2023-03-08 17:47:09 +00:00
|
|
|
_, err = m.Start()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return m, nil
|
|
|
|
}
|