-
Notifications
You must be signed in to change notification settings - Fork 199
/
rounderMock.go
50 lines (40 loc) · 1.15 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
package mock
import (
"math"
"time"
)
// RounderMock -
type RounderMock struct {
RoundIndex int64
RoundTimeStamp time.Time
RoundTimeDuration time.Duration
}
// Index -
func (rndm *RounderMock) Index() int64 {
return rndm.RoundIndex
}
// TimeDuration -
func (rndm *RounderMock) TimeDuration() time.Duration {
return rndm.RoundTimeDuration
}
// TimeStamp -
func (rndm *RounderMock) TimeStamp() time.Time {
return rndm.RoundTimeStamp
}
// UpdateRound -
func (rndm *RounderMock) 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 *RounderMock) RemainingTime(_ time.Time, _ time.Duration) time.Duration {
return rndm.RoundTimeDuration
}
// IsInterfaceNil returns true if there is no value under the interface
func (rndm *RounderMock) IsInterfaceNil() bool {
return rndm == nil
}