Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(manager)_: make sure to re-add revealed accounts in the response #5867

Merged
merged 1 commit into from
Oct 1, 2024
Merged
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
14 changes: 9 additions & 5 deletions protocol/communities/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4897,18 +4897,22 @@ func (m *Manager) ShareRequestsToJoinWithPrivilegedMembers(community *Community,
return nil
}

func (m *Manager) shareAcceptedRequestToJoinWithPrivilegedMembers(community *Community, requestsToJoin *RequestToJoin) error {
pk, err := common.HexToPubkey(requestsToJoin.PublicKey)
func (m *Manager) shareAcceptedRequestToJoinWithPrivilegedMembers(community *Community, requestToJoin *RequestToJoin) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func (m *Manager) shareAcceptedRequestToJoinWithPrivilegedMembers(community *Community, requestToJoin *RequestToJoin) error {
func (m *Manager) shareAcceptedRequestToJoinWithPrivilegedMembers(community *Community, requestToJoin *const RequestToJoin) error {

@ google can you please introduce this concept?

pk, err := common.HexToPubkey(requestToJoin.PublicKey)
if err != nil {
return err
}

acceptedRequestsToJoinWithoutRevealedAccounts := make(map[string]*protobuf.CommunityRequestToJoin)
acceptedRequestsToJoinWithRevealedAccounts := make(map[string]*protobuf.CommunityRequestToJoin)

acceptedRequestsToJoinWithRevealedAccounts[requestsToJoin.PublicKey] = requestsToJoin.ToCommunityRequestToJoinProtobuf()
requestsToJoin.RevealedAccounts = make([]*protobuf.RevealedAccount, 0)
acceptedRequestsToJoinWithoutRevealedAccounts[requestsToJoin.PublicKey] = requestsToJoin.ToCommunityRequestToJoinProtobuf()
acceptedRequestsToJoinWithRevealedAccounts[requestToJoin.PublicKey] = requestToJoin.ToCommunityRequestToJoinProtobuf()

revealedAccounts := requestToJoin.RevealedAccounts
requestToJoin.RevealedAccounts = make([]*protobuf.RevealedAccount, 0)
acceptedRequestsToJoinWithoutRevealedAccounts[requestToJoin.PublicKey] = requestToJoin.ToCommunityRequestToJoinProtobuf()
// Set back the revealed accounts
requestToJoin.RevealedAccounts = revealedAccounts

msgWithRevealedAccounts := &protobuf.CommunityPrivilegedUserSyncMessage{
Type: protobuf.CommunityPrivilegedUserSyncMessage_CONTROL_NODE_ACCEPT_REQUEST_TO_JOIN,
Expand Down
2 changes: 2 additions & 0 deletions protocol/communities_messenger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,8 @@ func (s *MessengerCommunitiesSuite) TestRequestAccess() {
response, err = s.bob.AcceptRequestToJoinCommunity(acceptRequestToJoin)
s.Require().NoError(err)
s.Require().NotNil(response)
s.Require().NotEmpty(response.RequestsToJoinCommunity())
s.Require().Len(response.RequestsToJoinCommunity()[0].RevealedAccounts, 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better to prevent panics in tests as much as possible

Suggested change
s.Require().Len(response.RequestsToJoinCommunity()[0].RevealedAccounts, 1)
s.Require().NotEmpty(response.RequestsToJoinCommunity())
s.Require().Len(response.RequestsToJoinCommunity()[0].RevealedAccounts, 1)


s.Require().Len(response.Communities(), 1)

Expand Down