Skip to content

Commit

Permalink
test: add simulation tests (#98)
Browse files Browse the repository at this point in the history
* test: add sim_test

* test: add decoder and its unit tests

* test: add randomized genesis params

* test: add params and unit tests

* chore: adding operations

* test: add operations and tests

* fix: lint checks

* fix: nolint check for interBlockCacheOpt

* test: nolint unused code

* lint: last test

* chore: fix broken test and add todo for public plan proposal

* chore: fix param changes, randomize epoch days, add farming fee collector, add workflow

* fix: broken test

* docs: fix backticks location

* chore: add migration tests, sort imports, fix db to newDB, update Makefile

* chore: fix simulation logic, add minter permission to module account, work in progress to solve harvest issue

* feat: adding public plan proposals

* chore: adding simulation for public plan proposals work in progress

* fix: add check for duplicate name value when creating private plans #101

* test: fix broken tests

* chore: remove comments, refactor logic, fixing harvest

* build: update github workflow to split simulation jobs

* chore: add public plans, remove unused test codes and clean up logics
- add request public plan proposal
- update request public plan proposal
- delete request public plan proposal
- comment TODO to improve public plans logic

* chore: debugging export and import simulation

* fix: update simulation logics for f1 spec

* fix: fix test plan dates and expected codes, lint

* fix: lint and validation logic of simulation

* fix: revert test plan and add validation logic for unstake

* chore: remove unused test functions

* fix: apply suggested reviews

* chore: fix lint

Co-authored-by: dongsam <[email protected]>
  • Loading branch information
jaybxyz and dongsam authored Sep 14, 2021
1 parent 566057d commit 14db7b7
Show file tree
Hide file tree
Showing 39 changed files with 2,084 additions and 225 deletions.
120 changes: 120 additions & 0 deletions .github/workflows/sims.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Sims
# Sims workflow runs multiple types of simulations (nondeterminism, import-export, after-import)
# This workflow will run on all Pull Requests, if a .go, .mod or .sum file have been changed
on:
pull_request:
push:
branches:
- master
- develop

jobs:
build:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'skip-sims')"
steps:
- uses: actions/checkout@v2
- uses: actions/[email protected]
with:
go-version: 1.16
- name: Display go version
run: go version
- run: make build

install-runsim:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/[email protected]
with:
go-version: 1.16
- name: Display go version
run: go version
- name: Install runsim
run: export GO111MODULE="on" && go get github.com/cosmos/tools/cmd/[email protected]
- uses: actions/[email protected]
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary

test-sim-nondeterminism:
runs-on: ubuntu-latest
needs: [build, install-runsim]
steps:
- uses: actions/checkout@v2
- uses: actions/[email protected]
with:
go-version: 1.16
- name: Display go version
run: go version
- uses: technote-space/get-diff-action@v4
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- uses: actions/[email protected]
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
if: env.GIT_DIFF
- name: test-sim-nondeterminism
run: |
make test-sim-nondeterminism
if: env.GIT_DIFF

# test-sim-import-export:
# runs-on: ubuntu-latest
# needs: [build, install-runsim]
# steps:
# - uses: actions/checkout@v2
# - uses: actions/[email protected]
# with:
# go-version: 1.16
# - name: Display go version
# run: go version
# - uses: technote-space/get-diff-action@v4
# with:
# SUFFIX_FILTER: |
# **/**.go
# go.mod
# go.sum
# SET_ENV_NAME_INSERTIONS: 1
# SET_ENV_NAME_LINES: 1
# - uses: actions/[email protected]
# with:
# path: ~/go/bin
# key: ${{ runner.os }}-go-runsim-binary
# if: env.GIT_DIFF
# - name: test-sim-import-export
# run: |
# make test-sim-import-export
# if: env.GIT_DIFF

# test-sim-after-import:
# runs-on: ubuntu-latest
# needs: [build, install-runsim]
# steps:
# - uses: actions/checkout@v2
# - uses: actions/[email protected]
# with:
# go-version: 1.16
# - name: Display go version
# run: go version
# - uses: technote-space/get-diff-action@v4
# with:
# SUFFIX_FILTER: |
# **/**.go
# go.mod
# go.sum
# SET_ENV_NAME_INSERTIONS: 1
# SET_ENV_NAME_LINES: 1
# - uses: actions/[email protected]
# with:
# path: ~/go/bin
# key: ${{ runner.os }}-go-runsim-binary
# if: env.GIT_DIFF
# - name: test-sim-after-import
# run: |
# make test-sim-after-import
# if: env.GIT_DIFF
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ jobs:
done
- uses: codecov/[email protected]
with:
file: ./coverage.txt
file: ./coverage.txt
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ BINDIR ?= $(GOPATH)/bin
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf
BUILDDIR ?= $(CURDIR)/build
SIMAPP = ./app

export GO111MODULE = on

Expand Down Expand Up @@ -154,6 +155,24 @@ benchmark:

.PHONY: test test-all test-unit test-race test-cover test-build

test-sim-nondeterminism:
@echo "Running non-determinism test..."
@go test -mod=readonly $(SIMAPP) -run TestAppStateDeterminism -Enabled=true \
-NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h

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

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

.PHONY: \
test-sim-nondeterminism \
test-sim-import-export \
test-sim-after-import

###############################################################################
### Localnet ###
###############################################################################
Expand Down
15 changes: 12 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ var (
mint.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(
paramsclient.ProposalHandler, distrclient.ProposalHandler, upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler,
paramsclient.ProposalHandler, distrclient.ProposalHandler,
upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler,
farmingclient.ProposalHandler,
// todo: farming proposal handler
),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
Expand All @@ -137,7 +137,7 @@ var (
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
farmingtypes.ModuleName: nil,
farmingtypes.ModuleName: {authtypes.Minter},
// todo: farming Staking Reserve Coin TBD
}
)
Expand Down Expand Up @@ -580,6 +580,15 @@ func RegisterSwaggerAPI(ctx client.Context, rtr *mux.Router) {
rtr.PathPrefix("/swagger/").Handler(http.StripPrefix("/swagger/", staticServer))
}

// GetMaccPerms returns a copy of the module account permissions
func GetMaccPerms() map[string][]string {
dupMaccPerms := make(map[string][]string)
for k, v := range maccPerms {
dupMaccPerms[k] = v
}
return dupMaccPerms
}

// initParamsKeeper init params keeper and its subspaces
func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)
Expand Down
Loading

0 comments on commit 14db7b7

Please sign in to comment.