func ValidCommentsDateInvariant(k Keeper) sdk.Invariant {
	return func(ctx sdk.Context) (string, bool) {
		var invalidCommentsIDs []string
		k.IteratePosts(ctx, func(_ int64, post types.Post) (stop bool) {
			if types.IsValidPostID(post.ParentID) {
				parentPost, _ := k.GetPost(ctx, post.ParentID)
				if post.Created.Before(parentPost.Created) {
					invalidCommentsIDs = append(invalidCommentsIDs, post.PostID)
				}
			}
			return false
		})
		return sdk.FormatInvariant(types.ModuleName, "comments dates before parent post date",
			fmt.Sprintf("The following post IDs referred to posts which are invalid comments "+
				"having creation date before parent post creation date:\n %s",
				formatOutputIDs(invalidCommentsIDs)),
		), invalidCommentsIDs != nil
	}
}
____________________________________________________________________________
ValidCommentsDateInvariant checks that comments creation date is always greater than parent creation date
package keeper
import (
	"fmt"
	"strings"
	sdk "github.com/cosmos/cosmos-sdk/types"
	"github.com/desmos-labs/desmos/v2/x/staging/posts/types"
)
func RegisterInvariants(ir sdk.InvariantRegistry, keeper Keeper) {
	ir.RegisterRoute(types.ModuleName, "valid-post",
		ValidPostsInvariant(keeper))
	ir.RegisterRoute(types.ModuleName, "comments-date",
		ValidCommentsDateInvariant(keeper))
	ir.RegisterRoute(types.ModuleName, "post-reactions",
		ValidPostForReactionsInvariant(keeper))
	ir.RegisterRoute(types.ModuleName, "poll-user-answers",
		ValidPollForUserAnswersInvariant(keeper))
}
func AllInvariants(k Keeper) sdk.Invariant {
	return func(ctx sdk.Context) (string, bool) {
		if res, stop := ValidPostsInvariant(k)(ctx); stop {
			return res, stop
		}
		if res, stop := ValidCommentsDateInvariant(k)(ctx); stop {
			return res, stop
		}
		if res, stop := ValidPollForUserAnswersInvariant(k)(ctx); stop {
			return res, stop
		}
		if res, stop := ValidPostForReactionsInvariant(k)(ctx); stop {
			return res, stop
		}
		return "Every invariant condition is fulfilled correctly", true
	}
}
func formatOutputIDs(ids []string) (outputIDs string) {
	return strings.Join(ids, "\n")
}
func ValidPostsInvariant(k Keeper) sdk.Invariant {
	return func(ctx sdk.Context) (string, bool) {
		var invalidPostIDs []string
		k.IteratePosts(ctx, func(_ int64, post types.Post) (stop bool) {
			if k.ValidatePost(ctx, post) != nil {
				invalidPostIDs = append(invalidPostIDs, post.PostID)
			}
			return false
		})
		return sdk.FormatInvariant(types.ModuleName, "invalid posts IDs",
			fmt.Sprintf("The following posts are invalid:\n %s", formatOutputIDs(invalidPostIDs)),
		), invalidPostIDs != nil
	}
}