-
Notifications
You must be signed in to change notification settings - Fork 201
/
multipleShardsCoordinatorMock.go
70 lines (55 loc) · 1.89 KB
/
multipleShardsCoordinatorMock.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
package mock
import (
"fmt"
"github.com/ElrondNetwork/elrond-go/data/state"
)
type multipleShardsCoordinatorMock struct {
noShards uint32
ComputeIdCalled func(address state.AddressContainer) uint32
CurrentShard uint32
}
func NewMultipleShardsCoordinatorMock() *multipleShardsCoordinatorMock {
return &multipleShardsCoordinatorMock{noShards: 1}
}
func NewMultiShardsCoordinatorMock(nrShard uint32) *multipleShardsCoordinatorMock {
return &multipleShardsCoordinatorMock{noShards: nrShard}
}
func (scm *multipleShardsCoordinatorMock) NumberOfShards() uint32 {
return scm.noShards
}
func (scm *multipleShardsCoordinatorMock) ComputeId(address state.AddressContainer) uint32 {
if scm.ComputeIdCalled == nil {
return scm.SelfId()
}
return scm.ComputeIdCalled(address)
}
func (scm *multipleShardsCoordinatorMock) SelfId() uint32 {
return scm.CurrentShard
}
func (scm *multipleShardsCoordinatorMock) SetSelfId(shardId uint32) error {
return nil
}
func (scm *multipleShardsCoordinatorMock) SameShard(firstAddress, secondAddress state.AddressContainer) bool {
return true
}
func (scm *multipleShardsCoordinatorMock) SetNoShards(noShards uint32) {
scm.noShards = noShards
}
// CommunicationIdentifier returns the identifier between current shard ID and destination shard ID
// identifier is generated such as the first shard from identifier is always smaller than the last
func (scm *multipleShardsCoordinatorMock) CommunicationIdentifier(destShardID uint32) string {
if destShardID == scm.CurrentShard {
return fmt.Sprintf("_%d", scm.CurrentShard)
}
if destShardID < scm.CurrentShard {
return fmt.Sprintf("_%d_%d", destShardID, scm.CurrentShard)
}
return fmt.Sprintf("_%d_%d", scm.CurrentShard, destShardID)
}
// IsInterfaceNil returns true if there is no value under the interface
func (scm *multipleShardsCoordinatorMock) IsInterfaceNil() bool {
if scm == nil {
return true
}
return false
}