diff --git a/examples/gno.land/r/demo/boards2/flag.gno b/examples/gno.land/r/demo/boards2/flag.gno index aa4ef00b0cd..e5744211ddf 100644 --- a/examples/gno.land/r/demo/boards2/flag.gno +++ b/examples/gno.land/r/demo/boards2/flag.gno @@ -5,7 +5,7 @@ import ( "strconv" ) -var flagThreshold = 3 +const flagThreshold = 1 type Flag struct { User std.Address diff --git a/examples/gno.land/r/demo/boards2/public.gno b/examples/gno.land/r/demo/boards2/public.gno index 62edded9003..c641c573ffe 100644 --- a/examples/gno.land/r/demo/boards2/public.gno +++ b/examples/gno.land/r/demo/boards2/public.gno @@ -76,9 +76,10 @@ 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 @@ -86,6 +87,8 @@ func CreateReply(bid BoardID, threadID, replyID PostID, body string) PostID { } 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 @@ -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") + } +} diff --git a/examples/gno.land/r/demo/boards2/z_2_a_filetest.gno b/examples/gno.land/r/demo/boards2/z_2_a_filetest.gno new file mode 100644 index 00000000000..626438d0c0a --- /dev/null +++ b/examples/gno.land/r/demo/boards2/z_2_a_filetest.gno @@ -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 diff --git a/examples/gno.land/r/demo/boards2/z_2_b_filetest.gno b/examples/gno.land/r/demo/boards2/z_2_b_filetest.gno new file mode 100644 index 00000000000..a4f4d403c8c --- /dev/null +++ b/examples/gno.land/r/demo/boards2/z_2_b_filetest.gno @@ -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 diff --git a/examples/gno.land/r/demo/boards2/z_2_c_filetest.gno b/examples/gno.land/r/demo/boards2/z_2_c_filetest.gno new file mode 100644 index 00000000000..c5ef6a5e6ed --- /dev/null +++ b/examples/gno.land/r/demo/boards2/z_2_c_filetest.gno @@ -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