Skip to content

Commit

Permalink
return board filetests, make them work
Browse files Browse the repository at this point in the history
  • Loading branch information
leohhhn committed Jan 16, 2025
1 parent b9aa62b commit 0eeac54
Show file tree
Hide file tree
Showing 34 changed files with 2,098 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/gno.land/r/demo/boards/public.gno
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func CreateBoard(name string) BoardID {
if !(std.IsOriginCall() || std.PrevRealm().IsUser()) {
panic("invalid non-user call")
}

bid := incGetBoardID()
caller := std.GetOrigCaller()
if usernameOf(caller) == "" {
Expand Down
22 changes: 22 additions & 0 deletions examples/gno.land/r/demo/boards/z_0_a_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards

import (
"gno.land/r/demo/boards"
)

var bid boards.BoardID

func init() {
bid = boards.CreateBoard("test_board")
boards.CreateThread(bid, "First Post (title)", "Body of the first post. (body)")
pid := boards.CreateThread(bid, "Second Post (title)", "Body of the second post. (body)")
boards.CreateReply(bid, pid, pid, "Reply of the second post")
}

func main() {
println(boards.Render("test_board"))
}

// Error:
// expected package name [boards_test] but got [boards]
27 changes: 27 additions & 0 deletions examples/gno.land/r/demo/boards/z_0_c_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards_test

// SEND: 200000000ugnot

import (
"std"

"gno.land/r/demo/boards"
users "gno.land/r/gnoland/users/v1"
)

var bid boards.BoardID

func init() {
std.TestSetRealm(std.NewUserRealm(std.Address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"))) // so that CurrentRealm.Addr() matches OrigCaller
std.TestSetRealm(std.NewUserRealm(std.Address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"))) // so that CurrentRealm.Addr() matches OrigCaller
users.Register("gnouser123")
boards.CreateThread(1, "First Post (title)", "Body of the first post. (body)")
}

func main() {
println(boards.Render("test_board"))
}

// Error:
// board not exist
28 changes: 28 additions & 0 deletions examples/gno.land/r/demo/boards/z_0_d_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards_test

// SEND: 200000000ugnot

import (
"std"

"gno.land/r/demo/boards"
users "gno.land/r/gnoland/users/v1"
)

var bid boards.BoardID

func init() {
std.TestSetRealm(std.NewUserRealm(std.Address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"))) // so that CurrentRealm.Addr() matches OrigCaller
std.TestSetRealm(std.NewUserRealm(std.Address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"))) // so that CurrentRealm.Addr() matches OrigCaller
users.Register("gnouser123")
bid = boards.CreateBoard("test_board")
boards.CreateReply(bid, 0, 0, "Reply of the second post")
}

func main() {
println(boards.Render("test_board"))
}

// Error:
// thread not exist
26 changes: 26 additions & 0 deletions examples/gno.land/r/demo/boards/z_0_e_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards_test

// SEND: 200000000ugnot

import (
"std"

"gno.land/r/demo/boards"
users "gno.land/r/gnoland/users/v1"
)

var bid boards.BoardID

func init() {
std.TestSetRealm(std.NewUserRealm(std.Address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"))) // so that CurrentRealm.Addr() matches OrigCaller
users.Register("gnouser123")
boards.CreateReply(bid, 0, 0, "Reply of the second post")
}

func main() {
println(boards.Render("test_board"))
}

// Error:
// board not exist
41 changes: 41 additions & 0 deletions examples/gno.land/r/demo/boards/z_0_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards_test

import (
"gno.land/r/demo/boards"
users "gno.land/r/gnoland/users/v1"
"std"
)

var bid boards.BoardID

func init() {
std.TestSetRealm(std.NewUserRealm(std.Address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"))) // so that CurrentRealm.Addr() matches OrigCaller
err := users.Register("gnouser123")

bid = boards.CreateBoard("test_board")
boards.CreateThread(bid, "First Post (title)", "Body of the first post. (body)")
pid := boards.CreateThread(bid, "Second Post (title)", "Body of the second post. (body)")
boards.CreateReply(bid, pid, pid, "Reply of the second post")
}

func main() {
println(boards.Render("test_board"))
}

// Output:
// \[[post](/r/demo/boards$help&func=CreateThread&bid=1)]
//
// ----------------------------------------
// ## [First Post (title)](/r/demo/boards:test_board/1)
//
// Body of the first post. (body)
// \- [@gnouser123](/r/gnoland/users/v1:gnouser123), [2009-02-13 11:31pm UTC](/r/demo/boards:test_board/1) \[[x](/r/demo/boards$help&func=DeletePost&bid=1&threadid=1&postid=1)] (0 replies) (0 reposts)
//
// ----------------------------------------
// ## [Second Post (title)](/r/demo/boards:test_board/2)
//
// Body of the second post. (body)
// \- [@gnouser123](/r/gnoland/users/v1:gnouser123), [2009-02-13 11:31pm UTC](/r/demo/boards:test_board/2) \[[x](/r/demo/boards$help&func=DeletePost&bid=1&threadid=2&postid=2)] (1 replies) (0 reposts)
//
//
36 changes: 36 additions & 0 deletions examples/gno.land/r/demo/boards/z_10_a_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards_test

// SEND: 200000000ugnot

import (
"std"
"strconv"

"gno.land/r/demo/boards"
users "gno.land/r/gnoland/users/v1"
)

var (
bid boards.BoardID
pid boards.PostID
)

func init() {
std.TestSetRealm(std.NewUserRealm(std.Address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"))) // so that CurrentRealm.Addr() matches OrigCaller
users.Register("gnouser123")

bid = boards.CreateBoard("test_board")
pid = boards.CreateThread(bid, "First Post in (title)", "Body of the first post. (body)")
}

func main() {
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
// boardId 2 not exist
boards.DeletePost(2, pid, pid, "")
println("----------------------------------------------------")
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
}

// Error:
// board not exist
36 changes: 36 additions & 0 deletions examples/gno.land/r/demo/boards/z_10_b_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards_test

// SEND: 200000000ugnot

import (
"std"
"strconv"

"gno.land/r/demo/boards"
users "gno.land/r/gnoland/users/v1"
)

var (
bid boards.BoardID
pid boards.PostID
)

func init() {
std.TestSetRealm(std.NewUserRealm(std.Address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"))) // so that CurrentRealm.Addr() matches OrigCaller
users.Register("gnouser123")

bid = boards.CreateBoard("test_board")
pid = boards.CreateThread(bid, "First Post in (title)", "Body of the first post. (body)")
}

func main() {
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
// pid of 2 not exist
boards.DeletePost(bid, 2, 2, "")
println("----------------------------------------------------")
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
}

// Error:
// thread not exist
51 changes: 51 additions & 0 deletions examples/gno.land/r/demo/boards/z_10_c_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards_test

// SEND: 200000000ugnot

import (
"std"
"strconv"

"gno.land/r/demo/boards"
users "gno.land/r/gnoland/users/v1"
)

var (
bid boards.BoardID
pid boards.PostID
rid boards.PostID
)

func init() {
std.TestSetRealm(std.NewUserRealm(std.Address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"))) // so that CurrentRealm.Addr() matches OrigCaller
users.Register("gnouser123")

bid = boards.CreateBoard("test_board")
pid = boards.CreateThread(bid, "First Post in (title)", "Body of the first post. (body)")
rid = boards.CreateReply(bid, pid, pid, "First reply of the First post\n")
}

func main() {
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
boards.DeletePost(bid, pid, rid, "")
println("----------------------------------------------------")
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
}

// Output:
// # First Post in (title)
//
// Body of the first post. (body)
// \- [@gnouser123](/r/gnoland/users/v1:gnouser123), [2009-02-13 11:31pm (UTC)](/r/demo/boards:test_board/1) \[[reply](/r/demo/boards$help&func=CreateReply&bid=1&threadid=1&postid=1)] \[[repost](/r/demo/boards$help&func=CreateRepost&bid=1&postid=1)] \[[x](/r/demo/boards$help&func=DeletePost&bid=1&threadid=1&postid=1)]
//
// > First reply of the First post
// >
// > \- [@gnouser123](/r/gnoland/users/v1:gnouser123), [2009-02-13 11:31pm (UTC)](/r/demo/boards:test_board/1/2) \[[reply](/r/demo/boards$help&func=CreateReply&bid=1&threadid=1&postid=2)] \[[x](/r/demo/boards$help&func=DeletePost&bid=1&threadid=1&postid=2)]
//
// ----------------------------------------------------
// # First Post in (title)
//
// Body of the first post. (body)
// \- [@gnouser123](/r/gnoland/users/v1:gnouser123), [2009-02-13 11:31pm (UTC)](/r/demo/boards:test_board/1) \[[reply](/r/demo/boards$help&func=CreateReply&bid=1&threadid=1&postid=1)] \[[repost](/r/demo/boards$help&func=CreateRepost&bid=1&postid=1)] \[[x](/r/demo/boards$help&func=DeletePost&bid=1&threadid=1&postid=1)]
//
41 changes: 41 additions & 0 deletions examples/gno.land/r/demo/boards/z_10_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards_test

// SEND: 200000000ugnot

import (
"std"
"strconv"

"gno.land/r/demo/boards"
users "gno.land/r/gnoland/users/v1"
)

var (
bid boards.BoardID
pid boards.PostID
)

func init() {
std.TestSetRealm(std.NewUserRealm(std.Address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"))) // so that CurrentRealm.Addr() matches OrigCaller
users.Register("gnouser123")

bid = boards.CreateBoard("test_board")
pid = boards.CreateThread(bid, "First Post in (title)", "Body of the first post. (body)")
}

func main() {
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
boards.DeletePost(bid, pid, pid, "")
println("----------------------------------------------------")
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
}

// Output:
// # First Post in (title)
//
// Body of the first post. (body)
// \- [@gnouser123](/r/gnoland/users/v1:gnouser123), [2009-02-13 11:31pm (UTC)](/r/demo/boards:test_board/1) \[[reply](/r/demo/boards$help&func=CreateReply&bid=1&threadid=1&postid=1)] \[[repost](/r/demo/boards$help&func=CreateRepost&bid=1&postid=1)] \[[x](/r/demo/boards$help&func=DeletePost&bid=1&threadid=1&postid=1)]
//
// ----------------------------------------------------
// thread does not exist with id: 1
36 changes: 36 additions & 0 deletions examples/gno.land/r/demo/boards/z_11_a_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards_test

// SEND: 200000000ugnot

import (
"std"
"strconv"

"gno.land/r/demo/boards"
users "gno.land/r/gnoland/users/v1"
)

var (
bid boards.BoardID
pid boards.PostID
)

func init() {
std.TestSetRealm(std.NewUserRealm(std.Address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"))) // so that CurrentRealm.Addr() matches OrigCaller
users.Register("gnouser123")

bid = boards.CreateBoard("test_board")
pid = boards.CreateThread(bid, "First Post in (title)", "Body of the first post. (body)")
}

func main() {
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
// board 2 not exist
boards.EditPost(2, pid, pid, "Edited: First Post in (title)", "Edited: Body of the first post. (body)")
println("----------------------------------------------------")
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
}

// Error:
// board not exist
36 changes: 36 additions & 0 deletions examples/gno.land/r/demo/boards/z_11_b_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards_test

// SEND: 200000000ugnot

import (
"std"
"strconv"

"gno.land/r/demo/boards"
users "gno.land/r/gnoland/users/v1"
)

var (
bid boards.BoardID
pid boards.PostID
)

func init() {
std.TestSetRealm(std.NewUserRealm(std.Address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"))) // so that CurrentRealm.Addr() matches OrigCaller
users.Register("gnouser123")

bid = boards.CreateBoard("test_board")
pid = boards.CreateThread(bid, "First Post in (title)", "Body of the first post. (body)")
}

func main() {
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
// thread 2 not exist
boards.EditPost(bid, 2, pid, "Edited: First Post in (title)", "Edited: Body of the first post. (body)")
println("----------------------------------------------------")
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
}

// Error:
// thread not exist
Loading

0 comments on commit 0eeac54

Please sign in to comment.