-
Notifications
You must be signed in to change notification settings - Fork 21
/
test.go
54 lines (44 loc) · 1.27 KB
/
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
package partialsigcontainer
import (
"testing"
"github.com/bloxapp/ssv-spec/ssv"
"github.com/bloxapp/ssv-spec/types"
"github.com/stretchr/testify/require"
)
type PartialSigContainerTest struct {
Name string
Quorum uint64
ValidatorPubKey []byte
SignatureMsgs []*types.PartialSignatureMessage
ExpectedError string
ExpectedResult []byte
ExpectedQuorum bool
}
func (test *PartialSigContainerTest) TestName() string {
return "PartialSigContainer " + test.Name
}
func (test *PartialSigContainerTest) Run(t *testing.T) {
ps := ssv.NewPartialSigContainer(test.Quorum)
roots := make(map[[32]byte]bool)
// Add signature messages
for _, sigMsg := range test.SignatureMsgs {
ps.AddSignature(sigMsg)
roots[sigMsg.SigningRoot] = true
}
for root := range roots {
// Check quorum
require.Equal(t, test.ExpectedQuorum, ps.HasQuorum(root))
result, err := ps.ReconstructSignature(root, test.ValidatorPubKey)
// Check the result and error
if len(test.ExpectedError) > 0 {
require.Error(t, err)
require.Contains(t, err.Error(), test.ExpectedError)
} else {
require.NoError(t, err)
require.EqualValues(t, test.ExpectedResult, result)
}
}
}
func (test *PartialSigContainerTest) GetPostState() (interface{}, error) {
return nil, nil
}