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: initilize simulation tests for custom zetachain modules #3095

Draft
wants to merge 13 commits into
base: develop
Choose a base branch
from
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,
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),
}
}
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

### 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 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
62 changes: 40 additions & 22 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 @@ -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,24 @@ 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")

// 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 interting with with them such as setting gas price causes the state for the auth module to change on export .
// We will need to explore this further to find a definitive answer
//{simApp.GetKey(authtypes.StoreKey), newSimApp.GetKey(authtypes.StoreKey), [][]byte{}},
{
simApp.GetKey(stakingtypes.StoreKey), newSimApp.GetKey(stakingtypes.StoreKey),
[][]byte{
Expand All @@ -388,13 +395,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 +479,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 +505,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 +533,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 +544,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