Skip to content

Commit

Permalink
fix: genesis import/export for csr
Browse files Browse the repository at this point in the history
  • Loading branch information
poorphd committed Jul 15, 2024
1 parent dac065a commit b3103b4
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 42 deletions.
36 changes: 17 additions & 19 deletions api/canto/csr/v1/genesis.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/canto/csr/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ message GenesisState {
// params defines all of the parameters of the module
Params params = 1 [ (gogoproto.nullable) = false ];
repeated CSR csrs = 2 [ (gogoproto.nullable) = false ];
bytes turnstile_address = 3;
string turnstile_address = 3;
}
9 changes: 4 additions & 5 deletions x/csr/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, accountKeeper authkeeper.Acco
for _, csr := range genState.Csrs {
k.SetCSR(ctx, csr)
}
if genState.TurnstileAddress != nil {
k.SetTurnstile(ctx, common.BytesToAddress(genState.TurnstileAddress))
if genState.TurnstileAddress != "" {
turnstileAddress := common.HexToAddress(genState.TurnstileAddress)
k.SetTurnstile(ctx, turnstileAddress)
}
// make sure that the csr module account is set on genesis
if acc := accountKeeper.GetModuleAccount(ctx, types.ModuleName); acc == nil {
Expand All @@ -41,9 +42,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {

turnstileAddr, ok := k.GetTurnstile(ctx)
if ok {
genesis.TurnstileAddress = turnstileAddr.Bytes()
} else {
genesis.TurnstileAddress = nil
genesis.TurnstileAddress = turnstileAddr.String()
}

return genesis
Expand Down
4 changes: 2 additions & 2 deletions x/csr/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (suite *KeeperTestSuite) TestImportExportGenesisEmpty() {
suite.Require().Empty(csrs)

genState := csr.ExportGenesis(suite.ctx, suite.app.CSRKeeper)
suite.Require().Nil(genState.TurnstileAddress)
suite.Require().Equal("", genState.TurnstileAddress)
suite.Require().Empty(genState.Csrs)

// Copy genState to genState2 and init with it
Expand All @@ -39,7 +39,7 @@ func (suite *KeeperTestSuite) TestImportExportGenesisEmpty() {
genState3 := csr.ExportGenesis(suite.ctx, suite.app.CSRKeeper)
suite.Equal(*genState, genState2)
suite.Equal(genState2, *genState3)
suite.Require().Nil(genState3.TurnstileAddress)
suite.Require().Equal("", genState3.TurnstileAddress)
suite.Require().Empty(genState3.Csrs)
}

Expand Down
4 changes: 2 additions & 2 deletions x/csr/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const DefaultIndex uint64 = 1

// DefaultGenesis returns the default Capability genesis state
func DefaultGenesis() *GenesisState {
return NewGenesisState(DefaultParams(), []CSR{}, nil)
return NewGenesisState(DefaultParams(), []CSR{}, "")
}

func NewGenesisState(params Params, csrs []CSR, turnstileAddress []byte) *GenesisState {
func NewGenesisState(params Params, csrs []CSR, turnstileAddress string) *GenesisState {
return &GenesisState{
Params: params,
Csrs: csrs,
Expand Down
24 changes: 11 additions & 13 deletions x/csr/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b3103b4

Please sign in to comment.