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

1.10 Kb · 42 lines
 1// PKGPATH: gno.land/r/gnoland/boards2/v0/filetests/z_hub_0_c_filetest
 2
 3// Test that reads are open to any caller
 4package z_hub_0_c_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 owner address = "g1skl80cuz8zq3lul9pgz5pc35l2pfzgxgfpsqkx"
15
16var boardID boards.ID
17
18func init(cur realm) {
19	testing.SetRealm(testing.NewUserRealm(owner))
20	boardID = boards2.CreateBoard(cross(cur), "test123", false, false)
21}
22
23func main(cur realm) {
24	// The read API performs no caller authorization: an EOA and a realm
25	// outside the Boards2 namespace must both be able to read.
26	testing.SetRealm(testing.NewUserRealm(owner))
27	_, found := boards2.GetBoard(uint64(boardID))
28	println("user realm:", found)
29
30	testing.SetRealm(testing.NewCodeRealm("gno.land/r/unrelated/caller"))
31	_, found = boards2.GetBoard(uint64(boardID))
32	println("unrelated realm:", found)
33
34	println("threads:", len(boards2.GetThreads(uint64(boardID), 0, 10)))
35	println("members:", len(boards2.GetMembers(uint64(boardID), 0, 10)))
36}
37
38// Output:
39// user realm: true
40// unrelated realm: true
41// threads: 0
42// members: 1