Skip to content

Commit

Permalink
feat: add x/group simulations (#251)
Browse files Browse the repository at this point in the history
* test

* Add simulation workflow

* setup simulations

* fix lint

* lint

* update workflow

* lint

* delete proto files

* make proto-gen

* add more sim tests

* fix test

* add operations

* WIP

* add weighted operations

* fix errors

* Update x/group/module/module.go

* WIP

* delete unused files

* WIP

* WIP

* fix lint issues

* fix lint issues

* fix create group account simulation

* add more weighted operations

* add more weighted operations

* refactor

* add weighted operations

* fix tests

* cleanup

* build flags

* fix build

* add build flags to simulations

* update sims.mk

* code format

* add pagination to groups

* review changes

* review changes

* review changes

* review changes

* add query groups tests

* review changes

* remove unused files

* review changes

* fix lint issue

* remove query all groups

* review changes

* go.mod

* fix error

* run make proto-gen

* fix errors

* fix lint error

* WIP group genesis simulation

* register group simulations

* add group accounts & proposals

* add random votes

* update doc

* run make proto-gen

* feat: add genesis simulation log

* review changes

* fix: lint error

* Update x/group/simulation/genesis.go

Co-authored-by: Anil Kumar Kammari <[email protected]>

* Update x/group/simulation/genesis.go

Co-authored-by: Anil Kumar Kammari <[email protected]>

* Update x/group/simulation/genesis.go

Co-authored-by: Anil Kumar Kammari <[email protected]>

* review changes

* try setup separate simulation jobs

* add build flags to simulations

* randomize votes

* update simulations jobs

* update simulation jobs

* test github action custom env variable

* add experimental flag to simulation actions

* add description to weights

* review changes

* Update x/group/module/module.go

Co-authored-by: Anil Kumar Kammari <[email protected]>

* review changes

* try fixing simulations

* fix simulations

Co-authored-by: Anil Kumar Kammari <[email protected]>
  • Loading branch information
aleem1314 and anilcse authored May 11, 2021
1 parent 40e2a34 commit efcc268
Show file tree
Hide file tree
Showing 20 changed files with 2,416 additions and 867 deletions.
284 changes: 284 additions & 0 deletions .github/workflows/sims.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
name: Sims
# Sims workflow runs multiple types of simulations (nondeterminism, import-export, after-import, multi-seed-short)
# This workflow will run on all Pull Requests, if a .go, .mod or .sum file have been changed
on:
pull_request:
push:
branches:
- master

jobs:
cleanup-runs:
runs-on: ubuntu-latest
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/master'"
steps:
- uses: rokroskar/workflow-run-cleanup-action@master
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

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.15
- 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.15
- 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

# experimental simulations
sim-nondeterminism-experimental:
runs-on: ubuntu-latest
needs: [build, install-runsim]
env:
EXPERIMENTAL: true
steps:
- uses: actions/checkout@v2
- uses: actions/[email protected]
with:
go-version: 1.15
- 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: sim-nondeterminism-experimental
run: |
make sim-regen-nondeterminism
if: env.GIT_DIFF

sim-import-export-experimental:
runs-on: ubuntu-latest
needs: [build, install-runsim]
env:
EXPERIMENTAL: true
steps:
- uses: actions/checkout@v2
- uses: actions/[email protected]
with:
go-version: 1.15
- 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: sim-import-export-experimental
run: |
make sim-regen-import-export
if: env.GIT_DIFF

sim-after-import-experimental:
runs-on: ubuntu-latest
needs: [build, install-runsim]
env:
EXPERIMENTAL: true
steps:
- uses: actions/checkout@v2
- uses: actions/[email protected]
with:
go-version: 1.15
- 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: sim-after-import-experimental
run: |
make sim-regen-after-import
if: env.GIT_DIFF

sim-fullapp-experimental:
runs-on: ubuntu-latest
needs: [build, install-runsim]
env:
EXPERIMENTAL: true
steps:
- uses: actions/checkout@v2
- uses: actions/[email protected]
with:
go-version: 1.15
- 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: sim-fullapp-experimental
run: |
make sim-regen-fast
if: env.GIT_DIFF


# stable simulation jobs
sim-nondeterminism-stable:
runs-on: ubuntu-latest
needs: [build, install-runsim]
env:
EXPERIMENTAL: false
steps:
- uses: actions/checkout@v2
- uses: actions/[email protected]
with:
go-version: 1.15
- 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: sim-nondeterminism-stable
run: |
make sim-regen-nondeterminism
if: env.GIT_DIFF

sim-import-export-stable:
runs-on: ubuntu-latest
needs: [build, install-runsim]
env:
EXPERIMENTAL: false
steps:
- uses: actions/checkout@v2
- uses: actions/[email protected]
with:
go-version: 1.15
- 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: sim-import-export-stable
run: |
make sim-regen-import-export
if: env.GIT_DIFF

sim-after-import-stable:
runs-on: ubuntu-latest
needs: [build, install-runsim]
env:
EXPERIMENTAL: false
steps:
- uses: actions/checkout@v2
- uses: actions/[email protected]
with:
go-version: 1.15
- 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: sim-after-import-stable
run: |
make sim-regen-after-import
if: env.GIT_DIFF

sim-fullapp-stable:
runs-on: ubuntu-latest
needs: [build, install-runsim]
env:
EXPERIMENTAL: false
steps:
- uses: actions/checkout@v2
- uses: actions/[email protected]
with:
go-version: 1.15
- 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: sim-fullapp-stable
run: |
make sim-regen-fast
if: env.GIT_DIFF
3 changes: 3 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/simapp"
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
Expand Down Expand Up @@ -89,6 +90,8 @@ const (
appName = "regen"
)

var _ simapp.App = &RegenApp{}

var (
// DefaultNodeHome default home directories for regen
DefaultNodeHome = os.ExpandEnv("$HOME/.regen")
Expand Down
11 changes: 8 additions & 3 deletions app/experimental_appconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry)
/* New Module Wiring START */
newModuleManager := server.NewManager(app.BaseApp, codec.NewProtoCodec(interfaceRegistry))

// BEGIN HACK: this is a total, ugly hack until x/auth supports ADR 033 or we have a suitable alternative
groupModule := group.Module{AccountKeeper: app.AccountKeeper}
// BEGIN HACK: this is a total, ugly hack until x/auth & x/bank supports ADR 033 or we have a suitable alternative
groupModule := group.Module{AccountKeeper: app.AccountKeeper, BankKeeper: app.BankKeeper}
// use a separate newModules from the global NewModules here because we need to pass state into the group module
newModules := []moduletypes.Module{
ecocredit.Module{},
Expand All @@ -97,8 +97,8 @@ func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry)
panic(err)
}

