-
Notifications
You must be signed in to change notification settings - Fork 202
/
requestHandlerStub.go
158 lines (135 loc) · 4.9 KB
/
requestHandlerStub.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package testscommon
import "time"
// RequestHandlerStub -
type RequestHandlerStub struct {
RequestShardHeaderCalled func(shardID uint32, hash []byte)
RequestMetaHeaderCalled func(hash []byte)
RequestMetaHeaderByNonceCalled func(nonce uint64)
RequestShardHeaderByNonceCalled func(shardID uint32, nonce uint64)
RequestTransactionHandlerCalled func(destShardID uint32, txHashes [][]byte)
RequestScrHandlerCalled func(destShardID uint32, txHashes [][]byte)
RequestRewardTxHandlerCalled func(destShardID uint32, txHashes [][]byte)
RequestMiniBlockHandlerCalled func(destShardID uint32, miniblockHash []byte)
RequestMiniBlocksHandlerCalled func(destShardID uint32, miniblocksHashes [][]byte)
RequestTrieNodesCalled func(destShardID uint32, hashes [][]byte, topic string)
RequestStartOfEpochMetaBlockCalled func(epoch uint32)
SetNumPeersToQueryCalled func(key string, intra int, cross int) error
GetNumPeersToQueryCalled func(key string) (int, int, error)
RequestTrieNodeCalled func(requestHash []byte, topic string, chunkIndex uint32)
CreateTrieNodeIdentifierCalled func(requestHash []byte, chunkIndex uint32) []byte
}
// SetNumPeersToQuery -
func (rhs *RequestHandlerStub) SetNumPeersToQuery(key string, intra int, cross int) error {
if rhs.SetNumPeersToQueryCalled != nil {
return rhs.SetNumPeersToQueryCalled(key, intra, cross)
}
return nil
}
// GetNumPeersToQuery -
func (rhs *RequestHandlerStub) GetNumPeersToQuery(key string) (int, int, error) {
if rhs.GetNumPeersToQueryCalled != nil {
return rhs.GetNumPeersToQueryCalled(key)
}
return 2, 2, nil
}
// RequestInterval -
func (rhs *RequestHandlerStub) RequestInterval() time.Duration {
return time.Second
}
// RequestStartOfEpochMetaBlock -
func (rhs *RequestHandlerStub) RequestStartOfEpochMetaBlock(epoch uint32) {
if rhs.RequestStartOfEpochMetaBlockCalled == nil {
return
}
rhs.RequestStartOfEpochMetaBlockCalled(epoch)
}
// SetEpoch -
func (rhs *RequestHandlerStub) SetEpoch(_ uint32) {
}
// RequestShardHeader -
func (rhs *RequestHandlerStub) RequestShardHeader(shardID uint32, hash []byte) {
if rhs.RequestShardHeaderCalled == nil {
return
}
rhs.RequestShardHeaderCalled(shardID, hash)
}
// RequestMetaHeader -
func (rhs *RequestHandlerStub) RequestMetaHeader(hash []byte) {
if rhs.RequestMetaHeaderCalled == nil {
return
}
rhs.RequestMetaHeaderCalled(hash)
}
// RequestMetaHeaderByNonce -
func (rhs *RequestHandlerStub) RequestMetaHeaderByNonce(nonce uint64) {
if rhs.RequestMetaHeaderByNonceCalled == nil {
return
}
rhs.RequestMetaHeaderByNonceCalled(nonce)
}
// RequestShardHeaderByNonce -
func (rhs *RequestHandlerStub) RequestShardHeaderByNonce(shardID uint32, nonce uint64) {
if rhs.RequestShardHeaderByNonceCalled == nil {
return
}
rhs.RequestShardHeaderByNonceCalled(shardID, nonce)
}
// RequestTransaction -
func (rhs *RequestHandlerStub) RequestTransaction(destShardID uint32, txHashes [][]byte) {
if rhs.RequestTransactionHandlerCalled == nil {
return
}
rhs.RequestTransactionHandlerCalled(destShardID, txHashes)
}
// RequestUnsignedTransactions -
func (rhs *RequestHandlerStub) RequestUnsignedTransactions(destShardID uint32, txHashes [][]byte) {
if rhs.RequestScrHandlerCalled == nil {
return
}
rhs.RequestScrHandlerCalled(destShardID, txHashes)
}
// RequestRewardTransactions -
func (rhs *RequestHandlerStub) RequestRewardTransactions(destShardID uint32, txHashes [][]byte) {
if rhs.RequestRewardTxHandlerCalled == nil {
return
}
rhs.RequestRewardTxHandlerCalled(destShardID, txHashes)
}
// RequestMiniBlock -
func (rhs *RequestHandlerStub) RequestMiniBlock(destShardID uint32, miniblockHash []byte) {
if rhs.RequestMiniBlockHandlerCalled == nil {
return
}
rhs.RequestMiniBlockHandlerCalled(destShardID, miniblockHash)
}
// RequestMiniBlocks -
func (rhs *RequestHandlerStub) RequestMiniBlocks(destShardID uint32, miniblocksHashes [][]byte) {
if rhs.RequestMiniBlocksHandlerCalled == nil {
return
}
rhs.RequestMiniBlocksHandlerCalled(destShardID, miniblocksHashes)
}
// RequestTrieNodes -
func (rhs *RequestHandlerStub) RequestTrieNodes(destShardID uint32, hashes [][]byte, topic string) {
if rhs.RequestTrieNodesCalled == nil {
return
}
rhs.RequestTrieNodesCalled(destShardID, hashes, topic)
}
// CreateTrieNodeIdentifier -
func (rhs *RequestHandlerStub) CreateTrieNodeIdentifier(requestHash []byte, chunkIndex uint32) []byte {
if rhs.CreateTrieNodeIdentifierCalled != nil {
return rhs.CreateTrieNodeIdentifierCalled(requestHash, chunkIndex)
}
return nil
}
// RequestTrieNode -
func (rhs *RequestHandlerStub) RequestTrieNode(requestHash []byte, topic string, chunkIndex uint32) {
if rhs.RequestTrieNodeCalled != nil {
rhs.RequestTrieNodeCalled(requestHash, topic, chunkIndex)
}
}
// IsInterfaceNil returns true if there is no value under the interface
func (rhs *RequestHandlerStub) IsInterfaceNil() bool {
return rhs == nil
}