Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

z_governed_instructions_filetest.gno

2.09 Kb · 66 lines
 1// PKGPATH: gno.land/r/gnops/valopers/proposal/filetests/z_governed_instructions_filetest
 2//
 3// Positive counterpart to
 4// r/gnops/valopers/filetests/z_foreign_realm_capability_filetest.gno.
 5//
 6// Sealing the privileged closure inside a dao.ProposalRequest closes the
 7// capability leak, but it would be worthless if it
 8// also broke the legitimate path. This runs the real thing end to end —
 9// propose, vote, execute — and asserts the instructions are actually
10// rewritten.
11//
12// Read the two files together: same write, but reachable ONLY with a
13// GovDAO majority behind it.
14package z_governed_instructions_filetest
15
16import (
17	"chain/runtime/unsafe"
18	"strings"
19	"testing"
20
21	"gno.land/r/gnops/valopers"
22	"gno.land/r/gnops/valopers/proposal"
23	"gno.land/r/gov/dao"
24	daov3init "gno.land/r/gov/dao/init/v0"
25)
26
27var member address = unsafe.OriginCaller()
28
29func init(cur realm) {
30	daov3init.InitWithUsers(cross(cur), member)
31
32	testing.SetOriginCaller(member)
33	testing.SetRealm(testing.NewUserRealm(member))
34
35	pr := proposal.ProposeNewInstructionsProposalRequest(cross(cur), "GOVERNED-INSTRUCTIONS")
36	dao.MustCreateProposal(cross(cur), pr)
37}
38
39func main(cur realm) {
40	testing.SetOriginCaller(member)
41
42	println("before:", strings.Contains(valopers.Render(""), "GOVERNED-INSTRUCTIONS"))
43
44	// Voter-facing disclosure (the pr6068 anti-phishing line, rendered as
45	// "Executor created in: ..."). It moved from r/gnops/valopers/proposal
46	// to r/gnops/valopers when request construction moved into the realm,
47	// so pin it rather than let it drift unobserved.
48	prop, err := dao.GetProposal(dao.ProposalID(0))
49	if err != nil {
50		panic(err)
51	}
52	println("title:", prop.Title())
53	println("executor created in:", prop.ExecutorCreationRealm())
54
55	dao.MustVoteOnProposal(cross(cur), dao.NewVoteRequest(dao.YesVote, dao.ProposalID(0)))
56	println("executed:", dao.ExecuteProposal(cross(cur), dao.ProposalID(0)))
57
58	println("after:", strings.Contains(valopers.Render(""), "GOVERNED-INSTRUCTIONS"))
59}
60
61// Output:
62// before: false
63// title: /r/gnops/valopers: Update instructions
64// executor created in: gno.land/r/gnops/valopers
65// executed: true
66// after: true