Skip to content

Commit

Permalink
fix: govDAO: Use GetOrigCaller() to be able to run proposals using Ms…
Browse files Browse the repository at this point in the history
…gRun (gnolang#2556)

Fixed that and also improve details rendering adding an extra space.

---------

Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
  • Loading branch information
ajnavarro authored Jul 9, 2024
1 parent f980fd6 commit a7fd05b
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 32 deletions.
18 changes: 10 additions & 8 deletions examples/gno.land/r/gov/dao/dao.gno
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func Propose(comment string, executor pproposal.Executor) int {
if executor == nil {
panic(msgMissingExecutor)
}
caller := std.PrevRealm().Addr()
caller := std.GetOrigCaller() // XXX: CHANGE THIS WHEN MSGRUN PERSIST CODE ESCAPING THE main() SCOPE! IT IS UNSAFE!
AssertIsMember(caller)

prop := &proposal{
Expand All @@ -78,7 +78,7 @@ func Propose(comment string, executor pproposal.Executor) int {

func VoteOnProposal(idx int, option string) {
assertProposalExists(idx)
caller := std.PrevRealm().Addr()
caller := std.GetOrigCaller() // XXX: CHANGE THIS WHEN MSGRUN PERSIST CODE ESCAPING THE main() SCOPE! IT IS UNSAFE!
AssertIsMember(caller)

prop := getProposal(idx)
Expand Down Expand Up @@ -151,7 +151,7 @@ func Render(path string) string {

output := ""
for idx, prop := range proposals {
output += ufmt.Sprintf("- [/r/gov/dao:%d](%d) - %s (**%s**)(by %s)\n", idx, idx, prop.comment, string(prop.Status()), prop.author)
output += ufmt.Sprintf("- [%d](/r/gov/dao:%d) - %s (**%s**)(by %s)\n", idx, idx, prop.comment, string(prop.Status()), prop.author)
}

return output
Expand All @@ -174,15 +174,17 @@ func Render(path string) string {
}

output := ""
output += ufmt.Sprintf("# Prop#%d", idx) + "\n"
output += "\n"
output += ufmt.Sprintf("# Prop #%d", idx)
output += "\n\n"
output += prop.comment
output += "\n"
output += "\n\n"
output += ufmt.Sprintf("Status: %s", string(prop.Status()))
output += "\n"
output += "\n\n"
output += ufmt.Sprintf("Voting status: %s", prop.voter.Status(vs))
output += "\n"
output += "\n\n"
output += ufmt.Sprintf("Author: %s", string(prop.author))
output += "\n\n"

return output
}

Expand Down
63 changes: 49 additions & 14 deletions examples/gno.land/r/gov/dao/dao_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,17 @@ func TestPackage(t *testing.T) {
})

out = Render("0")
expected = `# Prop#0
expected = `# Prop #0
dummy proposal
Status: active
Voting status: YES: 1, NO: 0, percent: 33, members: 3
Author: g1w5c47h6lta047h6lta047h6lta047h6ly5kscr`
Author: g1w5c47h6lta047h6lta047h6lta047h6ly5kscr
`

urequire.Equal(t, expected, out)

Expand All @@ -69,12 +74,17 @@ Author: g1w5c47h6lta047h6lta047h6lta047h6ly5kscr`
})

out = Render("0")
expected = `# Prop#0
expected = `# Prop #0
dummy proposal
Status: active
Voting status: YES: 1, NO: 1, percent: 33, members: 3
Author: g1w5c47h6lta047h6lta047h6lta047h6ly5kscr`
Author: g1w5c47h6lta047h6lta047h6lta047h6ly5kscr
`

urequire.Equal(t, expected, out)

Expand All @@ -84,12 +94,17 @@ Author: g1w5c47h6lta047h6lta047h6lta047h6ly5kscr`
})

out = Render("0")
expected = `# Prop#0
expected = `# Prop #0
dummy proposal
Status: accepted
Voting status: YES: 2, NO: 1, percent: 66, members: 3
Author: g1w5c47h6lta047h6lta047h6lta047h6ly5kscr`
Author: g1w5c47h6lta047h6lta047h6lta047h6ly5kscr
`

urequire.Equal(t, expected, out)

Expand All @@ -98,12 +113,17 @@ Author: g1w5c47h6lta047h6lta047h6lta047h6ly5kscr`
members = append(members, u4)

out = Render("0")
expected = `# Prop#0
expected = `# Prop #0
dummy proposal
Status: active
Voting status: YES: 2, NO: 1, percent: 50, members: 4
Author: g1w5c47h6lta047h6lta047h6lta047h6ly5kscr`
Author: g1w5c47h6lta047h6lta047h6lta047h6ly5kscr
`

urequire.Equal(t, expected, out)

Expand All @@ -113,25 +133,35 @@ Author: g1w5c47h6lta047h6lta047h6lta047h6ly5kscr`
})

