Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

z_upgrade_request_test.gno

2.16 Kb · 61 lines
 1package impl
 2
 3import (
 4	"testing"
 5
 6	"gno.land/p/nt/urequire/v0"
 7	"gno.land/r/gov/dao"
 8)
 9
10// Named z_* so it sorts after govdao_test.gno, whose TestUpgradeDaoImplementation
11// swaps the DAO implementation and asserts a hard-coded proposal id. This test
12// creates no proposal, so it is safe to run against the shared state.
13
14// An empty realmPkg would be stored verbatim as an allowlist entry, and
15// InAllowedDAOs compares by exact string against a caller's PkgPath() — which
16// is "" for a user realm. It would also render as a blank name in the grant
17// sentence, so the proposal would not say who it was empowering. Rejected at
18// proposal-construction time so the mistake surfaces to the author rather than
19// at execution. UpdateImpl rejects it too; see r/gov/dao/allowlist_test.gno.
20func TestUpgradeRequestRejectsBlankRealmPkg(cur realm, t *testing.T) {
21	testing.SetOriginCaller(m1)
22	testing.SetRealm(testing.NewUserRealm(m1))
23
24	for _, padded := range []string{" gno.land/r/x", "gno.land/r/x "} {
25		urequire.PanicsWithMessage(t, cur,
26			"realmPkg must not have leading or trailing spaces",
27			func() {
28				NewUpgradeDaoImplRequest(cur, &mockDAO{}, padded, "reason")
29			})
30	}
31
32	for _, blank := range []string{"", "   "} {
33		// PanicsWithMessage, not AbortsWithMessage: this is a same-realm call,
34		// so the guard raises a plain panic rather than a cross-realm abort.
35		urequire.PanicsWithMessage(t, cur,
36			"realmPkg must be the realm path being granted govDAO authority",
37			func() {
38				NewUpgradeDaoImplRequest(cur, &mockDAO{}, blank, "reason")
39			})
40	}
41}
42
43type mockDAO struct{}
44
45func (d *mockDAO) PreCreateProposal(_ int, rlm realm, r dao.ProposalRequest) (address, error) {
46	return m1, nil
47}
48
49func (d *mockDAO) PostCreateProposal(_ int, rlm realm, r dao.ProposalRequest, pid dao.ProposalID) {}
50
51func (d *mockDAO) VoteOnProposal(_ int, rlm realm, r dao.VoteRequest) error { return nil }
52
53func (d *mockDAO) PreExecuteProposal(_ int, rlm realm, pid dao.ProposalID) (bool, error) {
54	return true, nil
55}
56
57func (d *mockDAO) ExecuteProposal(_ int, rlm realm, pid dao.ProposalID, e dao.Executor) error {
58	return nil
59}
60
61func (d *mockDAO) Render(cur realm, pkgpath string, path string) string { return "" }