Skip to content

Commit

Permalink
Merge branch 'upgrade/cosmos46' of https://github.com/terra-money/core
Browse files Browse the repository at this point in the history
…into upgrade/cosmos46
  • Loading branch information
emidev98 committed Mar 17, 2023
2 parents 751fa31 + 3a44e93 commit 35afa41
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 10 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,14 @@ jobs:
file: ./coverage.txt # optional
fail_ci_if_error: true
if: "env.GIT_DIFF != ''"

test-simulation:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: 1.20.0
- uses: actions/checkout@v3
- name: simulate
run: |
make simulate
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ test-cover:
benchmark:
@go test -mod=readonly -bench=. ./...

.PHONY: test test-all test-cover test-unit test-race
simulate:
@go test -bench BenchmarkSimulation ./app -NumBlocks=200 -BlockSize 50 -Commit=true -Verbose=true -Enabled=true -Seed 1

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

###############################################################################
### Linting ###
Expand Down
44 changes: 38 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"path/filepath"
"strings"

authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"

"github.com/terra-money/core/v2/app/rpc"

"github.com/gorilla/mux"
Expand Down Expand Up @@ -425,7 +427,7 @@ func NewTerraApp(
appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms, terraappconfig.AccountAddressPrefix,
)
app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.BlockedModuleAccountAddrs(),
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.ModuleAccountAddrs(),
)
stakingKeeper := stakingkeeper.NewKeeper(
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName),
Expand Down Expand Up @@ -550,10 +552,8 @@ func NewTerraApp(
scopedICAHostKeeper,
app.MsgServiceRouter(),
)
icaModule := ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper)

app.InterTxKeeper = intertxkeeper.NewKeeper(appCodec, keys[intertxtypes.StoreKey], app.ICAControllerKeeper, scopedInterTxKeeper)
interTxModule := intertx.NewAppModule(appCodec, app.InterTxKeeper)
interTxIBCModule := intertx.NewIBCModule(app.InterTxKeeper)

