###### tags: `Testing`
# Test #8865 and Upgrade
The following test uses SimApp to test the fix for [#8865](https://github.com/cosmos/cosmos-sdk/pull/8865) after successful upgrade.
---
change to `release/v0.42.x`
build binary
```
./build/simd init test --chain-id test
```
```
nano ~/.simapp/config/genesis.json
```
update voting period to 20s
```
./build/simd add-genesis-account test1 5000000000stake
```
```
./build/simd gentx test1 1000000stake --chain-id test
```
```
./build/simd collect-gentxs
```
```
./build/simd start
```
...
```
./build/simd config chain-id test
```
```
./build/simd tx vesting create-vesting-account cosmos1nvuh4zpvan05qxj9746veyy2vr7l2n00y9nd5q 300stake 1624349030 --from test1 --broadcast-mode block --yes
```
```
./build/simd tx bank send cosmos1yunqnxp3ct0fr0p74awxu5f9vwf5uq9k9sg9yf cosmos1nvuh4zpvan05qxj9746veyy2vr7l2n00y9nd5q 10stake --broadcast-mode block --yes
```
```
./build/simd tx staking delegate cosmosvaloper1yunqnxp3ct0fr0p74awxu5f9vwf5uq9kqyusg6 300stake --from test2 --broadcast-mode block --yes
```
```
./build/simd tx bank send cosmos1nvuh4zpvan05qxj9746veyy2vr7l2n00y9nd5q cosmos1yunqnxp3ct0fr0p74awxu5f9vwf5uq9k9sg9yf 1stake --broadcast-mode block --yes
```
confirm panic
```
./build/simd tx gov submit-proposal software-upgrade v0.43 --title upgrade --description upgrade --upgrade-height 25 --from test1 --broadcast-mode block --yes
```
```
./build/simd tx gov deposit 1 10000000stake --from test1 --broadcast-mode block --yes
```
```
./build/simd tx gov vote 1 yes --from test1 --broadcast-mode block --yes
```
```
./build/simd tx gov vote 1 yes --from test2 --broadcast-mode block --yes
```
confirm chain halts
change to `v0.43.0-beta1`
add the following to simapp/app.go starting on line 260:
```
app.registerUpgradeHandlers()
```
add the following to simapp/app.go starting on line 420 (or anywhere in file):
```
func (app *SimApp) registerUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler("v0.43", func(ctx sdk.Context, plan upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) {
// 1st-time running in-store migrations, using 1 as fromVersion to
// avoid running InitGenesis.
fromVM := map[string]uint64{
"auth": 1,
"bank": 1,
"capability": 1,
"crisis": 1,
"distribution": 1,
"evidence": 1,
"gov": 1,
"mint": 1,
"params": 1,
"slashing": 1,
"staking": 1,
"upgrade": 1,
"vesting": 1,
"ibc": 1,
"genutil": 1,
"transfer": 1,
}
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}
if upgradeInfo.Name == "v0.43" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{"authz", "feegrant"},
}
// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}
```
add `storetypes` to imports
```
storetypes "github.com/cosmos/cosmos-sdk/store/types"
```
update `x/staking/legacy/v043/store.go` ([aleem's fix](https://github.com/cosmos/cosmos-sdk/commit/fbb50cfa0a43) not yet merged)
```
func migrateParamsStore(ctx sdk.Context, paramstore paramtypes.Subspace) {
if paramstore.HasKeyTable() {
paramstore.Set(ctx, types.KeyPowerReduction, sdk.DefaultPowerReduction)
} else {
paramstore.WithKeyTable(types.ParamKeyTable())
paramstore.Set(ctx, types.KeyPowerReduction, sdk.DefaultPowerReduction)
}
}
```
build binary
```
./build/simd start
```
```
./build/simd tx bank send cosmos1nvuh4zpvan05qxj9746veyy2vr7l2n00y9nd5q cosmos1yunqnxp3ct0fr0p74awxu5f9vwf5uq9k9sg9yf 1stake --broadcast-mode block --yes
```
confirm no panic