Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

z_hub_6_e_filetest.gno

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