ceremonyclient/consensus/votecollector/testutil.go
Cassandra Heart c797d482f9
v2.1.0.5 (#457)
* wip: conversion of hotstuff from flow into Q-oriented model

* bulk of tests

* remaining non-integration tests

* add integration test, adjust log interface, small tweaks

* further adjustments, restore full pacemaker shape

* add component lifecycle management+supervisor

* further refinements

* resolve timeout hanging

* mostly finalized state for consensus

* bulk of engine swap out

* lifecycle-ify most types

* wiring nearly complete, missing needed hooks for proposals

* plugged in, vetting message validation paths

* global consensus, plugged in and verified

* app shard now wired in too

* do not decode empty keys.yml (#456)

* remove obsolete engine.maxFrames config parameter (#454)

* default to Info log level unless debug is enabled (#453)

* respect config's  "logging" section params, remove obsolete single-file logging (#452)

* Trivial code cleanup aiming to reduce Go compiler warnings (#451)

* simplify range traversal

* simplify channel read for single select case

* delete rand.Seed() deprecated in Go 1.20 and no-op as of Go 1.24

* simplify range traversal

* simplify channel read for single select case

* remove redundant type from array

* simplify range traversal

* simplify channel read for single select case

* RC slate

* finalize 2.1.0.5

* Update comments in StrictMonotonicCounter

Fix comment formatting and clarify description.

---------

Co-authored-by: Black Swan <3999712+blacks1ne@users.noreply.github.com>
2025-11-11 05:00:17 -06:00

52 lines
1.7 KiB
Go

package votecollector
import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
"source.quilibrium.com/quilibrium/monorepo/consensus/helper"
mockconsensus "source.quilibrium.com/quilibrium/monorepo/consensus/mocks"
"source.quilibrium.com/quilibrium/monorepo/consensus/models"
)
type VoteProcessorTestSuiteBase struct {
suite.Suite
sigWeight uint64
provingTotalWeight uint64
onQCCreatedState mock.Mock
provingAggregator *mockconsensus.WeightedSignatureAggregator
minRequiredWeight uint64
proposal *models.SignedProposal[*helper.TestState, *helper.TestVote]
}
func (s *VoteProcessorTestSuiteBase) SetupTest() {
s.provingAggregator = &mockconsensus.WeightedSignatureAggregator{}
s.proposal = helper.MakeSignedProposal[*helper.TestState, *helper.TestVote]()
// let's assume we have 19 nodes each with weight 100
s.sigWeight = 100
s.minRequiredWeight = 1300 // we require at least 13 sigs to collect min weight
s.provingTotalWeight = 0
// setup proving signature aggregator
s.provingAggregator.On("TrustedAdd", mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
s.provingTotalWeight += s.sigWeight
}).Return(func(signerID models.Identity, sig []byte) uint64 {
return s.provingTotalWeight
}, func(signerID models.Identity, sig []byte) error {
return nil
}).Maybe()
s.provingAggregator.On("TotalWeight").Return(func() uint64 {
return s.provingTotalWeight
}).Maybe()
}
// onQCCreated is a special function that registers call in mocked state.
// ATTENTION: don't change name of this function since the same name is used in:
// s.onQCCreatedState.On("onQCCreated") statements
func (s *VoteProcessorTestSuiteBase) onQCCreated(qc models.QuorumCertificate) {
s.onQCCreatedState.Called(qc)
}