Skip to content

Commit

Permalink
fix: replace is zero time check (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
karzak committed Feb 2, 2021
1 parent 71f60ec commit 37be34b
Show file tree
Hide file tree
Showing 17 changed files with 30 additions and 36 deletions.
2 changes: 1 addition & 1 deletion x/auction/types/auctions.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (a BaseAuction) Validate() error {
if !a.Bid.IsValid() {
return fmt.Errorf("invalid bid: %s", a.Bid)
}
if a.EndTime.IsZero() || a.MaxEndTime.IsZero() {
if a.EndTime.Unix() <= 0 || a.MaxEndTime.Unix() <= 0 {
return errors.New("end time cannot be zero")
}
if a.EndTime.After(a.MaxEndTime) {
Expand Down
2 changes: 1 addition & 1 deletion x/bep3/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var (
DefaultMaxAmount sdk.Int = sdk.NewInt(1000000000000) // 10,000 BNB
DefaultMinBlockLock uint64 = 220
DefaultMaxBlockLock uint64 = 270
DefaultPreviousBlockTime = tmtime.Canonical(time.Unix(0, 0))
DefaultPreviousBlockTime = tmtime.Canonical(time.Unix(1, 0))
)

// Params governance parameters for bep3 module
Expand Down
2 changes: 1 addition & 1 deletion x/cdp/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func InitGenesis(ctx sdk.Context, k Keeper, pk types.PricefeedKeeper, sk types.S

for _, gat := range gs.PreviousAccumulationTimes {
k.SetInterestFactor(ctx, gat.CollateralType, gat.InterestFactor)
if !gat.PreviousAccumulationTime.IsZero() {
if gat.PreviousAccumulationTime.Unix() > 0 {
k.SetPreviousAccrualTime(ctx, gat.CollateralType, gat.PreviousAccumulationTime)
}
}
Expand Down
5 changes: 3 additions & 2 deletions x/cdp/legacy/v0_11/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func NewCDPWithFees(id uint64, owner sdk.AccAddress, collateral sdk.Coin, collat
}
}

// Validate performs stateless validation of cdp object state
func (cdp CDP) Validate() error {
if cdp.ID == 0 {
return errors.New("cdp id cannot be 0")
Expand All @@ -125,7 +126,7 @@ func (cdp CDP) Validate() error {
if !cdp.AccumulatedFees.IsValid() {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "accumulated fees %s", cdp.AccumulatedFees)
}
if cdp.FeesUpdated.IsZero() {
if cdp.FeesUpdated.Unix() <= 0 {
return errors.New("cdp updated fee time cannot be zero")
}
if strings.TrimSpace(cdp.Type) == "" {
Expand Down Expand Up @@ -631,7 +632,7 @@ func (gs GenesisState) Validate() error {
return err
}

if gs.PreviousDistributionTime.IsZero() {
if gs.PreviousDistributionTime.Unix() <= 0 {
return fmt.Errorf("previous distribution time not set")
}

Expand Down
2 changes: 1 addition & 1 deletion x/cdp/legacy/v0_13/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ func (cdp CDP) Validate() error {
if !cdp.AccumulatedFees.IsValid() {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "accumulated fees %s", cdp.AccumulatedFees)
}
if cdp.FeesUpdated.IsZero() {
if cdp.FeesUpdated.Unix() <= 0 {
return errors.New("cdp updated fee time cannot be zero")
}
if strings.TrimSpace(cdp.Type) == "" {
Expand Down
2 changes: 1 addition & 1 deletion x/cdp/types/cdp.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (cdp CDP) Validate() error {
if !cdp.AccumulatedFees.IsValid() {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "accumulated fees %s", cdp.AccumulatedFees)
}
if cdp.FeesUpdated.IsZero() {
if cdp.FeesUpdated.Unix() <= 0 {
return errors.New("cdp updated fee time cannot be zero")
}
if strings.TrimSpace(cdp.Type) == "" {
Expand Down
1 change: 0 additions & 1 deletion x/hard/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ var (
DefaultCheckLtvIndexCount = types.DefaultCheckLtvIndexCount
DefaultDeposits = types.DefaultDeposits
DefaultMoneyMarkets = types.DefaultMoneyMarkets
DefaultPreviousBlockTime = types.DefaultPreviousBlockTime
DefaultTotalBorrowed = types.DefaultTotalBorrowed
DefaultTotalReserves = types.DefaultTotalReserves
DefaultTotalSupplied = types.DefaultTotalSupplied
Expand Down
4 changes: 2 additions & 2 deletions x/hard/legacy/v0_11/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ func (ds DistributionSchedule) Validate() error {
if ds.RewardsPerSecond.Denom != "hard" {
return fmt.Errorf("reward denom should be hard, is %s", ds.RewardsPerSecond.Denom)
}
if ds.Start.IsZero() {
if ds.Start.Unix() <= 0 {
return errors.New("reward period start time cannot be 0")
}
if ds.End.IsZero() {
if ds.End.Unix() <= 0 {
return errors.New("reward period end time cannot be 0")
}
if ds.Start.After(ds.End) {
Expand Down
6 changes: 0 additions & 6 deletions x/hard/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ import (
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
tmtime "github.com/tendermint/tendermint/types/time"
)

// GenesisState default values
var (
DefaultPreviousBlockTime = tmtime.Canonical(time.Unix(0, 0))
)

// GenesisState is the state that must be provided at genesis.
Expand Down
10 changes: 5 additions & 5 deletions x/incentive/legacy/v0_11/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (gs GenesisState) Validate() error {
if err := gs.Params.Validate(); err != nil {
return err
}
if gs.PreviousBlockTime.IsZero() {
if gs.PreviousBlockTime.Unix() <= 0 {
return errors.New("previous block time cannot be 0")
}
if err := gs.RewardPeriods.Validate(); err != nil {
Expand Down Expand Up @@ -336,10 +336,10 @@ func NewRewardPeriod(collateralType string, start time.Time, end time.Time, rewa

// Validate performs a basic check of a RewardPeriod fields.
func (rp RewardPeriod) Validate() error {
if rp.Start.IsZero() {
if rp.Start.Unix() <= 0 {
return errors.New("reward period start time cannot be 0")
}
if rp.End.IsZero() {
if rp.End.Unix() <= 0 {
return errors.New("reward period end time cannot be 0")
}
if rp.Start.After(rp.End) {
Expand All @@ -348,7 +348,7 @@ func (rp RewardPeriod) Validate() error {
if !rp.Reward.IsValid() {
return fmt.Errorf("invalid reward amount: %s", rp.Reward)
}
if rp.ClaimEnd.IsZero() {
if rp.ClaimEnd.Unix() <= 0 {
return errors.New("reward period claim end time cannot be 0")
}
if err := rp.ClaimMultipliers.Validate(); err != nil {
Expand Down Expand Up @@ -404,7 +404,7 @@ func (cp ClaimPeriod) Validate() error {
if cp.ID == 0 {
return errors.New("claim period id cannot be 0")
}
if cp.End.IsZero() {
if cp.End.Unix() <= 0 {
return errors.New("claim period end time cannot be 0")
}
if err := cp.ClaimMultipliers.Validate(); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions x/incentive/legacy/v0_9/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (gs GenesisState) Validate() error {
if err := gs.Params.Validate(); err != nil {
return err
}
if gs.PreviousBlockTime.IsZero() {
if gs.PreviousBlockTime.Unix() <= 0 {
return errors.New("previous block time cannot be 0")
}
if err := gs.RewardPeriods.Validate(); err != nil {
Expand Down Expand Up @@ -259,10 +259,10 @@ func NewRewardPeriod(denom string, start time.Time, end time.Time, reward sdk.Co

// Validate performs a basic check of a RewardPeriod fields.
func (rp RewardPeriod) Validate() error {
if rp.Start.IsZero() {
if rp.Start.Unix() <= 0 {
return errors.New("reward period start time cannot be 0")
}
if rp.End.IsZero() {
if rp.End.Unix() <= 0 {
return errors.New("reward period end time cannot be 0")
}
if rp.Start.After(rp.End) {
Expand All @@ -271,7 +271,7 @@ func (rp RewardPeriod) Validate() error {
if !rp.Reward.IsValid() {
return fmt.Errorf("invalid reward amount: %s", rp.Reward)
}
if rp.ClaimEnd.IsZero() {
if rp.ClaimEnd.Unix() <= 0 {
return errors.New("reward period claim end time cannot be 0")
}
if rp.ClaimTimeLock == 0 {
Expand Down Expand Up @@ -324,7 +324,7 @@ func (cp ClaimPeriod) Validate() error {
if cp.ID == 0 {
return errors.New("claim period id cannot be 0")
}
if cp.End.IsZero() {
if cp.End.Unix() <= 0 {
return errors.New("claim period end time cannot be 0")
}
if cp.TimeLock == 0 {
Expand Down
8 changes: 4 additions & 4 deletions x/incentive/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (
DefaultMultipliers = Multipliers{}
DefaultClaims = USDXMintingClaims{}
DefaultGenesisAccumulationTimes = GenesisAccumulationTimes{}
DefaultClaimEnd = tmtime.Canonical(time.Unix(0, 0))
DefaultClaimEnd = tmtime.Canonical(time.Unix(1, 0))
GovDenom = cdptypes.DefaultGovDenom
PrincipalDenom = "usdx"
IncentiveMacc = kavadistTypes.ModuleName
Expand Down Expand Up @@ -154,7 +154,7 @@ func validateClaimEndParam(i interface{}) error {
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if endTime.IsZero() {
if endTime.Unix() <= 0 {
return fmt.Errorf("end time should not be zero")
}
return nil
Expand Down Expand Up @@ -193,10 +193,10 @@ func NewRewardPeriod(active bool, collateralType string, start time.Time, end ti

// Validate performs a basic check of a RewardPeriod fields.
func (rp RewardPeriod) Validate() error {
if rp.Start.IsZero() {
if rp.Start.Unix() <= 0 {
return errors.New("reward period start time cannot be 0")
}
if rp.End.IsZero() {
if rp.End.Unix() <= 0 {
return errors.New("reward period end time cannot be 0")
}
if rp.Start.After(rp.End) {
Expand Down
4 changes: 2 additions & 2 deletions x/kavadist/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (
KeyPeriods = []byte("Periods")
DefaultActive = false
DefaultPeriods = Periods{}
DefaultPreviousBlockTime = tmtime.Canonical(time.Unix(0, 0))
DefaultPreviousBlockTime = tmtime.Canonical(time.Unix(1, 0))
GovDenom = cdptypes.DefaultGovDenom
)

Expand Down Expand Up @@ -132,7 +132,7 @@ func validatePeriodsParams(i interface{}) error {
}
prevEnd = pr.End

if pr.Start.IsZero() || pr.End.IsZero() {
if pr.Start.Unix() <= 0 || pr.End.Unix() <= 0 {
return fmt.Errorf("start or end time cannot be zero: %s", pr)
}

Expand Down
2 changes: 1 addition & 1 deletion x/pricefeed/legacy/v0_9/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (pp PostedPrice) Validate() error {
if pp.Price.IsNegative() {
return fmt.Errorf("posted price cannot be negative %s", pp.Price)
}
if pp.Expiry.IsZero() {
if pp.Expiry.Unix() <= 0 {
return errors.New("expiry time cannot be zero")
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion x/pricefeed/types/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (pp PostedPrice) Validate() error {
if pp.Price.IsNegative() {
return fmt.Errorf("posted price cannot be negative %s", pp.Price)
}
if pp.Expiry.IsZero() {
if pp.Expiry.Unix() <= 0 {
return errors.New("expiry time cannot be zero")
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion x/pricefeed/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (msg MsgPostPrice) ValidateBasic() error {
if msg.Price.IsNegative() {
return fmt.Errorf("price cannot be negative: %s", msg.Price.String())
}
if msg.Expiry.IsZero() {
if msg.Expiry.Unix() <= 0 {
return errors.New("must set an expiration time")
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion x/validator-vesting/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (data GenesisState) IsEmpty() bool {

// ValidateGenesis returns nil because accounts are validated by auth
func ValidateGenesis(data GenesisState) error {
if data.PreviousBlockTime.IsZero() {
if data.PreviousBlockTime.Unix() <= 0 {
return errors.New("previous block time cannot be zero")
}
return nil
Expand Down

0 comments on commit 37be34b

Please sign in to comment.