forked from yuzhou8787/bdls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
45 lines (34 loc) · 1.05 KB
/
config_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package bdls
import (
"crypto/ecdsa"
"crypto/rand"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestVerifyConfig(t *testing.T) {
config := new(Config)
err := VerifyConfig(config)
assert.Equal(t, ErrConfigEpoch, err)
config.Epoch = time.Now()
err = VerifyConfig(config)
assert.Equal(t, ErrConfigStateCompare, err)
config.StateCompare = func(State, State) int { return 0 }
err = VerifyConfig(config)
assert.Equal(t, ErrConfigStateValidate, err)
config.StateValidate = func(State) bool { return true }
err = VerifyConfig(config)
assert.Equal(t, ErrConfigPrivateKey, err)
randKey, err := ecdsa.GenerateKey(S256Curve, rand.Reader)
assert.Nil(t, err)
config.PrivateKey = randKey
err = VerifyConfig(config)
assert.Equal(t, ErrConfigParticipants, err)
for i := 0; i < ConfigMinimumParticipants; i++ {
randKey, err := ecdsa.GenerateKey(S256Curve, rand.Reader)
assert.Nil(t, err)
config.Participants = append(config.Participants, DefaultPubKeyToIdentity(&randKey.PublicKey))
}
err = VerifyConfig(config)
assert.Nil(t, err)
}