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: simulation import and export #3033

Merged
merged 72 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
c3299ef
debug sim test
kingpinXD Sep 30, 2024
7d95021
start modifuing for v50
kingpinXD Oct 1, 2024
fcce58e
add sim test v1
kingpinXD Oct 1, 2024
b774b1e
add sim export
kingpinXD Oct 1, 2024
ac8fddf
move simulation tests to a separate directory
kingpinXD Oct 1, 2024
b55f439
remove unused functions
kingpinXD Oct 1, 2024
913aa19
add comments
kingpinXD Oct 2, 2024
10d8a38
enable gov module
kingpinXD Oct 2, 2024
49d430c
enable gov module
kingpinXD Oct 2, 2024
73fbcf5
fix lint error
kingpinXD Oct 2, 2024
cad3f4f
add todos for BasicManager
kingpinXD Oct 3, 2024
c07d519
add todos for BasicManager
kingpinXD Oct 3, 2024
4f3ebbe
add cleanup for TestFullAppSimulation
kingpinXD Oct 3, 2024
56b4698
register legacy router
kingpinXD Oct 3, 2024
c1db4cf
added a doc for simulation testing
kingpinXD Oct 3, 2024
d98add5
undo db close for multi threaded test
kingpinXD Oct 3, 2024
bff4121
add description for tests
kingpinXD Oct 14, 2024
74b0ad7
remove go module from simulation tests
kingpinXD Oct 15, 2024
f8c095d
make basicsmanager private
kingpinXD Oct 18, 2024
b49be6b
Update Makefile
kingpinXD Oct 22, 2024
cf4cb45
Update changelog.md
kingpinXD Oct 22, 2024
d5ae57c
format simulation.md
kingpinXD Oct 22, 2024
1f744f8
rebase develop
kingpinXD Oct 22, 2024
e1cc91f
add test for import export
kingpinXD Oct 22, 2024
d674455
add test for import export
kingpinXD Oct 22, 2024
651a61a
test sim after import
kingpinXD Oct 22, 2024
5e3bce7
add bench test
kingpinXD Oct 22, 2024
3b44c10
remove bench
kingpinXD Oct 23, 2024
6eea359
add changelog
kingpinXD Oct 23, 2024
9dfc005
remove cosmos utils
kingpinXD Oct 23, 2024
a40f4d9
remove print lines
kingpinXD Oct 23, 2024
fdbacce
add comments
kingpinXD Oct 23, 2024
a868450
ci: Add simulation tests workflow
Oct 23, 2024
924d063
Merge branch 'ci/add-simulation-test' into sim-import-export
kingpinXD Oct 23, 2024
bea00ab
merge ci workflow
kingpinXD Oct 23, 2024
21b91d4
Update .github/workflows/simulation-test.yaml
kingpinXD Oct 23, 2024
59bc886
Update simulation-test.yaml
julianrubino Oct 23, 2024
33bb1b9
add branch sim-import-export to trigger ci run
kingpinXD Oct 23, 2024
9791e99
format files
kingpinXD Oct 23, 2024
643490d
uncomment simulation tests from CI
kingpinXD Oct 23, 2024
064e05e
fix defer functions
kingpinXD Oct 23, 2024
57b5d4e
Rename sim tests file, add result aggregation and merge jobs
Oct 24, 2024
6fcad07
Merge branch 'develop' into sim-import-export
kingpinXD Oct 24, 2024
4b0dda4
ignore simulation tests from codecov
kingpinXD Oct 24, 2024
e8d127a
Merge remote-tracking branch 'origin/sim-import-export' into sim-impo…
kingpinXD Oct 24, 2024
d18978b
Add runs on to matrix conditional job
Oct 24, 2024
195bc8d
add default make-targets
Oct 24, 2024
7458f94
bump go
Oct 24, 2024
399569d
Update .github/workflows/sim.yaml workflow name
julianrubino Oct 25, 2024
cf60f5a
Delete main branch from sim test workflow
julianrubino Oct 25, 2024
5c682e9
improve formatting for simulation.md
kingpinXD Oct 25, 2024
06c5d75
move simulation tests to root directory
kingpinXD Oct 29, 2024
d27702d
remove panic for Import Export Test
kingpinXD Oct 29, 2024
cb4be57
Merge branch 'develop' into sim-import-export
kingpinXD Oct 29, 2024
5132383
Trigger Sim Tests on Labeled PRs or when any file from x/**/* is changed
Oct 29, 2024
902e191
Merge branch 'sim-import-export' of github.com:zeta-chain/node into s…
Oct 29, 2024
f2341e8
update sim.yaml
kingpinXD Oct 29, 2024
29f04e8
Update sim.yaml jobs needs
julianrubino Oct 29, 2024
2fdb90b
update sim.yaml
kingpinXD Oct 29, 2024
19c27fa
Merge remote-tracking branch 'origin/sim-import-export' into sim-impo…
kingpinXD Oct 29, 2024
eaa150d
update codecov.yml
kingpinXD Oct 29, 2024
0392598
Merge branch 'develop' into sim-import-export
kingpinXD Oct 29, 2024
476a623
fixed some comments
kingpinXD Oct 30, 2024
086f973
Merge remote-tracking branch 'origin/sim-import-export' into sim-impo…
kingpinXD Oct 30, 2024
ded60cb
remove directory sim
kingpinXD Oct 30, 2024
6cc76e8
remove directory sim
kingpinXD Oct 30, 2024
0e76223
Merge branch 'develop' into sim-import-export
kingpinXD Oct 30, 2024
d8b713a
format directory
kingpinXD Oct 30, 2024
6e3b843
Merge remote-tracking branch 'origin/sim-import-export' into sim-impo…
kingpinXD Oct 30, 2024
60a0aa4
remove utils file
kingpinXD Oct 31, 2024
b9abe91
add to codecov
kingpinXD Nov 1, 2024
897eb3e
Merge branch 'develop' into sim-import-export
kingpinXD Nov 1, 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
76 changes: 76 additions & 0 deletions .github/workflows/simulation-test.yaml
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
julianrubino marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Simulation Tests Workflow

