Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: initialize simulation tests for custom zetachain modules #3095

Merged
merged 38 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9369869
add crosschain decoders
kingpinXD Oct 24, 2024
873153d
decoders test
kingpinXD Oct 28, 2024
422d03b
add oeprations
kingpinXD Oct 31, 2024
39d9863
add fungible deploy contracts
kingpinXD Oct 31, 2024
84d2089
add fungible deploy contracts
kingpinXD Nov 1, 2024
5d68917
add simulation for observer module
kingpinXD Nov 5, 2024
c4dfcd7
add comments for crosschain operations
kingpinXD Nov 5, 2024
fa1234f
add comments for observer and fungible operations
kingpinXD Nov 5, 2024
9e3c7b3
rebase develop
kingpinXD Nov 6, 2024
9f976c0
generate files
kingpinXD Nov 7, 2024
bacd4b2
debug import export test
kingpinXD Nov 7, 2024
2b0509a
fix import export tests
kingpinXD Nov 7, 2024
d03ed5f
fix import export tests
kingpinXD Nov 7, 2024
7070211
fix app determinism test
kingpinXD Nov 8, 2024
cda3f22
update codecov.yml
kingpinXD Nov 8, 2024
9172df7
reduce weight for DeployedSystemContracts operation
kingpinXD Nov 8, 2024
8526eab
add new function to generate eth address from provided randomness
kingpinXD Nov 8, 2024
ea92069
Update x/fungible/simulation/decoders.go
kingpinXD Nov 8, 2024
977a22c
Update testutil/sample/sample.go
kingpinXD Nov 8, 2024
863cf0b
add validations
kingpinXD Nov 8, 2024
44abb89
add validations
kingpinXD Nov 8, 2024
94ecd5e
add randmoness to tss
kingpinXD Nov 8, 2024
13f919f
make requested changes 1
kingpinXD Nov 13, 2024
4975947
update state.go file
kingpinXD Nov 13, 2024
eea9fd4
update state.go file
kingpinXD Nov 13, 2024
083d861
change chains.IsEVMChain to chains.IsEthereumChain in deposit tests
kingpinXD Nov 14, 2024
fb0a626
add decoder for tss history
kingpinXD Nov 14, 2024
524b377
remove unnecessary todo
kingpinXD Nov 14, 2024
626b9c8
remove unnecessary todo
kingpinXD Nov 14, 2024
5861bc3
remove unused keys
kingpinXD Nov 15, 2024
d9dd460
Update simulation/simulation_test.go
kingpinXD Dec 9, 2024
cbce35b
fix comments and remove unused functions
kingpinXD Dec 10, 2024
256d013
Merge remote-tracking branch 'origin/crosschain-simulation-params' in…
kingpinXD Dec 10, 2024
8963569
fix comments and remove unused functions
kingpinXD Dec 10, 2024
8470009
improve comment wording for operation weights
kingpinXD Dec 10, 2024
98bab57
improve comment wording for operation weights
kingpinXD Dec 10, 2024
1167862
rebase develop
kingpinXD Dec 11, 2024
a05339e
rebase develop
kingpinXD Dec 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ test-sim-fullappsimulation:
$(call run-sim-test,"TestFullAppSimulation",TestFullAppSimulation,100,200,30m)

test-sim-import-export:
$(call run-sim-test,"test-import-export",TestAppImportExport,100,200,30m)
$(call run-sim-test,"test-import-export",TestAppImportExport,50,100,30m)
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved

test-sim-after-import:
$(call run-sim-test,"test-sim-after-import",TestAppSimulationAfterImport,100,200,30m)
Expand Down
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,8 @@ func New(
app.SlashingKeeper,
app.AuthorityKeeper,
app.LightclientKeeper,
app.BankKeeper,
app.AccountKeeper,
lumtis marked this conversation as resolved.
Show resolved Hide resolved
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

Expand Down
3 changes: 3 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,8 @@ func simulationModules(
evm.NewAppModule(app.EvmKeeper, app.AccountKeeper, app.GetSubspace(evmtypes.ModuleName)),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
crosschainmodule.NewAppModule(appCodec, app.CrosschainKeeper),
observermodule.NewAppModule(appCodec, *app.ObserverKeeper),
fungiblemodule.NewAppModule(appCodec, app.FungibleKeeper),
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
}
}
5 changes: 1 addition & 4 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

