Kind Realm (renderable)
Name v0
Namespace sys / validators
Exported functions 9
Module gno.land/r/sys/validators/v0
gno 0.9 validators_test.gno gno
⧉
1 // Tests for stateless v0. 2 // 3 // State isolation: gno's test runner constructs a fresh testParams 4 // per top-level TestXxx, but t.Run subtests share the same map. 5 // Each subtest below seeds (or clears) the valset slots it cares 6 // about up front; do the same when adding cases. 7 package AssertGenesisValopersConsistent (cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string})
GetValidator (addr string) struct{Address .uverse.address; PubKey string; VotingPower uint64}
GetValidators () []gno.land/p/sys/validators/v0.Validator
IsValidator (addr string) bool
NewValidatorProposalRequest (cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, changes []gno.land/r/sys/validators/v0.ValoperChange, title string, description string) struct{title string; description string; executor gno.land/r/gov/dao.Executor; filter gno.land/r/gov/dao.Filter}
NewValoperChange (operatorAddress string, power uint64) struct{OperatorAddress .uverse.address; Power uint64}
NotifyValoperChanged (cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, op string, signingPubKey string, signingAddress string, keepRunning bool)
Render (string) string
RotateValoperSigningKey (cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, op string, oldPubKey string, newPubKey string)
Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.
vm/qrender output, sanitized (docs/render-security.md) and displayed in an empty-sandbox iframe — scripts, forms and popups cannot run. Links stay inert in-preview; right-click to open.
validators
8
9 import (
10 "chain"
11 "testing"
12
13 "gno.land/p/nt/urequire/v0"
14 )
15
16 const (
17 // Three distinct deterministic test pubkeys (and the addresses
18 // they derive to) used across the cases below. Stable across
19 // runs.
20 pubKeyA = "gpub1pggj7ard9eg82cjtv4u52epjx56nzwgjyg9zq3ds6sdvc0shfkq02h6xx5g0jp04aadexfnpsmgjxu72xz9y30aqfrlpny"
21 pubKeyB = "gpub1pggj7ard9eg82cjtv4u52epjx56nzwgjyg9zqwpdwpd0f9fvqla089ndw5g9hcsufad77fml2vlu73fk8q8sh8v72cza5p"
22 pubKeyC = "gpub1pgfj7ard9eg82cjtv4u4xetrwqer2dntxyfzxz3pqddddqg2glc8x4fl7vxjlnr7p5a3czm5kcdp4239sg6yqdc4rc2r5cjrffs"
23
24 module = "node"
25 submodule = "valset"
26 currKey = "current"
27 propKey = "proposed"
28 dirtyKey = "dirty"
29 )
30
31 func resetValset(t *testing.T) {
32 t.Helper()
33 testing.SetSysParamStrings(module, submodule, currKey, [] string {})
34 testing.SetSysParamStrings(module, submodule, propKey, [] string {})
35 testing.SetSysParamBool(module, submodule, dirtyKey, false )
36 }
37
38 func mustAddr(t *testing.T, pk string ) address {
39 t.Helper()
40 a, err := chain.PubKeyAddress(pk)
41 urequire.NoError(t, err, "valid pubkey" )
42 return a
43 }
44
45 func TestEffectiveView_DirtyFalseReadsCurrent(cur realm, t *testing.T) {
46 resetValset(t)
47 testing.SetSysParamStrings(module, submodule, currKey, [] string {pubKeyA + ":10" })
48
49 addrA := mustAddr(t, pubKeyA)
50 urequire.True(t, IsValidator(addrA), "A in current" )
51 urequire.Equal(t, 1 , len(GetValidators()))
52 }
53
54 func TestEffectiveView_DirtyTrueReadsProposed(cur realm, t *testing.T) {
55 resetValset(t)
56 testing.SetSysParamStrings(module, submodule, currKey, [] string {pubKeyA + ":10" })
57 testing.SetSysParamStrings(module, submodule, propKey, [] string {pubKeyA + ":10" , pubKeyB + ":1" })
58 testing.SetSysParamBool(module, submodule, dirtyKey, true )
59
60 addrA := mustAddr(t, pubKeyA)
61 addrB := mustAddr(t, pubKeyB)
62 urequire.True(t, IsValidator(addrA), "A still visible" )
63 urequire.True(t, IsValidator(addrB), "B visible via proposed" )
64 urequire.Equal(t, 2 , len(GetValidators()))
65 }
66
67 func TestGetValidator_ReturnsParsedEntry(cur realm, t *testing.T) {
68 resetValset(t)
69 testing.SetSysParamStrings(module, submodule, currKey, [] string {pubKeyA + ":42" })
70
71 v := GetValidator(mustAddr(t, pubKeyA))
72 urequire.Equal(t, uint64 ( 42 ), v.VotingPower)
73 urequire.Equal(t, pubKeyA, v.PubKey)
74 }
75
76 func TestRender_DefaultTestHeight(cur realm, t *testing.T) {
77 resetValset(t)
78 testing.SetSysParamStrings(module, submodule, currKey, [] string {pubKeyA + ":10" })
79
80 out := Render( "" )
81 // gnovm/pkg/test/test.go sets DefaultHeight = 123.
82 urequire.Equal(t,
83 "## Valset at height 123\n\n- #0: " +mustAddr(t, pubKeyA).String()+ " (10)\n" ,
84 out)
85 }
86
87 // The same-block accumulation, panic-on-remove-of-missing,
88 // panic-on-add-of-existing, and pubkey-validation tests for the
89 // signing-keyed NewProposalRequest/newValsetChangeExecutor were
90 // removed alongside the function itself. Equivalent coverage for
91 // the operator-keyed flow lives in proposal_test.gno
92 // (TestNewValidatorProposalRequest_*) and cache_test.gno
93 // (TestRotateValoperSigningKey_AccumulatesAcrossSameBlock).
94 //
95 // Empty-final-set rejection in the executor still applies; it's
96 // covered by TestNewValidatorProposalRequest_RemoveOperator in
97 // proposal_test.gno.
98