From d7740a48e0e634fb09c8f28329d832e6701337bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Albi?= Date: Fri, 31 Jan 2025 09:18:47 +0100 Subject: [PATCH] test(boards2): add missing filetests for thread deletion (#3645) Add missing filetests for `DeleteThread()` function. Related to #3623 This covers all tests for the function: - Successfully delete a thread - Fail because board is not found - Fail because thread is not found - Fail because user has no permission to delete a thread - Successfully delete a thread using a user with permission to delete --- examples/gno.land/r/nt/boards2/public.gno | 1 + .../gno.land/r/nt/boards2/z_9_a_filetest.gno | 34 +++++++++++++++++ .../gno.land/r/nt/boards2/z_9_b_filetest.gno | 20 ++++++++++ .../gno.land/r/nt/boards2/z_9_c_filetest.gno | 23 ++++++++++++ .../gno.land/r/nt/boards2/z_9_d_filetest.gno | 33 +++++++++++++++++ .../gno.land/r/nt/boards2/z_9_e_filetest.gno | 37 +++++++++++++++++++ 6 files changed, 148 insertions(+) create mode 100644 examples/gno.land/r/nt/boards2/z_9_a_filetest.gno create mode 100644 examples/gno.land/r/nt/boards2/z_9_b_filetest.gno create mode 100644 examples/gno.land/r/nt/boards2/z_9_c_filetest.gno create mode 100644 examples/gno.land/r/nt/boards2/z_9_d_filetest.gno create mode 100644 examples/gno.land/r/nt/boards2/z_9_e_filetest.gno diff --git a/examples/gno.land/r/nt/boards2/public.gno b/examples/gno.land/r/nt/boards2/public.gno index fff727e0560..f6f3f7f0429 100644 --- a/examples/gno.land/r/nt/boards2/public.gno +++ b/examples/gno.land/r/nt/boards2/public.gno @@ -156,6 +156,7 @@ func DeleteThread(bid BoardID, threadID PostID) { assertHasBoardPermission(board, caller, PermissionThreadDelete) } + // TODO: Discuss how to deal with thread deletion board.DeleteThread(threadID) } diff --git a/examples/gno.land/r/nt/boards2/z_9_a_filetest.gno b/examples/gno.land/r/nt/boards2/z_9_a_filetest.gno new file mode 100644 index 00000000000..6d1bf46dda7 --- /dev/null +++ b/examples/gno.land/r/nt/boards2/z_9_a_filetest.gno @@ -0,0 +1,34 @@ +package main + +import ( + "std" + + "gno.land/r/nt/boards2" +) + +const ( + owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 + title = "Test Thread" + body = "Test body" +) + +var ( + bid boards2.BoardID + pid boards2.PostID +) + +func init() { + std.TestSetOrigCaller(owner) + bid = boards2.CreateBoard("test-board") + pid = boards2.CreateThread(bid, title, body) +} + +func main() { + boards2.DeleteThread(bid, pid) + + // Ensure thread doesn't exist + println(boards2.Render("test-board/1")) +} + +// Output: +// Thread does not exist with ID: 1 diff --git a/examples/gno.land/r/nt/boards2/z_9_b_filetest.gno b/examples/gno.land/r/nt/boards2/z_9_b_filetest.gno new file mode 100644 index 00000000000..70ae9fcaf6d --- /dev/null +++ b/examples/gno.land/r/nt/boards2/z_9_b_filetest.gno @@ -0,0 +1,20 @@ +package main + +import ( + "std" + + "gno.land/r/nt/boards2" +) + +const owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 + +func init() { + std.TestSetOrigCaller(owner) +} + +func main() { + boards2.DeleteThread(404, 1) +} + +// Error: +// board does not exist with ID: 404 diff --git a/examples/gno.land/r/nt/boards2/z_9_c_filetest.gno b/examples/gno.land/r/nt/boards2/z_9_c_filetest.gno new file mode 100644 index 00000000000..ff33634820c --- /dev/null +++ b/examples/gno.land/r/nt/boards2/z_9_c_filetest.gno @@ -0,0 +1,23 @@ +package main + +import ( + "std" + + "gno.land/r/nt/boards2" +) + +const owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 + +var bid boards2.BoardID + +func init() { + std.TestSetOrigCaller(owner) + bid = boards2.CreateBoard("test-board") +} + +func main() { + boards2.DeleteThread(bid, 404) +} + +// Error: +// thread does not exist with ID: 404 diff --git a/examples/gno.land/r/nt/boards2/z_9_d_filetest.gno b/examples/gno.land/r/nt/boards2/z_9_d_filetest.gno new file mode 100644 index 00000000000..d677c801622 --- /dev/null +++ b/examples/gno.land/r/nt/boards2/z_9_d_filetest.gno @@ -0,0 +1,33 @@ +package main + +import ( + "std" + + "gno.land/r/nt/boards2" +) + +const ( + owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 + user = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2 +) + +var ( + bid boards2.BoardID + pid boards2.PostID +) + +func init() { + std.TestSetOrigCaller(owner) + bid = boards2.CreateBoard("test-board") + pid = boards2.CreateThread(bid, "Foo", "bar") + + // Call using a user that has not permission to delete threads + std.TestSetOrigCaller(user) +} + +func main() { + boards2.DeleteThread(bid, pid) +} + +// Error: +// unauthorized diff --git a/examples/gno.land/r/nt/boards2/z_9_e_filetest.gno b/examples/gno.land/r/nt/boards2/z_9_e_filetest.gno new file mode 100644 index 00000000000..d63a0bd2bfb --- /dev/null +++ b/examples/gno.land/r/nt/boards2/z_9_e_filetest.gno @@ -0,0 +1,37 @@ +package main + +import ( + "std" + + "gno.land/r/nt/boards2" +) + +const ( + owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 + member = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2 +) + +var ( + bid boards2.BoardID + pid boards2.PostID +) + +func init() { + std.TestSetOrigCaller(owner) + bid = boards2.CreateBoard("test-board") + pid = boards2.CreateThread(bid, "Foo", "bar") + + // Invite a member using a role with permission to delete threads + boards2.InviteMember(bid, member, boards2.RoleAdmin) + std.TestSetOrigCaller(member) +} + +func main() { + boards2.DeleteThread(bid, pid) + + // Ensure thread doesn't exist + println(boards2.Render("test-board/1")) +} + +// Output: +// Thread does not exist with ID: 1