stringify_proposal_00_filetest.gno
2.38 Kb · 90 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.Member{
22 InvitationPoints: t.InvitationPoints,
23 }
24 default:
25 panic("unsupported tier: " + tier)
26 }
27}
28
29func init() {
30 // Load members for testing
31 mstore := memberstore.Get()
32 mstore.DeleteAll()
33 mstore.SetTier(memberstore.T1)
34 mstore.SetMember(memberstore.T1, testUser, memberByTier(memberstore.T1))
35
36 // Set up the DAO implementation using proper constructor
37 govDAO := impl.NewGovDAO()
38 dao.UpdateImpl(cross, dao.UpdateRequest{
39 DAO: govDAO,
40 AllowedDAOs: []string{"gno.land/r/test", "gno.land/r/gov/dao/v3/impl"},
41 })
42}
43
44func main() {
45 // Create an executor in a specific realm to test creation realm tracking
46 testing.SetRealm(testing.NewCodeRealm("gno.land/r/template/contract"))
47 executor := dao.NewSimpleExecutor(func(realm) error { return nil }, "Test executor description")
48
49 // Create a proposal request
50 proposalRequest := dao.NewProposalRequest(
51 "Test Proposal Title",
52 "This is a test proposal description to verify StringifyProposal works correctly.",
53 executor,
54 )
55
56 // Switch to user realm to create the proposal
57 testing.SetOriginCaller(testUser)
58 testing.SetRealm(testing.NewUserRealm(testUser))
59 pid := dao.MustCreateProposal(cross, proposalRequest)
60
61 // Get the proposal and test the core functionality
62 prop := dao.MustGetProposal(cross, pid)
63
64 // Test that executor string is captured correctly
65 println("Executor string:", prop.ExecutorString())
66
67 // Test that executor creation realm is captured correctly
68 println("Executor creation realm:", prop.ExecutorCreationRealm())
69
70 // Stringify
71 println("----")
72 println(impl.StringifyProposal(prop))
73}
74
75// Output:
76// Executor string: Test executor description
77// Executor creation realm: gno.land/r/template/contract
78// ----
79//
80// ### Title: Test Proposal Title
81//
82// ### Proposed by: g1w3jhxazlta047h6lta047h6lta047h6lwmjv0n
83//
84// This is a test proposal description to verify StringifyProposal works correctly.
85//
86// This proposal contains the following metadata:
87//
88// Test executor description
89//
90// Executor created in: gno.land/r/template/contract