z_8_b_filetest.gno
1.23 Kb · 42 lines
1// Test getting replies from a comment
2package main
3
4import (
5 "testing"
6
7 boards2 "gno.land/r/gnoland/boards2/v1"
8 "gno.land/r/gnoland/boards2/v1/hub"
9)
10
11var comment hub.Comment
12
13func init() {
14 testing.SetRealm(testing.NewUserRealm("g1rp7cmetn27eqlpjpc4vuusf8kaj746tysc0qgh"))
15 boardID := boards2.CreateBoard(cross, "test123", false, false)
16 threadID := boards2.CreateThread(cross, boardID, "Title", "Body")
17 commentID := boards2.CreateReply(cross, boardID, threadID, 0, "Comment")
18
19 // Create replies
20 boards2.CreateReply(cross, boardID, threadID, commentID, "Reply 1")
21 subCommentID := boards2.CreateReply(cross, boardID, threadID, commentID, "Reply 2")
22
23 // Add a sub-reply (it should not be included in the output)
24 boards2.CreateReply(cross, boardID, threadID, subCommentID, "Reply 3")
25
26 // Get readonly comment
27 testing.SetRealm(testing.NewCodeRealm("gno.land/r/gnoland/boards2/test"))
28 comment, _ = hub.GetComment(uint64(boardID), uint64(threadID), uint64(commentID))
29}
30
31func main() {
32 testing.SetRealm(testing.NewCodeRealm("gno.land/r/gnoland/boards2/test"))
33 replies := hub.GetReplies(comment.BoardID, comment.ThreadID, comment.ID, 0, comment.ReplyCount)
34
35 for _, r := range replies {
36 println(r.ID, r.Body)
37 }
38}
39
40// Output:
41// 3 Reply 1
42// 4 Reply 2