Skip to content

Commit

Permalink
fix(MessengerCommunitiesTokenPermissionsSuite)_: proper waiting
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-sirotin committed May 8, 2024
1 parent ed40e0d commit 9f18f00
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion protocol/communities_messenger_token_permissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (tckd *TestCommunitiesKeyDistributor) waitOnKeyDistribution(condition func(
return
}

case <-time.After(1000 * time.Millisecond):
case <-time.After(2000 * time.Millisecond):
errCh <- errors.New("timed out when waiting for key distribution")
return
}
Expand Down Expand Up @@ -1503,9 +1503,20 @@ func (s *MessengerCommunitiesTokenPermissionsSuite) testReevaluateMemberPrivileg
s.Require().NoError(err)
s.Require().True(checkRoleBasedOnThePermissionType(permissionType, &s.alice.identity.PublicKey, community))

waitOnPermissionsReevaluated := waitOnCommunitiesEvent(s.owner, func(sub *communities.Subscription) bool {
if sub.Community == nil {
return false
}
return checkRoleBasedOnThePermissionType(permissionType, &s.alice.identity.PublicKey, sub.Community)
})

// the control node re-evaluates the roles of the participants, checking that the privileged user has not lost his role
err = s.owner.communitiesManager.ForceMembersReevaluation(community.ID())
s.Require().NoError(err)

err = <-waitOnPermissionsReevaluated
s.Require().NoError(err)

community, err = s.owner.communitiesManager.GetByID(community.ID())
s.Require().NoError(err)
s.Require().True(checkRoleBasedOnThePermissionType(permissionType, &s.alice.identity.PublicKey, community))
Expand All @@ -1526,9 +1537,19 @@ func (s *MessengerCommunitiesTokenPermissionsSuite) testReevaluateMemberPrivileg
s.Require().NoError(err)
s.Require().False(community.HasTokenPermissions())

waitOnPermissionsReevaluated = waitOnCommunitiesEvent(s.owner, func(sub *communities.Subscription) bool {
if sub.Community == nil {
return false
}
return !checkRoleBasedOnThePermissionType(permissionType, &s.alice.identity.PublicKey, sub.Community)
})

err = s.owner.communitiesManager.ForceMembersReevaluation(community.ID())
s.Require().NoError(err)

err = <-waitOnPermissionsReevaluated
s.Require().NoError(err)

community, err = s.owner.communitiesManager.GetByID(community.ID())
s.Require().NoError(err)
s.Require().True(community.HasMember(&s.alice.identity.PublicKey))
Expand Down Expand Up @@ -1611,6 +1632,13 @@ func (s *MessengerCommunitiesTokenPermissionsSuite) testReevaluateMemberPrivileg
s.makeAddressSatisfyTheCriteria(testChainID1, aliceAddress1, tokenPermission.TokenCriteria[0])
s.makeAddressSatisfyTheCriteria(testChainID1, aliceAddress1, tokenMemberPermission.TokenCriteria[0])

waitOnAliceAddedToCommunity := waitOnCommunitiesEvent(s.owner, func(sub *communities.Subscription) bool {
if sub.Community == nil {
return false
}
return checkRoleBasedOnThePermissionType(permissionType, &s.alice.identity.PublicKey, sub.Community)
})

// join community as a privileged user
s.joinCommunity(community, s.alice, alicePassword, []string{aliceAddress1})

Expand All @@ -1622,6 +1650,9 @@ func (s *MessengerCommunitiesTokenPermissionsSuite) testReevaluateMemberPrivileg
err = s.owner.communitiesManager.ForceMembersReevaluation(community.ID())
s.Require().NoError(err)

err = <-waitOnAliceAddedToCommunity
s.Require().NoError(err)

community, err = s.owner.communitiesManager.GetByID(community.ID())
s.Require().NoError(err)
s.Require().True(checkRoleBasedOnThePermissionType(permissionType, &s.alice.identity.PublicKey, community))
Expand All @@ -1642,9 +1673,19 @@ func (s *MessengerCommunitiesTokenPermissionsSuite) testReevaluateMemberPrivileg
s.Require().NoError(err)
s.Require().Len(response.Communities()[0].TokenPermissions(), 1)

waitOnAliceLostPermission := waitOnCommunitiesEvent(s.owner, func(sub *communities.Subscription) bool {
if sub.Community == nil {
return false
}
return !checkRoleBasedOnThePermissionType(permissionType, &s.alice.identity.PublicKey, sub.Community)
})

err = s.owner.communitiesManager.ForceMembersReevaluation(community.ID())
s.Require().NoError(err)

err = <-waitOnAliceLostPermission
s.Require().NoError(err)

community, err = s.owner.communitiesManager.GetByID(community.ID())
s.Require().NoError(err)
s.Require().True(community.HasMember(&s.alice.identity.PublicKey))
Expand All @@ -1666,9 +1707,19 @@ func (s *MessengerCommunitiesTokenPermissionsSuite) testReevaluateMemberPrivileg
s.Require().NoError(err)
s.Require().Len(response.Communities()[0].TokenPermissions(), 0)

waitOnReevaluation := waitOnCommunitiesEvent(s.owner, func(sub *communities.Subscription) bool {
if sub.Community == nil {
return false
}
return !checkRoleBasedOnThePermissionType(permissionType, &s.alice.identity.PublicKey, sub.Community)
})

err = s.owner.communitiesManager.ForceMembersReevaluation(community.ID())
s.Require().NoError(err)

err = <-waitOnReevaluation
s.Require().NoError(err)

community, err = s.owner.communitiesManager.GetByID(community.ID())
s.Require().NoError(err)
s.Require().True(community.HasMember(&s.alice.identity.PublicKey))
Expand Down

0 comments on commit 9f18f00

Please sign in to comment.