Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions protocol/communities/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3942,7 +3942,7 @@ func (m *Manager) SaveRequestToJoinAndCommunity(requestToJoin *RequestToJoin, co
return community, requestToJoin, nil
}

func (m *Manager) CreateRequestToJoin(request *requests.RequestToJoinCommunity, customizationColor multiaccountscommon.CustomizationColor) *RequestToJoin {
func (m *Manager) CreateRequestToJoin(request *requests.RequestToJoinCommunity, customizationColor multiaccountscommon.CustomizationColor) (*RequestToJoin, error) {
clock := uint64(time.Now().Unix())
requestToJoin := &RequestToJoin{
PublicKey: crypto.PubkeyToHex(&m.identity.PublicKey),
Expand All @@ -3958,21 +3958,20 @@ func (m *Manager) CreateRequestToJoin(request *requests.RequestToJoinCommunity,

requestToJoin.CalculateID()

addSignature := len(request.Signatures) == len(request.AddressesToReveal)
if len(request.Signatures) != len(request.AddressesToReveal) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we call CreateRequestToJoin for an open community also?
If so the list of signatures is empty in that case and this will always return.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or AddressesToReveal is also empty in that case? I really don't remember.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested with Status Desktop.
Created a simplest community (auto accept, no permissions, no minted tokens). Member was still required to reveal addresses and input password for signatures. So it's the same flow, we should be good.

return nil, errors.New("number of signatures does not match number of addresses to reveal")
}

for i := range request.AddressesToReveal {
revealedAcc := &protobuf.RevealedAccount{
Address: request.AddressesToReveal[i],
Signature: request.Signatures[i],
IsAirdropAddress: types.HexToAddress(request.AddressesToReveal[i]) == types.HexToAddress(request.AirdropAddress),
}

if addSignature {
revealedAcc.Signature = request.Signatures[i]
}

requestToJoin.RevealedAccounts = append(requestToJoin.RevealedAccounts, revealedAcc)
}

return requestToJoin
return requestToJoin, nil
}

func (m *Manager) SaveRequestToJoin(request *RequestToJoin) error {
Expand Down
6 changes: 3 additions & 3 deletions protocol/communities_events_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"go.uber.org/zap"

gethcommon "github.com/ethereum/go-ethereum/common"
hexutil "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/hexutil"

"github.com/status-im/status-go/crypto"
"github.com/status-im/status-go/crypto/types"
Expand Down Expand Up @@ -426,8 +426,8 @@ func setUpOnRequestCommunityAndRoles(base CommunityEventsTestsInterface, role pr

joinOnRequestCommunity(s, community.ID(), base.GetControlNode(), base.GetEventSender(), password, accounts)

accounts = accountsTestData[base.GetEventSender().IdentityPublicKeyString()]
password = accountsPasswords[base.GetEventSender().IdentityPublicKeyString()]
accounts = accountsTestData[base.GetMember().IdentityPublicKeyString()]
password = accountsPasswords[base.GetMember().IdentityPublicKeyString()]

joinOnRequestCommunity(s, community.ID(), base.GetControlNode(), base.GetMember(), password, accounts)

Expand Down
8 changes: 4 additions & 4 deletions protocol/communities_messenger_shared_member_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/suite"

gethcommon "github.com/ethereum/go-ethereum/common"
hexutil "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/hexutil"

"github.com/status-im/status-go/crypto"
"github.com/status-im/status-go/crypto/types"
Expand Down Expand Up @@ -204,8 +204,8 @@ func (s *MessengerCommunitiesSharedMemberAddressSuite) TestJoinedCommunityMember
advertiseCommunityTo(&s.Suite, community, s.owner, s.alice)
advertiseCommunityTo(&s.Suite, community, s.owner, s.bob)

s.joinCommunity(community, s.alice, alicePassword, []string{})
s.joinCommunity(community, s.bob, bobPassword, []string{})
s.joinCommunity(community, s.alice, alicePassword, []string{aliceAddress1, aliceAddress2})
s.joinCommunity(community, s.bob, bobPassword, []string{bobAddress})

community, err := s.owner.GetCommunityByID(community.ID())
s.Require().NoError(err)
Expand Down Expand Up @@ -435,7 +435,7 @@ func (s *MessengerCommunitiesSharedMemberAddressSuite) TestSharedAddressesReturn

advertiseCommunityTo(&s.Suite, community, s.owner, s.alice)

s.joinCommunity(community, s.alice, alicePassword, []string{})
s.joinCommunity(community, s.alice, alicePassword, []string{aliceAddress1, aliceAddress2})

revealedAccounts, err := s.alice.GetRevealedAccounts(community.ID(), crypto.PubkeyToHex(&s.alice.identity.PublicKey))
s.Require().NoError(err)
Expand Down
3 changes: 2 additions & 1 deletion protocol/communities_messenger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3555,7 +3555,8 @@ func (s *MessengerCommunitiesSuite) TestCommunityBanUserRequestToJoin() {

request := s.createRequestToJoinCommunity(community.ID(), s.alice)
// We try to join the org
rtj := s.alice.communitiesManager.CreateRequestToJoin(request, s.alice.account.GetCustomizationColor())
rtj, err := s.alice.communitiesManager.CreateRequestToJoin(request, s.alice.account.GetCustomizationColor())
s.Require().NoError(err)

s.Require().NoError(err)

Expand Down
16 changes: 6 additions & 10 deletions protocol/messenger_activity_center_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ func (s *MessengerActivityCenterMessageSuite) advertiseCommunityTo(community *co
advertiseCommunityTo(&s.Suite, community, owner, user)
}

func (s *MessengerActivityCenterMessageSuite) joinCommunity(community *communities.Community, owner *Messenger, user *Messenger) {
joinCommunity(&s.Suite, community.ID(), owner, user, accountPassword, []string{commonAccountAddress})
}

type MessengerActivityCenterMessageSuite struct {
CommunitiesMessengerTestSuiteBase
m *Messenger // main instance of Messenger
Expand Down Expand Up @@ -115,7 +111,7 @@ func (s *MessengerActivityCenterMessageSuite) TestEveryoneMentionTag() {

// Alice joins the community
s.advertiseCommunityTo(community, bob, alice)
s.joinCommunity(community, bob, alice)
joinCommunity(&s.Suite, community.ID(), bob, alice, accountPassword, []string{aliceAccountAddress})

// alice sends a community message
inputMessage := common.NewMessage()
Expand Down Expand Up @@ -162,7 +158,7 @@ func (s *MessengerActivityCenterMessageSuite) TestReplyWithImage() {

// Alice joins the community
s.advertiseCommunityTo(community, bob, alice)
s.joinCommunity(community, bob, alice)
joinCommunity(&s.Suite, community.ID(), bob, alice, accountPassword, []string{aliceAccountAddress})

// Alice sends a community message
inputMessage := common.NewMessage()
Expand Down Expand Up @@ -237,7 +233,7 @@ func (s *MessengerActivityCenterMessageSuite) TestMuteCommunityActivityCenterNot

// Alice joins the community
s.advertiseCommunityTo(community, bob, alice)
s.joinCommunity(community, bob, alice)
joinCommunity(&s.Suite, community.ID(), bob, alice, accountPassword, []string{aliceAccountAddress})

// Bob mutes the community
time, err := bob.MuteAllCommunityChats(&requests.MuteCommunity{
Expand Down Expand Up @@ -287,7 +283,7 @@ func (s *MessengerActivityCenterMessageSuite) TestReadCommunityOverviewNotificat

// Alice joins the community
s.advertiseCommunityTo(community, bob, alice)
s.joinCommunity(community, bob, alice)
joinCommunity(&s.Suite, community.ID(), bob, alice, accountPassword, []string{aliceAccountAddress})

// Mark community overview notification read
err := alice.DismissActivityCenterNotificationsByCommunity(context.Background(), &requests.DismissCommunityNotifications{CommunityID: community.ID()})
Expand All @@ -310,7 +306,7 @@ func (s *MessengerActivityCenterMessageSuite) prepareCommunityChannelWithMention

// Alice joins the community
s.advertiseCommunityTo(community, bob, alice)
s.joinCommunity(community, bob, alice)
joinCommunity(&s.Suite, community.ID(), bob, alice, accountPassword, []string{aliceAccountAddress})

// Bob sends a mention message
mentionMessage := common.NewMessage()
Expand Down Expand Up @@ -495,7 +491,7 @@ func (s *MessengerActivityCenterMessageSuite) TestAliceDoesNotReceiveCommunityNo

// Alice joins the community
s.advertiseCommunityTo(community, bob, alice)
s.joinCommunity(community, bob, alice)
joinCommunity(&s.Suite, community.ID(), bob, alice, accountPassword, []string{aliceAccountAddress})

// Bob sends an another mention message
mentionMessage = common.NewMessage()
Expand Down
38 changes: 24 additions & 14 deletions protocol/messenger_communities.go
Original file line number Diff line number Diff line change
Expand Up @@ -1263,29 +1263,36 @@ func (m *Messenger) generateCommunityRequestsForSigning(memberPubKey string, com
return nil, err
}

containsAddress := func(addresses []string, targetAddress string) bool {
for _, address := range addresses {
if types.HexToAddress(address) == types.HexToAddress(targetAddress) {
return true
}
}
return false
if len(addressesToReveal) == 0 {
return nil, errors.New("no addresses to reveal")
}

msgsToSign := make([]personal.SignParams, 0)
walletAccountsMap := make(map[string]*accsmanagementtypes.Account, len(walletAccounts))
for _, walletAccount := range walletAccounts {
if walletAccount.Chat || walletAccount.Type == accsmanagementtypes.AccountTypeWatch {
continue
addressHex := strings.ToLower(walletAccount.Address.Hex())
walletAccountsMap[addressHex] = walletAccount
}

msgsToSign := make([]personal.SignParams, 0)
for _, address := range addressesToReveal {
walletAccount, ok := walletAccountsMap[strings.ToLower(address)]
if !ok {
return nil, fmt.Errorf("address %s not found in wallet", address)
}

if len(addressesToReveal) > 0 && !containsAddress(addressesToReveal, walletAccount.Address.Hex()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this condition en(addressesToReveal) > 0 was used in some tests. Basically, if it's empty, then all wallet accounts will be returned 🤔 Is this intended?

A few tests were relying on this behaviour, passing empty list of addresses:

s.joinCommunity(community, s.alice, alicePassword, []string{})
s.joinCommunity(community, s.bob, bobPassword, []string{})

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should explicitly return an error when an empty addressesToReveal is given?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added explicit error return here

continue
if walletAccount.Chat {
return nil, fmt.Errorf("address %s is a chat account", address)
}

if walletAccount.Type == accsmanagementtypes.AccountTypeWatch {
return nil, fmt.Errorf("address %s is a watch account", address)
}

requestID := []byte{}
if !isEdit {
requestID = communities.CalculateRequestID(memberPubKey, communityID)
}

msgsToSign = append(msgsToSign, personal.SignParams{
Data: types.EncodeHex(crypto.Keccak256(m.IdentityPublicKeyCompressed(), communityID, requestID)),
Address: walletAccount.Address.Hex(),
Expand Down Expand Up @@ -1354,7 +1361,7 @@ func (m *Messenger) RequestToJoinCommunity(request *requests.RequestToJoinCommun
// TODO: Because of changes that need to be done in tests, calling this function and providing `request` without `AddressesToReveal`
// is not an error, but it should be.
logger := m.logger.Named("RequestToJoinCommunity")
logger.Debug("Addresses to reveal", zap.Any("Addresses:", request.AddressesToReveal))
logger.Debug("addresses to reveal", zap.Strings("addresses", request.AddressesToReveal))

if err := request.Validate(); err != nil {
logger.Debug("request failed to validate", zap.Error(err), zap.Any("request", request))
Expand All @@ -1371,7 +1378,10 @@ func (m *Messenger) RequestToJoinCommunity(request *requests.RequestToJoinCommun
return nil, communities.ErrAlreadyJoined
}

requestToJoin := m.communitiesManager.CreateRequestToJoin(request, m.account.GetCustomizationColor())
requestToJoin, err := m.communitiesManager.CreateRequestToJoin(request, m.account.GetCustomizationColor())
if err != nil {
return nil, err
}

if len(request.AddressesToReveal) > 0 {
revealedAddresses := make([]gethcommon.Address, 0)
Expand Down
2 changes: 1 addition & 1 deletion protocol/messenger_delete_message_for_everyone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type MessengerDeleteMessageForEveryoneSuite struct {
func (s *MessengerDeleteMessageForEveryoneSuite) SetupTest() {
s.CommunitiesMessengerTestSuiteBase.SetupTest()
s.admin = s.newMessenger("", []string{})
s.bob = s.newMessenger(bobPassword, []string{bobPassword})
s.bob = s.newMessenger(bobPassword, []string{bobAddress})
s.moderator = s.newMessenger(aliceAccountAddress, []string{aliceAddress1})

_, err := s.admin.Start()
Expand Down
9 changes: 7 additions & 2 deletions protocol/messenger_profile_showcase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type TestMessengerProfileShowcase struct {

func (s *TestMessengerProfileShowcase) SetupTest() {
s.CommunitiesMessengerTestSuiteBase.SetupTest()
s.m = s.newMessenger("", []string{})
s.m = s.newMessenger(alicePassword, []string{aliceAddress1})
_, err := s.m.Start()
s.Require().NoError(err)
}
Expand Down Expand Up @@ -765,7 +765,12 @@ func (s *TestMessengerProfileShowcase) TestProfileShowcaseCommuniesGrantExpires(
func (s *TestMessengerProfileShowcase) TestProfileShowcaseCommuniesDispatchOnGrantUpdate() {
grantInvokesProfileDispatchIntervalBackup := grantInvokesProfileDispatchInterval
grantInvokesProfileDispatchInterval = 1 * time.Millisecond

//s.m = s.newMessenger(alicePassword, []string{aliceAddress1})
alice := s.m
//_, err := alice.Start()
//s.Require().NoError(err)
//defer TearDownMessenger(&s.Suite, alice)

// Set Display name to pass shouldPublishChatIdentity check
profileKp, _, _, err := accounts.GetProfileKeypairForTest(true, false, false)
Expand Down Expand Up @@ -803,7 +808,7 @@ func (s *TestMessengerProfileShowcase) TestProfileShowcaseCommuniesDispatchOnGra
advertiseCommunityTo(&s.Suite, community, owner, bob)

alice.communitiesManager.PermissionChecker = &testPermissionChecker{}
joinCommunity(&s.Suite, community.ID(), owner, alice, aliceAccountAddress, []string{aliceAddress1})
joinCommunity(&s.Suite, community.ID(), owner, alice, alicePassword, []string{aliceAddress1})

joinedCommunities, err := alice.communitiesManager.Joined()
s.Require().NoError(err)
Expand Down
18 changes: 18 additions & 0 deletions protocol/push_notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ import (
"time"

"github.com/stretchr/testify/suite"
"go.uber.org/mock/gomock"

"github.com/status-im/status-go/accounts-management/generator"
"github.com/status-im/status-go/crypto"
"github.com/status-im/status-go/crypto/types"
"github.com/status-im/status-go/multiaccounts/accounts"
"github.com/status-im/status-go/pkg/testutils"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/communities"
"github.com/status-im/status-go/protocol/contacts"
mock_protocol_accounts_manager "github.com/status-im/status-go/protocol/mock"
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/pushnotificationclient"
"github.com/status-im/status-go/protocol/pushnotificationserver"
Expand Down Expand Up @@ -933,6 +937,20 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotificationCommunityReq
return nil
})

ctrl := gomock.NewController(s.T())
accountsManagerMock := mock_protocol_accounts_manager.NewMockAccountsManager(ctrl)
accountsManagerMock.EXPECT().GetVerifiedWalletAccount(gomock.Any(), gomock.Any()).
Return(generator.NewAccount(nil, nil), nil).AnyTimes()

alice.accountsManager = accountsManagerMock

// add wallet account with keypair
kp, _, _, err := accounts.GetProfileKeypairForTest(false, true, false)
s.Require().NoError(err)
kp.Accounts[0].Address = types.HexToAddress(aliceAddress1)
err = alice.settings.SaveOrUpdateKeypair(kp)
s.Require().NoError(err)

request := createRequestToJoinCommunity(&s.Suite, community.ID(), alice, alicePassword, []string{aliceAddress1})
alice.communitiesManager.PermissionChecker = &testPermissionChecker{}
// We try to join the org
Expand Down
Loading