-
Notifications
You must be signed in to change notification settings - Fork 670
/
test_height_indexed_vm.go
49 lines (39 loc) · 1.18 KB
/
test_height_indexed_vm.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
49
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package block
import (
"errors"
"testing"
"github.com/ava-labs/avalanchego/ids"
)
var (
errVerifyHeightIndex = errors.New("unexpectedly called VerifyHeightIndex")
errGetBlockIDAtHeight = errors.New("unexpectedly called GetBlockIDAtHeight")
_ HeightIndexedChainVM = &TestHeightIndexedVM{}
)
// TestBatchedVM is a BatchedVM that is useful for testing.
type TestHeightIndexedVM struct {
T *testing.T
CantVerifyHeightIndex bool
CantGetBlockIDAtHeight bool
VerifyHeightIndexF func() error
GetBlockIDAtHeightF func(height uint64) (ids.ID, error)
}
func (vm *TestHeightIndexedVM) VerifyHeightIndex() error {
if vm.VerifyHeightIndexF != nil {
return vm.VerifyHeightIndexF()
}
if vm.CantVerifyHeightIndex && vm.T != nil {
vm.T.Fatal(errVerifyHeightIndex)
}
return errVerifyHeightIndex
}
func (vm *TestHeightIndexedVM) GetBlockIDAtHeight(height uint64) (ids.ID, error) {
if vm.GetBlockIDAtHeightF != nil {
return vm.GetBlockIDAtHeightF(height)
}
if vm.CantGetBlockIDAtHeight && vm.T != nil {
vm.T.Fatal(errGetAncestor)
}
return ids.Empty, errGetBlockIDAtHeight
}