-
Notifications
You must be signed in to change notification settings - Fork 179
/
signature.go
47 lines (42 loc) · 1.69 KB
/
signature.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
package helper
import (
"github.com/stretchr/testify/mock"
"go.uber.org/atomic"
"github.com/onflow/crypto"
"github.com/onflow/flow-go/consensus/hotstuff/mocks"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/utils/unittest"
)
func MakeWeightedSignatureAggregator(sigWeight uint64) *mocks.WeightedSignatureAggregator {
stakingSigAggtor := &mocks.WeightedSignatureAggregator{}
totalWeight := atomic.NewUint64(0)
stakingSigAggtor.On("TrustedAdd", mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
totalWeight.Add(sigWeight)
}).Return(func(signerID flow.Identifier, sig crypto.Signature) uint64 {
return totalWeight.Load()
}, func(signerID flow.Identifier, sig crypto.Signature) error {
return nil
}).Maybe()
stakingSigAggtor.On("TotalWeight").Return(func() uint64 {
return totalWeight.Load()
}).Maybe()
stakingSigAggtor.On("Aggregate").Return(unittest.IdentifierListFixture(5),
unittest.RandomBytes(48), nil).Maybe()
return stakingSigAggtor
}
func MakeRandomBeaconReconstructor(minRequiredShares int) *mocks.RandomBeaconReconstructor {
rbRector := &mocks.RandomBeaconReconstructor{}
rbSharesTotal := atomic.NewUint64(0)
rbRector.On("TrustedAdd", mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
rbSharesTotal.Inc()
}).Return(func(signerID flow.Identifier, sig crypto.Signature) bool {
return rbSharesTotal.Load() >= uint64(minRequiredShares)
}, func(signerID flow.Identifier, sig crypto.Signature) error {
return nil
}).Maybe()
rbRector.On("EnoughShares").Return(func() bool {
return rbSharesTotal.Load() >= uint64(minRequiredShares)
}).Maybe()
rbRector.On("Reconstruct").Return(unittest.SignatureFixture(), nil).Maybe()
return rbRector
}