Search Apps Documentation Source Content File Folder Download Copy Actions Download

z_7_b_filetest.gno

1.25 Kb · 43 lines
 1// PKGPATH: gno.land/r/gnoland/boards2/v1/hub/filetests/z_7_b_filetest
 2
 3// Test getting comments from a thread
 4package z_7_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 thread hub.Thread
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 1")
20
21	// Create another comment
22	boards2.CreateReply(cross(cur), boardID, threadID, 0, "Comment 2")
23
24	// Add a reply (it should not be included in the output)
25	boards2.CreateReply(cross(cur), boardID, threadID, commentID, "Reply")
26
27	// Get readonly thread
28	testing.SetRealm(testing.NewCodeRealm("gno.land/r/gnoland/boards2/test"))
29	thread, _ = hub.GetThread(cross(cur), uint64(boardID), uint64(threadID))
30}
31
32func main(cur realm) {
33	testing.SetRealm(testing.NewCodeRealm("gno.land/r/gnoland/boards2/test"))
34	comments := hub.GetComments(cross(cur), thread.BoardID, thread.ID, 0, thread.CommentCount)
35
36	for _, c := range comments {
37		println(c.ID, c.Body)
38	}
39}
40
41// Output:
42// 2 Comment 1
43// 3 Comment 2