github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/consensus/hotstuff/helper/signature.go (about) 1 package helper 2 3 import ( 4 "github.com/stretchr/testify/mock" 5 "go.uber.org/atomic" 6 7 "github.com/onflow/crypto" 8 9 "github.com/onflow/flow-go/consensus/hotstuff/mocks" 10 "github.com/onflow/flow-go/model/flow" 11 "github.com/onflow/flow-go/utils/unittest" 12 ) 13 14 func MakeWeightedSignatureAggregator(sigWeight uint64) *mocks.WeightedSignatureAggregator { 15 stakingSigAggtor := &mocks.WeightedSignatureAggregator{} 16 totalWeight := atomic.NewUint64(0) 17 stakingSigAggtor.On("TrustedAdd", mock.Anything, mock.Anything).Run(func(args mock.Arguments) { 18 totalWeight.Add(sigWeight) 19 }).Return(func(signerID flow.Identifier, sig crypto.Signature) uint64 { 20 return totalWeight.Load() 21 }, func(signerID flow.Identifier, sig crypto.Signature) error { 22 return nil 23 }).Maybe() 24 stakingSigAggtor.On("TotalWeight").Return(func() uint64 { 25 return totalWeight.Load() 26 }).Maybe() 27 stakingSigAggtor.On("Aggregate").Return(unittest.IdentifierListFixture(5), 28 unittest.RandomBytes(48), nil).Maybe() 29 return stakingSigAggtor 30 } 31 32 func MakeRandomBeaconReconstructor(minRequiredShares int) *mocks.RandomBeaconReconstructor { 33 rbRector := &mocks.RandomBeaconReconstructor{} 34 rbSharesTotal := atomic.NewUint64(0) 35 rbRector.On("TrustedAdd", mock.Anything, mock.Anything).Run(func(args mock.Arguments) { 36 rbSharesTotal.Inc() 37 }).Return(func(signerID flow.Identifier, sig crypto.Signature) bool { 38 return rbSharesTotal.Load() >= uint64(minRequiredShares) 39 }, func(signerID flow.Identifier, sig crypto.Signature) error { 40 return nil 41 }).Maybe() 42 rbRector.On("EnoughShares").Return(func() bool { 43 return rbSharesTotal.Load() >= uint64(minRequiredShares) 44 }).Maybe() 45 rbRector.On("Reconstruct").Return(unittest.SignatureFixture(), nil).Maybe() 46 return rbRector 47 }