parent
21eba9928c
commit
e6fee1a84e
|
@ -863,6 +863,44 @@ func (s *MessengerCommunitiesTokenPermissionsSuite) TestJoinCommunityWithAdminPe
|
||||||
s.Require().Equal(bobAddress, revealedAccounts[0].Address)
|
s.Require().Equal(bobAddress, revealedAccounts[0].Address)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *MessengerCommunitiesTokenPermissionsSuite) TestSharedAddressesReturnsRevealedAccount() {
|
||||||
|
community, _ := s.createCommunity()
|
||||||
|
|
||||||
|
permissionRequest := requests.CreateCommunityTokenPermission{
|
||||||
|
CommunityID: community.ID(),
|
||||||
|
Type: protobuf.CommunityTokenPermission_CAN_VIEW_AND_POST_CHANNEL,
|
||||||
|
TokenCriteria: []*protobuf.TokenCriteria{
|
||||||
|
&protobuf.TokenCriteria{
|
||||||
|
Type: protobuf.CommunityTokenType_ERC20,
|
||||||
|
ContractAddresses: map[uint64]string{testChainID1: "0x123"},
|
||||||
|
Symbol: "TEST",
|
||||||
|
AmountInWei: "100000000000000000000",
|
||||||
|
Decimals: uint64(18),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
response, err := s.owner.CreateCommunityTokenPermission(&permissionRequest)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Len(response.Communities(), 1)
|
||||||
|
|
||||||
|
s.advertiseCommunityTo(community, s.alice)
|
||||||
|
|
||||||
|
s.joinCommunity(community, s.alice, bobPassword, []string{})
|
||||||
|
|
||||||
|
revealedAccounts, err := s.alice.GetRevealedAccounts(community.ID(), common.PubkeyToHex(&s.alice.identity.PublicKey))
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Len(revealedAccounts, 2)
|
||||||
|
s.Require().Equal(aliceAddress1, revealedAccounts[0].Address)
|
||||||
|
s.Require().Equal(aliceAddress2, revealedAccounts[1].Address)
|
||||||
|
|
||||||
|
sharedAddresses, err := s.alice.getSharedAddresses(community.ID(), []string{})
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Len(sharedAddresses, 2)
|
||||||
|
s.Require().Equal(sharedAddresses[0].String(), revealedAccounts[0].Address)
|
||||||
|
s.Require().Equal(sharedAddresses[1].String(), revealedAccounts[1].Address)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *MessengerCommunitiesTokenPermissionsSuite) TestJoinCommunityAsMemberWithMemberAndAdminPermission() {
|
func (s *MessengerCommunitiesTokenPermissionsSuite) TestJoinCommunityAsMemberWithMemberAndAdminPermission() {
|
||||||
community, _ := s.createCommunity()
|
community, _ := s.createCommunity()
|
||||||
|
|
||||||
|
|
|
@ -4061,28 +4061,53 @@ func (m *Messenger) CheckPermissionsToJoinCommunity(request *requests.CheckPermi
|
||||||
return m.communitiesManager.CheckPermissionToJoin(request.CommunityID, addresses)
|
return m.communitiesManager.CheckPermissionToJoin(request.CommunityID, addresses)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) CheckCommunityChannelPermissions(request *requests.CheckCommunityChannelPermissions) (*communities.CheckChannelPermissionsResponse, error) {
|
func (m *Messenger) getSharedAddresses(communityID types.HexBytes, requestAddresses []string) ([]gethcommon.Address, error) {
|
||||||
if err := request.Validate(); err != nil {
|
addressesMap := make(map[string]struct{})
|
||||||
return nil, err
|
|
||||||
|
for _, v := range requestAddresses {
|
||||||
|
addressesMap[v] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
var addresses []gethcommon.Address
|
if len(requestAddresses) == 0 {
|
||||||
|
sharedAddresses, err := m.GetRevealedAccounts(communityID, common.PubkeyToHex(&m.identity.PublicKey))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
if len(request.Addresses) == 0 {
|
for _, v := range sharedAddresses {
|
||||||
|
addressesMap[v.Address] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(addressesMap) == 0 {
|
||||||
accounts, err := m.settings.GetActiveAccounts()
|
accounts, err := m.settings.GetActiveAccounts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, a := range accounts {
|
for _, a := range accounts {
|
||||||
addresses = append(addresses, gethcommon.HexToAddress(a.Address.Hex()))
|
addressesMap[a.Address.Hex()] = struct{}{}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for _, v := range request.Addresses {
|
|
||||||
addresses = append(addresses, gethcommon.HexToAddress(v))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var addresses []gethcommon.Address
|
||||||
|
for addr := range addressesMap {
|
||||||
|
addresses = append(addresses, gethcommon.HexToAddress(addr))
|
||||||
|
}
|
||||||
|
|
||||||
|
return addresses, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Messenger) CheckCommunityChannelPermissions(request *requests.CheckCommunityChannelPermissions) (*communities.CheckChannelPermissionsResponse, error) {
|
||||||
|
if err := request.Validate(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
addresses, err := m.getSharedAddresses(request.CommunityID, request.Addresses)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return m.communitiesManager.CheckChannelPermissions(request.CommunityID, request.ChatID, addresses)
|
return m.communitiesManager.CheckChannelPermissions(request.CommunityID, request.ChatID, addresses)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4091,21 +4116,9 @@ func (m *Messenger) CheckAllCommunityChannelsPermissions(request *requests.Check
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var addresses []gethcommon.Address
|
addresses, err := m.getSharedAddresses(request.CommunityID, request.Addresses)
|
||||||
|
if err != nil {
|
||||||
if len(request.Addresses) == 0 {
|
return nil, err
|
||||||
accounts, err := m.settings.GetActiveAccounts()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, a := range accounts {
|
|
||||||
addresses = append(addresses, gethcommon.HexToAddress(a.Address.Hex()))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for _, v := range request.Addresses {
|
|
||||||
addresses = append(addresses, gethcommon.HexToAddress(v))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return m.communitiesManager.CheckAllChannelsPermissions(request.CommunityID, addresses)
|
return m.communitiesManager.CheckAllChannelsPermissions(request.CommunityID, addresses)
|
||||||
|
|
Loading…
Reference in New Issue