forked from multiversx/mx-chain-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrapMock.go
61 lines (50 loc) · 1.76 KB
/
bootstrapMock.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
package mock
import (
"github.com/ElrondNetwork/elrond-go/core"
"github.com/ElrondNetwork/elrond-go/data"
"github.com/ElrondNetwork/elrond-go/data/block"
)
// BootstrapperMock mocks the implementation for a Bootstrapper
type BootstrapperMock struct {
CreateAndCommitEmptyBlockCalled func(uint32) (data.BodyHandler, data.HeaderHandler, error)
AddSyncStateListenerCalled func(func(bool))
GetNodeStateCalled func() core.NodeState
StartSyncingBlocksCalled func()
SetStatusHandlerCalled func(handler core.AppStatusHandler) error
}
// CreateAndCommitEmptyBlock -
func (boot *BootstrapperMock) CreateAndCommitEmptyBlock(shardForCurrentNode uint32) (data.BodyHandler, data.HeaderHandler, error) {
if boot.CreateAndCommitEmptyBlockCalled != nil {
return boot.CreateAndCommitEmptyBlockCalled(shardForCurrentNode)
}
return &block.Body{}, &block.Header{}, nil
}
// AddSyncStateListener -
func (boot *BootstrapperMock) AddSyncStateListener(syncStateNotifier func(isSyncing bool)) {
if boot.AddSyncStateListenerCalled != nil {
boot.AddSyncStateListenerCalled(syncStateNotifier)
}
}
// GetNodeState -
func (boot *BootstrapperMock) GetNodeState() core.NodeState {
if boot.GetNodeStateCalled != nil {
return boot.GetNodeStateCalled()
}
return core.NsSynchronized
}
// StartSyncingBlocks -
func (boot *BootstrapperMock) StartSyncingBlocks() {
boot.StartSyncingBlocksCalled()
}
// SetStatusHandler -
func (boot *BootstrapperMock) SetStatusHandler(handler core.AppStatusHandler) error {
return boot.SetStatusHandlerCalled(handler)
}
// Close -
func (boot *BootstrapperMock) Close() error {
return nil
}
// IsInterfaceNil returns true if there is no value under the interface
func (boot *BootstrapperMock) IsInterfaceNil() bool {
return boot == nil
}