-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessenger_mute_test.go
109 lines (80 loc) · 2.45 KB
/
messenger_mute_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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/protocol/tt"
"github.com/status-im/status-go/waku"
)
func TestMessengerMuteSuite(t *testing.T) {
suite.Run(t, new(MessengerMuteSuite))
}
type MessengerMuteSuite 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 (s *MessengerMuteSuite) 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.shh)
s.privateKey = s.m.identity
_, err := s.m.Start()
s.Require().NoError(err)
}
func (s *MessengerMuteSuite) TearDownTest() {
s.Require().NoError(s.m.Shutdown())
}
func (s *MessengerMuteSuite) newMessenger(shh types.Waku) *Messenger {
privateKey, err := crypto.GenerateKey()
s.Require().NoError(err)
messenger, err := newMessengerWithKey(s.shh, privateKey, s.logger, nil)
s.Require().NoError(err)
return messenger
}
func (s *MessengerMuteSuite) TestSetMute() {
key, err := crypto.GenerateKey()
s.Require().NoError(err)
theirMessenger, err := newMessengerWithKey(s.shh, key, s.logger, nil)
s.Require().NoError(err)
chatID := "status"
chat := CreatePublicChat(chatID, s.m.transport)
err = s.m.SaveChat(chat)
s.Require().NoError(err)
_, err = s.m.Join(chat)
s.Require().NoError(err)
err = theirMessenger.SaveChat(chat)
s.Require().NoError(err)
s.Require().NoError(s.m.MuteChat(chatID))
allChats := s.m.Chats()
s.Require().Len(allChats, 3)
var actualChat *Chat
for idx := range allChats {
if chat.ID == allChats[idx].ID {
actualChat = allChats[idx]
}
}
s.Require().NotNil(actualChat)
s.Require().True(actualChat.Muted)
s.Require().NoError(s.m.UnmuteChat(chatID))
allChats = s.m.Chats()
for idx := range allChats {
if chat.ID == allChats[idx].ID {
actualChat = allChats[idx]
}
}
s.Require().False(actualChat.Muted)
s.Require().NoError(theirMessenger.Shutdown())
}