2023-06-14 14:15:46 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
2023-08-04 10:28:46 +00:00
|
|
|
"math/big"
|
2023-06-14 14:15:46 +00:00
|
|
|
"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/common"
|
2023-08-04 10:28:46 +00:00
|
|
|
"github.com/status-im/status-go/protocol/communities"
|
2023-06-14 14:15:46 +00:00
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
|
|
|
"github.com/status-im/status-go/protocol/tt"
|
2023-08-04 10:28:46 +00:00
|
|
|
"github.com/status-im/status-go/services/wallet/bigint"
|
2023-06-14 14:15:46 +00:00
|
|
|
"github.com/status-im/status-go/waku"
|
|
|
|
)
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func TestAdminCommunityEventsSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(AdminCommunityEventsSuite))
|
2023-06-14 14:15:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
type AdminCommunityEventsSuite struct {
|
2023-06-14 14:15:46 +00:00
|
|
|
suite.Suite
|
|
|
|
owner *Messenger
|
|
|
|
admin *Messenger
|
|
|
|
alice *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
|
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) GetControlNode() *Messenger {
|
|
|
|
return s.owner
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AdminCommunityEventsSuite) GetEventSender() *Messenger {
|
|
|
|
return s.admin
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AdminCommunityEventsSuite) GetMember() *Messenger {
|
|
|
|
return s.alice
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AdminCommunityEventsSuite) GetSuite() *suite.Suite {
|
|
|
|
return &s.Suite
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AdminCommunityEventsSuite) SetupTest() {
|
2023-06-14 14:15:46 +00:00
|
|
|
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.owner = s.newMessenger()
|
|
|
|
s.admin = s.newMessenger()
|
|
|
|
s.alice = s.newMessenger()
|
|
|
|
_, err := s.owner.Start()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
_, err = s.admin.Start()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
_, err = s.alice.Start()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TearDownTest() {
|
2023-06-14 14:15:46 +00:00
|
|
|
s.Require().NoError(s.owner.Shutdown())
|
|
|
|
s.Require().NoError(s.admin.Shutdown())
|
|
|
|
s.Require().NoError(s.alice.Shutdown())
|
|
|
|
_ = s.logger.Sync()
|
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) newMessengerWithKey(shh types.Waku, privateKey *ecdsa.PrivateKey) *Messenger {
|
|
|
|
messenger, err := newCommunitiesTestMessenger(shh, privateKey, s.logger, nil, nil)
|
2023-06-14 14:15:46 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
return messenger
|
2023-06-14 14:15:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) newMessenger() *Messenger {
|
2023-06-14 14:15:46 +00:00
|
|
|
privateKey, err := crypto.GenerateKey()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
return s.newMessengerWithKey(s.shh, privateKey)
|
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TestAdminEditCommunityDescription() {
|
2023-06-14 14:15:46 +00:00
|
|
|
// TODO admin test: update to include edit tags, logo, banner, request to join required setting, pin setting, etc...
|
2023-07-26 12:16:50 +00:00
|
|
|
community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_ADMIN)
|
|
|
|
editCommunityDescription(s, community)
|
2023-06-14 14:15:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TestAdminCreateEditDeleteChannels() {
|
|
|
|
community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_ADMIN)
|
|
|
|
testCreateEditDeleteChannels(s, community)
|
2023-06-14 14:15:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TestAdminCreateEditDeleteBecomeMemberPermission() {
|
|
|
|
community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_ADMIN)
|
|
|
|
testCreateEditDeleteBecomeMemberPermission(s, community)
|
2023-06-14 14:15:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TestAdminCannotCreateBecomeAdminPermission() {
|
|
|
|
community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_ADMIN)
|
2023-06-14 14:15:46 +00:00
|
|
|
|
|
|
|
permissionRequest := createTestPermissionRequest(community)
|
|
|
|
permissionRequest.Type = protobuf.CommunityTokenPermission_BECOME_ADMIN
|
|
|
|
|
|
|
|
response, err := s.admin.CreateCommunityTokenPermission(permissionRequest)
|
|
|
|
s.Require().Nil(response)
|
|
|
|
s.Require().Error(err)
|
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TestAdminCannotEditBecomeAdminPermission() {
|
|
|
|
community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_ADMIN)
|
2023-07-26 16:01:19 +00:00
|
|
|
testEventSenderCannotEditBecomeAdminPermission(s, community)
|
2023-06-14 14:15:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TestAdminCannotDeleteBecomeAdminPermission() {
|
|
|
|
community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_ADMIN)
|
2023-07-26 16:01:19 +00:00
|
|
|
testEventSenderCannotDeleteBecomeAdminPermission(s, community)
|
2023-06-14 14:15:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TestAdminAcceptMemberRequestToJoin() {
|
|
|
|
community := setUpOnRequestCommunityAndRoles(s, protobuf.CommunityMember_ROLE_ADMIN)
|
2023-06-14 14:15:46 +00:00
|
|
|
|
|
|
|
// set up additional user that will send request to join
|
|
|
|
user := s.newMessenger()
|
2023-07-26 12:16:50 +00:00
|
|
|
testAcceptMemberRequestToJoin(s, community, user)
|
2023-06-14 14:15:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TestAdminRejectMemberRequestToJoin() {
|
|
|
|
community := setUpOnRequestCommunityAndRoles(s, protobuf.CommunityMember_ROLE_ADMIN)
|
2023-06-14 14:15:46 +00:00
|
|
|
|
|
|
|
// set up additional user that will send request to join
|
|
|
|
user := s.newMessenger()
|
2023-07-26 12:16:50 +00:00
|
|
|
testRejectMemberRequestToJoin(s, community, user)
|
2023-06-14 14:15:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TestAdminCreateEditDeleteCategories() {
|
|
|
|
community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_ADMIN)
|
|
|
|
testCreateEditDeleteCategories(s, community)
|
2023-06-14 14:15:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TestAdminReorderChannelsAndCategories() {
|
|
|
|
community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_ADMIN)
|
|
|
|
testReorderChannelsAndCategories(s, community)
|
2023-06-14 14:15:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TestAdminKickAdmin() {
|
|
|
|
community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_ADMIN)
|
|
|
|
testEventSenderKickTheSameRole(s, community)
|
2023-06-14 14:15:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TestOwnerKickControlNode() {
|
|
|
|
community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_ADMIN)
|
|
|
|
testEventSenderKickControlNode(s, community)
|
2023-06-14 14:15:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TestAdminKickMember() {
|
|
|
|
community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_ADMIN)
|
|
|
|
kickMember(s, community.ID(), common.PubkeyToHex(&s.alice.identity.PublicKey))
|
2023-06-14 14:15:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TestAdminBanAdmin() {
|
|
|
|
community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_ADMIN)
|
|
|
|
testOwnerBanTheSameRole(s, community)
|
2023-06-14 14:15:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TestAdminBanControlNode() {
|
|
|
|
community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_ADMIN)
|
|
|
|
testOwnerBanControlNode(s, community)
|
2023-06-14 14:15:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TestAdminBanUnbanMember() {
|
|
|
|
community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_ADMIN)
|
|
|
|
testBanUnbanMember(s, community)
|
2023-07-18 15:06:12 +00:00
|
|
|
}
|
2023-06-14 14:15:46 +00:00
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TestAdminDeleteAnyMessageInTheCommunity() {
|
|
|
|
community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_ADMIN)
|
|
|
|
testDeleteAnyMessageInTheCommunity(s, community)
|
2023-06-14 14:15:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TestAdminPinMessage() {
|
|
|
|
community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_ADMIN)
|
|
|
|
testEventSenderPinMessage(s, community)
|
2023-07-18 15:06:12 +00:00
|
|
|
}
|
|
|
|
|
2023-08-04 10:28:46 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TestAdminAddCommunityToken() {
|
|
|
|
community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_ADMIN)
|
|
|
|
|
|
|
|
tokenERC721 := &communities.CommunityToken{
|
|
|
|
CommunityID: community.IDString(),
|
|
|
|
TokenType: protobuf.CommunityTokenType_ERC721,
|
|
|
|
Address: "0x123",
|
|
|
|
Name: "StatusToken",
|
|
|
|
Symbol: "STT",
|
|
|
|
Description: "desc",
|
|
|
|
Supply: &bigint.BigInt{Int: big.NewInt(123)},
|
|
|
|
InfiniteSupply: false,
|
|
|
|
Transferable: true,
|
|
|
|
RemoteSelfDestruct: true,
|
|
|
|
ChainID: 1,
|
|
|
|
DeployState: communities.Deployed,
|
|
|
|
Base64Image: "ABCD",
|
|
|
|
}
|
2023-06-14 14:15:46 +00:00
|
|
|
|
2023-08-04 10:28:46 +00:00
|
|
|
_, err := s.admin.SaveCommunityToken(tokenERC721, nil)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
err = s.admin.AddCommunityToken(tokenERC721.CommunityID, tokenERC721.ChainID, tokenERC721.Address)
|
|
|
|
s.Require().Error(err)
|
2023-06-14 14:15:46 +00:00
|
|
|
}
|
2023-07-18 15:06:12 +00:00
|
|
|
|
2023-07-26 12:16:50 +00:00
|
|
|
func (s *AdminCommunityEventsSuite) TestMemberReceiveAdminEventsWhenOwnerOffline() {
|
|
|
|
community := setUpCommunityAndRoles(s, protobuf.CommunityMember_ROLE_ADMIN)
|
|
|
|
testMemberReceiveEventsWhenControlNodeOffline(s, community)
|
2023-07-18 15:06:12 +00:00
|
|
|
}
|