-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
91 lines (86 loc) · 2.12 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package gosss
import (
"math/big"
"testing"
)
func Test_prepare(t *testing.T) {
c := Config{}
c.prepare()
if c.Prime.Cmp(DefaultPrime) != 0 {
t.Errorf("expected %v, got %v", DefaultPrime, c.Prime)
}
newPrime := big.NewInt(1003)
c.Prime = new(big.Int).Set(newPrime)
c.prepare()
if c.Prime.Cmp(newPrime) != 0 {
t.Errorf("expected %v, got %v", newPrime, c.Prime)
}
if err := c.ValidPrime(); err == nil {
t.Errorf("expected error, got nil")
}
c.Prime = DefaultPrime
if err := c.ValidPrime(); err != nil {
t.Errorf("unexpected error: %v", err)
}
c.Prime = nil
if err := c.ValidPrime(); err == nil {
t.Errorf("expected error, got nil")
}
}
func TestValidPrime(t *testing.T) {
c := Config{}
c.prepare()
if err := c.ValidPrime(); err != nil {
t.Errorf("unexpected error: %v", err)
}
c.Prime = nil
if err := c.ValidPrime(); err == nil {
t.Errorf("expected error, got nil")
}
c.Prime = big.NewInt(1002)
if err := c.ValidPrime(); err == nil {
t.Errorf("expected error, got nil")
}
}
func TestValidConfig(t *testing.T) {
c := Config{}
c.prepare()
if err := c.ValidConfig([]byte{}); err == nil {
t.Errorf("expected error, got nil")
}
c.Shares = MinShares - 1
c.Min = MinMinShares
if err := c.ValidConfig([]byte{}); err == nil {
t.Errorf("expected error, got nil")
}
c.Shares = MinShares
c.Min = MinMinShares - 1
if err := c.ValidConfig([]byte{}); err == nil {
t.Errorf("expected error, got nil")
}
c.Shares = MinShares + 1
c.Min = MinMinShares - 1
if err := c.ValidConfig([]byte{}); err == nil {
t.Errorf("expected error, got nil")
}
c.Shares = MinShares
c.Min = MinMinShares
c.Prime = nil
if err := c.ValidConfig([]byte{}); err == nil {
t.Errorf("expected error, got nil")
}
c.Prime = new(big.Int).SetUint64(10007)
if err := c.ValidConfig([]byte("12345")); err == nil {
t.Errorf("expected error, got nil")
}
}
func TestMaxMessageLen(t *testing.T) {
c := Config{Prime: big.NewInt(13)}
if c.MaxMessageLen() != 0 {
t.Errorf("expected 0, got %d", c.MaxMessageLen())
}
c.Prime = big.NewInt(1000000000000000000)
if c.MaxMessageLen() != 7 {
t.Errorf("expected 7, got %d", c.MaxMessageLen())
}
}