github.com/evdatsion/aphelion-dpos-bft@v0.32.1/lite/base_verifier_test.go (about) 1 package lite 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 lerr "github.com/evdatsion/aphelion-dpos-bft/lite/errors" 9 "github.com/evdatsion/aphelion-dpos-bft/types" 10 ) 11 12 func TestBaseCert(t *testing.T) { 13 assert := assert.New(t) 14 15 keys := genPrivKeys(4) 16 // 20, 30, 40, 50 - the first 3 don't have 2/3, the last 3 do! 17 vals := keys.ToValidators(20, 10) 18 // and a Verifier based on our known set 19 chainID := "test-static" 20 cert := NewBaseVerifier(chainID, 2, vals) 21 22 cases := []struct { 23 keys privKeys 24 vals *types.ValidatorSet 25 height int64 26 first, last int // who actually signs 27 proper bool // true -> expect no error 28 changed bool // true -> expect validator change error 29 }{ 30 // height regression 31 {keys, vals, 1, 0, len(keys), false, false}, 32 // perfect, signed by everyone 33 {keys, vals, 2, 0, len(keys), true, false}, 34 // skip little guy is okay 35 {keys, vals, 3, 1, len(keys), true, false}, 36 // but not the big guy 37 {keys, vals, 4, 0, len(keys) - 1, false, false}, 38 // Changing the power a little bit breaks the static validator. 39 // The sigs are enough, but the validator hash is unknown. 40 {keys, keys.ToValidators(20, 11), 5, 0, len(keys), false, true}, 41 } 42 43 for _, tc := range cases { 44 sh := tc.keys.GenSignedHeader(chainID, tc.height, nil, tc.vals, tc.vals, 45 []byte("foo"), []byte("params"), []byte("results"), tc.first, tc.last) 46 err := cert.Verify(sh) 47 if tc.proper { 48 assert.Nil(err, "%+v", err) 49 } else { 50 assert.NotNil(err) 51 if tc.changed { 52 assert.True(lerr.IsErrUnexpectedValidators(err), "%+v", err) 53 } 54 } 55 } 56 }