Search Apps Documentation Source Content File Folder Download Copy Actions Download

z_7_b_filetest.gno

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