From 691a1ba97c14566fbbb4e206589f678a233eb8ad Mon Sep 17 00:00:00 2001 From: Manfred Touron <94029+moul@users.noreply.github.com> Date: Wed, 24 Jul 2024 13:04:33 +0200 Subject: [PATCH] feat(r/gnoland/home): add AdminSetOverride (#2583) My goal was to implement this for Test 4, but the current upgrade strategy does not include contract patching. --------- Signed-off-by: moul <94029+moul@users.noreply.github.com> --- examples/gno.land/r/gnoland/home/gno.mod | 1 + examples/gno.land/r/gnoland/home/home.gno | 20 ++++++++++++++++ .../r/gnoland/home/overide_filetest.gno | 24 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 examples/gno.land/r/gnoland/home/overide_filetest.gno diff --git a/examples/gno.land/r/gnoland/home/gno.mod b/examples/gno.land/r/gnoland/home/gno.mod index 2864958930c..cb2ec58b665 100644 --- a/examples/gno.land/r/gnoland/home/gno.mod +++ b/examples/gno.land/r/gnoland/home/gno.mod @@ -1,6 +1,7 @@ module gno.land/r/gnoland/home require ( + gno.land/p/demo/ownable v0.0.0-latest gno.land/p/demo/ufmt v0.0.0-latest gno.land/p/demo/ui v0.0.0-latest gno.land/r/gnoland/blog v0.0.0-latest diff --git a/examples/gno.land/r/gnoland/home/home.gno b/examples/gno.land/r/gnoland/home/home.gno index aca1007036e..62984711d79 100644 --- a/examples/gno.land/r/gnoland/home/home.gno +++ b/examples/gno.land/r/gnoland/home/home.gno @@ -3,6 +3,7 @@ package home import ( "std" + "gno.land/p/demo/ownable" "gno.land/p/demo/ufmt" "gno.land/p/demo/ui" blog "gno.land/r/gnoland/blog" @@ -12,7 +13,16 @@ import ( // XXX: use an updatable block system to update content from a DAO // XXX: var blocks avl.Tree +var ( + override string + admin = ownable.NewWithAddress("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq") // @manfred by default +) + func Render(_ string) string { + if override != "" { + return override + } + dom := ui.DOM{Prefix: "r/gnoland/home:"} dom.Title = "Welcome to gno.land" dom.Classes = []string{"gno-tmpl-section"} @@ -267,3 +277,13 @@ func discoverLinks() ui.Element { `), } } + +func AdminSetOverride(content string) { + admin.AssertCallerIsOwner() + override = content +} + +func AdminTransferOwnership(newAdmin std.Address) { + admin.AssertCallerIsOwner() + admin.TransferOwnership(newAdmin) +} diff --git a/examples/gno.land/r/gnoland/home/overide_filetest.gno b/examples/gno.land/r/gnoland/home/overide_filetest.gno new file mode 100644 index 00000000000..34356b93349 --- /dev/null +++ b/examples/gno.land/r/gnoland/home/overide_filetest.gno @@ -0,0 +1,24 @@ +package main + +import ( + "std" + + "gno.land/p/demo/testutils" + "gno.land/r/gnoland/home" +) + +func main() { + std.TestSetOrigCaller("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq") + home.AdminSetOverride("Hello World!") + println(home.Render("")) + home.AdminTransferOwnership(testutils.TestAddress("newAdmin")) + defer func() { + r := recover() + println("r: ", r) + }() + home.AdminSetOverride("Not admin anymore") +} + +// Output: +// Hello World! +// r: unauthorized; caller is not owner