Skip to content

Commit

Permalink
Merge pull request #112 from BitCannaGlobal/refactor-tests-and-root
Browse files Browse the repository at this point in the history
Refactor tests and root & delete comments
  • Loading branch information
RaulBernal authored Nov 8, 2022
2 parents 5c58020 + 5c4186c commit e10f881
Show file tree
Hide file tree
Showing 19 changed files with 1,670 additions and 240 deletions.
479 changes: 479 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

26 changes: 3 additions & 23 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,15 @@ import (
bcnamodule "github.com/BitCannaGlobal/bcna/x/bcna"
bcnamodulekeeper "github.com/BitCannaGlobal/bcna/x/bcna/keeper"
bcnamoduletypes "github.com/BitCannaGlobal/bcna/x/bcna/types"
// this line is used by starport scaffolding # stargate/app/moduleImport
)

const (
AccountAddressPrefix = "bcna"
Name = "bcna"
)

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals

func getGovProposalHandlers() []govclient.ProposalHandler {
var govProposalHandlers []govclient.ProposalHandler
// this line is used by starport scaffolding # stargate/app/govProposalHandlers

govProposalHandlers = append(govProposalHandlers,
paramsclient.ProposalHandler,
Expand All @@ -137,7 +133,6 @@ func getGovProposalHandlers() []govclient.ProposalHandler {
upgradeclient.LegacyCancelProposalHandler,
ibcclientclient.UpdateClientProposalHandler,
ibcclientclient.UpgradeProposalHandler,
// this line is used by starport scaffolding # stargate/app/govProposalHandler
)

return govProposalHandlers
Expand Down Expand Up @@ -173,7 +168,6 @@ var (
ica.AppModuleBasic{},
vesting.AppModuleBasic{},
bcnamodule.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
)

// module account permissions
Expand All @@ -187,7 +181,6 @@ var (
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
nft.ModuleName: nil,
// this line is used by starport scaffolding # stargate/app/maccPerms
}
)

Expand Down Expand Up @@ -250,7 +243,6 @@ type App struct {
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper

BcnaKeeper bcnamodulekeeper.Keeper
// this line is used by starport scaffolding # stargate/app/keeperDeclaration

// mm is the module manager
mm *module.Manager
Expand Down Expand Up @@ -308,7 +300,6 @@ func New(
group.StoreKey,
nftkeeper.StoreKey,
bcnamoduletypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -346,7 +337,9 @@ func New(
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
// this line is used by starport scaffolding # stargate/app/scopedKeeper
// Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating
// their scoped modules in `NewApp` with `ScopeToModule`
app.CapabilityKeeper.Seal()

// add keepers
app.AccountKeeper = authkeeper.NewAccountKeeper(
Expand Down Expand Up @@ -543,13 +536,10 @@ func New(
)
bcnaModule := bcnamodule.NewAppModule(appCodec, app.BcnaKeeper, app.AccountKeeper, app.BankKeeper)

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

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := ibcporttypes.NewRouter()
ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
AddRoute(ibctransfertypes.ModuleName, transferIBCModule)
// this line is used by starport scaffolding # ibc/app/router
app.IBCKeeper.SetRouter(ibcRouter)

/**** Module Options ****/
Expand Down Expand Up @@ -587,7 +577,6 @@ func New(
nftmodule.NewAppModule(appCodec, app.NFTKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
icaModule,
bcnaModule,
// this line is used by starport scaffolding # stargate/app/appModule
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down Expand Up @@ -618,7 +607,6 @@ func New(
paramstypes.ModuleName,
vestingtypes.ModuleName,
bcnamoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/beginBlockers
)

app.mm.SetOrderEndBlockers(
Expand All @@ -644,7 +632,6 @@ func New(
upgradetypes.ModuleName,
vestingtypes.ModuleName,
bcnamoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/endBlockers
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -675,7 +662,6 @@ func New(
upgradetypes.ModuleName,
vestingtypes.ModuleName,
bcnamoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
)

// Uncomment if you want to set a custom migration order here.
Expand Down Expand Up @@ -711,7 +697,6 @@ func New(
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),
// NFT simulation
bcnaModule,
// this line is used by starport scaffolding # stargate/app/appModule
)
app.sm.RegisterStoreDecoders()

Expand Down Expand Up @@ -750,17 +735,13 @@ func New(

app.ScopedIBCKeeper = scopedIBCKeeper
app.ScopedTransferKeeper = scopedTransferKeeper
// this line is used by starport scaffolding # stargate/app/beforeInitReturn

return app
}

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

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

// BeginBlocker application updates every begin block
func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
return app.mm.BeginBlock(ctx, req)
Expand Down Expand Up @@ -942,7 +923,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(bcnamoduletypes.ModuleName)
paramsKeeper.Subspace(nft.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace

return paramsKeeper
}
Expand Down
18 changes: 0 additions & 18 deletions app/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,16 @@ import (

app "github.com/BitCannaGlobal/bcna/app"

"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/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
)

func init() {
simapp.GetSimulatorFlags()
}

type SimApp interface {
app.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
}

// BenchmarkSimulation run the chain simulation
// Running using starport command:
// `starport chain simulate -v --numBlocks 200 --blockSize 50`
Expand Down
36 changes: 12 additions & 24 deletions cmd/bcnad/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ import (
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
"github.com/spf13/cast"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
tmcfg "github.com/tendermint/tendermint/config"
tmcli "github.com/tendermint/tendermint/libs/cli"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"

// this line is used by starport scaffolding # root/moduleImport
"github.com/BitCannaGlobal/bcna/app"
appparams "github.com/BitCannaGlobal/bcna/app/params"
)
Expand Down Expand Up @@ -77,17 +75,17 @@ func NewRootCmd() (*cobra.Command, appparams.EncodingConfig) {
},
}
initRootCmd(rootCmd, encodingConfig)
overwriteFlagDefaults(rootCmd, map[string]string{
flags.FlagChainID: strings.ReplaceAll(app.Name, "-", ""),
flags.FlagKeyringBackend: "test",
})

return rootCmd, encodingConfig
}

// initTendermintConfig helps to override default Tendermint Config values.
// return tmcfg.DefaultConfig if no custom configuration is required for the application.
func initTendermintConfig() *tmcfg.Config {
cfg := tmcfg.DefaultConfig()
// these values put a higher strain on node memory
cfg.P2P.MaxNumInboundPeers = 100
cfg.P2P.MaxNumOutboundPeers = 40
return cfg
}
func initRootCmd(
Expand All @@ -111,7 +109,6 @@ func initRootCmd(
tmcli.NewCompletionCmd(rootCmd, true),
debug.Cmd(),
config.Cmd(),
// this line is used by starport scaffolding # root/commands
)
a := appCreator{
encodingConfig,
Expand Down Expand Up @@ -178,24 +175,9 @@ func txCommand() *cobra.Command {
cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")
return cmd
}

func addModuleInitFlags(startCmd *cobra.Command) {
crisis.AddModuleInitFlags(startCmd)
// this line is used by starport scaffolding # root/arguments
}
func overwriteFlagDefaults(c *cobra.Command, defaults map[string]string) {
set := func(s *pflag.FlagSet, key, val string) {
if f := s.Lookup(key); f != nil {
f.DefValue = val
f.Value.Set(val)
}
}
for key, val := range defaults {
set(c.Flags(), key, val)
set(c.PersistentFlags(), key, val)
}
for _, c := range c.Commands() {
overwriteFlagDefaults(c, defaults)
}
}

type appCreator struct {
Expand Down Expand Up @@ -234,6 +216,12 @@ func (a appCreator) newApp(
cast.ToUint64(appOpts.Get(server.FlagStateSyncSnapshotInterval)),
cast.ToUint32(appOpts.Get(server.FlagStateSyncSnapshotKeepRecent)),
)

iavlCacheSize := int(cast.ToUint64(appOpts.Get("iavl-cache-size")))
if iavlCacheSize == 0 {
iavlCacheSize = 390_625 // 50mb
}

return app.New(
logger,
db,
Expand All @@ -254,7 +242,7 @@ func (a appCreator) newApp(
baseapp.SetIndexEvents(cast.ToStringSlice(appOpts.Get(server.FlagIndexEvents))),
baseapp.SetSnapshot(snapshotStore, snapshotOptions),
baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(server.FlagIAVLCacheSize))),
baseapp.SetIAVLDisableFastNode(cast.ToBool(appOpts.Get(server.FlagIAVLFastNode))),
baseapp.SetIAVLDisableFastNode(cast.ToBool(appOpts.Get(server.FlagDisableIAVLFastNode))),
)
}

Expand Down
Loading

0 comments on commit e10f881

Please sign in to comment.