Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/migrate tests to wakuv2 #6328

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions protocol/common/message_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
transport2 "github.com/status-im/status-go/protocol/transport"
"github.com/status-im/status-go/t/helpers"
wakutypes "github.com/status-im/status-go/waku/types"
"github.com/status-im/status-go/wakuv1"
"github.com/status-im/status-go/wakuv2"

"github.com/libp2p/go-libp2p/core/peer"

"github.com/golang/protobuf/proto"

Expand Down Expand Up @@ -67,9 +69,18 @@ func (s *MessageSenderSuite) SetupTest() {
s.logger,
)

wakuConfig := wakuv1.DefaultConfig
wakuConfig.MinimumAcceptedPoW = 0
shh := wakuv1.New(&wakuConfig, s.logger)
wakuConfig := wakuv2.DefaultConfig
shh, err := wakuv2.New(
nil,
"",
&wakuConfig,
s.logger,
database,
nil,
func([]byte, peer.ID, error) {},
nil,
)
s.Require().NoError(err)
s.Require().NoError(shh.Start())

whisperTransport, err := transport2.NewTransport(
Expand Down
7 changes: 1 addition & 6 deletions protocol/communities_events_eventual_consistency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/requests"
"github.com/status-im/status-go/protocol/tt"
"github.com/status-im/status-go/wakuv1"
)

