Skip to content

Commit

Permalink
Merge pull request #14 from Stride-Labs/TEST-40-fix-ibc-v2-dependencies
Browse files Browse the repository at this point in the history
TEST-40: Remove all dependencies on ibc-v2
  • Loading branch information
shellvish authored May 18, 2022
2 parents ae37167 + 28e47ab commit c5a50d2
Show file tree
Hide file tree
Showing 11 changed files with 805 additions and 522 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@

# Dependency directories (remove the comment below to include it)
# vendor/

# vscode
.vscode/*
135 changes: 72 additions & 63 deletions stride/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app

import (
"io"
"net/http"
"os"
"path/filepath"

Expand All @@ -15,7 +14,6 @@ import (
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
Expand Down Expand Up @@ -82,6 +80,7 @@ import (
ibcporttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
ibctesting "github.com/cosmos/ibc-go/v3/testing"
"github.com/spf13/cast"
abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
Expand All @@ -98,14 +97,8 @@ import (
icahosttypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"

"github.com/ignite-hq/cli/ignite/pkg/cosmoscmd"
"github.com/ignite-hq/cli/ignite/pkg/openapiconsole"

monitoringp "github.com/tendermint/spn/x/monitoringp"
monitoringpkeeper "github.com/tendermint/spn/x/monitoringp/keeper"
monitoringptypes "github.com/tendermint/spn/x/monitoringp/types"

"github.com/Stride-Labs/stride/docs"
// monitoringp "github.com/tendermint/spn/x/monitoringp"
// monitoringpkeeper "github.com/tendermint/spn/x/monitoringp/keeper"

epochsmodule "github.com/Stride-Labs/stride/x/epochs"
epochsmodulekeeper "github.com/Stride-Labs/stride/x/epochs/keeper"
Expand Down Expand Up @@ -170,7 +163,7 @@ var (
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
monitoringp.AppModuleBasic{},
// monitoringp.AppModuleBasic{},
stakeibcmodule.AppModuleBasic{},
epochsmodule.AppModuleBasic{},
interchainquery.AppModuleBasic{},
Expand All @@ -195,9 +188,8 @@ var (
)

var (
_ cosmoscmd.App = (*App)(nil)
_ servertypes.Application = (*App)(nil)
_ simapp.App = (*App)(nil)
_ servertypes.Application = (*StrideApp)(nil)
_ ibctesting.TestingApp = (*StrideApp)(nil)
)

func init() {
Expand All @@ -209,10 +201,10 @@ func init() {
DefaultNodeHome = filepath.Join(userHomeDir, "."+Name)
}

// App extends an ABCI application, but with most of its parameters exported.
// StrideApp extends an ABCI application, but with most of its parameters exported.
// They are exported for convenience in creating helper functions, as object
// capabilities aren't needed for testing.
type App struct {
type StrideApp struct {
*baseapp.BaseApp

cdc *codec.LegacyAmino
Expand All @@ -227,22 +219,22 @@ type App struct {
memKeys map[string]*sdk.MemoryStoreKey

// keepers
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
CrisisKeeper crisiskeeper.Keeper
UpgradeKeeper upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
MonitoringKeeper monitoringpkeeper.Keeper
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
CrisisKeeper crisiskeeper.Keeper
UpgradeKeeper upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
// MonitoringKeeper monitoringpkeeper.Keeper
ICAControllerKeeper icacontrollerkeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper

Expand All @@ -268,18 +260,18 @@ type App struct {
}

// New returns a reference to an initialized blockchain app
func New(
func NewStrideApp(
logger log.Logger,
db dbm.DB,
traceStore io.Writer,
loadLatest bool,
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig cosmoscmd.EncodingConfig,
encodingConfig EncodingConfig,
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) cosmoscmd.App {
) *StrideApp {
appCodec := encodingConfig.Marshaler
cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
Expand All @@ -293,7 +285,7 @@ func New(
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, monitoringptypes.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, // monitoringptypes.StoreKey,
stakeibcmoduletypes.StoreKey,
epochsmoduletypes.StoreKey,
interchainquerytypes.StoreKey,
Expand All @@ -303,7 +295,7 @@ func New(
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)

app := &App{
app := &StrideApp{
BaseApp: bApp,
cdc: cdc,
appCodec: appCodec,
Expand Down Expand Up @@ -539,7 +531,7 @@ func New(
genutiltypes.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
monitoringptypes.ModuleName,
// monitoringptypes.ModuleName,
icatypes.ModuleName,
stakeibcmoduletypes.ModuleName,
epochsmoduletypes.ModuleName,
Expand All @@ -565,7 +557,7 @@ func New(
upgradetypes.ModuleName,
ibchost.ModuleName,
ibctransfertypes.ModuleName,
monitoringptypes.ModuleName,
// monitoringptypes.ModuleName,
icatypes.ModuleName,
stakeibcmoduletypes.ModuleName,
epochsmoduletypes.ModuleName,
Expand Down Expand Up @@ -596,7 +588,7 @@ func New(
upgradetypes.ModuleName,
ibctransfertypes.ModuleName,
feegrant.ModuleName,
monitoringptypes.ModuleName,
// monitoringptypes.ModuleName,
icatypes.ModuleName,
stakeibcmoduletypes.ModuleName,
epochsmoduletypes.ModuleName,
Expand Down Expand Up @@ -674,23 +666,44 @@ func New(
}

// Name returns the name of the App
func (app *App) Name() string { return app.BaseApp.Name() }
func (app *StrideApp) Name() string { return app.BaseApp.Name() }

// GetBaseApp returns the base app of the application
func (app App) GetBaseApp() *baseapp.BaseApp { return app.BaseApp }
func (app *StrideApp) GetBaseApp() *baseapp.BaseApp { return app.BaseApp }

// GetStakingKeeper implements the TestingApp interface.
func (app *StrideApp) GetStakingKeeper() stakingkeeper.Keeper {
return app.StakingKeeper
}

// GetIBCKeeper implements the TestingApp interface.
func (app *StrideApp) GetIBCKeeper() *ibckeeper.Keeper {
return app.IBCKeeper
}

// GetScopedIBCKeeper implements the TestingApp interface.
func (app *StrideApp) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {
return app.ScopedIBCKeeper
}

// GetTxConfig implements the TestingApp interface.
func (app *StrideApp) GetTxConfig() client.TxConfig {
cfg := MakeEncodingConfig()
return cfg.TxConfig
}

// BeginBlocker application updates every begin block
func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
func (app *StrideApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
return app.mm.BeginBlock(ctx, req)
}

// EndBlocker application updates every end block
func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
func (app *StrideApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
return app.mm.EndBlock(ctx, req)
}

// InitChainer application update at chain initialization
func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
func (app *StrideApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
var genesisState GenesisState
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
Expand All @@ -700,12 +713,12 @@ func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.Res
}

// LoadHeight loads a particular height
func (app *App) LoadHeight(height int64) error {
func (app *StrideApp) LoadHeight(height int64) error {
return app.LoadVersion(height)
}

// ModuleAccountAddrs returns all the app's module account addresses.
func (app *App) ModuleAccountAddrs() map[string]bool {
func (app *StrideApp) ModuleAccountAddrs() map[string]bool {
modAccAddrs := make(map[string]bool)
for acc := range maccPerms {
modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true
Expand All @@ -718,55 +731,55 @@ func (app *App) ModuleAccountAddrs() map[string]bool {
//
// NOTE: This is solely to be used for testing purposes as it may be desirable
// for modules to register their own custom testing types.
func (app *App) LegacyAmino() *codec.LegacyAmino {
func (app *StrideApp) LegacyAmino() *codec.LegacyAmino {
return app.cdc
}

// AppCodec returns an app codec.
//
// NOTE: This is solely to be used for testing purposes as it may be desirable
// for modules to register their own custom testing types.
func (app *App) AppCodec() codec.Codec {
func (app *StrideApp) AppCodec() codec.Codec {
return app.appCodec
}

// InterfaceRegistry returns an InterfaceRegistry
func (app *App) InterfaceRegistry() types.InterfaceRegistry {
func (app *StrideApp) InterfaceRegistry() types.InterfaceRegistry {
return app.interfaceRegistry
}

// GetKey returns the KVStoreKey for the provided store key.
//
// NOTE: This is solely to be used for testing purposes.
func (app *App) GetKey(storeKey string) *sdk.KVStoreKey {
func (app *StrideApp) GetKey(storeKey string) *sdk.KVStoreKey {
return app.keys[storeKey]
}

// GetTKey returns the TransientStoreKey for the provided store key.
//
// NOTE: This is solely to be used for testing purposes.
func (app *App) GetTKey(storeKey string) *sdk.TransientStoreKey {
func (app *StrideApp) GetTKey(storeKey string) *sdk.TransientStoreKey {
return app.tkeys[storeKey]
}

// GetMemKey returns the MemStoreKey for the provided mem key.
//
// NOTE: This is solely used for testing purposes.
func (app *App) GetMemKey(storeKey string) *sdk.MemoryStoreKey {
func (app *StrideApp) GetMemKey(storeKey string) *sdk.MemoryStoreKey {
return app.memKeys[storeKey]
}

// GetSubspace returns a param subspace for a given module name.
//
// NOTE: This is solely to be used for testing purposes.
func (app *App) GetSubspace(moduleName string) paramstypes.Subspace {
func (app *StrideApp) GetSubspace(moduleName string) paramstypes.Subspace {
subspace, _ := app.ParamsKeeper.GetSubspace(moduleName)
return subspace
}

// RegisterAPIRoutes registers all application module routes with the provided
// API server.
func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) {
func (app *StrideApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) {
clientCtx := apiSvr.ClientCtx
rpc.RegisterRoutes(clientCtx, apiSvr.Router)
// Register legacy tx routes.
Expand All @@ -779,19 +792,15 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig
// Register legacy and grpc-gateway routes for all modules.
ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router)
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// register app's OpenAPI routes.
apiSvr.Router.Handle("/static/openapi.yml", http.FileServer(http.FS(docs.Docs)))
apiSvr.Router.HandleFunc("/", openapiconsole.Handler(Name, "/static/openapi.yml"))
}

// RegisterTxService implements the Application.RegisterTxService method.
func (app *App) RegisterTxService(clientCtx client.Context) {
func (app *StrideApp) RegisterTxService(clientCtx client.Context) {
authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry)
}

// RegisterTendermintService implements the Application.RegisterTendermintService method.
func (app *App) RegisterTendermintService(clientCtx client.Context) {
func (app *StrideApp) RegisterTendermintService(clientCtx client.Context) {
tmservice.RegisterTendermintService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.interfaceRegistry)
}

Expand All @@ -818,7 +827,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(monitoringptypes.ModuleName)
// paramsKeeper.Subspace(monitoringptypes.ModuleName)
paramsKeeper.Subspace(stakeibcmoduletypes.ModuleName)
paramsKeeper.Subspace(epochsmoduletypes.ModuleName)
paramsKeeper.Subspace(interchainquerytypes.ModuleName)
Expand All @@ -830,6 +839,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
}

// SimulationManager implements the SimulationApp interface
func (app *App) SimulationManager() *module.SimulationManager {
func (app *StrideApp) SimulationManager() *module.SimulationManager {
return app.sm
}
39 changes: 39 additions & 0 deletions stride/app/encoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package app

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
)

// TODO this file is heavily inspired by QS, we should see if any changes are needed

type EncodingConfig struct {
InterfaceRegistry types.InterfaceRegistry
Marshaler codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}

// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.
func MakeEncodingConfig() EncodingConfig {
amino := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewProtoCodec(interfaceRegistry)
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes)

encodingConfig := EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Marshaler: marshaler,
TxConfig: txCfg,
Amino: amino,
}

std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
return encodingConfig
}
Loading

0 comments on commit c5a50d2

Please sign in to comment.