Skip to content

Commit

Permalink
chore: polish code and add sim to ci
Browse files Browse the repository at this point in the history
  • Loading branch information
hacheigriega committed Feb 6, 2024
1 parent a439282 commit 42b5d06
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 26 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/simulations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Simulation
# Simulation workflow runs simulation test
# This workflow is run on pushes to master & every Pull Requests where a .go, .mod, .sum have been changed
on:
pull_request:
push:
branches:
- main

env:
GO_VERSION: "1.21.0"

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true
cache: true
cache-dependency-path: go.sum
-
name: Get git diff
uses: technote-space/[email protected]
with:
PATTERNS: |
**/**!(test).go
go.mod
go.sum
Makefile
- name: Run determinism check simulation
run: |
make test-sim-determinism
if: env.GIT_DIFF

- name: Run export-import simulation
run: |
make test-sim-export-import
if: env.GIT_DIFF

- name: Run after-import simulation
run: |
make test-sim-after-import
if: env.GIT_DIFF
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,40 @@ endif

.PHONY: cover-html run-tests $(TEST_TARGETS) test test-race docker-build-e2e

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

CURRENT_DIR = $(shell pwd)

test-sim-determinism:
@echo "Running determinism test..."
@cd ${CURRENT_DIR}/simulation && go test -mod=readonly -run TestAppStateDeterminism -Enabled=true \
-NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h

test-sim-export-import:
@echo "Running export-import test..."
@cd ${CURRENT_DIR}/simulation && go test -mod=readonly -run TestAppExportImport -Enabled=true \
-NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h

test-sim-after-import:
@echo "Running simulation-after-import test..."
@cd ${CURRENT_DIR}/simulation && go test -mod=readonly -run TestAppSimulationAfterImport -Enabled=true \
-NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h

.PHONY: test-sim-determinism test-sim-export-import test-sim-after-import

SIM_NUM_BLOCKS ?= 500
SIM_BLOCK_SIZE ?= 200
SIM_COMMIT ?= true

test-sim-benchmark:
@echo "Running application benchmark for numBlocks=$(SIM_NUM_BLOCKS), blockSize=$(SIM_BLOCK_SIZE). This may take awhile!"
@cd ${CURRENT_DIR}/simulation && go test -mod=readonly -run=^$$ $(.) -bench ^BenchmarkSimulation$$ \
-Enabled=true -NumBlocks=$(SIM_NUM_BLOCKS) -BlockSize=$(SIM_BLOCK_SIZE) -Commit=$(SIM_COMMIT) -timeout 24h

.PHONY: test-sim-benchmark

###############################################################################
### interchaintest ###
###############################################################################
Expand Down
19 changes: 0 additions & 19 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,18 +567,6 @@ func NewApp(
wasmOpts...,
)

// //
// //
// // Register the proposal types
// // Deprecated: Avoid adding new handlers, instead use the new proposal flow
// // by granting the governance module the right to execute the message.
// // See: https://docs.cosmos.network/main/modules/gov#proposal-messages
// govRouter := govv1beta1.NewRouter()
// govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
// AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper))
// //
// //

govConfig := govtypes.DefaultConfig()
govKeeper := govkeeper.NewKeeper(
appCodec,
Expand All @@ -592,13 +580,6 @@ func NewApp(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// //
// //
// // Set legacy router for backwards compatibility with gov v1beta1
// govKeeper.SetLegacyRouter(govRouter)
// //
// //

app.GovKeeper = *govKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// register the governance hooks
Expand Down
12 changes: 5 additions & 7 deletions simulation/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ func init() {
}

// BenchmarkSimulation run the chain simulation
// Running using starport command:
// `starport chain simulate -v --numBlocks 200 --blockSize 50`
// Running as go benchmark test:
// `go test -benchmem -run=^$ -bench ^BenchmarkSimulation ./app -NumBlocks=200 -BlockSize 50 -Commit=true -Verbose=true -Enabled=true`
// go test -benchmem -run=^$ -bench ^BenchmarkSimulation ./simulation -NumBlocks=200 -BlockSize 50 -Commit=true -Verbose=true -Enabled=true
func BenchmarkSimulation(b *testing.B) {
simcli.FlagSeedValue = time.Now().Unix()
simcli.FlagVerboseValue = true
Expand Down Expand Up @@ -162,7 +160,7 @@ func TestAppStateDeterminism(t *testing.T) {
)

fmt.Printf(
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
"running determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed,
)

Expand Down Expand Up @@ -193,16 +191,16 @@ 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,
"determinism in seed %d: %d/%d, attempt: %d/%d\n", config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed,
)
}
}
}
}

func TestAppImportExport(t *testing.T) {
func TestAppExportImport(t *testing.T) {
config := simcli.NewConfigFromFlags()
config.ChainID = "seda-simapp-import"
config.ChainID = "seda-simapp-export-import"

db, dir, logger, skip, err := simtestutil.SetupSimulation(
config,
Expand Down

0 comments on commit 42b5d06

Please sign in to comment.