-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Emission Enabled bolean flag to mint module
- Loading branch information
Showing
14 changed files
with
3,678 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
"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" | ||
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{}) | ||
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(¶msOld)) | ||
|
||
// 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) | ||
} |
Oops, something went wrong.