Search Apps Documentation Source Content File Folder Download Copy Actions Download

z_6_d_filetest.gno

1.66 Kb · 56 lines
 1// Test getting flags 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
11const (
12	owner     address = "g1rp7cmetn27eqlpjpc4vuusf8kaj746tysc0qgh"
13	admin             = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
14	moderator         = "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
15)
16
17var comment hub.Comment
18
19func init() {
20	testing.SetRealm(testing.NewUserRealm(owner))
21	boardID := boards2.CreateBoard(cross, "test123", false, false)
22	threadID := boards2.CreateThread(cross, boardID, "Title", "Body")
23	commentID := boards2.CreateReply(cross, boardID, threadID, 0, "Comment")
24
25	// Invite member
26	boards2.InviteMember(cross, boardID, admin, "admin")
27	boards2.InviteMember(cross, boardID, moderator, "moderator")
28
29	// Update flagging threshold to two flags
30	boards2.SetFlaggingThreshold(cross, boardID, 2)
31
32	// Add first flag
33	testing.SetRealm(testing.NewUserRealm(admin))
34	boards2.FlagReply(cross, boardID, threadID, commentID, "Reason 1")
35
36	// Add second flag
37	testing.SetRealm(testing.NewUserRealm(moderator))
38	boards2.FlagReply(cross, boardID, threadID, commentID, "Reason 2")
39
40	// Get readonly comment
41	testing.SetRealm(testing.NewCodeRealm("gno.land/r/gnoland/boards2/test"))
42	comment, _ = hub.GetComment(uint64(boardID), uint64(threadID), uint64(commentID))
43}
44
45func main() {
46	testing.SetRealm(testing.NewCodeRealm("gno.land/r/gnoland/boards2/test"))
47	flags := hub.GetFlags(comment.BoardID, comment.ThreadID, comment.ID, 0, comment.FlagCount)
48
49	for _, f := range flags {
50		println(f.User, f.Reason)
51	}
52}
53
54// Output:
55// g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5 Reason 1
56// g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj Reason 2