From f4dc8a9aa416470b284f202e8be847f4be2f7809 Mon Sep 17 00:00:00 2001 From: Manfred Touron <94029+moul@users.noreply.github.com> Date: Wed, 19 Jun 2024 19:43:02 +0200 Subject: [PATCH] feat: refactor govdao structure and examples (#2379) - remove `gov/integration/` - remove `gov/proposals/` - move the integration test in `gov/dao/*test.gno` - add `r/sys/validators.Render()` Signed-off-by: moul <94029+moul@users.noreply.github.com> --- .../gno.land/r/gov/dao/prop1_filetest.gno | 85 +++++++++++++++++++ examples/gno.land/r/gov/integration/gno.mod | 3 - .../r/gov/integration/integration.gno | 4 - .../gno.land/r/gov/integration/z_filetest.gno | 45 ---------- .../gno.land/r/gov/proposals/prop1/gno.mod | 6 -- .../gno.land/r/gov/proposals/prop1/prop1.gno | 36 -------- .../gno.land/r/sys/validators/validators.gno | 13 +++ 7 files changed, 98 insertions(+), 94 deletions(-) create mode 100644 examples/gno.land/r/gov/dao/prop1_filetest.gno delete mode 100644 examples/gno.land/r/gov/integration/gno.mod delete mode 100644 examples/gno.land/r/gov/integration/integration.gno delete mode 100644 examples/gno.land/r/gov/integration/z_filetest.gno delete mode 100644 examples/gno.land/r/gov/proposals/prop1/gno.mod delete mode 100644 examples/gno.land/r/gov/proposals/prop1/prop1.gno diff --git a/examples/gno.land/r/gov/dao/prop1_filetest.gno b/examples/gno.land/r/gov/dao/prop1_filetest.gno new file mode 100644 index 00000000000..7072618a4a7 --- /dev/null +++ b/examples/gno.land/r/gov/dao/prop1_filetest.gno @@ -0,0 +1,85 @@ +// Please note that this package is intended for demonstration purposes only. +// You could execute this code (the init part) by running a `maketx run` command +// or by uploading a similar package to a personal namespace. +// +// For the specific case of validators, a `r/gnoland/valopers` will be used to +// organize the lifecycle of validators (register, etc), and this more complex +// contract will be responsible to generate proposals. +package main + +import ( + "std" + + govdao "gno.land/r/gov/dao" + "gno.land/r/sys/validators" +) + +func init() { + // Create the validators change proposal. + changesFn := func() []validators.Change { + return []validators.Change{ + // add a new validator. + {Address: std.Address("g12345678"), Power: 1}, + // remove an existing validator. + {Address: std.Address("g000000000"), Power: 0}, + } + } + + // Wraps changesFn to emit a certified event only if executed from a + // complete governance proposal process. + executor := validators.NewPropExecutor(changesFn) + + // Create a proposal. + // XXX: payment + comment := "manual valset changes proposal example" + govdao.Propose(comment, executor) +} + +func main() { + println("--") + println(govdao.Render("")) + println("--") + println(govdao.Render("1")) + println("--") + govdao.VoteOnProposal(1, "YES") + println("--") + println(govdao.Render("1")) + println("--") + println(validators.Render("")) + println("--") + govdao.ExecuteProposal(1) + println("--") + println(govdao.Render("1")) + println("--") + println(validators.Render("")) +} + +// Output: +// -- +// - [/r/gov/dao:0](0) - manual valset changes proposal example (by g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm) +// -- +// # Prop#0 +// +// manual valset changes proposal example +// Status: active +// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm +// -- +// -- +// # Prop#0 +// +// manual valset changes proposal example +// Status: accepted +// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm +// -- +// No valset changes to apply. +// -- +// -- +// # Prop#0 +// +// manual valset changes proposal example +// Status: success +// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm +// -- +// Valset changes to apply: +// - g12345678 (1) +// - g000000000 (0) diff --git a/examples/gno.land/r/gov/integration/gno.mod b/examples/gno.land/r/gov/integration/gno.mod deleted file mode 100644 index f584f375133..00000000000 --- a/examples/gno.land/r/gov/integration/gno.mod +++ /dev/null @@ -1,3 +0,0 @@ -// Draft - -module integration diff --git a/examples/gno.land/r/gov/integration/integration.gno b/examples/gno.land/r/gov/integration/integration.gno deleted file mode 100644 index 5b47b3dec83..00000000000 --- a/examples/gno.land/r/gov/integration/integration.gno +++ /dev/null @@ -1,4 +0,0 @@ -// Package integration tests the govdao ecosystem from an external perspective. -// It aims to confirm that the system can remain static while supporting -// additional DAO use cases over time. -package integration diff --git a/examples/gno.land/r/gov/integration/z_filetest.gno b/examples/gno.land/r/gov/integration/z_filetest.gno deleted file mode 100644 index a85588e4f11..00000000000 --- a/examples/gno.land/r/gov/integration/z_filetest.gno +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - govdao "gno.land/r/gov/dao" - _ "gno.land/r/gov/proposals/prop1" -) - -func main() { - println("--") - println(govdao.Render("")) - println("--") - println(govdao.Render("1")) - println("--") - govdao.VoteOnProposal(1, "YES") - println("--") - println(govdao.Render("1")) - println("--") - govdao.ExecuteProposal(1) - println("--") - println(govdao.Render("1")) -} - -// Output: -// -- -// - [/r/gov/dao:0](0) - manual valset changes proposal example (by g1tk0fscr3p5g8hnhxq6v93jxcpm5g3cstlxfxa3) -// -- -// # Prop#0 -// -// manual valset changes proposal example -// Status: active -// Author: g1tk0fscr3p5g8hnhxq6v93jxcpm5g3cstlxfxa3 -// -- -// -- -// # Prop#0 -// -// manual valset changes proposal example -// Status: accepted -// Author: g1tk0fscr3p5g8hnhxq6v93jxcpm5g3cstlxfxa3 -// -- -// -- -// # Prop#0 -// -// manual valset changes proposal example -// Status: success -// Author: g1tk0fscr3p5g8hnhxq6v93jxcpm5g3cstlxfxa3 diff --git a/examples/gno.land/r/gov/proposals/prop1/gno.mod b/examples/gno.land/r/gov/proposals/prop1/gno.mod deleted file mode 100644 index 97faf2aff27..00000000000 --- a/examples/gno.land/r/gov/proposals/prop1/gno.mod +++ /dev/null @@ -1,6 +0,0 @@ -module gno.land/r/gov/proposals/prop1 - -require ( - gno.land/r/gov/dao v0.0.0-latest - gno.land/r/sys/validators v0.0.0-latest -) diff --git a/examples/gno.land/r/gov/proposals/prop1/prop1.gno b/examples/gno.land/r/gov/proposals/prop1/prop1.gno deleted file mode 100644 index 68cd9d60bfa..00000000000 --- a/examples/gno.land/r/gov/proposals/prop1/prop1.gno +++ /dev/null @@ -1,36 +0,0 @@ -// Package prop1 is an example of proposal creation using a contract. -// -// Please note that this package is intended for demonstration purposes only. -// You could execute this code by running a `maketx run` command or by uploading -// a similar package to a personal namespace. -// -// For the specific case of validators, a `r/gnoland/valopers` will be used to -// organize the lifecycle of validators (register, etc), and this more complex -// contract will be responsible to generate proposals. -package prop1 - -import ( - "std" - - govdao "gno.land/r/gov/dao" - "gno.land/r/sys/validators" -) - -func init() { - // Create the validators change proposal. - changesFn := func() []validators.Change { - return []validators.Change{ - {Address: std.Address("g12345678"), Power: 1}, // add a new validator - {Address: std.Address("g000000000"), Power: 0}, // remove an existing validator - } - } - - // Wraps changesFn to emit a certified event only if executed from a - // complete governance proposal process. - executor := validators.NewPropExecutor(changesFn) - - // Create a proposal. - // XXX: payment - comment := "manual valset changes proposal example" - govdao.Propose(comment, executor) -} diff --git a/examples/gno.land/r/sys/validators/validators.gno b/examples/gno.land/r/sys/validators/validators.gno index 5fb08ebbfc7..669b688727a 100644 --- a/examples/gno.land/r/sys/validators/validators.gno +++ b/examples/gno.land/r/sys/validators/validators.gno @@ -3,6 +3,7 @@ package validators import ( "std" + "strconv" "gno.land/p/gov/proposal" ) @@ -45,3 +46,15 @@ func getAndResetChanges() []Change { unappliedChanges = []Change{} return cpy } + +func Render(_ string) string { + if len(unappliedChanges) == 0 { + return "No valset changes to apply." + } + + output := "Valset changes to apply:\n" + for _, change := range unappliedChanges { + output += "- " + string(change.Address) + " (" + strconv.Itoa(change.Power) + ")\n" + } + return output +}