-
Notifications
You must be signed in to change notification settings - Fork 671
/
test_builder.go
48 lines (39 loc) · 1.16 KB
/
test_builder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package vertex
import (
"errors"
"testing"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/consensus/avalanche"
"github.com/ava-labs/avalanchego/snow/consensus/snowstorm"
)
var (
errBuild = errors.New("unexpectedly called Build")
_ Builder = &TestBuilder{}
)
type TestBuilder struct {
T *testing.T
CantBuildVtx bool
BuildVtxF func(parentIDs []ids.ID, txs []snowstorm.Tx) (avalanche.Vertex, error)
BuildStopVtxF func(parentIDs []ids.ID) (avalanche.Vertex, error)
}
func (b *TestBuilder) Default(cant bool) { b.CantBuildVtx = cant }
func (b *TestBuilder) BuildVtx(parentIDs []ids.ID, txs []snowstorm.Tx) (avalanche.Vertex, error) {
if b.BuildVtxF != nil {
return b.BuildVtxF(parentIDs, txs)
}
if b.CantBuildVtx && b.T != nil {
b.T.Fatal(errBuild)
}
return nil, errBuild
}
func (b *TestBuilder) BuildStopVtx(parentIDs []ids.ID) (avalanche.Vertex, error) {
if b.BuildStopVtxF != nil {
return b.BuildStopVtxF(parentIDs)
}
if b.CantBuildVtx && b.T != nil {
b.T.Fatal(errBuild)
}
return nil, errBuild
}