github.com/status-im/status-go@v1.1.0/protocol/communities_events_token_master_test.go (about) 1 package protocol 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/suite" 7 8 "github.com/status-im/status-go/protocol/common" 9 "github.com/status-im/status-go/protocol/communities/token" 10 "github.com/status-im/status-go/protocol/protobuf" 11 ) 12 13 func TestTokenMasterCommunityEventsSuite(t *testing.T) { 14 suite.Run(t, new(TokenMasterCommunityEventsSuite)) 15 } 16 17 type TokenMasterCommunityEventsSuite struct { 18 EventSenderCommunityEventsSuiteBase 19 } 20 21 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterEditCommunityDescription() { 22 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 23 editCommunityDescription(s, community) 24 } 25 26 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterCreateEditDeleteChannels() { 27 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 28 testCreateEditDeleteChannels(s, community) 29 } 30 31 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterCreateEditDeleteBecomeMemberPermission() { 32 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 33 testCreateEditDeleteBecomeMemberPermission(s, community, protobuf.CommunityTokenPermission_BECOME_MEMBER) 34 } 35 36 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterCannotCreateBecomeAdminPermission() { 37 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 38 testEventSenderCannotCreatePrivilegedCommunityPermission(s, community, protobuf.CommunityTokenPermission_BECOME_ADMIN) 39 } 40 41 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterCannotCreateBecomeTokenMasterPermission() { 42 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 43 testEventSenderCannotCreatePrivilegedCommunityPermission(s, community, protobuf.CommunityTokenPermission_BECOME_TOKEN_MASTER) 44 } 45 46 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterCannotEditBecomeAdminPermission() { 47 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 48 testEventSenderCannotEditPrivilegedCommunityPermission( 49 s, community, protobuf.CommunityTokenPermission_BECOME_ADMIN, protobuf.CommunityTokenPermission_BECOME_TOKEN_MASTER) 50 } 51 52 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterCannotEditBecomeTokenMasterPermission() { 53 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 54 testEventSenderCannotEditPrivilegedCommunityPermission( 55 s, community, protobuf.CommunityTokenPermission_BECOME_TOKEN_MASTER, protobuf.CommunityTokenPermission_BECOME_TOKEN_MASTER) 56 } 57 58 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterCannotDeleteBecomeAdminPermission() { 59 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 60 testEventSenderCannotDeletePrivilegedCommunityPermission( 61 s, community, protobuf.CommunityTokenPermission_BECOME_ADMIN, protobuf.CommunityTokenPermission_BECOME_TOKEN_MASTER) 62 } 63 64 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterCannotDeleteBecomeTokenMasterPermission() { 65 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 66 testEventSenderCannotDeletePrivilegedCommunityPermission( 67 s, community, protobuf.CommunityTokenPermission_BECOME_TOKEN_MASTER, protobuf.CommunityTokenPermission_BECOME_TOKEN_MASTER) 68 } 69 70 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterAcceptMemberRequestToJoin() { 71 community := setUpOnRequestCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER, []*Messenger{}) 72 // set up additional user that will send request to join 73 user := s.newMessenger("somePassword", []string{"0x0123400000000000000000000000000000000000"}) 74 s.SetupAdditionalMessengers([]*Messenger{user}) 75 76 testAcceptMemberRequestToJoin(s, community, user) 77 } 78 79 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterAcceptMemberRequestToJoinResponseSharedWithOtherEventSenders() { 80 additionalTokenMaster := s.newMessenger("qwerty", []string{eventsSenderAccountAddress}) 81 community := setUpOnRequestCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER, []*Messenger{additionalTokenMaster}) 82 83 // set up additional user that will send request to join 84 user := s.newMessenger("somePassword", []string{"0x0123400000000000000000000000000000000000"}) 85 s.SetupAdditionalMessengers([]*Messenger{user}) 86 87 testAcceptMemberRequestToJoinResponseSharedWithOtherEventSenders(s, community, user, additionalTokenMaster) 88 } 89 90 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterRejectMemberRequestToJoinResponseSharedWithOtherEventSenders() { 91 additionalTokenMaster := s.newMessenger("qwerty", []string{eventsSenderAccountAddress}) 92 community := setUpOnRequestCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER, []*Messenger{additionalTokenMaster}) 93 // set up additional user that will send request to join 94 user := s.newMessenger("somePassword", []string{"0x0123400000000000000000000000000000000000"}) 95 s.SetupAdditionalMessengers([]*Messenger{user}) 96 97 testRejectMemberRequestToJoinResponseSharedWithOtherEventSenders(s, community, user, additionalTokenMaster) 98 } 99 100 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterRejectMemberRequestToJoin() { 101 community := setUpOnRequestCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER, []*Messenger{}) 102 // set up additional user that will send request to join 103 user := s.newMessenger("somePassword", []string{"0x0123400000000000000000000000000000000000"}) 104 s.SetupAdditionalMessengers([]*Messenger{user}) 105 106 testRejectMemberRequestToJoin(s, community, user) 107 } 108 109 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterControlNodeHandlesMultipleEventSenderRequestToJoinDecisions() { 110 s.T().Skip("flaky test") 111 112 additionalTokenMaster := s.newMessenger("qwerty", []string{eventsSenderAccountAddress}) 113 community := setUpOnRequestCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER, []*Messenger{additionalTokenMaster}) 114 115 // set up additional user that will send request to join 116 user := s.newMessenger("somePassword", []string{"0x0123400000000000000000000000000000000000"}) 117 testControlNodeHandlesMultipleEventSenderRequestToJoinDecisions(s, community, user, additionalTokenMaster) 118 } 119 120 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterCreateEditDeleteCategories() { 121 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 122 testCreateEditDeleteCategories(s, community) 123 } 124 125 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterReorderChannelsAndCategories() { 126 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 127 testReorderChannelsAndCategories(s, community) 128 } 129 130 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterKickOwnerWithoutCommunityKey() { 131 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 132 testEventSenderKickTheSameRole(s, community) 133 } 134 135 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterKickControlNode() { 136 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 137 testEventSenderKickControlNode(s, community) 138 } 139 140 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterKickMember() { 141 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 142 kickMember(s, community.ID(), common.PubkeyToHex(&s.alice.identity.PublicKey)) 143 } 144 145 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterBanOwnerWithoutCommunityKey() { 146 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 147 testOwnerBanTheSameRole(s, community) 148 } 149 150 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterBanControlNode() { 151 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 152 testOwnerBanControlNode(s, community) 153 } 154 155 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterBanUnbanMember() { 156 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 157 testBanUnbanMember(s, community) 158 } 159 160 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterDeleteAnyMessageInTheCommunity() { 161 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 162 testDeleteAnyMessageInTheCommunity(s, community) 163 } 164 165 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterPinMessage() { 166 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 167 testEventSenderPinMessage(s, community) 168 } 169 170 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterAddCommunityToken() { 171 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 172 testAddAndSyncTokenFromEventSenderByControlNode(s, community, token.CommunityLevel) 173 } 174 175 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterAddTokenMasterAndOwnerToken() { 176 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 177 testEventSenderAddTokenMasterAndOwnerToken(s, community) 178 } 179 180 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterReceiveOwnerTokenFromControlNode() { 181 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 182 testAddAndSyncOwnerTokenFromControlNode(s, community, token.OwnerLevel) 183 } 184 185 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterReceiveTokenMasterTokenFromControlNode() { 186 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 187 testAddAndSyncTokenFromControlNode(s, community, token.MasterLevel) 188 } 189 190 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterReceiveCommunityTokenFromControlNode() { 191 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 192 testAddAndSyncTokenFromControlNode(s, community, token.CommunityLevel) 193 } 194 195 func (s *TokenMasterCommunityEventsSuite) TestMemberReceiveTokenMasterEventsWhenControlNodeOffline() { 196 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 197 testMemberReceiveEventsWhenControlNodeOffline(s, community) 198 } 199 200 func (s *TokenMasterCommunityEventsSuite) TestJoinedTokenMasterReceiveRequestsToJoinWithRevealedAccounts() { 201 // event sender will receive privileged role during permission creation 202 community := setUpOnRequestCommunityAndRoles(s, protobuf.CommunityMember_ROLE_NONE, []*Messenger{}) 203 204 // set up additional user (bob) that will send request to join 205 bob := s.newMessenger(accountPassword, []string{bobAccountAddress}) 206 207 // set up additional user that will join to the community as TokenMaster 208 newPrivilegedUser := s.newMessenger(accountPassword, []string{eventsSenderAccountAddress}) 209 210 s.SetupAdditionalMessengers([]*Messenger{bob, newPrivilegedUser}) 211 testJoinedPrivilegedMemberReceiveRequestsToJoin(s, community, bob, newPrivilegedUser, protobuf.CommunityTokenPermission_BECOME_TOKEN_MASTER) 212 } 213 214 func (s *TokenMasterCommunityEventsSuite) TestReceiveRequestsToJoinWithRevealedAccountsAfterGettingTokenMasterRole() { 215 // set up additional user (bob) that will send request to join 216 bob := s.newMessenger(accountPassword, []string{bobAccountAddress}) 217 s.SetupAdditionalMessengers([]*Messenger{bob}) 218 testMemberReceiveRequestsToJoinAfterGettingNewRole(s, bob, protobuf.CommunityTokenPermission_BECOME_TOKEN_MASTER) 219 } 220 221 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterAcceptsRequestToJoinAfterMemberLeave() { 222 community := setUpOnRequestCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER, []*Messenger{}) 223 224 // set up additional user that will send request to join 225 user := s.newMessenger("somePassword", []string{"0x0123400000000000000000000000000000000000"}) 226 s.SetupAdditionalMessengers([]*Messenger{user}) 227 testPrivilegedMemberAcceptsRequestToJoinAfterMemberLeave(s, community, user) 228 } 229 230 func (s *TokenMasterCommunityEventsSuite) TestTokenMasterBanMemberWithDeletingAllMessages() { 231 community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_TOKEN_MASTER) 232 testBanMemberWithDeletingAllMessages(s, community) 233 }