-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
epoching: fix genesis, param and bootstrapping (#41)
- Loading branch information
1 parent
d1372c3
commit 468dc96
Showing
14 changed files
with
219 additions
and
73 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
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
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
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 |
---|---|---|
@@ -1,24 +1,26 @@ | ||
package epoching | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/babylonchain/babylon/x/epoching/keeper" | ||
"github.com/babylonchain/babylon/x/epoching/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// InitGenesis initializes the capability module's state from a provided genesis | ||
// state. | ||
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { | ||
// this line is used by starport scaffolding # genesis/module/init | ||
// set params for this module | ||
k.SetParams(ctx, genState.Params) | ||
// init epoch number | ||
if err := k.SetEpochNumber(ctx, sdk.NewUint(0)); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
// ExportGenesis returns the capability module's exported genesis. | ||
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { | ||
genesis := types.DefaultGenesis() | ||
genesis.Params = k.GetParams(ctx) | ||
|
||
// this line is used by starport scaffolding # genesis/module/export | ||
|
||
return genesis | ||
return genesis | ||
} |
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 |
---|---|---|
@@ -1 +1,35 @@ | ||
package epoching_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/babylonchain/babylon/x/epoching" | ||
"github.com/stretchr/testify/require" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
|
||
simapp "github.com/babylonchain/babylon/app" | ||
"github.com/babylonchain/babylon/x/epoching/types" | ||
) | ||
|
||
func TestExportGenesis(t *testing.T) { | ||
app := simapp.Setup(false) | ||
ctx := app.BaseApp.NewContext(false, tmproto.Header{}) | ||
|
||
app.EpochingKeeper.SetParams(ctx, types.DefaultParams()) | ||
genesisState := epoching.ExportGenesis(ctx, app.EpochingKeeper) | ||
require.Equal(t, genesisState.Params, types.DefaultParams()) | ||
} | ||
|
||
func TestInitGenesis(t *testing.T) { | ||
app := simapp.Setup(false) | ||
ctx := app.BaseApp.NewContext(false, tmproto.Header{}) | ||
|
||
genesisState := types.GenesisState{ | ||
Params: types.Params{ | ||
EpochInterval: 100, | ||
}, | ||
} | ||
|
||
epoching.InitGenesis(ctx, app.EpochingKeeper, genesisState) | ||
require.Equal(t, app.EpochingKeeper.GetParams(ctx).EpochInterval, uint64(100)) | ||
} |
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
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
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
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
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 |
---|---|---|
@@ -1,24 +1,22 @@ | ||
package types | ||
|
||
import ( | ||
// this line is used by starport scaffolding # genesis/types/import | ||
) | ||
|
||
// DefaultIndex is the default capability global index | ||
const DefaultIndex uint64 = 1 | ||
|
||
// DefaultGenesis returns the default Capability genesis state | ||
func DefaultGenesis() *GenesisState { | ||
return &GenesisState{ | ||
// this line is used by starport scaffolding # genesis/types/default | ||
Params: DefaultParams(), | ||
// this line is used by starport scaffolding # genesis/types/default | ||
Params: DefaultParams(), | ||
} | ||
} | ||
|
||
// Validate performs basic genesis state validation returning an error upon any | ||
// failure. | ||
func (gs GenesisState) Validate() error { | ||
// this line is used by starport scaffolding # genesis/types/validate | ||
// this line is used by starport scaffolding # genesis/types/validate | ||
|
||
return gs.Params.Validate() | ||
} |
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
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
Oops, something went wrong.