func TestCommunityEventsEventualConsistencySuite(t *testing.T) {
Expand All @@ -30,12 +29,8 @@ func (s *CommunityEventsEventualConsistencySuite) SetupTest() {
s.accountsPasswords = make(map[string]string)
s.mockedBalances = createMockedWalletBalance(&s.Suite)

config := wakuv1.DefaultConfig
config.MinimumAcceptedPoW = 0
shh := wakuv1.New(&config, s.logger)
wakuWrapper, err := newTestWakuWrapper(&config, s.logger)
wakuWrapper, err := newTestWakuWrapper(s.logger)
s.Require().NoError(err)
s.Require().NoError(shh.Start())
s.shh = wakuWrapper

s.messagesOrderController = NewMessagesOrderController(messagesOrderRandom)
Expand Down
2 changes: 1 addition & 1 deletion protocol/communities_messenger_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func defaultTestCommunitiesMessengerSettings() *settings.Settings {
SendPushNotifications: true,
ProfilePicturesVisibility: 1,
DefaultSyncPeriod: 777600,
UseMailservers: true,
UseMailservers: false,
LinkPreviewRequestEnabled: true,
SendStatusUpdates: true,
WalletRootAddress: types.HexToAddress("0x1122334455667788990011223344556677889900")}
Expand Down
1 change: 0 additions & 1 deletion protocol/communities_messenger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,6 @@ func (s *MessengerCommunitiesSuite) TestPostToCommunityChat() {
s.Require().NoError(err)
s.Require().Len(response.Messages(), 1)
s.Require().Equal(inputMessage.Text, response.Messages()[0].Text)
s.Require().Equal(s.alice.account.GetCustomizationColor(), response.Contacts[0].CustomizationColor)

// check if response contains the chat we're interested in
// we use this instead of checking just the length of the chat because
Expand Down
19 changes: 14 additions & 5 deletions protocol/communities_messenger_test_suite_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/ecdsa"
"math/big"

"github.com/libp2p/go-libp2p/core/peer"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"

Expand All @@ -16,7 +17,7 @@ import (
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/requests"
"github.com/status-im/status-go/protocol/tt"
"github.com/status-im/status-go/wakuv1"
"github.com/status-im/status-go/wakuv2"

wakutypes "github.com/status-im/status-go/waku/types"
)
Expand Down Expand Up @@ -48,11 +49,19 @@ func (s *CommunitiesMessengerTestSuiteBase) SetupTest() {

s.mockedBalances = make(communities.BalancesByChain)

config := wakuv1.DefaultConfig
config.MinimumAcceptedPoW = 0
shh := wakuv1.New(&config, s.logger)
s.shh = shh
shh, err := wakuv2.New(
nil,
"",
&wakuv2.DefaultConfig,
s.logger,
nil,
nil,
func([]byte, peer.ID, error) {},
nil,
)
s.Require().NoError(err)
s.Require().NoError(shh.Start())
s.shh = shh
}

func (s *CommunitiesMessengerTestSuiteBase) TearDownTest() {
Expand Down
20 changes: 14 additions & 6 deletions protocol/messenger_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package protocol
import (
"crypto/ecdsa"

"github.com/libp2p/go-libp2p/core/peer"
"github.com/stretchr/testify/suite"

"go.uber.org/zap"
Expand All @@ -11,7 +12,7 @@ import (
"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/wakuv1"
"github.com/status-im/status-go/wakuv2"

wakutypes "github.com/status-im/status-go/waku/types"
)
Expand All @@ -20,12 +21,19 @@ const DefaultProfileDisplayName = ""

func (s *MessengerBaseTestSuite) SetupTest() {
s.logger = tt.MustCreateTestLogger()

config := wakuv1.DefaultConfig
config.MinimumAcceptedPoW = 0
shh := wakuv1.New(&config, s.logger)
s.shh = shh
shh, err := wakuv2.New(
nil,
"",
&wakuv2.DefaultConfig,
s.logger,
nil,
nil,
func([]byte, peer.ID, error) {},
nil,
)
s.Require().NoError(err)
s.Require().NoError(shh.Start())
s.shh = shh

s.m = s.newMessenger()
s.privateKey = s.m.identity
Expand Down
5 changes: 5 additions & 0 deletions protocol/messenger_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ func newTestMessenger(waku wakutypes.Waku, config testMessengerConfig) (*Messeng
m.retrievedMessagesIteratorFactory = config.messagesOrderController.newMessagesIterator
}

err = m.settings.SetUseMailservers(false)
if err != nil {
return nil, err
}

err = m.InitInstallations()
if err != nil {
return nil, err
Expand Down
19 changes: 14 additions & 5 deletions protocol/messenger_delete_message_for_me_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"testing"

"github.com/libp2p/go-libp2p/core/peer"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"

Expand All @@ -14,7 +15,7 @@ import (
"github.com/status-im/status-go/protocol/encryption/multidevice"
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/tt"
"github.com/status-im/status-go/wakuv1"
"github.com/status-im/status-go/wakuv2"

wakutypes "github.com/status-im/status-go/waku/types"
)
Expand Down Expand Up @@ -59,11 +60,19 @@ func (s *MessengerDeleteMessageForMeSuite) otherNewMessenger() *Messenger {
func (s *MessengerDeleteMessageForMeSuite) SetupTest() {
s.logger = tt.MustCreateTestLogger()

config := wakuv1.DefaultConfig
config.MinimumAcceptedPoW = 0
shh := wakuv1.New(&config, s.logger)
s.shh = shh
shh, err := wakuv2.New(
nil,
"",
&wakuv2.DefaultConfig,
s.logger,
nil,
nil,
func([]byte, peer.ID, error) {},
nil,
)
s.Require().NoError(err)
s.Require().NoError(shh.Start())
s.shh = shh

s.alice1 = s.newMessenger()
s.alice2 = s.newMessenger()
Expand Down
21 changes: 14 additions & 7 deletions protocol/messenger_identity_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/cenkalti/backoff/v3"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"
Expand All @@ -21,7 +22,7 @@ import (
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/requests"
"github.com/status-im/status-go/protocol/tt"
"github.com/status-im/status-go/wakuv1"
"github.com/status-im/status-go/wakuv2"

wakutypes "github.com/status-im/status-go/waku/types"
)
Expand All @@ -44,13 +45,19 @@ type MessengerProfilePictureHandlerSuite struct {
func (s *MessengerProfilePictureHandlerSuite) SetupSuite() {
s.logger = tt.MustCreateTestLogger()

// Setup Waku things
config := wakuv1.DefaultConfig
config.MinimumAcceptedPoW = 0
wakuLogger := s.logger.Named("Waku")
shh := wakuv1.New(&config, wakuLogger)
s.shh = shh
shh, err := wakuv2.New(
nil,
"",
&wakuv2.DefaultConfig,
s.logger.Named("Waku"),
nil,
nil,
func([]byte, peer.ID, error) {},
nil,
)
s.Require().NoError(err)
s.Require().NoError(shh.Start())
s.shh = shh
}

func (s *MessengerProfilePictureHandlerSuite) TearDownSuite() {
Expand Down
21 changes: 15 additions & 6 deletions protocol/messenger_peersyncing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"
"time"

"github.com/libp2p/go-libp2p/core/peer"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"

Expand All @@ -15,7 +16,7 @@ import (
"github.com/status-im/status-go/protocol/peersyncing"
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/tt"
"github.com/status-im/status-go/wakuv1"
"github.com/status-im/status-go/wakuv2"

wakutypes "github.com/status-im/status-go/waku/types"
)
Expand All @@ -42,11 +43,19 @@ func (s *MessengerPeersyncingSuite) SetupTest() {
s.logger = tt.MustCreateTestLogger()
peerSyncingLoopInterval = 500 * time.Millisecond

config := wakuv1.DefaultConfig
config.MinimumAcceptedPoW = 0
shh := wakuv1.New(&config, s.logger)
s.shh = shh
shh, err := wakuv2.New(
nil,
"",
&wakuv2.DefaultConfig,
s.logger,
nil,
nil,
func([]byte, peer.ID, error) {},
nil,
)
s.Require().NoError(err)
s.Require().NoError(shh.Start())
s.shh = shh

s.owner = s.newMessenger()
s.bob = s.newMessenger()
Expand All @@ -66,7 +75,7 @@ func (s *MessengerPeersyncingSuite) SetupTest() {
s.accountsPasswords[common.PubkeyToHex(&s.bob.identity.PublicKey)] = bobPassword
s.accountsPasswords[common.PubkeyToHex(&s.alice.identity.PublicKey)] = aliceAddress1

_, err := s.owner.Start()
_, err = s.owner.Start()
s.Require().NoError(err)
_, err = s.bob.Start()
s.Require().NoError(err)
Expand Down
20 changes: 15 additions & 5 deletions protocol/messenger_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"context"
"testing"

"github.com/status-im/status-go/wakuv1"
"github.com/libp2p/go-libp2p/core/peer"

"github.com/status-im/status-go/wakuv2"

"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/multiaccounts/common"
Expand All @@ -27,11 +29,19 @@ type MessengerSettingsSuite struct {
func (s *MessengerSettingsSuite) SetupTest() {
s.logger = tt.MustCreateTestLogger()

config := wakuv1.DefaultConfig
config.MinimumAcceptedPoW = 0
shh := wakuv1.New(&config, s.logger)
s.shh = shh
shh, err := wakuv2.New(
nil,
"",
&wakuv2.DefaultConfig,
s.logger,
nil,
nil,
func([]byte, peer.ID, error) {},
nil,
)
s.Require().NoError(err)
s.Require().NoError(shh.Start())
s.shh = shh

pk, err := crypto.GenerateKey()
s.Require().NoError(err)
Expand Down
12 changes: 7 additions & 5 deletions protocol/messenger_status_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,15 @@ func (m *Messenger) broadcastLatestUserStatus() {
ctx := context.Background()
go func() {
defer gocommon.LogOnPanic()

select {
// Ensure that we are connected before sending a message
time.Sleep(5 * time.Second)
m.sendCurrentUserStatus(ctx)
}()
case <-time.After(5 * time.Second):
m.sendCurrentUserStatus(ctx)
case <-m.quit:
return
}

go func() {
defer gocommon.LogOnPanic()
for {
select {
case <-time.After(5 * time.Minute):
Expand Down
19 changes: 14 additions & 5 deletions protocol/messenger_sync_chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
"errors"
"testing"

"github.com/libp2p/go-libp2p/core/peer"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"

"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/encryption/multidevice"
"github.com/status-im/status-go/protocol/tt"
"github.com/status-im/status-go/wakuv1"
"github.com/status-im/status-go/wakuv2"

wakutypes "github.com/status-im/status-go/waku/types"
)
Expand Down Expand Up @@ -60,11 +61,19 @@ func (s *MessengerSyncChatSuite) otherNewMessenger() *Messenger {
func (s *MessengerSyncChatSuite) SetupTest() {
s.logger = tt.MustCreateTestLogger()

config := wakuv1.DefaultConfig
config.MinimumAcceptedPoW = 0
shh := wakuv1.New(&config, s.logger)
s.shh = shh
shh, err := wakuv2.New(
nil,
"",
&wakuv2.DefaultConfig,
s.logger,
nil,
nil,
func([]byte, peer.ID, error) {},
nil,
)
s.Require().NoError(err)
s.Require().NoError(shh.Start())
s.shh = shh

s.alice1 = s.newMessenger()
s.alice2 = s.newMessenger()
Expand Down
Loading
Loading