Skip to content

Commit

Permalink
test: add simulation tests (#2947)
Browse files Browse the repository at this point in the history
* debug sim test

* start modifuing for v50

* add sim test v1

* add sim export

* move simulation tests to a separate directory

* remove unused functions

* add comments

* enable gov module

* enable gov module

* fix lint error

* add todos for BasicManager

* add todos for BasicManager

* add cleanup for TestFullAppSimulation

* register legacy router

* added a doc for simulation testing

* undo db close for multi threaded test

* add description for tests

* remove go module from simulation tests

* make basicsmanager private

* Update Makefile

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

* Update changelog.md

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

* format simulation.md

---------

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>
  • Loading branch information
kingpinXD and Francisco de Borja Aranda Castillejo authored Oct 22, 2024
1 parent 3aa68fe commit 0f8a4c2
Show file tree
Hide file tree
Showing 17 changed files with 1,032 additions and 395 deletions.
55 changes: 55 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,61 @@ start-upgrade-import-mainnet-test: zetanode-upgrade
export UPGRADE_HEIGHT=225 && \
cd contrib/localnet/ && ./scripts/import-data.sh mainnet && $(DOCKER_COMPOSE) --profile upgrade -f docker-compose.yml -f docker-compose-upgrade.yml up -d


###############################################################################
### Simulation Tests ###
###############################################################################

BINDIR ?= $(GOPATH)/bin
SIMAPP = ./tests/simulation


# Run sim is a cosmos tool which helps us to run multiple simulations in parallel.
runsim: $(BINDIR)/runsim
$(BINDIR)/runsim:
@echo 'Installing runsim...'
@TEMP_DIR=$$(mktemp -d) && \
cd $$TEMP_DIR && \
go install github.com/cosmos/tools/cmd/[email protected] && \
rm -rf $$TEMP_DIR || (echo 'Failed to install runsim' && exit 1)
@echo 'runsim installed successfully'


# Configuration parameters for simulation tests
# NumBlocks: Number of blocks to simulate
# BlockSize: Number of transactions in a block
# Commit: Whether to commit the block or not
# Period: Invariant check period
# Timeout: Timeout for the simulation test
define run-sim-test
@echo "Running $(1)..."
@go test -mod=readonly $(SIMAPP) -run $(2) -Enabled=true \
-NumBlocks=$(3) -BlockSize=$(4) -Commit=true -Period=0 -v -timeout $(5)
endef

test-sim-nondeterminism:
$(call run-sim-test,"non-determinism test",TestAppStateDeterminism,100,200,2h)

test-sim-fullappsimulation:
$(call run-sim-test,"TestFullAppSimulation",TestFullAppSimulation,100,200,2h)

test-sim-multi-seed-long: runsim
@echo "Running long multi-seed application simulation."
@$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 500 50 TestFullAppSimulation

test-sim-multi-seed-short: runsim
@echo "Running short multi-seed application simulation."
@$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 50 10 TestFullAppSimulation



.PHONY: \
test-sim-nondeterminism \
test-sim-fullappsimulation \
test-sim-multi-seed-long \
test-sim-multi-seed-short


###############################################################################
### GoReleaser ###
###############################################################################
Expand Down
103 changes: 44 additions & 59 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"encoding/json"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -178,64 +179,33 @@ func getGovProposalHandlers() []govclient.ProposalHandler {
return govProposalHandlers
}

var (
ModuleBasics = module.NewBasicManager(
auth.AppModuleBasic{},
genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
bank.AppModuleBasic{},
//capability.AppModuleBasic{},
staking.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(getGovProposalHandlers()),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
//ibc.AppModuleBasic{},
//ibctm.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
//transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
consensus.AppModuleBasic{},
evm.AppModuleBasic{},
feemarket.AppModuleBasic{},
authoritymodule.AppModuleBasic{},
lightclientmodule.AppModuleBasic{},
crosschainmodule.AppModuleBasic{},
//ibccrosschain.AppModuleBasic{},
observermodule.AppModuleBasic{},
fungiblemodule.AppModuleBasic{},
emissionsmodule.AppModuleBasic{},
groupmodule.AppModuleBasic{},
authzmodule.AppModuleBasic{},
)

// module account permissions
maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
//ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
crosschaintypes.ModuleName: {authtypes.Minter, authtypes.Burner},
//ibccrosschaintypes.ModuleName: nil,
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
fungibletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
emissionstypes.ModuleName: nil,
emissionstypes.UndistributedObserverRewardsPool: nil,
emissionstypes.UndistributedTSSRewardsPool: nil,
}
type GenesisState map[string]json.RawMessage

// module account permissions
var maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
//ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
crosschaintypes.ModuleName: {authtypes.Minter, authtypes.Burner},
//ibccrosschaintypes.ModuleName: nil,
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
fungibletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
emissionstypes.ModuleName: nil,
emissionstypes.UndistributedObserverRewardsPool: nil,
emissionstypes.UndistributedTSSRewardsPool: nil,
}

