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