Skip to content

Commit c7d044a

Browse files
committed
lint
1 parent eaa3606 commit c7d044a

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

app/upgrades.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func (app *App) RegisterUpgradeHandlers(cdc codec.BinaryCodec) {
5757
}
5858
}
5959
}
60+
6061
func UpdateExpeditedParams(ctx context.Context, gov govkeeper.Keeper) error {
6162
govParams, err := gov.Params.Get(ctx)
6263
if err != nil {
@@ -83,7 +84,8 @@ func UpdateExpeditedParams(ctx context.Context, gov govkeeper.Keeper) error {
8384
}
8485
govParams.ExpeditedThreshold = expeditedThreshold.String()
8586
if govParams.ExpeditedVotingPeriod != nil && govParams.VotingPeriod != nil && *govParams.ExpeditedVotingPeriod >= *govParams.VotingPeriod {
86-
period := time.Second * time.Duration(DefaultPeriodRatio()*govParams.VotingPeriod.Seconds())
87+
votingPeriod := DurationToDec(*govParams.VotingPeriod)
88+
period := DecToDuration(DefaultPeriodRatio().Mul(votingPeriod))
8789
govParams.ExpeditedVotingPeriod = &period
8890
}
8991
if err := govParams.ValidateBasic(); err != nil {
@@ -96,6 +98,14 @@ func DefaultThresholdRatio() sdkmath.LegacyDec {
9698
return govv1.DefaultExpeditedThreshold.Quo(govv1.DefaultThreshold)
9799
}
98100

99-
func DefaultPeriodRatio() float64 {
100-
return govv1.DefaultExpeditedPeriod.Seconds() / govv1.DefaultPeriod.Seconds()
101+
func DefaultPeriodRatio() sdkmath.LegacyDec {
102+
return DurationToDec(govv1.DefaultExpeditedPeriod).Quo(DurationToDec(govv1.DefaultPeriod))
103+
}
104+
105+
func DurationToDec(d time.Duration) sdkmath.LegacyDec {
106+
return sdkmath.LegacyMustNewDecFromStr(fmt.Sprintf("%f", d.Seconds()))
107+
}
108+
109+
func DecToDuration(d sdkmath.LegacyDec) time.Duration {
110+
return time.Second * time.Duration(d.RoundInt64())
101111
}

app/upgrades_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ func (suite *AppTestSuite) TestUpdateExpeditedParams() {
8989
suite.govParams.VotingPeriod = &period
9090
},
9191
exp: func(params govv1.Params) {
92-
expected := time.Second * time.Duration(app.DefaultPeriodRatio()*suite.govParams.VotingPeriod.Seconds())
92+
votingPeriod := app.DurationToDec(*suite.govParams.VotingPeriod)
93+
expected := app.DecToDuration(app.DefaultPeriodRatio().Mul(votingPeriod))
9394
suite.Require().Equal(expected, *params.ExpeditedVotingPeriod)
9495
},
9596
},

0 commit comments

Comments
 (0)