// module accounts that are NOT allowed to receive tokens
blockedReceivingModAcc = map[string]bool{
distrtypes.ModuleName: true,
authtypes.FeeCollectorName: true,
stakingtypes.BondedPoolName: true,
stakingtypes.NotBondedPoolName: true,
govtypes.ModuleName: true,
}
)
// module accounts that are NOT allowed to receive tokens
var blockedReceivingModAcc = map[string]bool{
distrtypes.ModuleName: true,
authtypes.FeeCollectorName: true,
stakingtypes.BondedPoolName: true,
stakingtypes.NotBondedPoolName: true,
govtypes.ModuleName: true,
}

var (
_ runtime.AppI = (*App)(nil)
Expand All @@ -260,6 +230,7 @@ type App struct {

mm *module.Manager
sm *module.SimulationManager
mb module.BasicManager
configurator module.Configurator

// sdk keepers
Expand Down Expand Up @@ -637,6 +608,7 @@ func New(
govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper))

govConfig := govtypes.DefaultConfig()
govKeeper := govkeeper.NewKeeper(
appCodec,
Expand All @@ -648,11 +620,14 @@ func New(
govConfig,
authAddr,
)

app.GovKeeper = *govKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// register governance hooks
),
)
// Set legacy router for backwards compatibility with gov v1beta1
// app.GovKeeper.SetLegacyRouter(govRouter)

// Create evidence Keeper for to register the IBC light client misbehaviour evidence route
evidenceKeeper := evidencekeeper.NewKeeper(
Expand Down Expand Up @@ -738,6 +713,8 @@ func New(
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
)

app.mb = ModuleBasics

// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so as to keep the
// CanWithdrawInvariant invariant.
Expand Down Expand Up @@ -813,6 +790,10 @@ func New(
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
app.mm.RegisterServices(app.configurator)

app.sm = module.NewSimulationManager(simulationModules(app, appCodec, skipGenesisInvariants)...)

app.sm.RegisterStoreDecoders()

// initialize stores
app.MountKVStores(keys)
app.MountTransientStores(tKeys)
Expand Down Expand Up @@ -920,7 +901,7 @@ func (app *App) ModuleAccountAddrs() map[string]bool {
return modAccAddrs
}

// LegacyAmino returns SimApp's amino codec.
// LegacyAmino returns app's amino 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.
Expand Down Expand Up @@ -983,7 +964,7 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig
nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// Register legacy and grpc-gateway routes for all modules.
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
app.mb.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// register app's OpenAPI routes.
if apiConfig.Swagger {
Expand Down Expand Up @@ -1075,6 +1056,10 @@ func (app *App) SimulationManager() *module.SimulationManager {
return app.sm
}

func (app *App) BasicManager() module.BasicManager {
return app.mb
}

func (app *App) BlockedAddrs() map[string]bool {
blockList := make(map[string]bool)

Expand Down
2 changes: 2 additions & 0 deletions app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func MakeEncodingConfig() ethermint.EncodingConfig {
encodingConfig := evmenc.MakeConfig(ModuleBasics)
registry := encodingConfig.InterfaceRegistry

// TODO test if we need to register these interfaces again as MakeConfig already registers them
// https://github.com/zeta-chain/node/issues/3003
cryptocodec.RegisterInterfaces(registry)
authtypes.RegisterInterfaces(registry)
authz.RegisterInterfaces(registry)
Expand Down
21 changes: 0 additions & 21 deletions app/genesis.go

This file was deleted.

66 changes: 0 additions & 66 deletions app/init_genesis.go

This file was deleted.

Loading

0 comments on commit 0f8a4c2

Please sign in to comment.