-
Notifications
You must be signed in to change notification settings - Fork 671
/
test_engine.go
42 lines (33 loc) · 934 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 snowman
import (
"context"
"errors"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/consensus/snowman"
"github.com/ava-labs/avalanchego/snow/engine/common"
)
var (
_ Engine = (*EngineTest)(nil)
errGetBlock = errors.New("unexpectedly called GetBlock")
)
// EngineTest is a test engine
type EngineTest struct {
common.EngineTest
CantGetBlock bool
GetBlockF func(context.Context, ids.ID) (snowman.Block, error)
}
func (e *EngineTest) Default(cant bool) {
e.EngineTest.Default(cant)
e.CantGetBlock = false
}
func (e *EngineTest) GetBlock(ctx context.Context, blkID ids.ID) (snowman.Block, error) {
if e.GetBlockF != nil {
return e.GetBlockF(ctx, blkID)
}
if e.CantGetBlock && e.T != nil {
e.T.Fatalf("Unexpectedly called GetBlock")
}
return nil, errGetBlock
}