Skip to content

Commit

Permalink
chore: remove cosmoscmd (lavanet#354)
Browse files Browse the repository at this point in the history
* chore: remove cosmoscmd

* remove cosmoscmd from tests

* docs: update short description
  • Loading branch information
fadeev authored Mar 15, 2023
1 parent eceb480 commit b49451f
Show file tree
Hide file tree
Showing 15 changed files with 796 additions and 2,990 deletions.
10 changes: 3 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ 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"
"github.com/ignite-hq/cli/ignite/pkg/cosmoscmd"
"github.com/ignite-hq/cli/ignite/pkg/openapiconsole"
"github.com/lavanet/lava/app/keepers"
appparams "github.com/lavanet/lava/app/params"
"github.com/lavanet/lava/app/upgrades"
"github.com/lavanet/lava/app/upgrades/v0_5_0"
"github.com/lavanet/lava/app/upgrades/v0_5_1"
Expand Down Expand Up @@ -217,7 +217,6 @@ var (
)

var (
_ cosmoscmd.App = (*LavaApp)(nil)
_ servertypes.Application = (*LavaApp)(nil)
_ simapp.App = (*LavaApp)(nil)
)
Expand Down Expand Up @@ -271,10 +270,10 @@ func New(
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig cosmoscmd.EncodingConfig,
encodingConfig appparams.EncodingConfig,
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) cosmoscmd.App {
) *LavaApp {
appCodec := encodingConfig.Marshaler
cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
Expand Down Expand Up @@ -727,9 +726,6 @@ func (app *LavaApp) setupUpgradeHandlers() {
// Name returns the name of the App
func (app *LavaApp) Name() string { return app.BaseApp.Name() }

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

// BeginBlocker application updates every begin block
func (app *LavaApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
return app.mm.BeginBlock(ctx, req)
Expand Down
35 changes: 35 additions & 0 deletions app/encoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package app

import (
"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"

"github.com/lavanet/lava/app/params"
)

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

return params.EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Marshaler: marshaler,
TxConfig: txCfg,
Amino: amino,
}
}

// MakeEncodingConfig creates an EncodingConfig for testing
func MakeEncodingConfig() params.EncodingConfig {
encodingConfig := makeEncodingConfig()
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
return encodingConfig
}
16 changes: 16 additions & 0 deletions app/params/encoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package params

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
)

// EncodingConfig specifies the concrete encoding types to use for a given app.
// This is provided for compatibility between protobuf and amino implementations.
type EncodingConfig struct {
InterfaceRegistry types.InterfaceRegistry
Marshaler codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}
36 changes: 7 additions & 29 deletions app/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ import (
"testing"
"time"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simulationtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
"github.com/ignite-hq/cli/ignite/pkg/cosmoscmd"
"github.com/lavanet/lava/app"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
Expand All @@ -24,19 +19,6 @@ func init() {
simapp.GetSimulatorFlags()
}

type SimApp interface {
cosmoscmd.App
GetBaseApp() *baseapp.BaseApp
AppCodec() codec.Codec
SimulationManager() *module.SimulationManager
ModuleAccountAddrs() map[string]bool
Name() string
LegacyAmino() *codec.LegacyAmino
BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock
EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock
InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain
}

var defaultConsensusParams = &abci.ConsensusParams{
Block: &abci.BlockParams{
MaxBytes: 200000,
Expand Down Expand Up @@ -71,7 +53,7 @@ func BenchmarkSimulation(b *testing.B) {
require.NoError(b, err)
})

encoding := cosmoscmd.MakeEncodingConfig(app.ModuleBasics)
encoding := app.MakeEncodingConfig()

app := app.New(
logger,
Expand All @@ -85,24 +67,20 @@ func BenchmarkSimulation(b *testing.B) {
simapp.EmptyAppOptions{},
)

simApp, ok := app.(SimApp)
require.True(b, ok, "can't use simapp")

// Run randomized simulations
_, simParams, simErr := simulation.SimulateFromSeed(
b,
os.Stdout,
simApp.GetBaseApp(),
simapp.AppStateFn(simApp.AppCodec(), simApp.SimulationManager()),
app.BaseApp,
simapp.AppStateFn(app.AppCodec(), app.SimulationManager()),
simulationtypes.RandomAccounts,
simapp.SimulationOperations(simApp, simApp.AppCodec(), config),
simApp.ModuleAccountAddrs(),
simapp.SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
simApp.AppCodec(),
app.AppCodec(),
)

// export state and simParams before the simulation error is checked
err = simapp.CheckExportSimulation(simApp, config, simParams)
err = simapp.CheckExportSimulation(app, config, simParams)
require.NoError(b, err)
require.NoError(b, simErr)

Expand Down
6 changes: 3 additions & 3 deletions app/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ignite-hq/cli/ignite/pkg/cosmoscmd"
"github.com/lavanet/lava/app"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmdb "github.com/tendermint/tm-db"
)

// Setup a new App for testing purposes
func TestSetup() (cosmoscmd.App, sdk.Context) {
func TestSetup() (app.LavaApp, sdk.Context) {
db := tmdb.NewMemDB()
stateStore := store.NewCommitMultiStore(db)
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
encoding := cosmoscmd.MakeEncodingConfig(ModuleBasics)
encoding := app.MakeEncodingConfig(ModuleBasics)
app := New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, encoding, simapp.EmptyAppOptions{})
return app, ctx
}
4 changes: 2 additions & 2 deletions app/upgrades/v0.2.0/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ignite-hq/cli/ignite/pkg/cosmoscmd"
"github.com/lavanet/lava/app"
keepertest "github.com/lavanet/lava/testutil/keeper"
v020 "github.com/lavanet/lava/x/spec/migrations/v0.2.0"
"github.com/stretchr/testify/suite"
Expand All @@ -16,7 +16,7 @@ type UpgradeTestSuite struct {
suite.Suite

ctx sdk.Context
app cosmoscmd.App
app app.LavaApp
}

func (suite *UpgradeTestSuite) SetupTestApp() {
Expand Down
4 changes: 2 additions & 2 deletions app/upgrades/v0_X_0/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ignite-hq/cli/ignite/pkg/cosmoscmd"
"github.com/lavanet/lava/app"
keepertest "github.com/lavanet/lava/testutil/keeper"
"github.com/stretchr/testify/suite"
)
Expand All @@ -15,7 +15,7 @@ type UpgradeTestSuite struct {
suite.Suite

ctx sdk.Context
app cosmoscmd.App
app app.LavaApp
}

func (suite *UpgradeTestSuite) SetupTestApp() {
Expand Down
4 changes: 2 additions & 2 deletions app/upgrades/v5/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ignite-hq/cli/ignite/pkg/cosmoscmd"
"github.com/lavanet/lava/app"
keepertest "github.com/lavanet/lava/testutil/keeper"
"github.com/lavanet/lava/x/conflict/keeper"
"github.com/lavanet/lava/x/conflict/types"
Expand All @@ -17,7 +17,7 @@ type UpgradeTestSuite struct {
suite.Suite

ctx sdk.Context
app cosmoscmd.App
app app.LavaApp
}

func (suite *UpgradeTestSuite) SetupTestApp() {
Expand Down
23 changes: 23 additions & 0 deletions cmd/lavad/cmd/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cmd

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

"github.com/lavanet/lava/app"
)

func initSDKConfig() {
// Set prefixes
accountPubKeyPrefix := app.AccountAddressPrefix + "pub"
validatorAddressPrefix := app.AccountAddressPrefix + "valoper"
validatorPubKeyPrefix := app.AccountAddressPrefix + "valoperpub"
consNodeAddressPrefix := app.AccountAddressPrefix + "valcons"
consNodePubKeyPrefix := app.AccountAddressPrefix + "valconspub"

// Set and seal config
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(app.AccountAddressPrefix, accountPubKeyPrefix)
config.SetBech32PrefixForValidator(validatorAddressPrefix, validatorPubKeyPrefix)
config.SetBech32PrefixForConsensusNode(consNodeAddressPrefix, consNodePubKeyPrefix)
config.Seal()
}
Loading

0 comments on commit b49451f

Please sign in to comment.