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_c_filetest.gno

1.50 Kb · 54 lines
 1// PKGPATH: gno.land/r/gnoland/boards2/v0/filetests/z_hub_6_c_filetest
 2
 3// Test getting flags from a thread
 4package z_hub_6_c_filetest
 5
 6import (
 7	"testing"
 8
 9	boards2 "gno.land/r/gnoland/boards2/v0"
10)
11
12const (
13	owner     address = "g1skl80cuz8zq3lul9pgz5pc35l2pfzgxgfpsqkx"
14	admin             = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
15	moderator         = "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
16)
17
18var thread boards2.Thread
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
25	// Invite members
26	boards2.InviteMember(cross(cur), boardID, admin, "admin")
27	boards2.InviteMember(cross(cur), boardID, moderator, "moderator")
28
29	// Update flagging threshold to two flags
30	boards2.SetFlaggingThreshold(cross(cur), boardID, 2)
31
32	// Add first flag
33	testing.SetRealm(testing.NewUserRealm(admin))
34	boards2.FlagThread(cross(cur), boardID, threadID, "Reason 1")
35
36	// Add second flag
37	testing.SetRealm(testing.NewUserRealm(moderator))
38	boards2.FlagThread(cross(cur), boardID, threadID, "Reason 2")
39
40	// Get readonly thread
41	thread, _ = boards2.GetThread(uint64(boardID), uint64(threadID))
42}
43
44func main(cur realm) {
45	flags := boards2.GetFlags(thread.BoardID(), thread.ID(), 0, 0, thread.FlagCount())
46
47	for _, f := range flags {
48		println(f.User(), f.Reason())
49	}
50}
51
52// Output:
53// g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5 Reason 1
54// g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj Reason 2