z_31_a_filetest.gno
1.37 Kb ยท 70 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 title1 = "Foo1"
12 body1 = "bar1"
13 title2 = "Foo2"
14 body2 = "bar2"
15)
16
17var (
18 bid boards2.BoardID
19 tid1 boards2.PostID
20 tid2 boards2.PostID
21)
22
23func init() {
24 testing.SetRealm(testing.NewUserRealm(owner))
25 bid = boards2.CreateBoard(cross, "test-board", false)
26 tid1 = boards2.CreateThread(cross, bid, title1, body1)
27 tid2 = boards2.CreateThread(cross, bid, title2, body2)
28}
29
30func main() {
31 testing.SetRealm(testing.NewUserRealm(owner))
32
33 // Just get the total count of threads
34 total, _ := boards2.GetPosts(bid, 0, 0, 0, 0)
35 println(total == 2)
36
37 // Get all threads
38 total, threads := boards2.GetPosts(bid, 0, 0, 0, 10)
39 println(len(threads) == 2)
40
41 // Check contents
42 println(threads[0].ID == tid1)
43 println(threads[0].Creator == owner)
44 println(threads[0].Title == title1)
45 println(threads[0].Body == body1)
46
47 println(threads[1].ID == tid2)
48 println(threads[1].Creator == owner)
49 println(threads[1].Title == title2)
50 println(threads[1].Body == body2)
51
52 // Get starting from the second thread
53 total, threads = boards2.GetPosts(bid, 0, 0, 1, 10)
54 println(len(threads) == 1)
55 println(threads[0].ID == tid2)
56}
57
58// Output:
59// true
60// true
61// true
62// true
63// true
64// true
65// true
66// true
67// true
68// true
69// true
70// true