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