/
test_common.go
52 lines (40 loc) · 1.22 KB
/
test_common.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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
// --------------------------------------------- TestPeriod
var _ Period = &TestPeriod{}
// TestPeriod Is identical to BlockPeriod but does
// not take into consideration the context in periodEnded() and periodStarted()
func NewTestPeriod(periodLength, periodStartBlock int64) TestPeriod {
return TestPeriod{
PeriodLength: periodLength,
PeriodStartBlock: periodStartBlock,
}
}
func (p TestPeriod) periodEndBlock() int64 {
return p.PeriodStartBlock + p.PeriodLength
}
func (p TestPeriod) GetPeriodUnit() string {
return BlockPeriodUnit
}
func (p TestPeriod) Validate() error {
// Validate period-related values
if p.PeriodStartBlock > p.periodEndBlock() {
return sdkerrors.Wrap(ErrInvalidPeriod, "start time is after end time")
} else if p.PeriodLength <= 0 {
return sdkerrors.Wrap(ErrInvalidPeriod, "period length must be greater than zero")
}
return nil
}
func (p TestPeriod) periodStarted(ctx sdk.Context) bool {
return true
}
func (p TestPeriod) periodEnded(ctx sdk.Context) bool {
return true
}
func (p TestPeriod) nextPeriod() Period {
p.PeriodStartBlock = p.periodEndBlock()
return &p
}