Skip to content

Commit

Permalink
SDK v.0.44.3 & Tendrmint v0.34.14 & IBC v.1.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
RaulBernal authored Nov 30, 2021
1 parent 39d8910 commit 223c9ee
Show file tree
Hide file tree
Showing 50 changed files with 1,956 additions and 228 deletions.
50 changes: 43 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ 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"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
Expand Down Expand Up @@ -159,8 +161,9 @@ var (
)

var (
_ cosmoscmd.CosmosApp = (*App)(nil)
_ cosmoscmd.App = (*App)(nil)
_ servertypes.Application = (*App)(nil)
_ simapp.App = (*App)(nil)
)

func init() {
Expand Down Expand Up @@ -213,11 +216,14 @@ type App struct {
BcnaKeeper bcnamodulekeeper.Keeper
// this line is used by starport scaffolding # stargate/app/keeperDeclaration

// the module manager
// mm is the module manager
mm *module.Manager

// sm is the simulation manager
sm *module.SimulationManager
}

// New returns a reference to an initialized Gaia.
// New returns a reference to an initialized blockchain app
func New(
logger log.Logger,
db dbm.DB,
Expand Down Expand Up @@ -316,13 +322,14 @@ func New(
)

// register the proposal types
//AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper))
govRouter := govtypes.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibchost.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper))

// Create Transfer Keepers
app.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName),
Expand All @@ -347,8 +354,9 @@ func New(
appCodec,
keys[bcnamoduletypes.StoreKey],
keys[bcnamoduletypes.MemStoreKey],
app.GetSubspace(bcnamoduletypes.ModuleName),
)
bcnaModule := bcnamodule.NewAppModule(appCodec, app.BcnaKeeper)
bcnaModule := bcnamodule.NewAppModule(appCodec, app.BcnaKeeper, app.AccountKeeper, app.BankKeeper)

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

Expand Down Expand Up @@ -431,6 +439,26 @@ func New(
app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
app.mm.RegisterServices(module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()))

// create the simulation manager and define the order of the modules for deterministic simulations
app.sm = module.NewSimulationManager(
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
params.NewAppModule(app.ParamsKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
ibc.NewAppModule(app.IBCKeeper),
transferModule,
bcnaModule,
// this line is used by starport scaffolding # stargate/app/appModule
)
app.sm.RegisterStoreDecoders()

// initialize stores
app.MountKVStores(keys)
app.MountTransientStores(tkeys)
Expand Down Expand Up @@ -472,6 +500,9 @@ func New(
// 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 @@ -515,15 +546,15 @@ func (app *App) LegacyAmino() *codec.LegacyAmino {
return app.cdc
}

// AppCodec returns Gaia's app codec.
// 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 {
return app.appCodec
}

// InterfaceRegistry returns Gaia's InterfaceRegistry
// InterfaceRegistry returns an InterfaceRegistry
func (app *App) InterfaceRegistry() types.InterfaceRegistry {
return app.interfaceRegistry
}
Expand Down Expand Up @@ -616,3 +647,8 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino

return paramsKeeper
}

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

import (
"os"
"testing"
"time"

"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"
"github.com/tendermint/spm/cosmoscmd"
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"
)

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,
MaxGas: 2000000,
},
Evidence: &tmproto.EvidenceParams{
MaxAgeNumBlocks: 302400,
MaxAgeDuration: 504 * time.Hour, // 3 weeks is the max duration
MaxBytes: 10000,
},
Validator: &tmproto.ValidatorParams{
PubKeyTypes: []string{
tmtypes.ABCIPubKeyTypeEd25519,
},
},
}

// go test -benchmem -run=^$ -bench ^BenchmarkSimulation -Commit=true -cpuprofile cpu.out
func BenchmarkSimulation(b *testing.B) {
simapp.FlagEnabledValue = true
simapp.FlagNumBlocksValue = 200
simapp.FlagBlockSizeValue = 50
simapp.FlagCommitValue = true
simapp.FlagVerboseValue = true

config, db, dir, logger, _, err := simapp.SetupSimulation("goleveldb-app-sim", "Simulation")
require.NoError(b, err, "simulation setup failed")

b.Cleanup(func() {
db.Close()
err = os.RemoveAll(dir)
require.NoError(b, err)
})

encoding := cosmoscmd.MakeEncodingConfig(app.ModuleBasics)

app := app.New(
logger,
db,
nil,
true,
map[int64]bool{},
app.DefaultNodeHome,
0,
encoding,
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()),
simulationtypes.RandomAccounts,
simapp.SimulationOperations(simApp, simApp.AppCodec(), config),
simApp.ModuleAccountAddrs(),
config,
simApp.AppCodec(),
)

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

if config.Commit {
simapp.PrintStats(db)
}
}
46 changes: 46 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,42 @@ paths:
format: uint64
tags:
- Query
/BitCannaGlobal/bcna/bcna/params:
get:
summary: Parameters queries the parameters of the module.
operationId: BitCannaGlobalBcnaBcnaParams
responses:
'200':
description: A successful response.
schema:
type: object
properties:
params:
description: params holds all the parameters of this module.
type: object
description: >-
QueryParamsResponse is response type for the Query/Params RPC
method.
default:
description: An unexpected error response.
schema:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
'@type':
type: string
additionalProperties: {}
tags:
- Query
/BitCannaGlobal/bcna/bcna/supplychain:
get:
summary: Queries a list of supplychain items.
Expand Down Expand Up @@ -12884,6 +12920,9 @@ definitions:
type: object
BitCannaGlobal.bcna.bcna.MsgUpdateSupplychainResponse:
type: object
BitCannaGlobal.bcna.bcna.Params:
type: object
description: Params defines the parameters for the module.
BitCannaGlobal.bcna.bcna.QueryAllBitcannaidResponse:
type: object
properties:
Expand Down Expand Up @@ -13002,6 +13041,13 @@ definitions:
type: string
creator:
type: string
BitCannaGlobal.bcna.bcna.QueryParamsResponse:
type: object
properties:
params:
description: params holds all the parameters of this module.
type: object
description: QueryParamsResponse is response type for the Query/Params RPC method.
BitCannaGlobal.bcna.bcna.Supplychain:
type: object
properties:
Expand Down
25 changes: 13 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@ module github.com/BitCannaGlobal/bcna
go 1.16

require (
github.com/99designs/keyring v1.1.6 // indirect
github.com/cosmos/cosmos-sdk v0.44.2
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/iavl v0.17.1 // indirect
github.com/cosmos/ibc-go v1.2.0
github.com/cosmos/cosmos-sdk v0.44.3
github.com/cosmos/ibc-go v1.2.3
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.2
github.com/google/go-cmp v0.5.6 // indirect
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/spf13/cast v1.3.1
github.com/spf13/cast v1.4.1
github.com/spf13/cobra v1.2.1
github.com/stretchr/testify v1.7.0
github.com/tendermint/spm v0.1.5
github.com/tendermint/tendermint v0.34.13
github.com/tendermint/spm v0.1.8
github.com/tendermint/tendermint v0.34.14
github.com/tendermint/tm-db v0.6.4
google.golang.org/genproto v0.0.0-20210903162649-d08c68adba83
google.golang.org/grpc v1.40.0
google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1
google.golang.org/grpc v1.42.0
)

require (
github.com/golang/protobuf v1.5.2
gopkg.in/yaml.v2 v2.4.0
)

replace (
github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/keybase/go-keychain => github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4
google.golang.org/grpc => google.golang.org/grpc v1.33.2
)
Loading

0 comments on commit 223c9ee

Please sign in to comment.