-
Notifications
You must be signed in to change notification settings - Fork 198
/
rounderMock.go
59 lines (48 loc) · 1.39 KB
/
rounderMock.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
package mock
import (
"math"
"time"
)
// RoundHandlerMock -
type RoundHandlerMock struct {
RoundIndex int64
RoundTimeStamp time.Time
RoundTimeDuration time.Duration
BeforeGenesisCalled func() bool
}
// BeforeGenesis -
func (rndm *RoundHandlerMock) BeforeGenesis() bool {
if rndm.BeforeGenesisCalled != nil {
return rndm.BeforeGenesisCalled()
}
return false
}
// Index -
func (rndm *RoundHandlerMock) Index() int64 {
return rndm.RoundIndex
}
// TimeDuration -
func (rndm *RoundHandlerMock) TimeDuration() time.Duration {
return rndm.RoundTimeDuration
}
// TimeStamp -
func (rndm *RoundHandlerMock) TimeStamp() time.Time {
return rndm.RoundTimeStamp
}
// UpdateRound -
func (rndm *RoundHandlerMock) UpdateRound(genesisRoundTimeStamp time.Time, timeStamp time.Time) {
delta := timeStamp.Sub(genesisRoundTimeStamp).Nanoseconds()
index := int64(math.Floor(float64(delta) / float64(rndm.RoundTimeDuration.Nanoseconds())))
if rndm.RoundIndex != index {
rndm.RoundIndex = index
rndm.RoundTimeStamp = genesisRoundTimeStamp.Add(time.Duration(index * rndm.RoundTimeDuration.Nanoseconds()))
}
}
// RemainingTime -
func (rndm *RoundHandlerMock) RemainingTime(_ time.Time, _ time.Duration) time.Duration {
return rndm.RoundTimeDuration
}
// IsInterfaceNil returns true if there is no value under the interface
func (rndm *RoundHandlerMock) IsInterfaceNil() bool {
return rndm == nil
}