Skip to content

Commit

Permalink
fix: state export for gov module constitution (osmosis-labs#8777)
Browse files Browse the repository at this point in the history
* fix: state export for gov module constitution

* fix: refactor execution to functions

* chore: add changelog

---------

Co-authored-by: Connor Barr <[email protected]>
  • Loading branch information
PaddyMc and crnbarr93 authored Oct 23, 2024
1 parent 8f19a69 commit ec77e75
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* [#8682](https://github.com/osmosis-labs/osmosis/pull/8682) chore: bump cosmwasm-optimizer
* [#8734](https://github.com/osmosis-labs/osmosis/pull/8734) chore: update cosmwasm vm
* [#8777](https://github.com/osmosis-labs/osmosis/pull/8777) fix: state export for gov module constitution
* [#8751](https://github.com/osmosis-labs/osmosis/pull/8751) fix: supply offsets for osmo token
* [#8764](https://github.com/osmosis-labs/osmosis/pull/8764) chore: add cosmwasm 1_3 feature
* [#8779](https://github.com/osmosis-labs/osmosis/pull/8779) chore: bump cometbft/cosmos-sdk versions
Expand Down
15 changes: 15 additions & 0 deletions app/upgrades/v27/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"context"

upgradetypes "cosmossdk.io/x/upgrade/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"

"github.com/osmosis-labs/osmosis/v26/app/keepers"
"github.com/osmosis-labs/osmosis/v26/app/upgrades"
Expand Down Expand Up @@ -34,6 +36,19 @@ func CreateUpgradeHandler(
// Remove the old key: []byte{0x88}
bk.RemoveOldSupplyOffset(ctx, OsmoToken)

sdkCtx := sdk.UnwrapSDKContext(ctx)

err = InitializeConstitutionCollection(sdkCtx, *keepers.GovKeeper)
if err != nil {
sdkCtx.Logger().Error("Error initializing Constitution Collection:", "message", err.Error())
}

return migrations, nil
}
}

// setting the default constitution for the chain
// this is in line with cosmos-sdk v5 gov migration: https://github.com/cosmos/cosmos-sdk/blob/v0.50.10/x/gov/migrations/v5/store.go#L57
func InitializeConstitutionCollection(ctx sdk.Context, govKeeper govkeeper.Keeper) error {
return govKeeper.Constitution.Set(ctx, "This chain has no constitution.")
}
27 changes: 21 additions & 6 deletions app/upgrades/v27/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ import (

"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/header"
upgradetypes "cosmossdk.io/x/upgrade/types"

"github.com/osmosis-labs/osmosis/v26/app/apptesting"
v27 "github.com/osmosis-labs/osmosis/v26/app/upgrades/v27"

"cosmossdk.io/x/upgrade"

upgradetypes "cosmossdk.io/x/upgrade/types"
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"

"github.com/osmosis-labs/osmosis/osmomath"
"github.com/osmosis-labs/osmosis/v26/app/apptesting"
v27 "github.com/osmosis-labs/osmosis/v26/app/upgrades/v27"
)

const (
Expand All @@ -37,6 +34,7 @@ func (s *UpgradeTestSuite) TestUpgrade() {
s.Setup()
s.preModule = upgrade.NewAppModule(s.App.UpgradeKeeper, addresscodec.NewBech32Codec("osmo"))

s.PrepareGovModuleConstitutionTest()
s.PrepareSupplyOffsetTest()

// Run the upgrade
Expand All @@ -46,6 +44,7 @@ func (s *UpgradeTestSuite) TestUpgrade() {
s.Require().NoError(err)
})

s.ExecuteGovModuleConstitutionTest()
s.ExecuteSupplyOffsetTest()
}

Expand All @@ -60,6 +59,22 @@ func dummyUpgrade(s *UpgradeTestSuite) {
s.Ctx = s.Ctx.WithHeaderInfo(header.Info{Height: v27UpgradeHeight, Time: s.Ctx.BlockTime().Add(time.Second)}).WithBlockHeight(v27UpgradeHeight)
}

// PrepareGovModuleConstitutionTest prepares the gov module constitution migration test
func (s *UpgradeTestSuite) PrepareGovModuleConstitutionTest() {
govKeeper := s.App.GovKeeper
pre, err := govKeeper.Constitution.Get(s.Ctx)
s.Require().NoError(err)
s.Require().Equal("", pre)
}

// ExecuteGovModuleConstitutionTest executes the gov module constitution migration test
func (s *UpgradeTestSuite) ExecuteGovModuleConstitutionTest() {
govKeeper := s.App.GovKeeper
post, err := govKeeper.Constitution.Get(s.Ctx)
s.Require().NoError(err)
s.Require().Equal("This chain has no constitution.", post)
}

func (s *UpgradeTestSuite) PrepareSupplyOffsetTest() {
// Set some supply offsets
s.App.BankKeeper.AddSupplyOffset(s.Ctx, v27.OsmoToken, osmomath.NewInt(1000))
Expand Down

0 comments on commit ec77e75

Please sign in to comment.