Skip to content

Commit

Permalink
feat: add e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
x1unix committed Dec 19, 2024
1 parent e6a6fc4 commit 4505b95
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards2/flag.gno
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strconv"
)

var flagThreshold = 3
const flagThreshold = 1

type Flag struct {
User std.Address
Expand Down
11 changes: 10 additions & 1 deletion examples/gno.land/r/demo/boards2/public.gno
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,19 @@ func CreateReply(bid BoardID, threadID, replyID PostID, body string) PostID {
board := mustGetBoard(bid)
thread := mustGetThread(board, threadID)

assertThreadVisible(thread)

// TODO: Assert thread is not locked
// TODO: Assert that caller is a board member (when board type is invite only)

var reply *Post
if replyID == threadID {
// When the parent reply is the thread just add reply to thread
reply = thread.AddReply(caller, body)
} else {
// Try to get parent reply and add a new child reply
post := mustGetReply(thread, replyID)
assertThreadVisible(thread)

reply = post.AddReply(caller, body)
}
return reply.id
Expand Down Expand Up @@ -260,3 +263,9 @@ func assertReplyExists(thread *Post, replyID PostID) {
panic("reply not found: " + replyID.String())
}
}

func assertThreadVisible(thread *Post) {
if thread.Hidden() {
panic("thread with ID: " + thread.GetPostID().String() + " was hidden")
}
}
23 changes: 23 additions & 0 deletions examples/gno.land/r/demo/boards2/z_2_a_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"std"

"gno.land/r/demo/boards2"
)

const owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1

func init() {
std.TestSetOrigCaller(owner)
}

func main() {
bid := boards2.CreateBoard("test1")
pid := boards2.CreateThread(bid, "thread", "thread")
boards2.FlagThread(bid, pid, "reason")
rid := boards2.CreateReply(bid, pid, pid, "reply")
}

// Error:
// thread with ID: 1 was hidden
26 changes: 26 additions & 0 deletions examples/gno.land/r/demo/boards2/z_2_b_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"std"

"gno.land/r/demo/boards2"
)

const owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1

func init() {
std.TestSetOrigCaller(owner)
}

func main() {
// ensure that nested replies denied if root thread is hidden.
bid := boards2.CreateBoard("test1")
pid := boards2.CreateThread(bid, "thread", "thread")
rid := boards2.CreateReply(bid, pid, pid, "reply1")

boards2.FlagThread(bid, pid, "reason")
_ = boards2.CreateReply(bid, pid, rid, "reply1.1")
}

// Error:
// thread with ID: 1 was hidden
26 changes: 26 additions & 0 deletions examples/gno.land/r/demo/boards2/z_2_c_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"std"

"gno.land/r/demo/boards2"
)

const owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1

func init() {
std.TestSetOrigCaller(owner)
}

func main() {
// ensure that nested replies denied if root thread is hidden.
bid := boards2.CreateBoard("test1")
pid := boards2.CreateThread(bid, "thread", "thread")
rid := boards2.CreateReply(bid, pid, pid, "reply1")

boards2.FlagReply(bid, pid, rid, "reason")
_ = boards2.CreateReply(bid, pid, rid, "reply1.1")
}

// Error:
// thread with ID: 2 was hidden

0 comments on commit 4505b95

Please sign in to comment.