Search Apps Documentation Source Content File Folder Download Copy Actions Download

z_6_c_filetest.gno

1.52 Kb · 55 lines
 1// Test getting flags 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
11const (
12	owner     address = "g1rp7cmetn27eqlpjpc4vuusf8kaj746tysc0qgh"
13	admin             = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
14	moderator         = "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
15)
16
17var thread hub.Thread
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
24	// Invite members
25	boards2.InviteMember(cross, boardID, admin, "admin")
26	boards2.InviteMember(cross, boardID, moderator, "moderator")
27
28	// Update flagging threshold to two flags
29	boards2.SetFlaggingThreshold(cross, boardID, 2)
30
31	// Add first flag
32	testing.SetRealm(testing.NewUserRealm(admin))
33	boards2.FlagThread(cross, boardID, threadID, "Reason 1")
34
35	// Add second flag
36	testing.SetRealm(testing.NewUserRealm(moderator))
37	boards2.FlagThread(cross, boardID, threadID, "Reason 2")
38
39	// Get readonly thread
40	testing.SetRealm(testing.NewCodeRealm("gno.land/r/gnoland/boards2/test"))
41	thread, _ = hub.GetThread(uint64(boardID), uint64(threadID))
42}
43
44func main() {
45	testing.SetRealm(testing.NewCodeRealm("gno.land/r/gnoland/boards2/test"))
46	flags := hub.GetFlags(thread.BoardID, thread.ID, 0, 0, thread.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