gecko/snow/consensus/snowball/parameters_test.go

152 lines
3.0 KiB
Go
Raw Normal View History

2020-03-10 12:20:34 -07:00
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package snowball
import (
"fmt"
2020-03-31 21:52:50 -07:00
"strings"
2020-03-10 12:20:34 -07:00
"testing"
)
func TestParametersValid(t *testing.T) {
p := Parameters{
2020-03-31 20:11:44 -07:00
K: 1,
Alpha: 1,
BetaVirtuous: 1,
BetaRogue: 1,
ConcurrentRepolls: 1,
2020-03-10 12:20:34 -07:00
}
if err := p.Valid(); err != nil {
t.Fatal(err)
}
}
2020-03-31 21:52:50 -07:00
func TestParametersAnotherValid(t *testing.T) {
p := Parameters{
K: 1,
Alpha: 1,
BetaVirtuous: 28,
BetaRogue: 30,
ConcurrentRepolls: 1,
}
if err := p.Valid(); err != nil {
t.Fatal(err)
}
}
func TestParametersYetAnotherValid(t *testing.T) {
p := Parameters{
K: 1,
Alpha: 1,
BetaVirtuous: 3,
BetaRogue: 3,
ConcurrentRepolls: 1,
}
if err := p.Valid(); err != nil {
t.Fatal(err)
}
}
2020-03-10 12:20:34 -07:00
func TestParametersInvalidK(t *testing.T) {
p := Parameters{
2020-03-31 20:11:44 -07:00
K: 0,
Alpha: 1,
BetaVirtuous: 1,
BetaRogue: 1,
ConcurrentRepolls: 1,
2020-03-10 12:20:34 -07:00
}
if err := p.Valid(); err == nil {
t.Fatalf("Should have failed due to invalid k")
}
}
func TestParametersInvalidAlpha(t *testing.T) {
p := Parameters{
2020-03-31 20:11:44 -07:00
K: 1,
Alpha: 0,
BetaVirtuous: 1,
BetaRogue: 1,
ConcurrentRepolls: 1,
2020-03-10 12:20:34 -07:00
}
if err := p.Valid(); err == nil {
t.Fatalf("Should have failed due to invalid alpha")
}
}
func TestParametersInvalidBetaVirtuous(t *testing.T) {
p := Parameters{
2020-03-31 20:11:44 -07:00
K: 1,
Alpha: 1,
BetaVirtuous: 0,
BetaRogue: 1,
ConcurrentRepolls: 1,
2020-03-10 12:20:34 -07:00
}
if err := p.Valid(); err == nil {
t.Fatalf("Should have failed due to invalid beta virtuous")
}
}
func TestParametersInvalidBetaRogue(t *testing.T) {
p := Parameters{
2020-03-31 20:11:44 -07:00
K: 1,
Alpha: 1,
BetaVirtuous: 1,
BetaRogue: 0,
ConcurrentRepolls: 1,
2020-03-10 12:20:34 -07:00
}
if err := p.Valid(); err == nil {
t.Fatalf("Should have failed due to invalid beta rogue")
}
}
2020-03-28 21:48:39 -07:00
func TestParametersAnotherInvalidBetaRogue(t *testing.T) {
p := Parameters{
2020-03-31 21:52:50 -07:00
K: 1,
Alpha: 1,
BetaVirtuous: 28,
BetaRogue: 3,
ConcurrentRepolls: 1,
2020-03-28 21:48:39 -07:00
}
if err := p.Valid(); err == nil {
t.Fatalf("Should have failed due to invalid beta rogue")
2020-03-31 21:52:50 -07:00
} else if !strings.Contains(err.Error(), "\n") {
t.Fatalf("Should have described the extensive error")
2020-03-28 21:48:39 -07:00
}
}
func TestParametersInvalidConcurrentRepolls(t *testing.T) {
tests := []Parameters{
Parameters{
K: 1,
Alpha: 1,
BetaVirtuous: 1,
BetaRogue: 1,
ConcurrentRepolls: 2,
},
Parameters{
K: 1,
Alpha: 1,
BetaVirtuous: 1,
BetaRogue: 1,
ConcurrentRepolls: 0,
},
}
for _, p := range tests {
label := fmt.Sprintf("ConcurrentRepolls=%d", p.ConcurrentRepolls)
t.Run(label, func(t *testing.T) {
if err := p.Valid(); err == nil {
t.Error("Should have failed due to invalid concurrent repolls")
}
})
2020-03-31 20:11:44 -07:00
}
}