icaControllerIBCModule := icacontroller.NewIBCMiddleware(interTxIBCModule, app.ICAControllerKeeper)
Expand Down Expand Up @@ -673,8 +673,8 @@ func NewTerraApp(
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
ibctransfer.NewAppModule(app.TransferKeeper),
ibcfee.NewAppModule(app.IBCFeeKeeper),
icaModule,
interTxModule,
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),
intertx.NewAppModule(appCodec, app.InterTxKeeper),
router.NewAppModule(&app.RouterKeeper),
// this line is used by starport scaffolding # stargate/app/appModule
wasm.NewAppModule(appCodec, &app.wasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
Expand Down Expand Up @@ -896,7 +896,7 @@ func (app *TerraApp) LoadHeight(height int64) error {
}

// ModuleAccountAddrs returns all the app's module account addresses.
func (app *TerraApp) BlockedModuleAccountAddrs() map[string]bool {
func (app *TerraApp) ModuleAccountAddrs() map[string]bool {
modAccAddrs := make(map[string]bool)
for acc := range maccPerms {
modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true
Expand Down Expand Up @@ -1122,3 +1122,35 @@ func (app *TerraApp) enforceStakingForVestingTokens(ctx sdk.Context, genesisStat
}
}
}

func (app *TerraApp) SimulationManager() *module.SimulationManager {
appCodec := app.appCodec
// create the simulation manager and define the order of the modules for deterministic simulations
sm := module.NewSimulationManager(
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, minttypes.DefaultInflationCalculationFn),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
params.NewAppModule(app.ParamsKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
ibc.NewAppModule(app.IBCKeeper),
ibctransfer.NewAppModule(app.TransferKeeper),
ibcfee.NewAppModule(app.IBCFeeKeeper),
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),
router.NewAppModule(&app.RouterKeeper),
wasm.NewAppModule(appCodec, &app.wasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
tokenfactory.NewAppModule(app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper),
alliance.NewAppModule(appCodec, app.AllianceKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
// does not implement simulation
// intertx.NewAppModule(appCodec, app.InterTxKeeper),
// ibchooks.NewAppModule(app.AccountKeeper),
)
sm.RegisterStoreDecoders()
return sm
}
114 changes: 114 additions & 0 deletions app/simulation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package app_test

import (
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"
"os"
"testing"

"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/terra-money/core/v2/app"
"github.com/terra-money/core/v2/app/wasmconfig"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simulationtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
)

func init() {
simapp.GetSimulatorFlags()
}

type SimApp interface {
app.TerraApp
GetBaseApp() *baseapp.BaseApp
AppCodec() codec.Codec
SimulationManager() *module.SimulationManager
ModuleAccountAddrs() map[string]bool
Name() string
LegacyAmino() *codec.LegacyAmino
BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock
EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock
InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain
}

// 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`
func BenchmarkSimulation(b *testing.B) {
simapp.FlagEnabledValue = true
simapp.FlagCommitValue = true

config, db, dir, logger, _, err := simapp.SetupSimulation("goleveldb-app-sim", "Simulation")
require.NoError(b, err, "simulation setup failed")

b.Cleanup(func() {
db.Close()
err = os.RemoveAll(dir)
require.NoError(b, err)
})

encoding := app.MakeEncodingConfig()

simApp := app.NewTerraApp(
logger,
db,
nil,
true,
map[int64]bool{},
app.DefaultNodeHome,
0,
encoding,
simapp.EmptyAppOptions{},
wasmconfig.DefaultConfig(),
)

// Run randomized simulations
_, simParams, simErr := simulation.SimulateFromSeed(
b,
os.Stdout,
simApp.BaseApp,
simapp.AppStateFn(simApp.AppCodec(), simApp.SimulationManager()),
simulationtypes.RandomAccounts,
simapp.SimulationOperations(simApp, simApp.AppCodec(), config),
simApp.ModuleAccountAddrs(),
config,
simApp.AppCodec(),
)

// export state and simParams before the simulation error is checked
err = simapp.CheckExportSimulation(simApp, config, simParams)
require.NoError(b, err)
require.NoError(b, simErr)

if config.Commit {
simapp.PrintStats(db)
}
}

func TestSimulationManager(t *testing.T) {
db := dbm.NewMemDB()
encoding := app.MakeEncodingConfig()

simApp := app.NewTerraApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db,
nil,
true,
map[int64]bool{},
app.DefaultNodeHome,
0,
encoding,
simapp.EmptyAppOptions{},
wasmconfig.DefaultConfig(),
)
sm := simApp.SimulationManager()
require.NotNil(t, sm)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ require (
replace (
github.com/CosmWasm/wasmd => github.com/notional-labs/wasmd v0.30.0-sdk469.4
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk => github.com/terra-money/cosmos-sdk v0.46.11-terra.rc.3
github.com/cosmos/cosmos-sdk => github.com/terra-money/cosmos-sdk v0.46.11-terra.rc.5
github.com/cosmos/ledger-cosmos-go => github.com/terra-money/ledger-terra-go v0.11.2
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/tendermint/tendermint => github.com/terra-money/tendermint v0.34.27-terra.rc.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,8 @@ github.com/tendermint/tm-db v0.6.8-0.20221109095132-774cdfe7e6b0 h1:mQuaSKG8GtmA
github.com/tendermint/tm-db v0.6.8-0.20221109095132-774cdfe7e6b0/go.mod h1:J/0Izsq+rOsOHxSD2dirEhtpB576Fo5iyz0eTn26TBs=
github.com/terra-money/alliance v0.1.0-beta1 h1:hfESA38+PwGGlQMK7GggIfVda3fTD5VsPrnA8AM+7WM=
github.com/terra-money/alliance v0.1.0-beta1/go.mod h1:/bcf84Eq6y1SYKUCZU8erraD69Kjy0fdadlygb01Q5U=
github.com/terra-money/cosmos-sdk v0.46.11-terra.rc.3 h1:P2r5JewLSojn6zzUvNoKgO4Bn2rIYxoCtorFpGd8HEk=
github.com/terra-money/cosmos-sdk v0.46.11-terra.rc.3/go.mod h1:fo6GsbfWOIzaIzd+AiYYzOOIYjLkCJvjAv3CQCKfgRw=
github.com/terra-money/cosmos-sdk v0.46.11-terra.rc.5 h1:kjtBJvryUFrxg7LUHW8SDQrO9+J+0GBJABDZzwNBJD4=
github.com/terra-money/cosmos-sdk v0.46.11-terra.rc.5/go.mod h1:fo6GsbfWOIzaIzd+AiYYzOOIYjLkCJvjAv3CQCKfgRw=
github.com/terra-money/ledger-terra-go v0.11.2 h1:BVXZl+OhJOri6vFNjjVaTabRLApw9MuG7mxWL4V718c=
github.com/terra-money/ledger-terra-go v0.11.2/go.mod h1:ClJ2XMj1ptcnONzKH+GhVPi7Y8pXIT+UzJ0TNt0tfZE=
github.com/terra-money/tendermint v0.34.27-terra.rc.1 h1:GxhSoJauC3Z3lwaXWR/YEjw9Hd93EA5D4o3wdtw+09w=
Expand Down

0 comments on commit 35afa41

Please sign in to comment.