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_unknown_proposal_test.gno

1.13 Kb · 31 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// A proposal id this implementation has no status for — an unknown id, or a
15// proposal that outlived the GovDAO instance that created it (statuses live on
16// the instance). The nil deref this used to hit surfaced as "runtime error:
17// nil pointer dereference", which reads like a VM fault rather than a bad
18// request.
19//
20// Note what this does NOT assert: that the proposal becomes rejectable.
21// dao.executeProposal panics on ANY error from PreExecuteProposal, ahead of
22// its execErrorRejects branch, so the guard buys a named error and nothing
23// more.
24func TestExecuteUnknownProposalNamesTheError(cur realm, t *testing.T) {
25	testing.SetOriginCaller(m1)
26	testing.SetRealm(testing.NewUserRealm(m1))
27
28	urequire.AbortsWithMessage(t, cur, "proposal not found", func() {
29		dao.ExecuteProposal(cross(cur), dao.ProposalID(999999))
30	})
31}