-
Notifications
You must be signed in to change notification settings - Fork 672
/
test_builder.go
47 lines (39 loc) · 987 Bytes
/
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
// (c) 2019-2020, 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(
epoch uint32,
parentIDs []ids.ID,
txs []snowstorm.Tx,
restrictions []ids.ID,
) (avalanche.Vertex, error)
}
func (b *TestBuilder) Default(cant bool) { b.CantBuildVtx = cant }
func (b *TestBuilder) BuildVtx(
epoch uint32,
parentIDs []ids.ID,
txs []snowstorm.Tx,
restrictions []ids.ID,
) (avalanche.Vertex, error) {
if b.BuildVtxF != nil {
return b.BuildVtxF(epoch, parentIDs, txs, restrictions)
}
if b.CantBuildVtx && b.T != nil {
b.T.Fatal(errBuild)
}
return nil, errBuild
}