From 93d7e21cbe0f60f618ae0341efd0c93326cccdf6 Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Fri, 31 Jan 2025 12:36:01 +0100 Subject: [PATCH 1/3] fix: correct `EditReply` function Replies don't have a title only a body which should not be empty. --- examples/gno.land/r/nt/boards2/public.gno | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/gno.land/r/nt/boards2/public.gno b/examples/gno.land/r/nt/boards2/public.gno index 06505b4a2fc..3e7f2753474 100644 --- a/examples/gno.land/r/nt/boards2/public.gno +++ b/examples/gno.land/r/nt/boards2/public.gno @@ -201,18 +201,20 @@ func EditThread(bid BoardID, threadID PostID, title, body string) { thread.Update(title, body) } -func EditReply(bid BoardID, threadID, replyID PostID, title, body string) { +func EditReply(bid BoardID, threadID, replyID PostID, body string) { assertIsUserCall() + body = strings.TrimSpace(body) + assertBodyIsNotEmpty(body) + board := mustGetBoard(bid) thread := mustGetThread(board, threadID) reply := mustGetReply(thread, replyID) - caller := std.GetOrigCaller() - if caller != reply.GetCreator() { + if std.GetOrigCaller() != reply.GetCreator() { panic("only the reply creator is allowed to edit it") } - reply.Update(title, body) + reply.Update("", body) } func InviteMember(bid BoardID, user std.Address, role Role) { From 1df1152b6ff3d63ab1276220f15811efce5baaaa Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Fri, 31 Jan 2025 14:52:15 +0100 Subject: [PATCH 2/3] test: add missing filetest for reply edit --- examples/gno.land/r/nt/boards2/public.gno | 2 + .../gno.land/r/nt/boards2/z_12_a_filetest.gno | 37 +++++++++++++++++ .../gno.land/r/nt/boards2/z_12_b_filetest.gno | 40 +++++++++++++++++++ .../gno.land/r/nt/boards2/z_12_c_filetest.gno | 20 ++++++++++ .../gno.land/r/nt/boards2/z_12_d_filetest.gno | 23 +++++++++++ .../gno.land/r/nt/boards2/z_12_e_filetest.gno | 27 +++++++++++++ .../gno.land/r/nt/boards2/z_12_f_filetest.gno | 32 +++++++++++++++ .../gno.land/r/nt/boards2/z_12_g_filetest.gno | 34 ++++++++++++++++ .../gno.land/r/nt/boards2/z_12_h_filetest.gno | 28 +++++++++++++ 9 files changed, 243 insertions(+) create mode 100644 examples/gno.land/r/nt/boards2/z_12_a_filetest.gno create mode 100644 examples/gno.land/r/nt/boards2/z_12_b_filetest.gno create mode 100644 examples/gno.land/r/nt/boards2/z_12_c_filetest.gno create mode 100644 examples/gno.land/r/nt/boards2/z_12_d_filetest.gno create mode 100644 examples/gno.land/r/nt/boards2/z_12_e_filetest.gno create mode 100644 examples/gno.land/r/nt/boards2/z_12_f_filetest.gno create mode 100644 examples/gno.land/r/nt/boards2/z_12_g_filetest.gno create mode 100644 examples/gno.land/r/nt/boards2/z_12_h_filetest.gno diff --git a/examples/gno.land/r/nt/boards2/public.gno b/examples/gno.land/r/nt/boards2/public.gno index 3e7f2753474..7c764399a4e 100644 --- a/examples/gno.land/r/nt/boards2/public.gno +++ b/examples/gno.land/r/nt/boards2/public.gno @@ -210,6 +210,8 @@ func EditReply(bid BoardID, threadID, replyID PostID, body string) { board := mustGetBoard(bid) thread := mustGetThread(board, threadID) reply := mustGetReply(thread, replyID) + assertReplyVisible(reply) + if std.GetOrigCaller() != reply.GetCreator() { panic("only the reply creator is allowed to edit it") } diff --git a/examples/gno.land/r/nt/boards2/z_12_a_filetest.gno b/examples/gno.land/r/nt/boards2/z_12_a_filetest.gno new file mode 100644 index 00000000000..9650bf29bb0 --- /dev/null +++ b/examples/gno.land/r/nt/boards2/z_12_a_filetest.gno @@ -0,0 +1,37 @@ +package main + +import ( + "std" + "strings" + + "gno.land/r/nt/boards2" +) + +const ( + owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 + body = "Test reply" + path = "test-board/1/2" +) + +var ( + bid boards2.BoardID + tid, rid boards2.PostID +) + +func init() { + std.TestSetOrigCaller(owner) + bid = boards2.CreateBoard("test-board") + tid = boards2.CreateThread(bid, "Foo", "bar") + rid = boards2.CreateReply(bid, tid, 0, "body") +} + +func main() { + boards2.EditReply(bid, tid, rid, body) + + // Render content must contain the modified reply + content := boards2.Render(path) + println(strings.Contains(content, "\n> "+body+"\n")) +} + +// Output: +// true diff --git a/examples/gno.land/r/nt/boards2/z_12_b_filetest.gno b/examples/gno.land/r/nt/boards2/z_12_b_filetest.gno new file mode 100644 index 00000000000..406d658c731 --- /dev/null +++ b/examples/gno.land/r/nt/boards2/z_12_b_filetest.gno @@ -0,0 +1,40 @@ +package main + +import ( + "std" + "strings" + + "gno.land/r/nt/boards2" +) + +const ( + owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 + body = "Test reply" + path = "test-board/1/2" +) + +var ( + bid boards2.BoardID + tid, rid boards2.PostID +) + +func init() { + std.TestSetOrigCaller(owner) + bid = boards2.CreateBoard("test-board") + tid = boards2.CreateThread(bid, "Foo", "bar") + + // Create a reply and a sub reply + parentRID := boards2.CreateReply(bid, tid, 0, "Parent") + rid = boards2.CreateReply(bid, tid, parentRID, "Child") +} + +func main() { + boards2.EditReply(bid, tid, rid, body) + + // Render content must contain the modified reply + content := boards2.Render(path) + println(strings.Contains(content, "\n> > "+body+"\n")) +} + +// Output: +// true diff --git a/examples/gno.land/r/nt/boards2/z_12_c_filetest.gno b/examples/gno.land/r/nt/boards2/z_12_c_filetest.gno new file mode 100644 index 00000000000..56501415bb6 --- /dev/null +++ b/examples/gno.land/r/nt/boards2/z_12_c_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.EditReply(404, 1, 0, "body") +} + +// Error: +// board does not exist with ID: 404 diff --git a/examples/gno.land/r/nt/boards2/z_12_d_filetest.gno b/examples/gno.land/r/nt/boards2/z_12_d_filetest.gno new file mode 100644 index 00000000000..373168e6a74 --- /dev/null +++ b/examples/gno.land/r/nt/boards2/z_12_d_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.EditReply(bid, 404, 0, "body") +} + +// Error: +// thread does not exist with ID: 404 diff --git a/examples/gno.land/r/nt/boards2/z_12_e_filetest.gno b/examples/gno.land/r/nt/boards2/z_12_e_filetest.gno new file mode 100644 index 00000000000..f43d272de8f --- /dev/null +++ b/examples/gno.land/r/nt/boards2/z_12_e_filetest.gno @@ -0,0 +1,27 @@ +package main + +import ( + "std" + + "gno.land/r/nt/boards2" +) + +const owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 + +var ( + bid boards2.BoardID + tid boards2.PostID +) + +func init() { + std.TestSetOrigCaller(owner) + bid = boards2.CreateBoard("test-board") + tid = boards2.CreateThread(bid, "Foo", "bar") +} + +func main() { + boards2.EditReply(bid, tid, 404, "body") +} + +// Error: +// reply does not exist with ID: 404 diff --git a/examples/gno.land/r/nt/boards2/z_12_f_filetest.gno b/examples/gno.land/r/nt/boards2/z_12_f_filetest.gno new file mode 100644 index 00000000000..aa8778785a4 --- /dev/null +++ b/examples/gno.land/r/nt/boards2/z_12_f_filetest.gno @@ -0,0 +1,32 @@ +package main + +import ( + "std" + + "gno.land/r/nt/boards2" +) + +const ( + owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 + user = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2 +) + +var ( + bid boards2.BoardID + tid, rid boards2.PostID +) + +func init() { + std.TestSetOrigCaller(owner) + bid = boards2.CreateBoard("test-board") + tid = boards2.CreateThread(bid, "Foo", "bar") + rid = boards2.CreateReply(bid, tid, 0, "body") + std.TestSetOrigCaller(user) +} + +func main() { + boards2.EditReply(bid, tid, rid, "new body") +} + +// Error: +// only the reply creator is allowed to edit it diff --git a/examples/gno.land/r/nt/boards2/z_12_g_filetest.gno b/examples/gno.land/r/nt/boards2/z_12_g_filetest.gno new file mode 100644 index 00000000000..e3506b8c1a1 --- /dev/null +++ b/examples/gno.land/r/nt/boards2/z_12_g_filetest.gno @@ -0,0 +1,34 @@ +package main + +import ( + "std" + + "gno.land/r/nt/boards2" +) + +const ( + owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 + user = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2 +) + +var ( + bid boards2.BoardID + tid, rid boards2.PostID +) + +func init() { + std.TestSetOrigCaller(owner) + bid = boards2.CreateBoard("test-board") + tid = boards2.CreateThread(bid, "Foo", "bar") + rid = boards2.CreateReply(bid, tid, 0, "body") + + // Flag the reply so it's hidden + boards2.FlagReply(bid, tid, rid, "reason") +} + +func main() { + boards2.EditReply(bid, tid, rid, "body") +} + +// Error: +// reply with ID: 2 was hidden diff --git a/examples/gno.land/r/nt/boards2/z_12_h_filetest.gno b/examples/gno.land/r/nt/boards2/z_12_h_filetest.gno new file mode 100644 index 00000000000..2fbd84be1b7 --- /dev/null +++ b/examples/gno.land/r/nt/boards2/z_12_h_filetest.gno @@ -0,0 +1,28 @@ +package main + +import ( + "std" + + "gno.land/r/nt/boards2" +) + +const owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 + +var ( + bid boards2.BoardID + tid, rid boards2.PostID +) + +func init() { + std.TestSetOrigCaller(owner) + bid = boards2.CreateBoard("test-board") + tid = boards2.CreateThread(bid, "Foo", "bar") + rid = boards2.CreateReply(bid, tid, 0, "body") +} + +func main() { + boards2.EditReply(bid, tid, rid, "") +} + +// Error: +// body is empty From d5a83a1e91b014200c9a00a3fd5117275fbaf806 Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Fri, 31 Jan 2025 15:01:18 +0100 Subject: [PATCH 3/3] fix: correct `CreateReply` function so filetests pass This correction is already present in an unmerged PR for reply creation filtests. CHanging it here again so tests in this PR pass. --- examples/gno.land/r/nt/boards2/public.gno | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gno.land/r/nt/boards2/public.gno b/examples/gno.land/r/nt/boards2/public.gno index 7c764399a4e..46f03d34cce 100644 --- a/examples/gno.land/r/nt/boards2/public.gno +++ b/examples/gno.land/r/nt/boards2/public.gno @@ -100,7 +100,7 @@ func CreateReply(bid BoardID, threadID, replyID PostID, body string) PostID { assertThreadVisible(thread) var reply *Post - if replyID == threadID { + if replyID == 0 { // When the parent reply is the thread just add reply to thread reply = thread.AddReply(caller, body) } else {