@@ -2,6 +2,7 @@ package app
22
33import (
44 "fmt"
5+ "strings"
56 "time"
67
78 tmos "github.com/cometbft/cometbft/libs/os"
@@ -42,10 +43,14 @@ type TestnetValidator struct {
4243 Delegations []TestnetDelegation
4344}
4445
46+ type TestnetVotingPeriod struct {
47+ time.Duration
48+ }
49+
4550type TestnetGovConfig struct {
4651 VotingParams * struct {
47- VotingPeriod time. Duration `json:"voting_period,omitempty"`
48- ExpeditedVotePeriod time. Duration `json:"expedited_vote_period"`
52+ VotingPeriod TestnetVotingPeriod `json:"voting_period,omitempty"`
53+ ExpeditedVotePeriod TestnetVotingPeriod `json:"expedited_vote_period"`
4954 } `json:"voting_params,omitempty"`
5055}
5156
@@ -65,6 +70,27 @@ type TestnetConfig struct {
6570 Upgrade TestnetUpgrade
6671}
6772
73+ func TrimQuotes (data string ) string {
74+ data = strings .TrimPrefix (data , "\" " )
75+ return strings .TrimSuffix (data , "\" " )
76+ }
77+
78+ func (t * TestnetVotingPeriod ) UnmarshalJSON (data []byte ) error {
79+ val := TrimQuotes (string (data ))
80+
81+ if ! strings .HasSuffix (val , "s" ) {
82+ return fmt .Errorf ("invalid format of voting period. must contain time unit. Valid time units are ns|us(µs)|ms|s|m|h" ) // nolint: goerr113
83+ }
84+
85+ var err error
86+ t .Duration , err = time .ParseDuration (val )
87+ if err != nil {
88+ return err
89+ }
90+
91+ return nil
92+ }
93+
6894// InitAkashAppForTestnet is broken down into two sections:
6995// Required Changes: Changes that, if not made, will cause the testnet to halt or panic
7096// Optional Changes: Changes to customize the testnet to one's liking (lower vote times, fund accounts, etc)
@@ -258,8 +284,8 @@ func InitAkashAppForTestnet(
258284 if err != nil {
259285 panic (err .Error ())
260286 }
261- govParams .ExpeditedVotingPeriod = & tcfg .Gov .VotingParams .ExpeditedVotePeriod
262- govParams .VotingPeriod = & tcfg .Gov .VotingParams .VotingPeriod
287+ govParams .ExpeditedVotingPeriod = & tcfg .Gov .VotingParams .ExpeditedVotePeriod . Duration
288+ govParams .VotingPeriod = & tcfg .Gov .VotingParams .VotingPeriod . Duration
263289 govParams .MinDeposit = sdk .NewCoins (sdk .NewInt64Coin (sdkutil .DenomUakt , 100000000 ))
264290 govParams .ExpeditedMinDeposit = sdk .NewCoins (sdk .NewInt64Coin (sdkutil .DenomUakt , 150000000 ))
265291
0 commit comments