Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

z_hub_6_d_filetest.gno

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