fix: TestAdminBanMemberWithDeletingAllMessages test fix (#4855)

This commit is contained in:
Mykhailo Prakhov 2024-03-01 17:37:20 +01:00 committed by GitHub
parent 571f30777e
commit 84713384bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 28 deletions

View File

@ -1746,7 +1746,7 @@ func (m *Manager) preprocessDescription(id types.HexBytes, description *protobuf
} }
func (m *Manager) handleCommunityDescriptionMessageCommon(community *Community, description *protobuf.CommunityDescription, payload []byte, newControlNode *ecdsa.PublicKey) (*CommunityResponse, error) { func (m *Manager) handleCommunityDescriptionMessageCommon(community *Community, description *protobuf.CommunityDescription, payload []byte, newControlNode *ecdsa.PublicKey) (*CommunityResponse, error) {
prevClock := community.config.CommunityDescription.Clock
changes, err := community.UpdateCommunityDescription(description, payload, newControlNode) changes, err := community.UpdateCommunityDescription(description, payload, newControlNode)
if err != nil { if err != nil {
return nil, err return nil, err
@ -1811,11 +1811,13 @@ func (m *Manager) handleCommunityDescriptionMessageCommon(community *Community,
} }
} }
err = m.persistence.DeleteCommunityEvents(community.ID()) if description.Clock > prevClock {
if err != nil { err = m.persistence.DeleteCommunityEvents(community.ID())
return nil, err if err != nil {
return nil, err
}
community.config.EventsData = nil
} }
community.config.EventsData = nil
// Set Joined if we are part of the member list // Set Joined if we are part of the member list
if !community.Joined() && community.hasMember(&m.identity.PublicKey) { if !community.Joined() && community.hasMember(&m.identity.PublicKey) {

View File

@ -50,7 +50,7 @@ func waitOnMessengerResponse(s *suite.Suite, fnWait MessageResponseValidator, us
func(r *MessengerResponse) bool { func(r *MessengerResponse) bool {
err := fnWait(r) err := fnWait(r)
if err != nil { if err != nil {
user.logger.Error("WaitOnMessengerResponse: ", zap.Error(err)) user.logger.Error("response error: ", zap.Error(err))
} }
return err == nil return err == nil
}, },
@ -735,41 +735,35 @@ func banMember(base CommunityEventsTestsInterface, banRequest *requests.BanUserF
s.Require().True(modifiedCommmunity.HasMember(&base.GetMember().identity.PublicKey)) s.Require().True(modifiedCommmunity.HasMember(&base.GetMember().identity.PublicKey))
s.Require().Equal(communities.CommunityMemberBanPending, modifiedCommmunity.PendingAndBannedMembers()[bannedPK]) s.Require().Equal(communities.CommunityMemberBanPending, modifiedCommmunity.PendingAndBannedMembers()[bannedPK])
// 2. wait for event as a sender verifier := "event sender"
waitOnMessengerResponse(s, func(response *MessengerResponse) error { verifyPendingState := func(response *MessengerResponse) error {
modifiedCommmunity, err := getModifiedCommunity(response, types.EncodeHex(banRequest.CommunityID)) modifiedCommmunity, err := getModifiedCommunity(response, types.EncodeHex(banRequest.CommunityID))
if err != nil { if err != nil {
return err return err
} }
if !modifiedCommmunity.HasMember(&base.GetMember().identity.PublicKey) { if !modifiedCommmunity.HasMember(&base.GetMember().identity.PublicKey) {
return errors.New("event sender: alice should not be not banned (yet)") return errors.New(verifier + ": alice should not be not banned (yet)")
} }
if modifiedCommmunity.PendingAndBannedMembers()[bannedPK] != communities.CommunityMemberBanPending { state, exists := modifiedCommmunity.PendingAndBannedMembers()[bannedPK]
return errors.New("event sender: alice should be in the pending state") if !exists {
return errors.New(verifier + ": alice is not in the pending and banned members list")
}
if state != communities.CommunityMemberBanPending {
return errors.New("event sender: alice has invalid state: " + string(state))
} }
return nil return nil
}, base.GetEventSender()) }
// 2. wait for event as a sender
waitOnMessengerResponse(s, verifyPendingState, base.GetEventSender())
// 3. wait for event as the community member and check we are still until control node gets it // 3. wait for event as the community member and check we are still until control node gets it
waitOnMessengerResponse(s, func(response *MessengerResponse) error { verifier = "alice"
modifiedCommmunity, err := getModifiedCommunity(response, types.EncodeHex(banRequest.CommunityID)) waitOnMessengerResponse(s, verifyPendingState, base.GetMember())
if err != nil {
return err
}
if !modifiedCommmunity.HasMember(&base.GetMember().identity.PublicKey) {
return errors.New("member: alice should not be not banned (yet)")
}
if len(modifiedCommmunity.PendingAndBannedMembers()) == 0 {
return errors.New("member: alice should know about banned and pending members")
}
return nil
}, base.GetMember())
checkMsgDeletion := func(messenger *Messenger, expectedMsgsCount int) { checkMsgDeletion := func(messenger *Messenger, expectedMsgsCount int) {
msgs, err := messenger.persistence.GetCommunityMemberAllMessagesID(bannedPK, communityStr) msgs, err := messenger.persistence.GetCommunityMemberAllMessagesID(bannedPK, communityStr)