Skip to content

Commit

Permalink
feat: refactor govdao structure and examples (gnolang#2379)
Browse files Browse the repository at this point in the history
- remove `gov/integration/`
- remove `gov/proposals/`
- move the integration test in `gov/dao/*test.gno`
- add `r/sys/validators.Render()`

Signed-off-by: moul <[email protected]>
  • Loading branch information
moul authored and gfanton committed Jul 23, 2024
1 parent ca37da4 commit f4dc8a9
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 94 deletions.
85 changes: 85 additions & 0 deletions examples/gno.land/r/gov/dao/prop1_filetest.gno
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 0 additions & 3 deletions examples/gno.land/r/gov/integration/gno.mod

This file was deleted.

4 changes: 0 additions & 4 deletions examples/gno.land/r/gov/integration/integration.gno

This file was deleted.

45 changes: 0 additions & 45 deletions examples/gno.land/r/gov/integration/z_filetest.gno

This file was deleted.

6 changes: 0 additions & 6 deletions examples/gno.land/r/gov/proposals/prop1/gno.mod

This file was deleted.

36 changes: 0 additions & 36 deletions examples/gno.land/r/gov/proposals/prop1/prop1.gno

This file was deleted.

13 changes: 13 additions & 0 deletions examples/gno.land/r/sys/validators/validators.gno
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package validators

import (
"std"
"strconv"

"gno.land/p/gov/proposal"
)
Expand Down Expand Up @@ -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
}

0 comments on commit f4dc8a9

Please sign in to comment.