Skip to content

Commit

Permalink
First test of gmp module
Browse files Browse the repository at this point in the history
  • Loading branch information
luckychess committed Nov 12, 2024
1 parent 2572508 commit b9a3899
Show file tree
Hide file tree
Showing 40 changed files with 3,273 additions and 5 deletions.
38 changes: 33 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ import (
peerskeeper "github.com/sagaxyz/ssc/x/peers/keeper"
peerstypes "github.com/sagaxyz/ssc/x/peers/types"

gmpmodule "github.com/sagaxyz/ssc/x/gmp"
gmpmodulekeeper "github.com/sagaxyz/ssc/x/gmp/keeper"
gmpmoduletypes "github.com/sagaxyz/ssc/x/gmp/types"

// this line is used by starport scaffolding # stargate/app/moduleImport

ante "github.com/sagaxyz/ssc/app/ante"
Expand Down Expand Up @@ -217,6 +221,7 @@ var (
peers.AppModuleBasic{},
consensus.AppModuleBasic{},
ccvprovider.AppModuleBasic{},
gmpmodule.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
)

Expand Down Expand Up @@ -297,11 +302,13 @@ type App struct {
ScopedTransferKeeper ibccapabilitykeeper.ScopedKeeper
ScopedICAHostKeeper ibccapabilitykeeper.ScopedKeeper

ChainletKeeper *chainletmodulekeeper.Keeper
EscrowKeeper escrowmodulekeeper.Keeper
BillingKeeper billingmodulekeeper.Keeper
DacKeeper aclkeeper.Keeper
PeersKeeper peerskeeper.Keeper
ChainletKeeper *chainletmodulekeeper.Keeper
EscrowKeeper escrowmodulekeeper.Keeper
BillingKeeper billingmodulekeeper.Keeper
DacKeeper aclkeeper.Keeper
PeersKeeper peerskeeper.Keeper
ScopedGmpKeeper ibccapabilitykeeper.ScopedKeeper
GmpKeeper gmpmodulekeeper.Keeper
// this line is used by starport scaffolding # stargate/app/keeperDeclaration

// mm is the module manager
Expand Down Expand Up @@ -366,6 +373,7 @@ func New(
acltypes.StoreKey,
peerstypes.StoreKey,
ccvprovidertypes.StoreKey,
gmpmoduletypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
)
tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -749,6 +757,19 @@ func New(
)
epochsModule := epochsmodule.NewAppModule(app.EpochsKeeper)

scopedGmpKeeper := app.CapabilityKeeper.ScopeToModule(gmpmoduletypes.ModuleName)
app.ScopedGmpKeeper = scopedGmpKeeper
app.GmpKeeper = *gmpmodulekeeper.NewKeeper(
appCodec,
keys[gmpmoduletypes.StoreKey],
keys[gmpmoduletypes.MemStoreKey],
app.GetSubspace(gmpmoduletypes.ModuleName),
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.PortKeeper,
scopedGmpKeeper,
)
gmpModule := gmpmodule.NewAppModule(appCodec, app.GmpKeeper, app.AccountKeeper, app.BankKeeper)

// this line is used by starport scaffolding # stargate/app/keeperDefinition

/**** IBC Routing ****/
Expand All @@ -757,12 +778,14 @@ func New(
app.CapabilityKeeper.Seal()

icaControllerStack := icacontroller.NewIBCMiddleware(nil, icaControllerKeeper)
gmpIBCModule := gmpmodule.NewIBCModule(app.GmpKeeper, icaControllerStack)
// Create static IBC router, add transfer route, then set and seal it
ibcRouter := ibcporttypes.NewRouter()
ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
AddRoute(ibctransfertypes.ModuleName, transferIBCModule).
AddRoute(ccvprovidertypes.ModuleName, providerModule)
ibcRouter.AddRoute(gmpmoduletypes.ModuleName, gmpIBCModule)
// this line is used by starport scaffolding # ibc/app/router
app.IBCKeeper.SetRouter(ibcRouter)

Expand Down Expand Up @@ -810,6 +833,7 @@ func New(
billingModule,
aclModule,
peersModule,
gmpModule,
// this line is used by starport scaffolding # stargate/app/appModule
)
// BasicModuleManager defines the module BasicManager is in charge of setting up basic,
Expand Down Expand Up @@ -866,6 +890,7 @@ func New(
acltypes.ModuleName,
peerstypes.StoreKey,
consensusparamtypes.ModuleName,
gmpmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/beginBlockers
)

Expand Down Expand Up @@ -901,6 +926,7 @@ func New(
acltypes.ModuleName,
peerstypes.ModuleName,
consensusparamtypes.ModuleName,
gmpmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/endBlockers
)

Expand Down Expand Up @@ -941,6 +967,7 @@ func New(
acltypes.ModuleName,
peerstypes.ModuleName,
consensusparamtypes.ModuleName,
gmpmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
}
app.mm.SetOrderInitGenesis(genesisModuleOrder...)
Expand Down Expand Up @@ -1233,6 +1260,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(billingmoduletypes.ModuleName)
paramsKeeper.Subspace(acltypes.ModuleName)
paramsKeeper.Subspace(peerstypes.ModuleName)
paramsKeeper.Subspace(gmpmoduletypes.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace

return paramsKeeper
Expand Down
14 changes: 14 additions & 0 deletions proto/ssc/gmp/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
syntax = "proto3";

package ssc.gmp;

import "gogoproto/gogo.proto";
import "ssc/gmp/params.proto";

option go_package = "github.com/sagaxyz/ssc/x/gmp/types";

// GenesisState defines the gmp module's genesis state.
message GenesisState {
Params params = 1 [ (gogoproto.nullable) = false ];
string port_id = 2;
}
10 changes: 10 additions & 0 deletions proto/ssc/gmp/packet.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
syntax = "proto3";
package ssc.gmp;

option go_package = "github.com/sagaxyz/ssc/x/gmp/types";

message GmpPacketData {
oneof packet { NoData noData = 1; }
}

message NoData {}
9 changes: 9 additions & 0 deletions proto/ssc/gmp/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
syntax = "proto3";
package ssc.gmp;

import "gogoproto/gogo.proto";

option go_package = "github.com/sagaxyz/ssc/x/gmp/types";

// Params defines the parameters for the module.
message Params { option (gogoproto.goproto_stringer) = false; }
26 changes: 26 additions & 0 deletions proto/ssc/gmp/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
syntax = "proto3";
package ssc.gmp;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "ssc/gmp/params.proto";

option go_package = "github.com/sagaxyz/ssc/x/gmp/types";

// Query defines the gRPC querier service.
service Query {
// Parameters queries the parameters of the module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/sagaxyz/ssc/gmp/params";
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {
// params holds all the parameters of this module.
Params params = 1 [ (gogoproto.nullable) = false ];
}
7 changes: 7 additions & 0 deletions proto/ssc/gmp/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";
package ssc.gmp;

option go_package = "github.com/sagaxyz/ssc/x/gmp/types";

// Msg defines the Msg service.
service Msg {}
98 changes: 98 additions & 0 deletions testutil/keeper/gmp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package keeper

import (
"testing"

"github.com/sagaxyz/ssc/x/gmp/keeper"
"github.com/sagaxyz/ssc/x/gmp/types"

"cosmossdk.io/log"
"cosmossdk.io/store"
"cosmossdk.io/store/metrics"
storetypes "cosmossdk.io/store/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmdb "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
"github.com/stretchr/testify/require"
)

// gmpChannelKeeper is a stub of cosmosibckeeper.ChannelKeeper.
type gmpChannelKeeper struct{}

func (gmpChannelKeeper) GetChannel(ctx sdk.Context, portID, channelID string) (channeltypes.Channel, bool) {
return channeltypes.Channel{}, false
}

func (gmpChannelKeeper) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) {
return 0, false
}

func (gmpChannelKeeper) SendPacket(
ctx sdk.Context,
channelCap *capabilitytypes.Capability,
sourcePort string,
sourceChannel string,
timeoutHeight clienttypes.Height,
timeoutTimestamp uint64,
data []byte,
) (uint64, error) {
return 0, nil
}

func (gmpChannelKeeper) ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error {
return nil
}

// gmpportKeeper is a stub of cosmosibckeeper.PortKeeper
type gmpPortKeeper struct{}

func (gmpPortKeeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability {
return &capabilitytypes.Capability{}
}

func GmpKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
logger := log.NewNopLogger()

storeKey := storetypes.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)

db := tmdb.NewMemDB()
stateStore := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil)
require.NoError(t, stateStore.LoadLatestVersion())

registry := codectypes.NewInterfaceRegistry()
appCodec := codec.NewProtoCodec(registry)
capabilityKeeper := capabilitykeeper.NewKeeper(appCodec, storeKey, memStoreKey)

paramsSubspace := typesparams.NewSubspace(appCodec,
types.Amino,
storeKey,
memStoreKey,
"GmpParams",
)
k := keeper.NewKeeper(
appCodec,
storeKey,
memStoreKey,
paramsSubspace,
gmpChannelKeeper{},
gmpPortKeeper{},
capabilityKeeper.ScopeToModule("GmpScopedKeeper"),
)

ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, logger)

// Initialize params
k.SetParams(ctx, types.DefaultParams())

return k, ctx
}
32 changes: 32 additions & 0 deletions x/gmp/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cli

import (
"fmt"
// "strings"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
// "github.com/cosmos/cosmos-sdk/client/flags"
// sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/sagaxyz/ssc/x/gmp/types"
)

// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string) *cobra.Command {
// Group gmp queries under a subcommand
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

cmd.AddCommand(CmdQueryParams())
// this line is used by starport scaffolding # 1

return cmd
}

36 changes: 36 additions & 0 deletions x/gmp/client/cli/query_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cli

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"

"github.com/sagaxyz/ssc/x/gmp/types"
)

func CmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "shows the parameters of the module",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
36 changes: 36 additions & 0 deletions x/gmp/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cli

import (
"fmt"
"time"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
// "github.com/cosmos/cosmos-sdk/client/flags"
"github.com/sagaxyz/ssc/x/gmp/types"
)

var (
DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds())
)

const (
flagPacketTimeoutTimestamp = "packet-timeout-timestamp"
listSeparator = ","
)

// GetTxCmd returns the transaction commands for this module
func GetTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

// this line is used by starport scaffolding # 1

return cmd
}
Loading

0 comments on commit b9a3899

Please sign in to comment.