out = Render("0")
expected = `# Prop#0
expected = `# Prop #0
dummy proposal
Status: accepted
Voting status: YES: 3, NO: 1, percent: 75, members: 4
Author: g1w5c47h6lta047h6lta047h6lta047h6ly5kscr`
Author: g1w5c47h6lta047h6lta047h6lta047h6ly5kscr
`

urequire.Equal(t, expected, out)

ExecuteProposal(pid)
urequire.True(t, called)

out = Render("0")
expected = `# Prop#0
expected = `# Prop #0
dummy proposal
Status: succeeded
Voting status: YES: 3, NO: 1, percent: 75, members: 4
Author: g1w5c47h6lta047h6lta047h6lta047h6ly5kscr`
Author: g1w5c47h6lta047h6lta047h6lta047h6ly5kscr
`

urequire.Equal(t, expected, out)

Expand All @@ -145,12 +175,17 @@ Author: g1w5c47h6lta047h6lta047h6lta047h6ly5kscr`

// even if we added a new member the executed proposal is showing correctly the members that voted on it
out = Render("0")
expected = `# Prop#0
expected = `# Prop #0
dummy proposal
Status: succeeded
Voting status: YES: 3, NO: 1, percent: 75, members: 4
Author: g1w5c47h6lta047h6lta047h6lta047h6ly5kscr`
Author: g1w5c47h6lta047h6lta047h6lta047h6ly5kscr
`

urequire.Equal(t, expected, out)

Expand Down
25 changes: 20 additions & 5 deletions examples/gno.land/r/gov/dao/prop1_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -81,34 +81,49 @@ func main() {

// Output:
// --
// - [/r/gov/dao:0](0) - adding someone to vote (**succeeded**)(by g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm)
// - [/r/gov/dao:1](1) - manual valset changes proposal example (**active**)(by g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm)
// - [0](/r/gov/dao:0) - adding someone to vote (**succeeded**)(by g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm)
// - [1](/r/gov/dao:1) - manual valset changes proposal example (**active**)(by g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm)
//
// --
// # Prop#1
// # Prop #1
//
// manual valset changes proposal example
//
// Status: active
//
// Voting status: YES: 0, NO: 0, percent: 0, members: 1
//
// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
//
//
// --
// --
// # Prop#1
// # Prop #1
//
// manual valset changes proposal example
//
// Status: accepted
//
// Voting status: YES: 1, NO: 0, percent: 100, members: 1
//
// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
//
//
// --
// No valset changes to apply.
// --
// --
// # Prop#1
// # Prop #1
//
// manual valset changes proposal example
//
// Status: succeeded
//
// Voting status: YES: 1, NO: 0, percent: 100, members: 1
//
// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
//
//
// --
// Valset changes:
// - #123: g12345678 (10)
Expand Down
25 changes: 20 additions & 5 deletions examples/gno.land/r/gov/dao/prop2_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -65,36 +65,51 @@ func main() {

// Output:
// --
// - [/r/gov/dao:0](0) - adding someone to vote (**succeeded**)(by g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm)
// - [/r/gov/dao:1](1) - post a new blogpost about govdao (**active**)(by g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm)
// - [0](/r/gov/dao:0) - adding someone to vote (**succeeded**)(by g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm)
// - [1](/r/gov/dao:1) - post a new blogpost about govdao (**active**)(by g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm)
//
// --
// # Prop#1
// # Prop #1
//
// post a new blogpost about govdao
//
// Status: active
//
// Voting status: YES: 0, NO: 0, percent: 0, members: 1
//
// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
//
//
// --
// --
// # Prop#1
// # Prop #1
//
// post a new blogpost about govdao
//
// Status: accepted
//
// Voting status: YES: 1, NO: 0, percent: 100, members: 1
//
// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
//
//
// --
// # Gnoland's Blog
//
// No posts.
// --
// --
// # Prop#1
// # Prop #1
//
// post a new blogpost about govdao
//
// Status: succeeded
//
// Voting status: YES: 1, NO: 0, percent: 100, members: 1
//
// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
//
//
// --
// # Gnoland's Blog
//
Expand Down

0 comments on commit a7fd05b

Please sign in to comment.