Skip to content

Commit

Permalink
feat: integrate with v0.52.x (2/n) (#4423)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Nov 26, 2024
1 parent eaba5cf commit 9be0fb6
Show file tree
Hide file tree
Showing 28 changed files with 409 additions and 420 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
- [#4377](https://github.com/ignite/cli/pull/4377) Add multi node (validator) testnet.
- [#4326](https://github.com/ignite/cli/pull/4326) Add `buf.build` version to `ignite version` command
- [#4362](https://github.com/ignite/cli/pull/4362) Scaffold `Makefile`
- [#4289](https://github.com/ignite/cli/pull/4289) Cosmos SDK v0.52 support
- [#4289](https://github.com/ignite/cli/pull/4289), [#4423](https://github.com/ignite/cli/pull/4423) Cosmos SDK v0.52 support

### Changes

Expand Down
2 changes: 0 additions & 2 deletions ignite/cmd/scaffold_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ This command does the following:
* Creates a directory with module's protocol buffer files in "proto/"
* Creates a directory with module's boilerplate Go code in "x/"
* Imports the newly created module by modifying "app/app.go"
* Creates a file in "testutil/keeper/" that contains logic to create a keeper
for testing purposes
This command will proceed with module scaffolding even if "app/app.go" doesn't
have the required default placeholders. If the placeholders are missing, you
Expand Down
1 change: 1 addition & 0 deletions ignite/templates/app/files/go.mod.plush
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ require (
cosmossdk.io/core v1.0.0
cosmossdk.io/depinject v1.0.0
cosmossdk.io/errors v1.0.1
cosmossdk.io/errors/v2 v2.0.0-20241122152243-fdb7688804d1
cosmossdk.io/log v1.4.1
cosmossdk.io/math v1.4.0
cosmossdk.io/store v1.1.1-0.20240909133312-50288938d1b6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"

keepertest "<%= ModulePath %>/testutil/keeper"
"<%= ModulePath %>/x/<%= moduleName %>/keeper"
"<%= ModulePath %>/x/<%= moduleName %>/types"
)

func TestMsgServerSend<%= packetName.UpperCamel %>(t *testing.T) {
k, ctx, addressCodec := keepertest.<%= title(moduleName) %>Keeper(t)
<%= MsgSigner.LowerCamel %>, err := addressCodec.BytesToString([]byte("signerAddr__________________"))
f := initFixture(t)
srv := keeper.NewMsgServerImpl(f.keeper)
<%= MsgSigner.LowerCamel %>, err := f.addressCodec.BytesToString([]byte("signerAddr__________________"))
require.NoError(t, err)
srv := keeper.NewMsgServerImpl(k)

tests := []struct {
name string
Expand Down Expand Up @@ -73,7 +72,7 @@ func TestMsgServerSend<%= packetName.UpperCamel %>(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err = srv.Send<%= packetName.UpperCamel %>(ctx, &tt.msg)
_, err = srv.Send<%= packetName.UpperCamel %>(f.ctx, &tt.msg)
if tt.err != nil {
require.ErrorContains(t, err, tt.err.Error())
return
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package keeper

import (
"context"

"<%= modulePath %>/x/<%= moduleName %>/types"
)

// InitGenesis initializes the module's state from a provided genesis state.
func (k Keeper) InitGenesis(ctx context.Context, genState types.GenesisState) error {
// this line is used by starport scaffolding # genesis/module/init
return k.Params.Set(ctx, genState.Params)
}

// ExportGenesis returns the module's exported genesis.
func (k Keeper) ExportGenesis(ctx context.Context) (*types.GenesisState, error) {
var err error

genesis := types.DefaultGenesis()
genesis.Params, err = k.Params.Get(ctx)
if err != nil {
return nil, err
}

// this line is used by starport scaffolding # genesis/module/export

return genesis, nil
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
package <%= moduleName %>_test
package keeper_test

import (
"testing"

keepertest "<%= modulePath %>/testutil/keeper"
"<%= modulePath %>/testutil/nullify"
<%= moduleName %> "<%= modulePath %>/x/<%= moduleName %>/module"
"<%= modulePath %>/x/<%= moduleName %>/types"

"github.com/stretchr/testify/require"
)

func TestGenesis(t *testing.T) {
genesisState := types.GenesisState{
Params: types.DefaultParams(),
Params: types.DefaultParams(),
<%= if (isIBC) { %>PortId: types.PortID,<% } %>
// this line is used by starport scaffolding # genesis/test/state
}

k, ctx, _ := keepertest.<%= title(moduleName) %>Keeper(t)
err := <%= moduleName %>.InitGenesis(ctx, k, genesisState)
f := initFixture(t)
err := f.keeper.InitGenesis(f.ctx, genesisState)
require.NoError(t, err)
got, err := <%= moduleName %>.ExportGenesis(ctx, k)
got, err := f.keeper.ExportGenesis(f.ctx)
require.NoError(t, err)
require.NotNil(t, got)

Expand All @@ -30,4 +29,4 @@ func TestGenesis(t *testing.T) {
<%= if (isIBC) { %>require.Equal(t, genesisState.PortId, got.PortId)<% } %>
require.Equal(t, genesisState.Params, got.Params)
// this line is used by starport scaffolding # genesis/test/assert
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"

"cosmossdk.io/collections"
"cosmossdk.io/core/store"
"cosmossdk.io/core/address"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/log"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -22,52 +22,47 @@ import (
"<%= modulePath %>/x/<%= moduleName %>/types"
)

type (
Keeper struct {
cdc codec.BinaryCodec
addressCodec address.Codec
storeService store.KVStoreService
logger log.Logger
type Keeper struct {
appmodule.Environment

// the address capable of executing a MsgUpdateParams message.
// Typically, this should be the x/gov module account.
authority string
cdc codec.BinaryCodec
addressCodec address.Codec
// Address capable of executing a MsgUpdateParams message.
// Typically, this should be the x/gov module account.
authority []byte

Schema collections.Schema
Params collections.Item[types.Params]
// this line is used by starport scaffolding # collection/type
Schema collections.Schema
Params collections.Item[types.Params]
// this line is used by starport scaffolding # collection/type

<%= if (isIBC) { %>
ibcKeeperFn func() *ibckeeper.Keeper
capabilityScopedFn func(string) capabilitykeeper.ScopedKeeper<% } %>
<%= for (dependency) in dependencies { %>
<%= toVariableName(dependency.KeeperName()) %> types.<%= dependency.KeeperName() %><% } %>
}
)
<%= if (isIBC) { %>
ibcKeeperFn func() *ibckeeper.Keeper
capabilityScopedFn func(string) capabilitykeeper.ScopedKeeper<% } %>
<%= for (dependency) in dependencies { %>
<%= toVariableName(dependency.KeeperName()) %> types.<%= dependency.KeeperName() %><% } %>
}

func NewKeeper(
env appmodule.Environment,
cdc codec.BinaryCodec,
addressCodec address.Codec,
storeService store.KVStoreService,
logger log.Logger,
authority string,<%= if (isIBC) { %>
authority []byte,<%= if (isIBC) { %>
ibcKeeperFn func() *ibckeeper.Keeper,
capabilityScopedFn func(string) capabilitykeeper.ScopedKeeper,<% } %>
<%= for (dependency) in dependencies { %>
<%= toVariableName(dependency.KeeperName()) %> types.<%= dependency.KeeperName() %>,<% } %>
) Keeper {
if _, err := addressCodec.StringToBytes(authority); err != nil {
if _, err := addressCodec.BytesToString(authority); err != nil {
panic(fmt.Sprintf("invalid authority address %s: %s", authority, err))
}

sb := collections.NewSchemaBuilder(storeService)
sb := collections.NewSchemaBuilder(env.KVStoreService)

k := Keeper{
Environment: env,
cdc: cdc,
addressCodec: addressCodec,
storeService: storeService,
authority: authority,
logger: logger,<%= if (isIBC) { %>
authority: authority,<%= if (isIBC) { %>
ibcKeeperFn: ibcKeeperFn,
capabilityScopedFn: capabilityScopedFn,<% } %>
<%= for (dependency) in dependencies { %>
Expand All @@ -86,21 +81,17 @@ func NewKeeper(
}

// GetAuthority returns the module's authority.
func (k Keeper) GetAuthority() string {
func (k Keeper) GetAuthority() []byte {
return k.authority
}

// Logger returns a module-specific logger.
func (k Keeper) Logger() log.Logger {
return k.logger.With("module", fmt.Sprintf("x/%s", types.ModuleName))
}

<%= if (isIBC) { %>// ----------------------------------------------------------------------------
<%= if (isIBC) { %>
// ----------------------------------------------------------------------------
// IBC Keeper Logic
// ----------------------------------------------------------------------------

// ChanCloseInit defines a wrapper function for the channel Keeper's function.
func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string) error {
func (k Keeper) ChanCloseInit(ctx context.Context, portID, channelID string) error {
capName := host.ChannelCapabilityPath(portID, channelID)
chanCap, ok := k.ScopedKeeper().GetCapability(ctx, capName)
if !ok {
Expand All @@ -110,7 +101,7 @@ func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string) error {
}

// ShouldBound checks if the IBC app module can be bound to the desired port
func (k Keeper) ShouldBound(ctx sdk.Context, portID string) bool {
func (k Keeper) ShouldBound(ctx context.Context, portID string) bool {
scopedKeeper := k.ScopedKeeper()
if scopedKeeper == nil {
return false
Expand All @@ -121,33 +112,33 @@ func (k Keeper) ShouldBound(ctx sdk.Context, portID string) bool {

// BindPort defines a wrapper function for the port Keeper's function in
// order to expose it to module's InitGenesis function
func (k Keeper) BindPort(ctx sdk.Context, portID string) error {
func (k Keeper) BindPort(ctx context.Context, portID string) error {
cap := k.ibcKeeperFn().PortKeeper.BindPort(ctx, portID)
return k.ClaimCapability(ctx, cap, host.PortPath(portID))
}

// GetPort returns the portID for the IBC app module. Used in ExportGenesis
func (k Keeper) GetPort(ctx sdk.Context) string {
func (k Keeper) GetPort(ctx context.Context) string {
storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
store := prefix.NewStore(storeAdapter, []byte{})
return string(store.Get(types.PortKey))
}

// SetPort sets the portID for the IBC app module. Used in InitGenesis
func (k Keeper) SetPort(ctx sdk.Context, portID string) {
func (k Keeper) SetPort(ctx context.Context, portID string) {
storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
store := prefix.NewStore(storeAdapter, []byte{})
store.Set(types.PortKey, []byte(portID))
}

// AuthenticateCapability wraps the scopedKeeper's AuthenticateCapability function
func (k Keeper) AuthenticateCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) bool {
func (k Keeper) AuthenticateCapability(ctx context.Context, cap *capabilitytypes.Capability, name string) bool {
return k.ScopedKeeper().AuthenticateCapability(ctx, cap, name)
}

// ClaimCapability allows the IBC app module to claim a capability that core IBC
// passes to it
func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error {
func (k Keeper) ClaimCapability(ctx context.Context, cap *capabilitytypes.Capability, name string) error {
return k.ScopedKeeper().ClaimCapability(ctx, cap, name)
}

Expand Down
Loading

0 comments on commit 9be0fb6

Please sign in to comment.