fix: replace is zero time check (#787)

This commit is contained in:
Kevin Davis 2021-02-02 14:42:51 -07:00 committed by GitHub
parent 71f60ec4d9
commit 37be34b4d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 30 additions and 36 deletions

View File

@ -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) {

View File

@ -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

View File

@ -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)
}
}

View File

@ -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")
@ -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) == "" {
@ -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")
}

View File

@ -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) == "" {

View File

@ -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) == "" {

View File

@ -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

View File

@ -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) {

View File

@ -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.

View File

@ -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 {
@ -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) {
@ -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 {
@ -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 {

View File

@ -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 {
@ -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) {
@ -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 {
@ -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 {

View File

@ -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
@ -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
@ -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) {

View File

@ -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
)
@ -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)
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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