on:
# The workflow runs when code is pushed to either the main or develop branches
push:
branches:
- main
- develop
# The workflow runs when a pull request is opened or updated
pull_request:
# Run daily at 6AM UTC Daily
schedule:
- cron: "0 6 * * *"
# It can be run manually targetting a specific test
workflow_dispatch:
inputs:
test-target:
description: 'Makefile test target to run (e.g., test-sim-nondeterminism)'
required: true
default: 'test-sim-fullappsimulation'

concurrency:
# Ensures that only one run of this workflow is active per branch or commit
group: runsim-${{ github.head_ref || github.sha }}
# If a new run is triggered for the same branch/commit while an old one is still in progress, the previous run will be canceled
cancel-in-progress: true

jobs:
# This job is responsible for setting up the environment and installing the necessary dependencies, including runsim
install-dependencies:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Install runsim and dependencies
run: |
make runsim

run-simulation-tests:
needs: install-dependencies
runs-on: ubuntu-22.04
strategy:
matrix:
# The matrix strategy allows running multiple simulation tests in parallel. In this case, it runs the following targets from the Makefile
test-target:
- "test-sim-nondeterminism"
- "test-sim-fullappsimulation"
- "test-sim-import-export"
- "test-sim-after-import"
steps:
- name: Checkout code
uses: actions/checkout@v3

# It runs the specified test from the Makefile by calling make ${{ matrix.test-target }}, where test-target is one of the matrix values
- name: Run Simulation Test - ${{ matrix.test-target }}
run: |
make ${{ matrix.test-target }}
julianrubino marked this conversation as resolved.
Show resolved Hide resolved
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved

kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
manual-run:
runs-on: ubuntu-22.04
if: github.event_name == 'workflow_dispatch'
steps:
- name: Checkout code
uses: actions/checkout@v3
# This job only runs if the workflow was triggered by a manual dispatch (workflow_dispatch)
- name: Run Simulation Test - ${{ github.event.inputs.test-target }}
env:
TEST_TARGET: ${{ github.event.inputs.test-target }}
run: |
make "$TEST_TARGET"
julianrubino marked this conversation as resolved.
Show resolved Hide resolved
24 changes: 20 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -381,16 +381,22 @@ $(BINDIR)/runsim:
# Period: Invariant check period
# Timeout: Timeout for the simulation test
define run-sim-test
@echo "Running $(1)..."
@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)
$(call run-sim-test,"non-determinism test",TestAppStateDeterminism,100,200,30m)

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

test-sim-import-export:
$(call run-sim-test,"test-import-export",TestAppImportExport,100,200,30m)

test-sim-after-import:
$(call run-sim-test,"test-sim-after-import",TestAppSimulationAfterImport,100,200,30m)

test-sim-multi-seed-long: runsim
@echo "Running long multi-seed application simulation."
Expand All @@ -400,13 +406,23 @@ test-sim-multi-seed-short: runsim
@echo "Running short multi-seed application simulation."
@$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 50 10 TestFullAppSimulation

test-sim-import-export-long: runsim
@echo "Running application import/export simulation. This may take several minutes"
@$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 50 5 TestAppImportExport

test-sim-after-import-long: runsim
@echo "Running application simulation-after-import. This may take several minute"
@$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 50 5 TestAppSimulationAfterImport

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


###############################################################################
Expand Down
4 changes: 4 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,10 @@ func (app *App) BasicManager() module.BasicManager {
return app.mb
}

func (app *App) ModuleManager() *module.Manager {
return app.mm
}

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

