Search Apps Documentation Source Content File Folder Download Copy Actions Download

z_31_c_filetest.gno

1.66 Kb ยท 71 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	reply                 = "reply"
14	reply1ToReply         = "reply1 to reply"
15	reply2ToReply         = "reply2 to reply"
16)
17
18var (
19	bid         boards2.BoardID
20	tid         boards2.PostID
21	rid         boards2.PostID
22	rid1ToReply boards2.PostID
23	rid2ToReply boards2.PostID
24)
25
26func init() {
27	testing.SetRealm(testing.NewUserRealm(owner))
28	bid = boards2.CreateBoard(cross, "test-board", false)
29	tid = boards2.CreateThread(cross, bid, title, body)
30	rid = boards2.CreateReply(cross, bid, tid, 0, reply)
31	rid1ToReply = boards2.CreateReply(cross, bid, tid, rid, reply1ToReply)
32	rid2ToReply = boards2.CreateReply(cross, bid, tid, rid, reply2ToReply)
33}
34
35func main() {
36	testing.SetRealm(testing.NewUserRealm(owner))
37
38	// Just get the total count of replies to reply
39	total, _ := boards2.GetPosts(bid, tid, rid, 0, 0)
40	println(total == 2)
41
42	// Get all replies to reply
43	total, replies := boards2.GetPosts(bid, tid, rid, 0, 10)
44	println(len(replies) == 2)
45
46	// Check contents
47	println(replies[0].ID == rid1ToReply)
48	println(replies[0].Creator == owner)
49	println(replies[0].Body == reply1ToReply)
50
51	println(replies[1].ID == rid2ToReply)
52	println(replies[1].Creator == owner)
53	println(replies[1].Body == reply2ToReply)
54
55	// Get starting from the second reply to reply
56	total, replies = boards2.GetPosts(bid, tid, rid, 1, 10)
57	println(len(replies) == 1)
58	println(replies[0].ID == rid2ToReply)
59}
60
61// Output:
62// true
63// true
64// true
65// true
66// true
67// true
68// true
69// true
70// true
71// true