Skip to content

Commit

Permalink
Add Emission Enabled bolean flag to mint module
Browse files Browse the repository at this point in the history
  • Loading branch information
relyt29 committed Dec 16, 2024
1 parent 7520daa commit 22ebf8a
Show file tree
Hide file tree
Showing 14 changed files with 3,678 additions and 78 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

* [#694](https://github.com/allora-network/allora-chain/pull/694) Make fuzzer whitelist aware
* [#708](https://github.com/allora-network/allora-chain/pull/708) Add Emission Enabled bolean flag to Mint Module

### Fixed

Expand Down
915 changes: 915 additions & 0 deletions x/mint/api/mint/v5/genesis.pulsar.go

Large diffs are not rendered by default.

1,459 changes: 1,459 additions & 0 deletions x/mint/api/mint/v5/types.pulsar.go

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions x/mint/migrations/v5/migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package v5

import (
"github.com/allora-network/allora-chain/x/mint/keeper"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// migrate the store from version 4 to version 5
func MigrateStore(ctx sdk.Context, mintKeeper keeper.Keeper) error {
ctx.Logger().Info("MIGRATING MINT MODULE FROM VERSION 4 TO VERSION 5")
return migrateParams(ctx, mintKeeper)
}

// We add an additional boolean param that controls
// whether or not emissions is turned on
// For an already running network it should just be turned on
func migrateParams(ctx sdk.Context, mintKeeper keeper.Keeper) error {
ctx.Logger().Info("MIGRATING MINT MODULE PARAMS FROM VERSION 4 TO VERSION 5")

params, err := mintKeeper.Params.Get(ctx)
if err != nil {
ctx.Logger().Error("failed to get current params from keeper", "error", err)
return err
}

// set the emission enabled param to true by default
params.EmissionEnabled = true

err = mintKeeper.Params.Set(ctx, params)
if err != nil {
ctx.Logger().Error("failed to set updated params in keeper", "error", err)
return err
}

return nil
}
120 changes: 120 additions & 0 deletions x/mint/migrations/v5/migrate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package v5_test

import (
"testing"

"github.com/stretchr/testify/suite"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/golang/mock/gomock"

"cosmossdk.io/core/store"
minttestutil "github.com/allora-network/allora-chain/x/mint/testutil"
"github.com/allora-network/allora-chain/x/mint/types"

Check failure on line 13 in x/mint/migrations/v5/migrate_test.go

View workflow job for this annotation

GitHub Actions / lint

ST1019: package "github.com/allora-network/allora-chain/x/mint/types" is being imported more than once (stylecheck)

"github.com/allora-network/allora-chain/x/mint/keeper"
mint "github.com/allora-network/allora-chain/x/mint/module"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"

v5 "github.com/allora-network/allora-chain/x/mint/migrations/v5"
minttypes "github.com/allora-network/allora-chain/x/mint/types"

Check failure on line 21 in x/mint/migrations/v5/migrate_test.go

View workflow job for this annotation

GitHub Actions / lint

ST1019(related information): other import of "github.com/allora-network/allora-chain/x/mint/types" (stylecheck)
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"

storetypes "cosmossdk.io/store/types"
oldV4Types "github.com/allora-network/allora-chain/x/mint/migrations/v5/oldtypes"
cosmostestutil "github.com/cosmos/cosmos-sdk/testutil"
)

type MintV5MigrationTestSuite struct {
suite.Suite
ctrl *gomock.Controller

ctx sdk.Context
storeService store.KVStoreService
mintKeeper *keeper.Keeper
}

func TestMintV5MigrationTestSuite(t *testing.T) {
suite.Run(t, new(MintV5MigrationTestSuite))
}

func (s *MintV5MigrationTestSuite) SetupTest() {
encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModule{})

Check failure on line 43 in x/mint/migrations/v5/migrate_test.go

View workflow job for this annotation

GitHub Actions / lint

mint.AppModule is missing field AppModuleBasic (exhaustruct)
key := storetypes.NewKVStoreKey(minttypes.StoreKey)
storeService := runtime.NewKVStoreService(key)
s.storeService = storeService
testCtx := cosmostestutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test"))

// gomock initializations
s.ctrl = gomock.NewController(s.T())
accountKeeper := minttestutil.NewMockAccountKeeper(s.ctrl)
bankKeeper := minttestutil.NewMockBankKeeper(s.ctrl)
emissionsKeeper := minttestutil.NewMockEmissionsKeeper(s.ctrl)
stakingKeeper := minttestutil.NewMockStakingKeeper(s.ctrl)
accountKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(authtypes.NewModuleAddress(types.ModuleName))
mintKeeper := keeper.NewKeeper(
encCfg.Codec,
storeService,
stakingKeeper,
accountKeeper,
bankKeeper,
emissionsKeeper,
authtypes.FeeCollectorName,
)

s.ctx = testCtx.Ctx
s.storeService = storeService
s.mintKeeper = &mintKeeper
}

// In this test we check that the mint module params have been migrated
// and the expected new fields are added and set to true:
// EmissionEnabled
func (s *MintV5MigrationTestSuite) TestMigrateParams() {
storageService := s.mintKeeper.GetStorageService()
store := runtime.KVStoreAdapter(storageService.OpenKVStore(s.ctx))
cdc := s.mintKeeper.GetBinaryCodec()

defaultParams := minttypes.DefaultParams()
paramsOld := oldV4Types.Params{
MintDenom: defaultParams.MintDenom,
MaxSupply: defaultParams.MaxSupply,
FEmission: defaultParams.FEmission,
OneMonthSmoothingDegree: defaultParams.OneMonthSmoothingDegree,
EcosystemTreasuryPercentOfTotalSupply: defaultParams.EcosystemTreasuryPercentOfTotalSupply,
FoundationTreasuryPercentOfTotalSupply: defaultParams.FoundationTreasuryPercentOfTotalSupply,
ParticipantsPercentOfTotalSupply: defaultParams.ParticipantsPercentOfTotalSupply,
InvestorsPercentOfTotalSupply: defaultParams.InvestorsPercentOfTotalSupply,
TeamPercentOfTotalSupply: defaultParams.TeamPercentOfTotalSupply,
MaximumMonthlyPercentageYield: defaultParams.MaximumMonthlyPercentageYield,
InvestorsPreseedPercentOfTotalSupply: defaultParams.InvestorsPreseedPercentOfTotalSupply,
}

store.Set(minttypes.ParamsKey, cdc.MustMarshal(&paramsOld))

// Run migration
err := v5.MigrateStore(s.ctx, *s.mintKeeper)
s.Require().NoError(err)

paramsExpected := defaultParams
paramsExpected.EmissionEnabled = true

// TO BE ADDED:
// - EmissionEnabled - set to true

params, err := s.mintKeeper.GetParams(s.ctx)
s.Require().NoError(err)
s.Require().Equal(paramsExpected.MintDenom, params.MintDenom)
s.Require().Equal(paramsExpected.MaxSupply, params.MaxSupply)
s.Require().Equal(paramsExpected.FEmission, params.FEmission)
s.Require().Equal(paramsExpected.OneMonthSmoothingDegree, params.OneMonthSmoothingDegree)
s.Require().Equal(paramsExpected.EcosystemTreasuryPercentOfTotalSupply, params.EcosystemTreasuryPercentOfTotalSupply)
s.Require().Equal(paramsExpected.FoundationTreasuryPercentOfTotalSupply, params.FoundationTreasuryPercentOfTotalSupply)
s.Require().Equal(paramsExpected.ParticipantsPercentOfTotalSupply, params.ParticipantsPercentOfTotalSupply)
s.Require().Equal(paramsExpected.InvestorsPercentOfTotalSupply, params.InvestorsPercentOfTotalSupply)
s.Require().Equal(paramsExpected.TeamPercentOfTotalSupply, params.TeamPercentOfTotalSupply)
s.Require().Equal(paramsExpected.MaximumMonthlyPercentageYield, params.MaximumMonthlyPercentageYield)
s.Require().Equal(paramsExpected.InvestorsPreseedPercentOfTotalSupply, params.InvestorsPreseedPercentOfTotalSupply)
s.Require().Equal(paramsExpected.EmissionEnabled, params.EmissionEnabled)
}
Loading

0 comments on commit 22ebf8a

Please sign in to comment.