2020-11-18 09:16:51 +00:00
|
|
|
package communities
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
|
|
_ "github.com/mutecomm/go-sqlcipher" // require go-sqlcipher that overrides default implementation
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/crypto"
|
2020-11-18 09:16:51 +00:00
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
|
|
|
"github.com/status-im/status-go/protocol/sqlite"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestManagerSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(ManagerSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
type ManagerSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
manager *Manager
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ManagerSuite) SetupTest() {
|
|
|
|
db, err := sqlite.OpenInMemory()
|
|
|
|
s.Require().NoError(err)
|
2021-01-11 10:32:51 +00:00
|
|
|
key, err := crypto.GenerateKey()
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().NoError(err)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
m, err := NewManager(&key.PublicKey, db, nil, nil)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NoError(m.Start())
|
2020-11-18 09:16:51 +00:00
|
|
|
s.manager = m
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ManagerSuite) TestCreateCommunity() {
|
|
|
|
description := &protobuf.CommunityDescription{
|
|
|
|
Permissions: &protobuf.CommunityPermissions{
|
|
|
|
Access: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
|
|
|
},
|
|
|
|
Identity: &protobuf.ChatIdentity{
|
|
|
|
DisplayName: "status",
|
|
|
|
Description: "status community description",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
community, err := s.manager.CreateCommunity(description)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(community)
|
|
|
|
|
|
|
|
communities, err := s.manager.All()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
// Consider status default community
|
|
|
|
s.Require().Len(communities, 2)
|
|
|
|
|
|
|
|
actualCommunity := communities[0]
|
|
|
|
if bytes.Equal(community.ID(), communities[1].ID()) {
|
|
|
|
actualCommunity = communities[1]
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Require().Equal(community.ID(), actualCommunity.ID())
|
|
|
|
s.Require().Equal(community.PrivateKey(), actualCommunity.PrivateKey())
|
|
|
|
s.Require().True(proto.Equal(community.config.CommunityDescription, actualCommunity.config.CommunityDescription))
|
|
|
|
}
|