Skip to content

Commit 02c8db7

Browse files
feat(cov): simulator test coverage (#15)
* feat(cov): simulator tests coverage * ci: add simulator tests * ci: run ci when `main` changes * chore(make): add simulator support * chore: fix ci comment --------- Co-authored-by: Reece Williams <[email protected]>
1 parent 191544b commit 02c8db7

File tree

9 files changed

+125
-1956
lines changed

9 files changed

+125
-1956
lines changed

.coverageignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
*.pb.go
22
*.pb.gw.go
33
*.pulsar.go
4-
*_simulation.go

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: Build appd
22

33
on:
4+
push:
5+
branches:
6+
- main
47
pull_request:
58

69
concurrency:

.github/workflows/e2e.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: E2E
22

33
on:
4+
push:
5+
branches:
6+
- main
47
pull_request:
58

69
permissions:

.github/workflows/simulator.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Simulator tests
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
8+
env:
9+
GO_VERSION: 1.21.0
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
tests:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Check out source
20+
uses: actions/checkout@v4
21+
- name: Set up Go
22+
uses: actions/setup-go@v5
23+
with:
24+
go-version: ${{ env.GO_VERSION }}
25+
check-latest: true
26+
- name: Full application simulation (fixed seed)
27+
run: make sim-full-app
28+
- name: Simulation after state import (fixed seed)
29+
run: make sim-after-import
30+
# # Requires wiring v2
31+
# # https://github.com/strangelove-ventures/tokenfactory/issues/13
32+
# - name: Simulation import/export (fixed seed)
33+
# run: make sim-import-export
34+
- name: Simulate application state determinism (fixed seed)
35+
run: make sim-app-determinism

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: Unit Tests
22

33
on:
4+
push:
5+
branches:
6+
- main
47
pull_request:
58

69
env:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ cache
2727
state
2828

2929
configs/logs.json
30+
go.work.sum

Makefile

Lines changed: 78 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,44 @@ test-integration:
130130
@echo "--> Running integration tests"
131131
cd integration; go test -v ./...
132132

133+
COV_ROOT="/tmp/tokenfactory-coverage"
134+
COV_UNIT_E2E="${COV_ROOT}/unit-e2e"
135+
COV_SIMULATION="${COV_ROOT}/simulation"
136+
COV_PKG="github.com/strangelove-ventures/tokenfactory/..."
137+
COV_SIM_CMD=${COV_SIMULATION}/simulation.test
138+
COV_SIM_COMMON=-Enabled=True -NumBlocks=100 -Commit=true -Period=5 -Verbose=false -test.v -test.gocoverdir=${COV_SIMULATION}
139+
133140
coverage: ## Run coverage report
134-
@echo "--> Running coverage"
135-
@go test -race -cpu=$$(nproc) -covermode=atomic -coverprofile=coverage.out $$(go list ./...) ./interchaintest/... -coverpkg=github.com/strangelove-ventures/tokenfactory/... > /dev/null 2>&1
136-
@echo "--> Running coverage filter"
137-
@./scripts/filter-coverage.sh
138-
@echo "--> Running coverage report"
139-
@go tool cover -func=coverage-filtered.out
140-
@echo "--> Running coverage html"
141-
@go tool cover -html=coverage-filtered.out -o coverage.html
141+
@echo "--> Creating GOCOVERDIR"
142+
@mkdir -p ${COV_UNIT_E2E} ${COV_SIMULATION}
143+
@echo "--> Cleaning up coverage files, if any"
144+
@rm -rf ${COV_UNIT_E2E}/* ${COV_SIMULATION}/*
145+
@echo "--> Building instrumented simulation test binary"
146+
@go test -c ./app -mod=readonly -covermode=atomic -coverpkg=${COV_PKG} -cover -o ${COV_SIM_CMD}
147+
@echo " --> Running Full App Simulation"
148+
@${COV_SIM_CMD} -test.run TestFullAppSimulation ${COV_SIM_COMMON} > /dev/null 2>&1
149+
# Enable after wiring v2 is implemented
150+
# @echo " --> Running App Import/Export Simulation"
151+
# @${COV_SIM_CMD} -test.run TestAppImportExport ${COV_SIM_COMMON} > /dev/null 2>&1
152+
@echo " --> Running App Simulation After Import"
153+
@${COV_SIM_CMD} -test.run TestAppSimulationAfterImport ${COV_SIM_COMMON} > /dev/null 2>&1
154+
@echo " --> Running App State Determinism Simulation"
155+
@${COV_SIM_CMD} -test.run TestAppStateDeterminism ${COV_SIM_COMMON} > /dev/null 2>&1
156+
@echo "--> Running unit & e2e tests coverage"
157+
@go test -timeout 30m -race -covermode=atomic -v -cpu=$$(nproc) -cover $$(go list ./...) ./interchaintest/... -coverpkg=${COV_PKG} -args -test.gocoverdir="${COV_UNIT_E2E}" > /dev/null 2>&1
158+
@echo "--> Merging coverage reports"
159+
@go tool covdata merge -i=${COV_UNIT_E2E},${COV_SIMULATION} -o ${COV_ROOT}
160+
@echo "--> Converting binary coverage report to text format"
161+
@go tool covdata textfmt -i=${COV_ROOT} -o ${COV_ROOT}/coverage-merged.out
162+
@echo "--> Filtering coverage reports"
163+
@./scripts/filter-coverage.sh ${COV_ROOT}/coverage-merged.out ${COV_ROOT}/coverage-merged-filtered.out
164+
@echo "--> Generating coverage report"
165+
@go tool cover -func=${COV_ROOT}/coverage-merged-filtered.out
166+
@echo "--> Generating HTML coverage report"
167+
@go tool cover -html=${COV_ROOT}/coverage-merged-filtered.out -o coverage.html
142168
@echo "--> Coverage report available at coverage.html"
143169
@echo "--> Cleaning up coverage files"
144-
@rm coverage.out
170+
@rm -rf ${COV_UNIT_E2E}/* ${COV_SIMULATION}/*
145171
@echo "--> Running coverage complete"
146172

147173
.PHONY: test test-integration coverage
@@ -189,6 +215,49 @@ lint-fix:
189215
.PHONY: lint lint-fix
190216

191217
##################
218+
### Simulation ###
219+
##################
220+
221+
SIM_NUM_BLOCKS ?= 100
222+
SIM_PERIOD ?= 5
223+
SIM_COMMIT ?= true
224+
SIM_ENABLED ?= true
225+
SIM_VERBOSE ?= false
226+
SIM_TIMEOUT ?= 24h
227+
SIM_SEED ?= 42
228+
SIM_COMMON_ARGS = -NumBlocks=${SIM_NUM_BLOCKS} -Enabled=${SIM_ENABLED} -Commit=${SIM_COMMIT} -Period=${SIM_PERIOD} -Verbose=${SIM_VERBOSE} -Seed=${SIM_SEED} -v -timeout ${SIM_TIMEOUT}
229+
230+
sim-full-app:
231+
@echo "--> Running full app simulation (blocks: ${SIM_NUM_BLOCKS}, commit: ${SIM_COMMIT}, period: ${SIM_PERIOD}, seed: ${SIM_SEED}"
232+
@go test ./app -run TestFullAppSimulation ${SIM_COMMON_ARGS}
233+
234+
sim-full-app-random:
235+
$(MAKE) sim-full-app SIM_SEED=$$RANDOM
236+
237+
# Note: known to fail when using app wiring v1
238+
sim-import-export:
239+
@echo "--> Running app import/export simulation (blocks: ${SIM_NUM_BLOCKS}, commit: ${SIM_COMMIT}, period: ${SIM_PERIOD}, seed: ${SIM_SEED}"
240+
@go test ./app -run TestAppImportExport ${SIM_COMMON_ARGS}
241+
242+
# Note: known to fail when using app wiring v1
243+
sim-import-export-random:
244+
$(MAKE) sim-import-export SIM_SEED=$$RANDOM
245+
246+
sim-after-import:
247+
@echo "--> Running app after import simulation (blocks: ${SIM_NUM_BLOCKS}, commit: ${SIM_COMMIT}, period: ${SIM_PERIOD}, seed: ${SIM_SEED}"
248+
@go test ./app -run TestAppSimulationAfterImport ${SIM_COMMON_ARGS}
249+
250+
sim-after-import-random:
251+
$(MAKE) sim-after-import SIM_SEED=$$RANDOM
252+
253+
sim-app-determinism:
254+
@echo "--> Running app determinism simulation (blocks: ${SIM_NUM_BLOCKS}, commit: ${SIM_COMMIT}, period: ${SIM_PERIOD}, seed: ${SIM_SEED}"
255+
@go test ./app -run TestAppStateDeterminism ${SIM_COMMON_ARGS}
256+
257+
sim-app-determinism-random:
258+
$(MAKE) sim-app-determinism SIM_SEED=$$RANDOM
259+
260+
.PHONY: sim-full-app sim-full-app-random sim-import-export sim-after-import sim-app-determinism sim-import-export-random sim-after-import-random sim-app-determinism-random
192261
### Security ###
193262
##################
194263
govulncheck_version=latest

0 commit comments

Comments
 (0)