Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mint): fix pruning panic, add developer and community funding #161

Merged
merged 10 commits into from
Jun 30, 2022
9 changes: 7 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ import (
const (
AccountAddressPrefix = "elesto"
Name = "elesto"
upgradeName = "testnet-upgrade-2022-06-21" // Latest upgrade to be applied for the chain
upgradeName = "testnetUpgrade20220706" // Latest upgrade to be applied for the chain
)

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals
Expand Down Expand Up @@ -655,7 +655,12 @@ func New(
}

if upgradeInfo.Name == upgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{}
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{
icahosttypes.StoreKey,
credential.StoreKey,
},
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
Expand Down
5 changes: 5 additions & 0 deletions x/mint/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/elesto-dao/elesto/v2/x/mint/migrations/testnetUpgrade20220621"
"github.com/elesto-dao/elesto/v2/x/mint/migrations/testnetUpgrade20220706"
)

// Migrator is a struct for handling in-place store migrations.
Expand All @@ -20,3 +21,7 @@ func NewMigrator(keeper Keeper) Migrator {
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return testnetUpgrade20220621.MigrateParams(ctx, m.keeper)
}

func (m Migrator) Migrate2to3(ctx sdk.Context) error {
return testnetUpgrade20220706.Migrate(ctx, m.keeper)
}
22 changes: 22 additions & 0 deletions x/mint/migrations/testnetUpgrade20220706/store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package testnetUpgrade20220706

import (
sdk "github.com/cosmos/cosmos-sdk/types"

mintTypes "github.com/elesto-dao/elesto/v2/x/mint/types"
)

type ExpectedKeeper interface {
SetParams(ctx sdk.Context, params mintTypes.Params)
MintCoins(ctx sdk.Context, amt sdk.Coins) error
GetSupply(ctx sdk.Context, denom string) sdk.Coin
}

func Migrate(ctx sdk.Context, keeper ExpectedKeeper) error {
// reset params, and hardcode the mint denom as "utsp"
p := mintTypes.DefaultParams()
p.MintDenom = "utsp"
keeper.SetParams(ctx, p)

return nil
}
83 changes: 83 additions & 0 deletions x/mint/migrations/testnetUpgrade20220706/store_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package testnetUpgrade20220706_test

import (
"fmt"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elesto-dao/elesto/v2/app"
"github.com/elesto-dao/elesto/v2/x/mint/migrations/testnetUpgrade20220706"
mintTypes "github.com/elesto-dao/elesto/v2/x/mint/types"
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)

func (b *bogusMigrationKeeper) SetParams(ctx sdk.Context, params mintTypes.Params) {
if b.failSetParams {
panic("cannot set params")
}
}

func (b *bogusMigrationKeeper) MintCoins(ctx sdk.Context, amt sdk.Coins) error {
if b.failMint {
return fmt.Errorf("cannot mint")
}

return nil
}

func (b *bogusMigrationKeeper) BurnCoins(ctx sdk.Context, amt sdk.Coins) error {
gsora marked this conversation as resolved.
Show resolved Hide resolved
if b.failBurn {
return fmt.Errorf("cannot burn")
}

return nil
}

func (b *bogusMigrationKeeper) GetSupply(ctx sdk.Context, denom string) sdk.Coin {
if b.failGetSupply {
c := sdk.Coin{}
c.Denom = "a"

return c
}
for _, t := range b.supply {
if t.Denom == denom {
return t
}
}

return sdk.Coin{}
}

type bogusMigrationKeeper struct {
failSetParams bool
failMint bool
failBurn bool
failGetSupply bool
supply sdk.Coins
}

func TestMigrate(t *testing.T) {
app := app.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

testnetUpgrade20220706.Migrate(ctx, app.MintKeeper)

require.Equal(t, "utsp", app.MintKeeper.GetParams(ctx).MintDenom)
require.Equal(t, "stake", mintTypes.DefaultParams().MintDenom)
}


func TestFailSetParams(t *testing.T) {
app := app.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

keeper := &bogusMigrationKeeper{
failSetParams: true,
}

require.Panics(t, func() {
_ = testnetUpgrade20220706.Migrate(ctx, keeper)
})
}
6 changes: 5 additions & 1 deletion x/mint/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
if err := cfg.RegisterMigration(types.ModuleName, 1, migrator.Migrate1to2); err != nil {
panic(fmt.Errorf("cannot migrate x/mint store from version 1 to version 2, %w", err))
}

if err := cfg.RegisterMigration(types.ModuleName, 2, migrator.Migrate2to3); err != nil {
panic(fmt.Errorf("cannot migrate x/mint store from version 2 to version 3, %w", err))
}
}

// InitGenesis performs genesis initialization for the mint module. It returns
Expand All @@ -149,7 +153,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
}

// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 2 }
func (AppModule) ConsensusVersion() uint64 { return 3 }

// BeginBlock returns the begin blocker for the mint module.
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
Expand Down
3 changes: 1 addition & 2 deletions x/mint/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"

Expand Down Expand Up @@ -42,7 +41,7 @@ func TestRandomizedGenState(t *testing.T) {
var genState types.GenesisState
simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &genState)

require.Equal(t, sdk.DefaultBondDenom, genState.Params.MintDenom)
require.Equal(t, "stake", genState.Params.MintDenom)
require.Equal(t, types.DefaultParams().BlocksPerYear, genState.Params.BlocksPerYear)
require.Equal(t, types.DefaultParams().MaxSupply, genState.Params.MaxSupply)
}
Expand Down