return newModuleManager
/* New Module Wiring END */
return newModuleManager
}

func (app *RegenApp) registerUpgradeHandlers() {
Expand All @@ -122,6 +122,11 @@ func setCustomOrderInitGenesis() []string {
func (app *RegenApp) setCustomSimulationManager() []module.AppModuleSimulation {
return []module.AppModuleSimulation{
wasm.NewAppModule(&app.wasmKeeper, app.StakingKeeper),
group.Module{
Registry: app.interfaceRegistry,
BankKeeper: app.BankKeeper,
AccountKeeper: app.AccountKeeper,
},
}
}

Expand Down
8 changes: 4 additions & 4 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import (
"os"
"testing"

"github.com/cosmos/cosmos-sdk/simapp"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/simapp/helpers"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
Expand Down Expand Up @@ -90,7 +90,7 @@ func simulateFromSeed(t *testing.T, app *RegenApp, config simtypes.Config) (bool
t, os.Stdout, app.BaseApp,
simapp.AppStateFn(app.AppCodec(), app.SimulationManager()),
simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
simapp.SimulationOperations(app, app.AppCodec(), config),
SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
app.AppCodec(),
Expand Down Expand Up @@ -244,7 +244,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
newApp.BaseApp,
simapp.AppStateFn(app.AppCodec(), app.SimulationManager()),
simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
simapp.SimulationOperations(newApp, newApp.AppCodec(), config),
SimulationOperations(newApp, newApp.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
app.appCodec,
Expand Down
Loading

0 comments on commit efcc268

Please sign in to comment.