@@ -26,13 +26,20 @@ import (
2626 utypes "pkg.akt.dev/node/upgrades/types"
2727)
2828
29+ type TestnetDelegation struct {
30+ Address sdk.AccAddress `json:"address"`
31+ Amount sdk.Coin `json:"amount"`
32+ }
33+
2934type TestnetValidator struct {
3035 OperatorAddress sdk.Address
3136 ConsensusAddress sdk.ConsAddress
3237 ConsensusPubKey * types.Any
38+ Status stakingtypes.BondStatus
3339 Moniker string
3440 Commission stakingtypes.Commission
3541 MinSelfDelegation sdkmath.Int
42+ Delegations []TestnetDelegation
3643}
3744
3845type TestnetGov struct {
@@ -44,8 +51,13 @@ type TestnetUpgrade struct {
4451 Name string
4552}
4653
54+ type TestnetAccount struct {
55+ Address sdk.AccAddress `json:"address"`
56+ Balances []sdk.Coin `json:"balances"`
57+ }
58+
4759type TestnetConfig struct {
48- Accounts []sdk. AccAddress
60+ Accounts []TestnetAccount
4961 Validators []TestnetValidator
5062 Gov TestnetGov
5163 Upgrade TestnetUpgrade
@@ -81,14 +93,14 @@ func InitAkashAppForTestnet(
8193 stakingStore := ctx .KVStore (stakingKey )
8294 iterator , err := app .Keepers .Cosmos .Staking .ValidatorsPowerStoreIterator (ctx )
8395 if err != nil {
84- return nil
96+ panic ( err . Error ())
8597 }
8698 for ; iterator .Valid (); iterator .Next () {
8799 stakingStore .Delete (iterator .Key ())
88100 }
89101 _ = iterator .Close ()
90102
91- // Remove all validators from last validators store
103+ // Remove all validators from the last validators store
92104 iterator , err = app .Keepers .Cosmos .Staking .LastValidatorsIterator (ctx )
93105 if err != nil {
94106 return nil
@@ -98,7 +110,7 @@ func InitAkashAppForTestnet(
98110 }
99111 _ = iterator .Close ()
100112
101- // Remove all validators from validator store
113+ // Remove all validators from the validator store
102114 iterator = storetypes .KVStorePrefixIterator (stakingStore , stakingtypes .ValidatorsKey )
103115 for ; iterator .Valid (); iterator .Next () {
104116 stakingStore .Delete (iterator .Key ())
@@ -112,14 +124,29 @@ func InitAkashAppForTestnet(
112124 }
113125 _ = iterator .Close ()
114126
127+ // BANK
128+ //
129+
130+ // Fund localakash accounts
131+ for _ , account := range tcfg .Accounts {
132+ err := app .Keepers .Cosmos .Bank .MintCoins (ctx , minttypes .ModuleName , account .Balances )
133+ if err != nil {
134+ panic (err .Error ())
135+ }
136+ err = app .Keepers .Cosmos .Bank .SendCoinsFromModuleToAccount (ctx , minttypes .ModuleName , account .Address , account .Balances )
137+ if err != nil {
138+ panic (err .Error ())
139+ }
140+ }
141+
115142 for _ , val := range tcfg .Validators {
116143 _ , bz , err := bech32 .DecodeAndConvert (val .OperatorAddress .String ())
117144 if err != nil {
118- return nil
145+ panic ( err . Error ())
119146 }
120147 bech32Addr , err := bech32 .ConvertAndEncode ("akashvaloper" , bz )
121148 if err != nil {
122- return nil
149+ panic ( err . Error ())
123150 }
124151
125152 // Create Validator struct for our new validator.
@@ -128,41 +155,35 @@ func InitAkashAppForTestnet(
128155 ConsensusPubkey : val .ConsensusPubKey ,
129156 Jailed : false ,
130157 Status : stakingtypes .Bonded ,
131- Tokens : sdkmath .NewInt (900000000000000 ),
132- DelegatorShares : sdkmath .LegacyMustNewDecFromStr ("10000000 " ),
158+ Tokens : sdkmath .NewInt (0 ),
159+ DelegatorShares : sdkmath .LegacyMustNewDecFromStr ("0 " ),
133160 Description : stakingtypes.Description {
134- Moniker : "Testnet Validator" ,
135- },
136- Commission : stakingtypes.Commission {
137- CommissionRates : stakingtypes.CommissionRates {
138- Rate : sdkmath .LegacyMustNewDecFromStr ("0.05" ),
139- MaxRate : sdkmath .LegacyMustNewDecFromStr ("0.1" ),
140- MaxChangeRate : sdkmath .LegacyMustNewDecFromStr ("0.05" ),
141- },
161+ Moniker : val .Moniker ,
142162 },
143- MinSelfDelegation : sdkmath .OneInt (),
163+ Commission : val .Commission ,
164+ MinSelfDelegation : val .MinSelfDelegation ,
144165 }
145166
146167 // Add our validator to power and last validators store
147168 err = app .Keepers .Cosmos .Staking .SetValidator (ctx , newVal )
148169 if err != nil {
149- return nil
170+ panic ( err . Error ())
150171 }
151172 err = app .Keepers .Cosmos .Staking .SetValidatorByConsAddr (ctx , newVal )
152173 if err != nil {
153- return nil
174+ panic ( err . Error ())
154175 }
155176 err = app .Keepers .Cosmos .Staking .SetValidatorByPowerIndex (ctx , newVal )
156177 if err != nil {
157- return nil
178+ panic ( err . Error ())
158179 }
159180 valAddr , err := sdk .ValAddressFromBech32 (newVal .GetOperator ())
160181 if err != nil {
161- return nil
182+ panic ( err . Error ())
162183 }
163184 err = app .Keepers .Cosmos .Staking .SetLastValidatorPower (ctx , valAddr , 0 )
164185 if err != nil {
165- return nil
186+ panic ( err . Error ())
166187 }
167188 if err := app .Keepers .Cosmos .Staking .Hooks ().AfterValidatorCreated (ctx , valAddr ); err != nil {
168189 panic (err )
@@ -174,23 +195,23 @@ func InitAkashAppForTestnet(
174195 // Initialize records for this validator across all distribution stores
175196 valAddr , err = sdk .ValAddressFromBech32 (newVal .GetOperator ())
176197 if err != nil {
177- return nil
198+ panic ( err . Error ())
178199 }
179200 err = app .Keepers .Cosmos .Distr .SetValidatorHistoricalRewards (ctx , valAddr , 0 , distrtypes .NewValidatorHistoricalRewards (sdk.DecCoins {}, 1 ))
180201 if err != nil {
181- return nil
202+ panic ( err . Error ())
182203 }
183204 err = app .Keepers .Cosmos .Distr .SetValidatorCurrentRewards (ctx , valAddr , distrtypes .NewValidatorCurrentRewards (sdk.DecCoins {}, 1 ))
184205 if err != nil {
185- return nil
206+ panic ( err . Error ())
186207 }
187208 err = app .Keepers .Cosmos .Distr .SetValidatorAccumulatedCommission (ctx , valAddr , distrtypes .InitialValidatorAccumulatedCommission ())
188209 if err != nil {
189- return nil
210+ panic ( err . Error ())
190211 }
191212 err = app .Keepers .Cosmos .Distr .SetValidatorOutstandingRewards (ctx , valAddr , distrtypes.ValidatorOutstandingRewards {Rewards : sdk.DecCoins {}})
192213 if err != nil {
193- return nil
214+ panic ( err . Error ())
194215 }
195216
196217 // SLASHING
@@ -205,7 +226,19 @@ func InitAkashAppForTestnet(
205226 }
206227 err = app .Keepers .Cosmos .Slashing .SetValidatorSigningInfo (ctx , newConsAddr , newValidatorSigningInfo )
207228 if err != nil {
208- return nil
229+ panic (err .Error ())
230+ }
231+
232+ for _ , del := range val .Delegations {
233+ vl , err := app .Keepers .Cosmos .Staking .GetValidator (ctx , valAddr )
234+ if err != nil {
235+ panic (err .Error ())
236+ }
237+
238+ _ , err = app .Keepers .Cosmos .Staking .Delegate (ctx , del .Address , del .Amount .Amount , stakingtypes .Unbonded , vl , true )
239+ if err != nil {
240+ panic (err )
241+ }
209242 }
210243 }
211244 //
@@ -217,7 +250,7 @@ func InitAkashAppForTestnet(
217250
218251 govParams , err := app .Keepers .Cosmos .Gov .Params .Get (ctx )
219252 if err != nil {
220- return nil
253+ panic ( err . Error ())
221254 }
222255 govParams .ExpeditedVotingPeriod = & tcfg .Gov .ExpeditedVotePeriod
223256 govParams .VotingPeriod = & tcfg .Gov .VotePeriod
@@ -226,27 +259,7 @@ func InitAkashAppForTestnet(
226259
227260 err = app .Keepers .Cosmos .Gov .Params .Set (ctx , govParams )
228261 if err != nil {
229- return nil
230- }
231-
232- // BANK
233- //
234-
235- defaultCoins := sdk .NewCoins (
236- sdk .NewInt64Coin ("uakt" , 1000000000000 ),
237- sdk .NewInt64Coin ("ibc/12C6A0C374171B595A0A9E18B83FA09D295FB1F2D8C6DAA3AC28683471752D84" , 1000000000000 ), // axlUSDC
238- )
239-
240- // Fund localakash accounts
241- for _ , account := range tcfg .Accounts {
242- err := app .Keepers .Cosmos .Bank .MintCoins (ctx , minttypes .ModuleName , defaultCoins )
243- if err != nil {
244- return nil
245- }
246- err = app .Keepers .Cosmos .Bank .SendCoinsFromModuleToAccount (ctx , minttypes .ModuleName , account , defaultCoins )
247- if err != nil {
248- return nil
249- }
262+ panic (err .Error ())
250263 }
251264
252265 // UPGRADE
0 commit comments