Expand Down
7 changes: 2 additions & 5 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str

// withdraw all validator commission
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
_, err := app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
if err != nil {
panic(err)
}
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
return false
})

Expand Down Expand Up @@ -162,7 +159,7 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
counter := int16(0)

for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(iter.Key()[1:])
addr := sdk.ValAddress(iter.Key()[2:])
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
validator, found := app.StakingKeeper.GetValidator(ctx, addr)
if !found {
panic("expected validator, not found")
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* [2894](https://github.com/zeta-chain/node/pull/2894) - increase gas limit for TSS vote tx
* [2932](https://github.com/zeta-chain/node/pull/2932) - add gateway upgrade as part of the upgrade test
* [2947](https://github.com/zeta-chain/node/pull/2947) - initialize simulation tests
* [3033](https://github.com/zeta-chain/node/pull/3033) - initialize simulation tests for import and export

### Fixes

Expand Down
29 changes: 26 additions & 3 deletions docs/development/SIMULATION_TESTING.md
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,38 @@ At the end of the run it tries to export the genesis state to make sure the expo
```bash
make test-sim-full-app
```

### Import Export simulation test
The import export simulation test runs a full application simulation
and exports the application state at the end of the run.
This state is then then imported into a new simulation.
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
At the end of the run we compare the keys for the application state for both the simulations
to make sure they are the same.
```bash
make test-sim-import-export
```
### Import and run simulation test
This simulation test exports the application state at the end of the run and imports it into a new simulation.
```bash
make test-sim-import-export
```
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
### Multi seed long test
Multi seed long test runs a full application simulation with multiple seeds and multiple blocks.This runs the test for a longer duration compared to the multi seed short test
```bash
make test-sim-multi-seed-long
```

### Multi seed short test
lumtis marked this conversation as resolved.
Show resolved Hide resolved
Multi seed short test runs a full application simulation with multiple seeds and multiple blocks. This runs the test for a longer duration compared to the multi seed long test
```bash
make test-sim-multi-seed-short
```
```
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
### Import Export long test
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
This test runs the import export simulation test for a longer duration.It uses the runsim tool to run the same test in parallel threads
```bash
make test-sim-import-export-long
```
### Import and run simulation test
This test runs the import and run simulation test for a longer duration. It uses the runsim tool to run the same test in parallel threads
```bash
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
make test-sim-after-import-longg
```

31 changes: 31 additions & 0 deletions tests/simulation/sim/sim_utils.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package sim
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved

import (
"encoding/json"
"fmt"
"os"

dbm "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/runtime"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/zeta-chain/ethermint/app"
evmante "github.com/zeta-chain/ethermint/app/ante"

Expand Down Expand Up @@ -66,3 +70,30 @@
fmt.Println(db.Stats()["leveldb.stats"])
fmt.Println("GoLevelDB cached block size", db.Stats()["leveldb.cachedblock"])
}

// CheckExportSimulation exports the app state and simulation parameters to JSON
// if the export paths are defined.
func CheckExportSimulation(app runtime.AppI, config simtypes.Config, params simtypes.Params) error {
if config.ExportStatePath != "" {
exported, err := app.ExportAppStateAndValidators(false, nil, nil)
if err != nil {
return err
}

Check warning on line 81 in tests/simulation/sim/sim_utils.go

View check run for this annotation

Codecov / codecov/patch

tests/simulation/sim/sim_utils.go#L76-L81

Added lines #L76 - L81 were not covered by tests

if err := os.WriteFile(config.ExportStatePath, []byte(exported.AppState), 0o600); err != nil {
return err
}

Check warning on line 85 in tests/simulation/sim/sim_utils.go

View check run for this annotation

Codecov / codecov/patch

tests/simulation/sim/sim_utils.go#L83-L85

Added lines #L83 - L85 were not covered by tests
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
}

if config.ExportParamsPath != "" {
paramsBz, err := json.MarshalIndent(params, "", " ")
if err != nil {
return err
}

Check warning on line 92 in tests/simulation/sim/sim_utils.go

View check run for this annotation

Codecov / codecov/patch

tests/simulation/sim/sim_utils.go#L88-L92

Added lines #L88 - L92 were not covered by tests

if err := os.WriteFile(config.ExportParamsPath, paramsBz, 0o600); err != nil {
return err
}

Check warning on line 96 in tests/simulation/sim/sim_utils.go

View check run for this annotation

Codecov / codecov/patch

tests/simulation/sim/sim_utils.go#L94-L96

Added lines #L94 - L96 were not covered by tests
}
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
return nil

Check warning on line 98 in tests/simulation/sim/sim_utils.go

View check run for this annotation

Codecov / codecov/patch

tests/simulation/sim/sim_utils.go#L98

Added line #L98 was not covered by tests
}
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading