Skip to content

Commit

Permalink
merge: alloc module for minting rewards distribution, simulation tests
Browse files Browse the repository at this point in the history
- alloc module for allocation of minting rewards
- simulation test functions
  • Loading branch information
harish551 authored Feb 14, 2022
2 parents dd593e4 + 35fe779 commit 38a3d87
Show file tree
Hide file tree
Showing 63 changed files with 18,393 additions and 20,465 deletions.
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,32 @@ lint:
@echo "--> Running linter"
@golangci-lint run
@go mod verify


########################################
### Testing
SIMAPP = ./app

PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')
PACKAGES_UNITTEST=$(shell go list ./... | grep -v '/simulation' | grep -v '/cli_test')

test: test-unit

test-unit:
@VERSION=$(VERSION) go test -mod=readonly -tags='ledger test_ledger_mock' -ldflags '$(ldflags)' ${PACKAGES_UNITTEST}

test-sim-nondeterminism:
@echo "Running non-determinism test..."
@go test -mod=readonly $(SIMAPP) -run TestAppStateDeterminism -Enabled=true \
-NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h

test-sim-nondeterminism-fast:
@echo "Running non-determinism test..."
@go test -mod=readonly $(SIMAPP) -run TestAppStateDeterminism -Enabled=true \
-NumBlocks=10 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h

test-sim-custom-genesis-fast:
@echo "Running custom genesis simulation..."
@echo "By default, $(shell pwd)/testdata/genesis.json will be used."
@go test -mod=readonly $(SIMAPP) -run TestFullAppSimulation -Genesis=$(shell pwd)/testdata/genesis.json \
-Enabled=true -NumBlocks=10 -BlockSize=200 -Commit=true -Seed=99 -Period=5 -v -timeout 24h
166 changes: 109 additions & 57 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,15 @@ import (
"os"
"path/filepath"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/spf13/cast"
"github.com/tendermint/spm/openapiconsole"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"
appparams "github.com/OmniFlix/omniflixhub/app/params"
customAuthRest "github.com/OmniFlix/omniflixhub/custom/auth/client/rest"
"github.com/OmniFlix/omniflixhub/docs"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
Expand All @@ -32,6 +26,7 @@ import (
"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 @@ -90,15 +85,24 @@ import (
porttypes "github.com/cosmos/ibc-go/v2/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v2/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v2/modules/core/keeper"
"github.com/spf13/cast"
"github.com/tendermint/spm/openapiconsole"
abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/OmniFlix/onft"
onftkeeper "github.com/OmniFlix/onft/keeper"
onfttypes "github.com/OmniFlix/onft/types"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"

"github.com/OmniFlix/marketplace/x/marketplace"
marketplacekeeper "github.com/OmniFlix/marketplace/x/marketplace/keeper"
marketplacetypes "github.com/OmniFlix/marketplace/x/marketplace/types"
"github.com/OmniFlix/omniflixhub/x/alloc"
allockeeper "github.com/OmniFlix/omniflixhub/x/alloc/keeper"
alloctypes "github.com/OmniFlix/omniflixhub/x/alloc/types"
"github.com/OmniFlix/onft"
onftkeeper "github.com/OmniFlix/onft/keeper"
onfttypes "github.com/OmniFlix/onft/types"
// this line is used by starport scaffolding # stargate/app/moduleImport

)

const Name = "omniflixhub"
Expand Down Expand Up @@ -148,6 +152,8 @@ var (
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},

alloc.AppModuleBasic{},
onft.AppModuleBasic{},
marketplace.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
Expand All @@ -162,8 +168,10 @@ var (
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
onfttypes.ModuleName: nil,
marketplacetypes.ModuleName: nil,
alloctypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
onfttypes.ModuleName: nil,
marketplacetypes.ModuleName: nil,
// this line is used by starport scaffolding # stargate/app/maccPerms
}
)

Expand Down Expand Up @@ -199,39 +207,45 @@ 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
AuthzKeeper authzkeeper.Keeper
ONFTKeeper onftkeeper.Keeper
MarketplaceKeeper marketplacekeeper.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
AuthzKeeper authzkeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper

// the module manager
AllocKeeper allockeeper.Keeper
ONFTKeeper onftkeeper.Keeper
MarketplaceKeeper marketplacekeeper.Keeper
// this line is used by starport scaffolding # stargate/app/keeperDeclaration

// module manager
mm *module.Manager

// the configurator
// simulation manager
sm *module.SimulationManager

// configurator
configurator module.Configurator
}

// New returns a reference to an initialized app.

func New(
func NewOmniFlixApp(
logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool,
homePath string, invCheckPeriod uint, encodingConfig appparams.EncodingConfig,
// this line is used by starport scaffolding # stargate/app/newArgument
Expand All @@ -252,9 +266,8 @@ func New(
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, feegrant.StoreKey,
authzkeeper.StoreKey, onfttypes.StoreKey, marketplacetypes.StoreKey,
authzkeeper.StoreKey, alloctypes.StoreKey, onfttypes.StoreKey, marketplacetypes.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 @@ -353,25 +366,8 @@ func New(
appCodec,
homePath,
app.BaseApp,
)

app.ONFTKeeper = onftkeeper.NewKeeper(
appCodec,
keys[onfttypes.StoreKey],
)

onftModule := onft.NewAppModule(appCodec, app.ONFTKeeper)

app.MarketplaceKeeper = marketplacekeeper.NewKeeper(
appCodec,
keys[marketplacetypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.ONFTKeeper,
)

marketplaceModule := marketplace.NewAppModule(appCodec, app.MarketplaceKeeper)

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.StakingKeeper = *stakingKeeper.SetHooks(
Expand Down Expand Up @@ -431,6 +427,35 @@ func New(
&stakingKeeper,
govRouter,
)
app.AllocKeeper = *allockeeper.NewKeeper(
appCodec,
keys[alloctypes.StoreKey],
keys[alloctypes.MemStoreKey],

app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
app.DistrKeeper,
app.GetSubspace(alloctypes.ModuleName),
)
allocModule := alloc.NewAppModule(appCodec, app.AllocKeeper)

app.ONFTKeeper = onftkeeper.NewKeeper(
appCodec,
keys[onfttypes.StoreKey],
)

onftModule := onft.NewAppModule(appCodec, app.ONFTKeeper)

app.MarketplaceKeeper = marketplacekeeper.NewKeeper(
appCodec,
keys[marketplacetypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.ONFTKeeper,
)

marketplaceModule := marketplace.NewAppModule(appCodec, app.MarketplaceKeeper)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
Expand Down Expand Up @@ -469,6 +494,7 @@ func New(
ibc.NewAppModule(app.IBCKeeper),
params.NewAppModule(app.ParamsKeeper),
transferModule,
allocModule,
onftModule,
marketplaceModule,
// this line is used by starport scaffolding # stargate/app/appModule
Expand All @@ -483,11 +509,13 @@ func New(
upgradetypes.ModuleName,
capabilitytypes.ModuleName,
minttypes.ModuleName,
alloctypes.ModuleName, // must run before distribution module
distrtypes.ModuleName,
slashingtypes.ModuleName,
evidencetypes.ModuleName,
stakingtypes.ModuleName,
ibchost.ModuleName,
feegrant.ModuleName,
)

app.mm.SetOrderEndBlockers(
Expand Down Expand Up @@ -519,6 +547,7 @@ func New(
ibctransfertypes.ModuleName,
feegrant.ModuleName,
authz.ModuleName,
alloctypes.ModuleName,
onfttypes.ModuleName,
marketplacetypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
Expand All @@ -529,12 +558,33 @@ func New(
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
app.mm.RegisterServices(app.configurator)

// 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),
)

app.sm.RegisterStoreDecoders()

// initialize stores
app.MountKVStores(keys)
app.MountTransientStores(tkeys)
app.MountMemoryStores(memKeys)

// initialize BaseApp
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)

anteHandler, err := NewAnteHandler(
HandlerOptions{
HandlerOptions: ante.HandlerOptions{
Expand All @@ -550,10 +600,7 @@ func New(
if err != nil {
panic(fmt.Errorf("failed to create AnteHandler: %s", err))
}

app.SetAnteHandler(anteHandler)
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)

if loadLatest {
Expand Down Expand Up @@ -684,6 +731,10 @@ func (app *App) RegisterTxService(clientCtx client.Context) {
authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry)
}

func (app *App) SimulationManager() *module.SimulationManager {
return app.sm
}

// RegisterTendermintService implements the Application.RegisterTendermintService method.
func (app *App) RegisterTendermintService(clientCtx client.Context) {
tmservice.RegisterTendermintService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.interfaceRegistry)
Expand Down Expand Up @@ -712,6 +763,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(alloctypes.ModuleName)
paramsKeeper.Subspace(onfttypes.ModuleName)
paramsKeeper.Subspace(marketplacetypes.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace
Expand Down
15 changes: 15 additions & 0 deletions app/helpers/test_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package helpers

// SimAppChainID hardcoded chainID for simulation
const (
SimAppChainID = "simapp-1"
)



type EmptyAppOptions struct{}

// Get implements AppOptions
func (ao EmptyAppOptions) Get(o string) interface{} {
return nil
}
Loading

0 comments on commit 38a3d87

Please sign in to comment.