-
Notifications
You must be signed in to change notification settings - Fork 661
/
test_state_syncable_vm.go
85 lines (73 loc) · 2.5 KB
/
test_state_syncable_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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package block
import (
"errors"
"testing"
)
var (
_ StateSyncableVM = &TestStateSyncableVM{}
errStateSyncEnabled = errors.New("unexpectedly called StateSyncEnabled")
errStateSyncGetOngoingSummary = errors.New("unexpectedly called StateSyncGetOngoingSummary")
errGetLastStateSummary = errors.New("unexpectedly called GetLastStateSummary")
errParseStateSummary = errors.New("unexpectedly called ParseStateSummary")
errGetStateSummary = errors.New("unexpectedly called GetStateSummary")
)
type TestStateSyncableVM struct {
T *testing.T
CantStateSyncEnabled,
CantStateSyncGetOngoingSummary,
CantGetLastStateSummary,
CantParseStateSummary,
CantGetStateSummary bool
StateSyncEnabledF func() (bool, error)
GetOngoingSyncStateSummaryF func() (StateSummary, error)
GetLastStateSummaryF func() (StateSummary, error)
ParseStateSummaryF func(summaryBytes []byte) (StateSummary, error)
GetStateSummaryF func(uint64) (StateSummary, error)
}
func (vm *TestStateSyncableVM) StateSyncEnabled() (bool, error) {
if vm.StateSyncEnabledF != nil {
return vm.StateSyncEnabledF()
}
if vm.CantStateSyncEnabled && vm.T != nil {
vm.T.Fatal(errStateSyncEnabled)
}
return false, errStateSyncEnabled
}
func (vm *TestStateSyncableVM) GetOngoingSyncStateSummary() (StateSummary, error) {
if vm.GetOngoingSyncStateSummaryF != nil {
return vm.GetOngoingSyncStateSummaryF()
}
if vm.CantStateSyncGetOngoingSummary && vm.T != nil {
vm.T.Fatal(errStateSyncGetOngoingSummary)
}
return nil, errStateSyncGetOngoingSummary
}
func (vm *TestStateSyncableVM) GetLastStateSummary() (StateSummary, error) {
if vm.GetLastStateSummaryF != nil {
return vm.GetLastStateSummaryF()
}
if vm.CantGetLastStateSummary && vm.T != nil {
vm.T.Fatal(errGetLastStateSummary)
}
return nil, errGetLastStateSummary
}
func (vm *TestStateSyncableVM) ParseStateSummary(summaryBytes []byte) (StateSummary, error) {
if vm.ParseStateSummaryF != nil {
return vm.ParseStateSummaryF(summaryBytes)
}
if vm.CantParseStateSummary && vm.T != nil {
vm.T.Fatal(errParseStateSummary)
}
return nil, errParseStateSummary
}
func (vm *TestStateSyncableVM) GetStateSummary(key uint64) (StateSummary, error) {
if vm.GetStateSummaryF != nil {
return vm.GetStateSummaryF(key)
}
if vm.CantGetStateSummary && vm.T != nil {
vm.T.Fatal(errGetStateSummary)
}
return nil, errGetStateSummary
}