Skip to content

Commit

Permalink
fix lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Oct 3, 2024
1 parent 49d430c commit 73fbcf5
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 31 deletions.
1 change: 1 addition & 0 deletions app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
evmenc "github.com/zeta-chain/ethermint/encoding"
ethermint "github.com/zeta-chain/ethermint/types"
evmtypes "github.com/zeta-chain/ethermint/x/evm/types"

authoritytypes "github.com/zeta-chain/node/x/authority/types"
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
emissionstypes "github.com/zeta-chain/node/x/emissions/types"
Expand Down
34 changes: 29 additions & 5 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
// non-dependant module elements, such as codec registration
// and genesis verification.
func newBasicManagerFromManager(app *App) module.BasicManager {
var moduleBasics []module.AppModuleBasic
moduleBasics := make([]module.AppModuleBasic, 0)
for _, m := range app.mm.Modules {
m, ok := m.(module.AppModuleBasic)
if !ok {
Expand Down Expand Up @@ -62,11 +62,35 @@ func simulationModules(
_ bool,
) []module.AppModuleSimulation {
return []module.AppModuleSimulation{
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
auth.NewAppModule(
appCodec,
app.AccountKeeper,
authsims.RandomGenesisAccounts,
app.GetSubspace(authtypes.ModuleName),
),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)),
gov.NewAppModule(
appCodec,
&app.GovKeeper,
app.AccountKeeper,
app.BankKeeper,
app.GetSubspace(govtypes.ModuleName),
),
staking.NewAppModule(
appCodec,
app.StakingKeeper,
app.AccountKeeper,
app.BankKeeper,
app.GetSubspace(stakingtypes.ModuleName),
),
distr.NewAppModule(
appCodec,
app.DistrKeeper,
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
app.GetSubspace(distrtypes.ModuleName),
),
slashing.NewAppModule(
appCodec,
app.SlashingKeeper,
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* [2874](https://github.com/zeta-chain/node/pull/2874) - add support for multiple runs for precompile tests
* [2895](https://github.com/zeta-chain/node/pull/2895) - add e2e test for bitcoin deposit and call
* [2894](https://github.com/zeta-chain/node/pull/2894) - increase gas limit for TSS vote tx
* [2947](https://github.com/zeta-chain/node/pull/2947/) - add simulation tests

### Fixes

Expand Down
6 changes: 2 additions & 4 deletions e2e/runner/admin_evm.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package runner

import (
"fmt"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/stretchr/testify/require"

Expand All @@ -14,7 +12,7 @@ func (r *E2ERunner) UpdateTssAddressForConnector() {

tx, err := r.ConnectorEth.UpdateTssAddress(r.EVMAuth, r.TSSAddress)
require.NoError(r, err)
r.Logger.Info(fmt.Sprintf("TSS Address Update Tx: %s", tx.Hash().String()))
r.Logger.Info("TSS Address Update Tx: %s", tx.Hash().String())
receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout)
utils.RequireTxSuccessful(r, receipt)

Expand All @@ -28,7 +26,7 @@ func (r *E2ERunner) UpdateTssAddressForErc20custody() {

tx, err := r.ERC20Custody.UpdateTSSAddress(r.EVMAuth, r.TSSAddress)
require.NoError(r, err)
r.Logger.Info(fmt.Sprintf("TSS ERC20 Address Update Tx: %s", tx.Hash().String()))
r.Logger.Info("TSS ERC20 Address Update Tx: %s", tx.Hash().String())
receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout)
utils.RequireTxSuccessful(r, receipt)

Expand Down
2 changes: 1 addition & 1 deletion e2e/runner/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (r *E2ERunner) PrintTestReports(tr TestReports) {
if err != nil {
r.Logger.Print("Error rendering test report: %s", err)
}
r.Logger.PrintNoPrefix(table)
r.Logger.PrintNoPrefix("%s", table)
}

// NetworkReport is a struct that contains the report for the network used after running e2e tests
Expand Down
56 changes: 48 additions & 8 deletions tests/simulation/sim/sim_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,66 @@ var (
// GetSimulatorFlags gets the values of all the available simulation flags
func GetSimulatorFlags() {
// config fields
flag.StringVar(&FlagGenesisFileValue, "Genesis", "", "custom simulation genesis file; cannot be used with params file")
flag.StringVar(&FlagParamsFileValue, "Params", "", "custom simulation params file which overrides any random params; cannot be used with genesis")
flag.StringVar(&FlagExportParamsPathValue, "ExportParamsPath", "", "custom file path to save the exported params JSON")
flag.IntVar(&FlagExportParamsHeightValue, "ExportParamsHeight", 0, "height to which export the randomly generated params")
flag.StringVar(&FlagExportStatePathValue, "ExportStatePath", "", "custom file path to save the exported app state JSON")
flag.StringVar(&FlagExportStatsPathValue, "ExportStatsPath", "", "custom file path to save the exported simulation statistics JSON")
flag.StringVar(
&FlagGenesisFileValue,
"Genesis",
"",
"custom simulation genesis file; cannot be used with params file",
)
flag.StringVar(
&FlagParamsFileValue,
"Params",
"",
"custom simulation params file which overrides any random params; cannot be used with genesis",
)
flag.StringVar(
&FlagExportParamsPathValue,
"ExportParamsPath",
"",
"custom file path to save the exported params JSON",
)
flag.IntVar(
&FlagExportParamsHeightValue,
"ExportParamsHeight",
0,
"height to which export the randomly generated params",
)
flag.StringVar(
&FlagExportStatePathValue,
"ExportStatePath",
"",
"custom file path to save the exported app state JSON",
)
flag.StringVar(
&FlagExportStatsPathValue,
"ExportStatsPath",
"",
"custom file path to save the exported simulation statistics JSON",
)
flag.Int64Var(&FlagSeedValue, "Seed", 42, "simulation random seed")
flag.IntVar(&FlagInitialBlockHeightValue, "InitialBlockHeight", 1, "initial block to start the simulation")
flag.IntVar(&FlagNumBlocksValue, "NumBlocks", 500, "number of new blocks to simulate from the initial block height")
flag.IntVar(&FlagBlockSizeValue, "BlockSize", 200, "operations per block")
flag.BoolVar(&FlagLeanValue, "Lean", false, "lean simulation log output")
flag.BoolVar(&FlagCommitValue, "Commit", false, "have the simulation commit")
flag.BoolVar(&FlagOnOperationValue, "SimulateEveryOperation", false, "run slow invariants every operation")
flag.BoolVar(&FlagAllInvariantsValue, "PrintAllInvariants", false, "print all invariants if a broken invariant is found")
flag.BoolVar(
&FlagAllInvariantsValue,
"PrintAllInvariants",
false,
"print all invariants if a broken invariant is found",
)

// simulation flags
flag.BoolVar(&FlagEnabledValue, "Enabled", false, "enable the simulation")
flag.BoolVar(&FlagVerboseValue, "Verbose", false, "verbose log output")
flag.UintVar(&FlagPeriodValue, "Period", 0, "run slow invariants only once every period assertions")
flag.Int64Var(&FlagGenesisTimeValue, "GenesisTime", 0, "override genesis UNIX time instead of using a random UNIX time")
flag.Int64Var(
&FlagGenesisTimeValue,
"GenesisTime",
0,
"override genesis UNIX time instead of using a random UNIX time",
)
}

// NewConfigFromFlags creates a simulation from the retrieved values of the flags.
Expand Down
32 changes: 28 additions & 4 deletions tests/simulation/sim/sim_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ const (
// AppStateFn returns the initial application state using a genesis or the simulation parameters.
// It panics if the user provides files for both of them.
// If a file is not given for the genesis or the sim params, it creates a randomized one.
func AppStateFn(cdc codec.Codec, simManager *module.SimulationManager, genesisState map[string]json.RawMessage) simtypes.AppStateFn {
func AppStateFn(
cdc codec.Codec,
simManager *module.SimulationManager,
genesisState map[string]json.RawMessage,
) simtypes.AppStateFn {
return func(r *rand.Rand, accs []simtypes.Account, config simtypes.Config,
) (appState json.RawMessage, simAccs []simtypes.Account, chainID string, genesisTimestamp time.Time) {
if FlagGenesisTimeValue == 0 {
Expand Down Expand Up @@ -74,11 +78,27 @@ func AppStateFn(cdc codec.Codec, simManager *module.SimulationManager, genesisSt
if err != nil {
panic(err)
}
appState, simAccs = AppStateRandomizedFn(simManager, r, cdc, accs, genesisTimestamp, appParams, genesisState)
appState, simAccs = AppStateRandomizedFn(
simManager,
r,
cdc,
accs,
genesisTimestamp,
appParams,
genesisState,
)

default:
appParams := make(simtypes.AppParams)
appState, simAccs = AppStateRandomizedFn(simManager, r, cdc, accs, genesisTimestamp, appParams, genesisState)
appState, simAccs = AppStateRandomizedFn(
simManager,
r,
cdc,
accs,
genesisTimestamp,
appParams,
genesisState,
)
}

rawState := make(map[string]json.RawMessage)
Expand Down Expand Up @@ -223,7 +243,11 @@ func AppStateRandomizedFn(

// AppStateFromGenesisFileFn util function to generate the genesis AppState
// from a genesis.json file.
func AppStateFromGenesisFileFn(r io.Reader, cdc codec.JSONCodec, genesisFile string) (tmtypes.GenesisDoc, []simtypes.Account, error) {
func AppStateFromGenesisFileFn(
r io.Reader,
cdc codec.JSONCodec,
genesisFile string,
) (tmtypes.GenesisDoc, []simtypes.Account, error) {
bytes, err := os.ReadFile(genesisFile)
if err != nil {
panic(err)
Expand Down
9 changes: 7 additions & 2 deletions tests/simulation/sim/sim_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/zeta-chain/ethermint/app"
evmante "github.com/zeta-chain/ethermint/app/ante"

zetaapp "github.com/zeta-chain/node/app"
"github.com/zeta-chain/node/app/ante"
)

func NewSimApp(logger log.Logger, db dbm.DB, appOptions servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp)) (*zetaapp.App, error) {

func NewSimApp(
logger log.Logger,
db dbm.DB,
appOptions servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) (*zetaapp.App, error) {
encCdc := zetaapp.MakeEncodingConfig()

// Set load latest version to false as we manually set it later.
Expand Down
47 changes: 40 additions & 7 deletions tests/simulation/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,23 @@ func TestAppStateDeterminism(t *testing.T) {
}
// For the same seed, the app hash produced at the end of each run should be the same
for j := 0; j < numTimesToRunPerSeed; j++ {
db, dir, logger, _, err := cosmossimutils.SetupSimulation(config, SimDBBackend, SimDBName, simutils.FlagVerboseValue, simutils.FlagEnabledValue)
db, dir, logger, _, err := cosmossimutils.SetupSimulation(
config,
SimDBBackend,
SimDBName,
simutils.FlagVerboseValue,
simutils.FlagEnabledValue,
)
require.NoError(t, err)
appOptions[flags.FlagHome] = dir

simApp, err := simutils.NewSimApp(logger, db, appOptions, interBlockCacheOpt(), baseapp.SetChainID(SimAppChainID))
simApp, err := simutils.NewSimApp(
logger,
db,
appOptions,
interBlockCacheOpt(),
baseapp.SetChainID(SimAppChainID),
)

fmt.Printf(
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
Expand All @@ -98,7 +110,11 @@ func TestAppStateDeterminism(t *testing.T) {
t,
os.Stdout,
simApp.BaseApp,
simutils.AppStateFn(simApp.AppCodec(), simApp.SimulationManager(), simApp.ModuleBasics.DefaultGenesis(simApp.AppCodec())),
simutils.AppStateFn(
simApp.AppCodec(),
simApp.SimulationManager(),
simApp.ModuleBasics.DefaultGenesis(simApp.AppCodec()),
),
cosmossim.RandomAccounts,
cosmossimutils.SimulationOperations(simApp, simApp.AppCodec(), config),
blockedAddresses,
Expand All @@ -114,8 +130,15 @@ func TestAppStateDeterminism(t *testing.T) {

if j != 0 {
require.Equal(
t, string(appHashList[0]), string(appHashList[j]),
"non-determinism in seed %d: %d/%d, attempt: %d/%d\n", config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed,
t,
string(appHashList[0]),
string(appHashList[j]),
"non-determinism in seed %d: %d/%d, attempt: %d/%d\n",
config.Seed,
i+1,
numSeeds,
j+1,
numTimesToRunPerSeed,
)
}
}
Expand All @@ -132,7 +155,13 @@ func TestFullAppSimulation(t *testing.T) {
config.BlockMaxGas = SimBlockMaxGas
config.DBBackend = SimDBBackend

db, dir, logger, skip, err := cosmossimutils.SetupSimulation(config, SimDBBackend, SimDBName, simutils.FlagVerboseValue, simutils.FlagEnabledValue)
db, dir, logger, skip, err := cosmossimutils.SetupSimulation(
config,
SimDBBackend,
SimDBName,
simutils.FlagVerboseValue,
simutils.FlagEnabledValue,
)
if skip {
t.Skip("skipping application simulation")
}
Expand All @@ -154,7 +183,11 @@ func TestFullAppSimulation(t *testing.T) {
t,
os.Stdout,
simApp.BaseApp,
simutils.AppStateFn(simApp.AppCodec(), simApp.SimulationManager(), simApp.ModuleBasics.DefaultGenesis(simApp.AppCodec())),
simutils.AppStateFn(
simApp.AppCodec(),
simApp.SimulationManager(),
simApp.ModuleBasics.DefaultGenesis(simApp.AppCodec()),
),
cosmossim.RandomAccounts,
cosmossimutils.SimulationOperations(simApp, simApp.AppCodec(), config),
blockedAddresses,
Expand Down

0 comments on commit 73fbcf5

Please sign in to comment.