-
Notifications
You must be signed in to change notification settings - Fork 672
/
test_engine.go
42 lines (33 loc) · 932 Bytes
/
test_engine.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
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package avalanche
import (
"context"
"errors"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/consensus/avalanche"
"github.com/ava-labs/avalanchego/snow/engine/common"
)
var (
_ Engine = (*EngineTest)(nil)
errGetVtx = errors.New("unexpectedly called GetVtx")
)
// EngineTest is a test engine
type EngineTest struct {
common.EngineTest
CantGetVtx bool
GetVtxF func(ctx context.Context, vtxID ids.ID) (avalanche.Vertex, error)
}
func (e *EngineTest) Default(cant bool) {
e.EngineTest.Default(cant)
e.CantGetVtx = false
}
func (e *EngineTest) GetVtx(ctx context.Context, vtxID ids.ID) (avalanche.Vertex, error) {
if e.GetVtxF != nil {
return e.GetVtxF(ctx, vtxID)
}
if e.CantGetVtx && e.T != nil {
e.T.Fatalf("Unexpectedly called GetVtx")
}
return nil, errGetVtx
}