Skip to content

Commit

Permalink
fix(sequencers): sequencers genesis operator address not exported (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin authored Apr 8, 2024
1 parent 8e4b891 commit 2a1f308
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 8 deletions.
18 changes: 12 additions & 6 deletions x/sequencers/genesis.go → x/sequencers/keeper/genesis.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package sequencers
package keeper

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

"github.com/dymensionxyz/dymension-rdk/x/sequencers/keeper"
"github.com/dymensionxyz/dymension-rdk/x/sequencers/types"
)

// InitGenesis initializes the capability module's state from a provided genesis state.
// InitGenesis initializes the sequencers module's state from a provided genesis state.
// We return the for ValidatorUpdate only the sequencers set by dymint
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) []abci.ValidatorUpdate {
func (k *Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) []abci.ValidatorUpdate {
var updates []abci.ValidatorUpdate
k.SetParams(ctx, genState.Params)

Expand Down Expand Up @@ -56,9 +55,16 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
return updates
}

// ExportGenesis returns the capability module's exported genesis.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
// ExportGenesis returns the sequencers module's exported genesis.
func (k *Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
genesis := types.DefaultGenesis()
genesis.Params = k.GetParams(ctx)

sequencers := k.GetAllSequencers(ctx)
// other cases are not supported. will be handled by the sequencer switch feature
if len(sequencers) == 1 {
genesis.GenesisOperatorAddress = sequencers[0].OperatorAddress
}

return genesis
}
45 changes: 45 additions & 0 deletions x/sequencers/keeper/genesis_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package keeper_test

import (
"testing"

cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"

testkeepers "github.com/dymensionxyz/dymension-rdk/testutil/keepers"
"github.com/dymensionxyz/dymension-rdk/testutil/utils"
)

func TestEpochsInitAndExportGenesis(t *testing.T) {
app := utils.Setup(t, false)
k, ctx := testkeepers.NewTestSequencerKeeperFromApp(app)

params := k.GetParams(ctx)
seqs := k.GetAllSequencers(ctx)
require.Equal(t, 1, len(seqs))
expectedOperator := seqs[0].GetOperator().String()
require.NotEmpty(t, expectedOperator)

genState := k.ExportGenesis(ctx)
assert.Equal(t, expectedOperator, genState.GenesisOperatorAddress)
assert.Equal(t, params, genState.Params)

// Test InitGenesis
genState.Params.HistoricalEntries = 100

// init dymint sequencer as expected for initGenesis
pubkey := utils.CreateTestPubKeys(1)[0]
tmPubkey, err := cryptocodec.ToTmProtoPublicKey(pubkey)
require.NoError(t, err)
dymintSeq := abci.ValidatorUpdate{
PubKey: tmPubkey,
Power: 1,
}

k.SetDymintSequencers(ctx, []abci.ValidatorUpdate{dymintSeq})

_ = k.InitGenesis(ctx, *genState)
assert.Equal(t, genState.Params, k.GetParams(ctx))
}
4 changes: 2 additions & 2 deletions x/sequencers/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.Ra
// Initialize global index to index in genesis state
var genState types.GenesisState
cdc.MustUnmarshalJSON(gs, &genState)
return InitGenesis(ctx, am.keeper, genState)
return am.keeper.InitGenesis(ctx, genState)
}

// ExportGenesis returns the capability module's exported genesis state as raw JSON bytes.
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
genState := ExportGenesis(ctx, am.keeper)
genState := am.keeper.ExportGenesis(ctx)
return cdc.MustMarshalJSON(genState)
}

Expand Down

0 comments on commit 2a1f308

Please sign in to comment.