vspd/helpers_test.go
2020-05-15 08:48:22 +01:00

36 lines
861 B
Go

package main
import (
"testing"
"github.com/decred/dcrd/chaincfg/v3"
"github.com/decred/dcrd/dcrutil/v3"
)
func TestVoteBits(t *testing.T) {
var tests = []struct {
voteBits uint16
isValid bool
}{
{0, false},
{dcrutil.BlockValid, true},
{dcrutil.BlockValid | 0x0002, true},
{dcrutil.BlockValid | 0x0003, true},
{dcrutil.BlockValid | 0x0004, true},
{dcrutil.BlockValid | 0x0005, true},
{dcrutil.BlockValid | 0x0006, false},
{dcrutil.BlockValid | 0x0007, false},
{dcrutil.BlockValid | 0x0008, true},
}
params := chaincfg.MainNetParams()
voteVersion := currentVoteVersion(params)
for _, test := range tests {
isValid := isValidVoteBits(params, voteVersion, test.voteBits)
if isValid != test.isValid {
t.Fatalf("isValidVoteBits failed for votebits '%d': want %v, got %v",
test.voteBits, test.isValid, isValid)
}
}
}