### Tests
* [3075](https://github.com/zeta-chain/node/pull/3075) - ton: withdraw concurrent, deposit & revert.

### Refactor

### Tests
* [3095](https://github.com/zeta-chain/node/pull/3095) - initialize simulation tests for custom zetachain modules
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved

### Fixes
* [3041](https://github.com/zeta-chain/node/pull/3041) - replace libp2p public DHT with private gossip peer discovery and connection gater for inbound connections
Expand Down
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ignore:
- "x/**/events.go"
- "x/**/migrator.go"
- "x/**/module_simulation.go"
- "x/**/simulation/**/*"
- "x/**/simulation/*.go"
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
- "**/*.proto"
- "**/*.md"
- "**/*.yml"
Expand Down
2 changes: 1 addition & 1 deletion contrib/docker-scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,4 @@ else

logt "Start Network"
start_network
fi
fi
16 changes: 8 additions & 8 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ which accepts a path for the resulting pprof file.
cmd.Flags().
String(server.FlagMinGasPrices, "", "Minimum gas prices to accept for transactions; Any fee in a tx must meet this minimum (e.g. 0.01photon;0.0001stake)")

//nolint:lll
//nolint:lll
cmd.Flags().
IntSlice(server.FlagUnsafeSkipUpgrades, []int{}, "Skip a set of upgrade heights to continue the old binary")
cmd.Flags().
Expand All @@ -192,7 +192,7 @@ which accepts a path for the resulting pprof file.
cmd.Flags().
Uint64(server.FlagPruningInterval, 0, "Height interval at which pruned heights are removed from disk (ignored if pruning is not 'custom')")

//nolint:lll
//nolint:lll
cmd.Flags().Uint(server.FlagInvCheckPeriod, 0, "Assert registered invariants every N blocks")
cmd.Flags().
Uint64(server.FlagMinRetainBlocks, 0, "Minimum block height offset during ABCI commit to prune Tendermint blocks")
Expand Down Expand Up @@ -220,11 +220,11 @@ which accepts a path for the resulting pprof file.
cmd.Flags().
Uint64(srvflags.JSONRPCGasCap, config.DefaultGasCap, "Sets a cap on gas that can be used in eth_call/estimateGas unit is aphoton (0=infinite)")

//nolint:lll
//nolint:lll
cmd.Flags().
Float64(srvflags.JSONRPCTxFeeCap, config.DefaultTxFeeCap, "Sets a cap on transaction fee that can be sent via the RPC APIs (1 = default 1 photon)")

//nolint:lll
//nolint:lll
cmd.Flags().
Int32(srvflags.JSONRPCFilterCap, config.DefaultFilterCap, "Sets the global cap for total number of filters that can be created")
cmd.Flags().
Expand All @@ -236,26 +236,26 @@ which accepts a path for the resulting pprof file.
cmd.Flags().
Bool(srvflags.JSONRPCAllowUnprotectedTxs, config.DefaultAllowUnprotectedTxs, "Allow for unprotected (non EIP155 signed) transactions to be submitted via the node's RPC when the global parameter is disabled")

//nolint:lll
//nolint:lll
cmd.Flags().
Int32(srvflags.JSONRPCLogsCap, config.DefaultLogsCap, "Sets the max number of results can be returned from single `eth_getLogs` query")
cmd.Flags().
Int32(srvflags.JSONRPCBlockRangeCap, config.DefaultBlockRangeCap, "Sets the max block range allowed for `eth_getLogs` query")
cmd.Flags().
Int(srvflags.JSONRPCMaxOpenConnections, config.DefaultMaxOpenConnections, "Sets the maximum number of simultaneous connections for the server listener")

//nolint:lll
//nolint:lll
cmd.Flags().Bool(srvflags.JSONRPCEnableIndexer, false, "Enable the custom tx indexer for json-rpc")
cmd.Flags().Bool(srvflags.JSONRPCEnableMetrics, false, "Define if EVM rpc metrics server should be enabled")

cmd.Flags().
String(srvflags.EVMTracer, config.DefaultEVMTracer, "the EVM tracer type to collect execution traces from the EVM transaction execution (json|struct|access_list|markdown)")

//nolint:lll
//nolint:lll
cmd.Flags().
Uint64(srvflags.EVMMaxTxGasWanted, config.DefaultMaxTxGasWanted, "the gas wanted for each eth tx returned in ante handler in check tx mode")

//nolint:lll
//nolint:lll

cmd.Flags().String(srvflags.TLSCertPath, "", "the cert.pem file path for the server TLS configuration")
cmd.Flags().String(srvflags.TLSKeyPath, "", "the key.pem file path for the server TLS configuration")
Expand Down
66 changes: 43 additions & 23 deletions simulation/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,30 @@ import (

abci "github.com/cometbft/cometbft/abci/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/store"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
cosmossimutils "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
cosmossim "github.com/cosmos/cosmos-sdk/types/simulation"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/simulation"
cosmossimcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/require"
evmtypes "github.com/zeta-chain/ethermint/x/evm/types"
"github.com/zeta-chain/node/app"
zetasimulation "github.com/zeta-chain/node/simulation"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server"
cosmossimutils "github.com/cosmos/cosmos-sdk/testutil/sims"
cosmossim "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
cosmossimcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli"
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
fungibletypes "github.com/zeta-chain/node/x/fungible/types"
observertypes "github.com/zeta-chain/node/x/observer/types"
)

// AppChainID hardcoded chainID for simulation
Expand All @@ -42,9 +43,9 @@ func init() {
}

type StoreKeysPrefixes struct {
A storetypes.StoreKey
B storetypes.StoreKey
Prefixes [][]byte
A storetypes.StoreKey
B storetypes.StoreKey
SkipPrefixes [][]byte
}

const (
Expand Down Expand Up @@ -81,7 +82,7 @@ func TestAppStateDeterminism(t *testing.T) {
config.DBBackend = SimDBBackend
config.BlockMaxGas = SimBlockMaxGas

numSeeds := 3
numSeeds := 2
numTimesToRunPerSeed := 5

// We will be overriding the random seed and just run a single simulation on the provided seed value
Expand Down Expand Up @@ -136,6 +137,7 @@ func TestAppStateDeterminism(t *testing.T) {
simApp.AppCodec(),
simApp.SimulationManager(),
simApp.BasicManager().DefaultGenesis(simApp.AppCodec()),
nil,
),
cosmossim.RandomAccounts,
cosmossimutils.SimulationOperations(simApp, simApp.AppCodec(), config),
Expand Down Expand Up @@ -225,6 +227,7 @@ func TestFullAppSimulation(t *testing.T) {
simApp.AppCodec(),
simApp.SimulationManager(),
simApp.BasicManager().DefaultGenesis(simApp.AppCodec()),
nil,
),
cosmossim.RandomAccounts,
cosmossimutils.SimulationOperations(simApp, simApp.AppCodec(), config),
Expand Down Expand Up @@ -295,6 +298,7 @@ func TestAppImportExport(t *testing.T) {
simApp.AppCodec(),
simApp.SimulationManager(),
simApp.BasicManager().DefaultGenesis(simApp.AppCodec()),
nil,
),
cosmossim.RandomAccounts,
cosmossimutils.SimulationOperations(simApp, simApp.AppCodec(), config),
Expand All @@ -314,7 +318,6 @@ func TestAppImportExport(t *testing.T) {
exported, err := simApp.ExportAppStateAndValidators(false, []string{}, []string{})
require.NoError(t, err)

t.Log("importing genesis")
newDB, newDir, _, _, err := cosmossimutils.SetupSimulation(
config,
SimDBBackend+"_new",
Expand Down Expand Up @@ -360,20 +363,26 @@ func TestAppImportExport(t *testing.T) {
ctxSimApp := simApp.NewContext(true, tmproto.Header{
Height: simApp.LastBlockHeight(),
ChainID: SimAppChainID,
}).WithChainID(SimAppChainID)
})

ctxNewSimApp := newSimApp.NewContext(true, tmproto.Header{
Height: simApp.LastBlockHeight(),
ChainID: SimAppChainID,
}).WithChainID(SimAppChainID)
})

// Use genesis state from the first app to initialize the second app
newSimApp.ModuleManager().InitGenesis(ctxNewSimApp, newSimApp.AppCodec(), genesisState)
newSimApp.StoreConsensusParams(ctxNewSimApp, exported.ConsensusParams)

t.Log("comparing stores")
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved

// The ordering of the keys is not important, we compare the same prefix for both simulations
storeKeysPrefixes := []StoreKeysPrefixes{
{simApp.GetKey(authtypes.StoreKey), newSimApp.GetKey(authtypes.StoreKey), [][]byte{}},
// Interaction with EVM module,
//such as deploying contracts or interacting with them such as setting gas price,
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
// causes the state for the auth module to change on export.The order of keys within the store is modified.
// We will need to explore this further to find a definitive answer
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
//{simApp.GetKey(authtypes.StoreKey), newSimApp.GetKey(authtypes.StoreKey), [][]byte{}},
{
simApp.GetKey(stakingtypes.StoreKey), newSimApp.GetKey(stakingtypes.StoreKey),
[][]byte{
Expand All @@ -388,13 +397,23 @@ func TestAppImportExport(t *testing.T) {
{simApp.GetKey(govtypes.StoreKey), newSimApp.GetKey(govtypes.StoreKey), [][]byte{}},
{simApp.GetKey(evidencetypes.StoreKey), newSimApp.GetKey(evidencetypes.StoreKey), [][]byte{}},
{simApp.GetKey(evmtypes.StoreKey), newSimApp.GetKey(evmtypes.StoreKey), [][]byte{}},
{simApp.GetKey(crosschaintypes.StoreKey), newSimApp.GetKey(crosschaintypes.StoreKey), [][]byte{
// We update the timestamp for cctx when importing the genesis state which results in a different value
crosschaintypes.KeyPrefix(crosschaintypes.CCTXKey),
}},

{simApp.GetKey(observertypes.StoreKey), newSimApp.GetKey(observertypes.StoreKey), [][]byte{
// The order of ballots when importing is not preserved which causes the value to be different.
observertypes.KeyPrefix(observertypes.BallotListKey),
}},
{simApp.GetKey(fungibletypes.StoreKey), newSimApp.GetKey(fungibletypes.StoreKey), [][]byte{}},
}

for _, skp := range storeKeysPrefixes {
storeA := ctxSimApp.KVStore(skp.A)
storeB := ctxNewSimApp.KVStore(skp.B)

failedKVAs, failedKVBs := sdk.DiffKVStores(storeA, storeB, skp.Prefixes)
failedKVAs, failedKVBs := sdk.DiffKVStores(storeA, storeB, skp.SkipPrefixes)
require.Equal(t, len(failedKVAs), len(failedKVBs), "unequal sets of key-values to compare")

t.Logf("compared %d different key/value pairs between %s and %s\n", len(failedKVAs), skp.A, skp.B)
Expand Down Expand Up @@ -462,6 +481,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
simApp.AppCodec(),
simApp.SimulationManager(),
simApp.BasicManager().DefaultGenesis(simApp.AppCodec()),
nil,
),
cosmossim.RandomAccounts,
cosmossimutils.SimulationOperations(simApp, simApp.AppCodec(), config),
Expand All @@ -487,8 +507,6 @@ func TestAppSimulationAfterImport(t *testing.T) {
exported, err := simApp.ExportAppStateAndValidators(true, []string{}, []string{})
require.NoError(t, err)

t.Log("importing genesis")

newDB, newDir, _, _, err := cosmossimutils.SetupSimulation(
config,
SimDBBackend+"_new",
Expand Down Expand Up @@ -517,6 +535,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
)
require.NoError(t, err)

t.Log("Importing genesis into the new app")
newSimApp.InitChain(abci.RequestInitChain{
ChainId: SimAppChainID,
AppStateBytes: exported.AppState,
Expand All @@ -527,9 +546,10 @@ func TestAppSimulationAfterImport(t *testing.T) {
os.Stdout,
newSimApp.BaseApp,
zetasimulation.AppStateFn(
simApp.AppCodec(),
simApp.SimulationManager(),
simApp.BasicManager().DefaultGenesis(simApp.AppCodec()),
nil,
nil,
nil,
exported.AppState,
),
cosmossim.RandomAccounts,
cosmossimutils.SimulationOperations(newSimApp, newSimApp.AppCodec(), config),
Expand Down
Loading
Loading