github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/consensus/hotstuff/committees/threshold_test.go (about)

     1  package committees
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  // TestComputeQCWeightThreshold tests computing the HotStuff safety threshold
    10  // for producing a QC.
    11  func TestComputeQCWeightThreshold(t *testing.T) {
    12  	// testing lowest values
    13  	for i := 1; i <= 302; i++ {
    14  		threshold := WeightThresholdToBuildQC(uint64(i))
    15  
    16  		boundaryValue := float64(i) * 2.0 / 3.0
    17  		assert.True(t, boundaryValue < float64(threshold))
    18  		assert.False(t, boundaryValue < float64(threshold-1))
    19  	}
    20  }
    21  
    22  // TestComputeTOWeightThreshold tests computing the HotStuff safety threshold
    23  // for producing a TO.
    24  func TestComputeTOWeightThreshold(t *testing.T) {
    25  	// testing lowest values
    26  	for totalWeight := uint64(1); totalWeight <= 302; totalWeight++ {
    27  		threshold := WeightThresholdToTimeout(totalWeight)
    28  
    29  		assert.Greater(t, threshold*3, totalWeight)         // 3*threshold > totalWeight
    30  		assert.LessOrEqual(t, (threshold-1)*3, totalWeight) // 3*(threshold-1) <= totalWeight
    31  	}
    32  }