Search Apps Documentation Source Content File Folder Download Copy Actions Download

z_31_b_filetest.gno

1.37 Kb ยท 68 lines
 1package main
 2
 3import (
 4	"testing"
 5
 6	boards2 "gno.land/r/gnoland/boards2/v1"
 7)
 8
 9const (
10	owner  address = "g16jpf0puufcpcjkph5nxueec8etpcldz7zwgydq" // @devx
11	title          = "Foo"
12	body           = "bar"
13	reply1         = "reply1"
14	reply2         = "reply2"
15)
16
17var (
18	bid  boards2.BoardID
19	tid  boards2.PostID
20	rid1 boards2.PostID
21	rid2 boards2.PostID
22)
23
24func init() {
25	testing.SetRealm(testing.NewUserRealm(owner))
26	bid = boards2.CreateBoard(cross, "test-board", false)
27	tid = boards2.CreateThread(cross, bid, title, body)
28	rid1 = boards2.CreateReply(cross, bid, tid, 0, reply1)
29	rid2 = boards2.CreateReply(cross, bid, tid, 0, reply2)
30}
31
32func main() {
33	testing.SetRealm(testing.NewUserRealm(owner))
34
35	// Just get the total count of replies
36	total, _ := boards2.GetPosts(bid, tid, 0, 0, 0)
37	println(total == 2)
38
39	// Get all replies
40	total, replies := boards2.GetPosts(bid, tid, 0, 0, 10)
41	println(len(replies) == 2)
42
43	// Check contents
44	println(replies[0].ID == rid1)
45	println(replies[0].Creator == owner)
46	println(replies[0].Body == reply1)
47
48	println(replies[1].ID == rid2)
49	println(replies[1].Creator == owner)
50	println(replies[1].Body == reply2)
51
52	// Get starting from the second reply
53	total, replies = boards2.GetPosts(bid, tid, 0, 1, 10)
54	println(len(replies) == 1)
55	println(replies[0].ID == rid2)
56}
57
58// Output:
59// true
60// true
61// true
62// true
63// true
64// true
65// true
66// true
67// true
68// true