maintainer_test.gno
2.22 Kb · 76 lines
1package maintainer
2
3import (
4 "testing"
5
6 "gno.land/p/nt/testutils/v0"
7 "gno.land/p/nt/uassert/v0"
8)
9
10var (
11 bot = testutils.TestAddress("maintainerbot")
12 rev1 = testutils.TestAddress("rev1")
13 rev2 = testutils.TestAddress("rev2")
14)
15
16func TestPolicyGate(cur realm, t *testing.T) {
17 testing.SetRealm(testing.NewUserRealm(bot))
18 id := Propose(cross(cur), "v2", "artifact#H", 3) // 3-block challenge window
19
20 // Approval blocked: no tests, no reviews, window open.
21 uassert.AbortsWithMessage(t, cur, "policy: tests have not passed", func(cur realm) {
22 Approve(cur, id)
23 })
24
25 AttestTests(cross(cur), id, true)
26 uassert.AbortsWithMessage(t, cur, "policy: need 2 reviews, have 0", func(cur realm) {
27 Approve(cur, id)
28 })
29
30 // One low review blocks on the min-score rule.
31 testing.SetRealm(testing.NewUserRealm(rev1))
32 AddReview(cross(cur), id, 90, "looks good")
33 testing.SetRealm(testing.NewUserRealm(rev2))
34 AddReview(cross(cur), id, 70, "concerns")
35 testing.SetRealm(testing.NewUserRealm(bot))
36 uassert.AbortsWithMessage(t, cur, "policy: review from "+short(rev2)+" scored 70 < 80", func(cur realm) {
37 Approve(cur, id)
38 })
39}
40
41func TestFullApprovalPath(cur realm, t *testing.T) {
42 testing.SetRealm(testing.NewUserRealm(bot))
43 id := Propose(cross(cur), "v3", "artifact#H3", 2)
44 AttestTests(cross(cur), id, true)
45
46 testing.SetRealm(testing.NewUserRealm(rev1))
47 AddReview(cross(cur), id, 85, "ok")
48 testing.SetRealm(testing.NewUserRealm(rev2))
49 AddReview(cross(cur), id, 95, "great")
50
51 // Challenge window still open -> blocked.
52 testing.SetRealm(testing.NewUserRealm(bot))
53 uassert.AbortsWithMessage(t, cur, "policy: challenge window still open", func(cur realm) {
54 Approve(cur, id)
55 })
56
57 testing.SkipHeights(10)
58 Approve(cross(cur), id)
59 uassert.True(t, GetProposal(id).Approved)
60 uassert.Equal(t, "v3", LatestVersion())
61
62 // Deprecate it.
63 Deprecate(cross(cur), "v3", "CVE-xyz")
64 uassert.True(t, IsDeprecated("v3"))
65
66 uassert.True(t, len(Render("")) > 0)
67 uassert.True(t, len(Render("1")) > 0)
68}
69
70func TestProposerCannotReview(cur realm, t *testing.T) {
71 testing.SetRealm(testing.NewUserRealm(bot))
72 id := Propose(cross(cur), "v4", "a#4", 0)
73 uassert.AbortsWithMessage(t, cur, "proposer cannot review own proposal", func(cur realm) {
74 AddReview(cur, id, 100, "self five")
75 })
76}