stringify_proposal_00_filetest.gno
2.36 Kb · 85 lines
1// PKGPATH: gno.land/r/test
2package test
3
4import (
5 "testing"
6
7 "gno.land/p/nt/testutils/v0"
8 "gno.land/r/gov/dao"
9 "gno.land/r/gov/dao/v3/impl"
10 "gno.land/r/gov/dao/v3/memberstore"
11)
12
13var (
14 testUser = testutils.TestAddress("test")
15)
16
17func memberByTier(tier string) *memberstore.Member {
18 switch tier {
19 case memberstore.T1:
20 t, _ := memberstore.GetTier(memberstore.T1)
21 return memberstore.NewMember(t.InvitationPoints)
22 default:
23 panic("unsupported tier: " + tier)
24 }
25}
26
27func init(cur realm) {
28 // Load members for testing
29 mstore := memberstore.Get(0, cur)
30 mstore.DeleteAll()
31 mstore.SetTier(memberstore.T1)
32 mstore.SetMember(memberstore.T1, testUser, memberByTier(memberstore.T1))
33
34 // Set up the DAO implementation using proper constructor
35 govDAO := impl.NewGovDAO()
36 dao.UpdateImpl(cross(cur), dao.NewUpdateRequest(govDAO, []string{"gno.land/r/test", "gno.land/r/gov/dao/v3/impl"}))
37}
38
39func main(cur realm) {
40 // Create an executor in a specific realm to test creation realm tracking
41 testing.SetRealm(testing.NewCodeRealm("gno.land/r/template/contract"))
42 executor := dao.NewSimpleExecutor(0, cur, func(realm) error { return nil }, "Test executor description")
43
44 // Create a proposal request
45 proposalRequest := dao.NewProposalRequest(
46 "Test Proposal Title",
47 "This is a test proposal description to verify StringifyProposal works correctly.",
48 executor,
49 )
50
51 // Switch to user realm to create the proposal
52 testing.SetOriginCaller(testUser)
53 testing.SetRealm(testing.NewUserRealm(testUser))
54 pid := dao.MustCreateProposal(cross(cur), proposalRequest)
55
56 // Get the proposal and test the core functionality
57 prop := dao.MustGetProposal(pid)
58
59 // Test that executor string is captured correctly
60 println("Executor string:", prop.ExecutorString())
61
62 // Test that executor creation realm is captured correctly
63 println("Executor creation realm:", prop.ExecutorCreationRealm())
64
65 // Stringify
66 println("----")
67 println(impl.StringifyProposal(prop))
68}
69
70// Output:
71// Executor string: Test executor description
72// Executor creation realm: gno.land/r/template/contract
73// ----
74//
75// ### Title: Test Proposal Title
76//
77// ### Proposed by: g1w3jhxazlta047h6lta047h6lta047h6lwmjv0n
78//
79// This is a test proposal description to verify StringifyProposal works correctly.
80//
81// This proposal contains the following metadata:
82//
83// Test executor description
84//
85// Executor created in: gno.land/r/template/contract