2019-05-18 01:42:24 -07:00
|
|
|
package simapp
|
2018-04-06 22:12:00 -07:00
|
|
|
|
|
|
|
import (
|
2020-08-13 06:20:02 -07:00
|
|
|
"encoding/json"
|
2018-07-25 14:10:07 -07:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2021-04-02 08:41:35 -07:00
|
|
|
"github.com/golang/mock/gomock"
|
2018-12-10 06:27:25 -08:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-02-10 09:49:31 -08:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
2018-12-10 06:27:25 -08:00
|
|
|
"github.com/tendermint/tendermint/libs/log"
|
2021-02-10 09:49:31 -08:00
|
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
2019-08-02 06:20:39 -07:00
|
|
|
dbm "github.com/tendermint/tm-db"
|
2018-12-10 06:27:25 -08:00
|
|
|
|
2021-02-25 02:43:31 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
2021-04-02 08:41:35 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/tests/mocks"
|
2021-02-10 09:49:31 -08:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
2021-02-25 02:43:31 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
refactor!: BaseApp {Check,Deliver}Tx with middleware design (#9920)
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->
## Description
ref: #9585
This PR if the 1st step (out of 2) in the #9585 refactor. It transforms baseapp's ABCI {Check,Deliver}Tx into middleware stacks. A middleware is defined by the following interfaces:
```go
// types/tx package
type Handler interface {
CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error)
DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error)
SimulateTx(ctx context.Context, tx sdk.Tx, req RequestSimulateTx) (ResponseSimulateTx, error)
}
type Middleware func(Handler) Handler
```
This Pr doesn't migrate antehandlers, but only baseapp's runTx and runMsgs as middlewares. It bundles antehandlers into one single middleware (for now).
More specifically, it introduces the 5 following middlewares:
| Middleware | Description |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| RunMsgsTxMiddleware | This middleware replaces the old baseapp's `runMsgs`. |
| LegacyAnteMiddleware | This middleware is temporary, it bundles all antehandlers into one middleware. It's only created for the purpose of breaking the refactor into 2 pieces. **It will be removed in Part 2**, and each antehandler will be replaced by its own middleware. |
| IndexEventsTxMiddleware | This is a simple middleware that chooses which events to index in Tendermint. Replaces `baseapp.indexEvents` (which unfortunately still exists in baseapp too, because it's used to index Begin/EndBlock events) |
| RecoveryTxMiddleware | This index recovers from panics. It replaces baseapp.runTx's panic recovery. |
| GasTxMiddleware | This replaces the [`Setup`](https://github.com/cosmos/cosmos-sdk/blob/master/x/auth/ante/setup.go) Antehandler. It sets a GasMeter on sdk.Context. Note that before, GasMeter was set on sdk.Context inside the antehandlers, and there was some mess around the fact that antehandlers had their own panic recovery system so that the GasMeter could be read by baseapp's recovery system. Now, this mess is all removed: one middleware sets GasMeter, another one handles recovery. |
---
### Author Checklist
*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*
I have...
- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [x] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed
### Reviewers Checklist
*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*
I have...
- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2021-08-25 07:40:33 -07:00
|
|
|
authmiddleware "github.com/cosmos/cosmos-sdk/x/auth/middleware"
|
2021-02-25 02:43:31 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
|
2021-05-17 08:42:44 -07:00
|
|
|
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
|
2021-04-02 08:41:35 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
2021-02-25 02:43:31 -08:00
|
|
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/capability"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/crisis"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/distribution"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/evidence"
|
2021-05-07 00:10:47 -07:00
|
|
|
feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module"
|
2021-02-25 02:43:31 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/genutil"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/gov"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/mint"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/params"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/slashing"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/upgrade"
|
2018-04-06 22:12:00 -07:00
|
|
|
)
|
|
|
|
|
2021-01-06 07:20:12 -08:00
|
|
|
func TestSimAppExportAndBlockedAddrs(t *testing.T) {
|
|
|
|
encCfg := MakeTestEncodingConfig()
|
2019-08-02 06:20:39 -07:00
|
|
|
db := dbm.NewMemDB()
|
2021-09-15 14:18:01 -07:00
|
|
|
app := NewSimappWithCustomOptions(t, false, SetupOptions{
|
|
|
|
Logger: log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
|
|
|
|
DB: db,
|
|
|
|
InvCheckPeriod: 0,
|
|
|
|
EncConfig: encCfg,
|
|
|
|
HomePath: DefaultNodeHome,
|
|
|
|
SkipUpgradeHeights: map[int64]bool{},
|
|
|
|
AppOpts: EmptyAppOptions{},
|
|
|
|
})
|
2018-04-06 22:12:00 -07:00
|
|
|
|
2021-01-06 07:20:12 -08:00
|
|
|
for acc := range maccPerms {
|
2021-03-10 14:31:21 -08:00
|
|
|
require.True(
|
|
|
|
t,
|
|
|
|
app.BankKeeper.BlockedAddr(app.AccountKeeper.GetModuleAddress(acc)),
|
|
|
|
"ensure that blocked addresses are properly set in bank keeper",
|
|
|
|
)
|
2021-01-06 07:20:12 -08:00
|
|
|
}
|
|
|
|
|
2019-05-18 01:42:24 -07:00
|
|
|
app.Commit()
|
2019-06-05 16:26:17 -07:00
|
|
|
|
|
|
|
// Making a new app object with the db, so that initchain hasn't been called
|
2021-01-06 07:20:12 -08:00
|
|
|
app2 := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{})
|
2021-09-15 14:18:01 -07:00
|
|
|
_, err := app2.ExportAppStateAndValidators(false, []string{})
|
2019-06-05 16:26:17 -07:00
|
|
|
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
|
2018-04-06 22:12:00 -07:00
|
|
|
}
|
2019-08-13 13:59:01 -07:00
|
|
|
|
|
|
|
func TestGetMaccPerms(t *testing.T) {
|
|
|
|
dup := GetMaccPerms()
|
|
|
|
require.Equal(t, maccPerms, dup, "duplicated module account permissions differed from actual module account permissions")
|
|
|
|
}
|
2021-02-10 09:49:31 -08:00
|
|
|
|
|
|
|
func TestRunMigrations(t *testing.T) {
|
|
|
|
db := dbm.NewMemDB()
|
|
|
|
encCfg := MakeTestEncodingConfig()
|
2021-02-25 02:43:31 -08:00
|
|
|
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
|
|
|
|
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{})
|
|
|
|
|
|
|
|
// Create a new baseapp and configurator for the purpose of this test.
|
|
|
|
bApp := baseapp.NewBaseApp(appName, logger, db, encCfg.TxConfig.TxDecoder())
|
|
|
|
bApp.SetCommitMultiStoreTracer(nil)
|
|
|
|
bApp.SetInterfaceRegistry(encCfg.InterfaceRegistry)
|
refactor!: BaseApp {Check,Deliver}Tx with middleware design (#9920)
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->
## Description
ref: #9585
This PR if the 1st step (out of 2) in the #9585 refactor. It transforms baseapp's ABCI {Check,Deliver}Tx into middleware stacks. A middleware is defined by the following interfaces:
```go
// types/tx package
type Handler interface {
CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error)
DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error)
SimulateTx(ctx context.Context, tx sdk.Tx, req RequestSimulateTx) (ResponseSimulateTx, error)
}
type Middleware func(Handler) Handler
```
This Pr doesn't migrate antehandlers, but only baseapp's runTx and runMsgs as middlewares. It bundles antehandlers into one single middleware (for now).
More specifically, it introduces the 5 following middlewares:
| Middleware | Description |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| RunMsgsTxMiddleware | This middleware replaces the old baseapp's `runMsgs`. |
| LegacyAnteMiddleware | This middleware is temporary, it bundles all antehandlers into one middleware. It's only created for the purpose of breaking the refactor into 2 pieces. **It will be removed in Part 2**, and each antehandler will be replaced by its own middleware. |
| IndexEventsTxMiddleware | This is a simple middleware that chooses which events to index in Tendermint. Replaces `baseapp.indexEvents` (which unfortunately still exists in baseapp too, because it's used to index Begin/EndBlock events) |
| RecoveryTxMiddleware | This index recovers from panics. It replaces baseapp.runTx's panic recovery. |
| GasTxMiddleware | This replaces the [`Setup`](https://github.com/cosmos/cosmos-sdk/blob/master/x/auth/ante/setup.go) Antehandler. It sets a GasMeter on sdk.Context. Note that before, GasMeter was set on sdk.Context inside the antehandlers, and there was some mess around the fact that antehandlers had their own panic recovery system so that the GasMeter could be read by baseapp's recovery system. Now, this mess is all removed: one middleware sets GasMeter, another one handles recovery. |
---
### Author Checklist
*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*
I have...
- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [x] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed
### Reviewers Checklist
*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*
I have...
- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2021-08-25 07:40:33 -07:00
|
|
|
msr := authmiddleware.NewMsgServiceRouter(encCfg.InterfaceRegistry)
|
2021-02-25 02:43:31 -08:00
|
|
|
app.BaseApp = bApp
|
refactor!: BaseApp {Check,Deliver}Tx with middleware design (#9920)
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->
## Description
ref: #9585
This PR if the 1st step (out of 2) in the #9585 refactor. It transforms baseapp's ABCI {Check,Deliver}Tx into middleware stacks. A middleware is defined by the following interfaces:
```go
// types/tx package
type Handler interface {
CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error)
DeliverTx(ctx context.Context, tx sdk.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error)
SimulateTx(ctx context.Context, tx sdk.Tx, req RequestSimulateTx) (ResponseSimulateTx, error)
}
type Middleware func(Handler) Handler
```
This Pr doesn't migrate antehandlers, but only baseapp's runTx and runMsgs as middlewares. It bundles antehandlers into one single middleware (for now).
More specifically, it introduces the 5 following middlewares:
| Middleware | Description |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| RunMsgsTxMiddleware | This middleware replaces the old baseapp's `runMsgs`. |
| LegacyAnteMiddleware | This middleware is temporary, it bundles all antehandlers into one middleware. It's only created for the purpose of breaking the refactor into 2 pieces. **It will be removed in Part 2**, and each antehandler will be replaced by its own middleware. |
| IndexEventsTxMiddleware | This is a simple middleware that chooses which events to index in Tendermint. Replaces `baseapp.indexEvents` (which unfortunately still exists in baseapp too, because it's used to index Begin/EndBlock events) |
| RecoveryTxMiddleware | This index recovers from panics. It replaces baseapp.runTx's panic recovery. |
| GasTxMiddleware | This replaces the [`Setup`](https://github.com/cosmos/cosmos-sdk/blob/master/x/auth/ante/setup.go) Antehandler. It sets a GasMeter on sdk.Context. Note that before, GasMeter was set on sdk.Context inside the antehandlers, and there was some mess around the fact that antehandlers had their own panic recovery system so that the GasMeter could be read by baseapp's recovery system. Now, this mess is all removed: one middleware sets GasMeter, another one handles recovery. |
---
### Author Checklist
*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*
I have...
- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [x] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed
### Reviewers Checklist
*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*
I have...
- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2021-08-25 07:40:33 -07:00
|
|
|
app.configurator = module.NewConfigurator(app.appCodec, msr, app.GRPCQueryRouter())
|
2021-02-10 09:49:31 -08:00
|
|
|
|
2021-02-25 02:43:31 -08:00
|
|
|
// We register all modules on the Configurator, except x/bank. x/bank will
|
|
|
|
// serve as the test subject on which we run the migration tests.
|
|
|
|
//
|
|
|
|
// The loop below is the same as calling `RegisterServices` on
|
|
|
|
// ModuleManager, except that we skip x/bank.
|
|
|
|
for _, module := range app.mm.Modules {
|
|
|
|
if module.Name() == banktypes.ModuleName {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
module.RegisterServices(app.configurator)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the chain
|
|
|
|
app.InitChain(abci.RequestInitChain{})
|
|
|
|
app.Commit()
|
|
|
|
|
2021-02-10 09:49:31 -08:00
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
moduleName string
|
|
|
|
forVersion uint64
|
|
|
|
expRegErr bool // errors while registering migration
|
|
|
|
expRegErrMsg string
|
|
|
|
expRunErr bool // errors while running migration
|
|
|
|
expRunErrMsg string
|
|
|
|
expCalled int
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"cannot register migration for version 0",
|
|
|
|
"bank", 0,
|
|
|
|
true, "module migration versions should start at 1: invalid version", false, "", 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"throws error on RunMigrations if no migration registered for bank",
|
|
|
|
"", 1,
|
|
|
|
false, "", true, "no migrations found for module bank: not found", 0,
|
|
|
|
},
|
|
|
|
{
|
2021-07-26 10:51:04 -07:00
|
|
|
"can register 1->2 migration handler for x/bank, cannot run migration",
|
2021-02-10 09:49:31 -08:00
|
|
|
"bank", 1,
|
2021-07-26 10:51:04 -07:00
|
|
|
false, "", true, "no migration found for module bank from version 2 to version 3: not found", 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"can register 2->3 migration handler for x/bank, can run migration",
|
|
|
|
"bank", 2,
|
2021-02-10 09:49:31 -08:00
|
|
|
false, "", false, "", 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cannot register migration handler for same module & forVersion",
|
|
|
|
"bank", 1,
|
|
|
|
true, "another migration for module bank and version 1 already exists: internal logic error", false, "", 0,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
// Since it's very hard to test actual in-place store migrations in
|
2021-02-19 07:02:53 -08:00
|
|
|
// tests (due to the difficulty of maintaining multiple versions of a
|
2021-02-10 09:49:31 -08:00
|
|
|
// module), we're just testing here that the migration logic is
|
|
|
|
// called.
|
|
|
|
called := 0
|
|
|
|
|
|
|
|
if tc.moduleName != "" {
|
|
|
|
// Register migration for module from version `forVersion` to `forVersion+1`.
|
|
|
|
err = app.configurator.RegisterMigration(tc.moduleName, tc.forVersion, func(sdk.Context) error {
|
|
|
|
called++
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
if tc.expRegErr {
|
|
|
|
require.EqualError(t, err, tc.expRegErrMsg)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-02-25 02:43:31 -08:00
|
|
|
// Run migrations only for bank. That's why we put the initial
|
|
|
|
// version for bank as 1, and for all other modules, we put as
|
|
|
|
// their latest ConsensusVersion.
|
2021-04-02 08:41:35 -07:00
|
|
|
_, err = app.mm.RunMigrations(
|
|
|
|
app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}), app.configurator,
|
2021-03-19 15:01:29 -07:00
|
|
|
module.VersionMap{
|
2021-02-25 02:43:31 -08:00
|
|
|
"bank": 1,
|
|
|
|
"auth": auth.AppModule{}.ConsensusVersion(),
|
2021-05-17 08:42:44 -07:00
|
|
|
"authz": authzmodule.AppModule{}.ConsensusVersion(),
|
2021-02-25 02:43:31 -08:00
|
|
|
"staking": staking.AppModule{}.ConsensusVersion(),
|
|
|
|
"mint": mint.AppModule{}.ConsensusVersion(),
|
|
|
|
"distribution": distribution.AppModule{}.ConsensusVersion(),
|
|
|
|
"slashing": slashing.AppModule{}.ConsensusVersion(),
|
|
|
|
"gov": gov.AppModule{}.ConsensusVersion(),
|
|
|
|
"params": params.AppModule{}.ConsensusVersion(),
|
|
|
|
"upgrade": upgrade.AppModule{}.ConsensusVersion(),
|
|
|
|
"vesting": vesting.AppModule{}.ConsensusVersion(),
|
2021-05-07 00:10:47 -07:00
|
|
|
"feegrant": feegrantmodule.AppModule{}.ConsensusVersion(),
|
2021-02-25 02:43:31 -08:00
|
|
|
"evidence": evidence.AppModule{}.ConsensusVersion(),
|
|
|
|
"crisis": crisis.AppModule{}.ConsensusVersion(),
|
|
|
|
"genutil": genutil.AppModule{}.ConsensusVersion(),
|
|
|
|
"capability": capability.AppModule{}.ConsensusVersion(),
|
2021-02-10 09:49:31 -08:00
|
|
|
},
|
|
|
|
)
|
|
|
|
if tc.expRunErr {
|
|
|
|
require.EqualError(t, err, tc.expRunErrMsg)
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
2021-04-02 08:41:35 -07:00
|
|
|
// Make sure bank's migration is called.
|
2021-02-10 09:49:31 -08:00
|
|
|
require.Equal(t, tc.expCalled, called)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2021-03-19 15:01:29 -07:00
|
|
|
|
2021-04-02 08:41:35 -07:00
|
|
|
func TestInitGenesisOnMigration(t *testing.T) {
|
|
|
|
db := dbm.NewMemDB()
|
|
|
|
encCfg := MakeTestEncodingConfig()
|
|
|
|
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
|
|
|
|
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{})
|
|
|
|
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
|
|
|
|
|
|
|
|
// Create a mock module. This module will serve as the new module we're
|
|
|
|
// adding during a migration.
|
|
|
|
mockCtrl := gomock.NewController(t)
|
|
|
|
t.Cleanup(mockCtrl.Finish)
|
|
|
|
mockModule := mocks.NewMockAppModule(mockCtrl)
|
|
|
|
mockDefaultGenesis := json.RawMessage(`{"key": "value"}`)
|
|
|
|
mockModule.EXPECT().DefaultGenesis(gomock.Eq(app.appCodec)).Times(1).Return(mockDefaultGenesis)
|
|
|
|
mockModule.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(app.appCodec), gomock.Eq(mockDefaultGenesis)).Times(1).Return(nil)
|
2021-05-25 02:18:59 -07:00
|
|
|
mockModule.EXPECT().ConsensusVersion().Times(1).Return(uint64(0))
|
2021-04-02 08:41:35 -07:00
|
|
|
|
|
|
|
app.mm.Modules["mock"] = mockModule
|
|
|
|
|
2021-04-13 12:00:04 -07:00
|
|
|
// Run migrations only for "mock" module. We exclude it from
|
|
|
|
// the VersionMap to simulate upgrading with a new module.
|
2021-04-02 08:41:35 -07:00
|
|
|
_, err := app.mm.RunMigrations(ctx, app.configurator,
|
|
|
|
module.VersionMap{
|
|
|
|
"bank": bank.AppModule{}.ConsensusVersion(),
|
|
|
|
"auth": auth.AppModule{}.ConsensusVersion(),
|
2021-05-17 08:42:44 -07:00
|
|
|
"authz": authzmodule.AppModule{}.ConsensusVersion(),
|
2021-04-02 08:41:35 -07:00
|
|
|
"staking": staking.AppModule{}.ConsensusVersion(),
|
|
|
|
"mint": mint.AppModule{}.ConsensusVersion(),
|
|
|
|
"distribution": distribution.AppModule{}.ConsensusVersion(),
|
|
|
|
"slashing": slashing.AppModule{}.ConsensusVersion(),
|
|
|
|
"gov": gov.AppModule{}.ConsensusVersion(),
|
|
|
|
"params": params.AppModule{}.ConsensusVersion(),
|
|
|
|
"upgrade": upgrade.AppModule{}.ConsensusVersion(),
|
|
|
|
"vesting": vesting.AppModule{}.ConsensusVersion(),
|
2021-05-07 00:10:47 -07:00
|
|
|
"feegrant": feegrantmodule.AppModule{}.ConsensusVersion(),
|
2021-04-02 08:41:35 -07:00
|
|
|
"evidence": evidence.AppModule{}.ConsensusVersion(),
|
|
|
|
"crisis": crisis.AppModule{}.ConsensusVersion(),
|
|
|
|
"genutil": genutil.AppModule{}.ConsensusVersion(),
|
|
|
|
"capability": capability.AppModule{}.ConsensusVersion(),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2021-03-19 15:01:29 -07:00
|
|
|
func TestUpgradeStateOnGenesis(t *testing.T) {
|
|
|
|
encCfg := MakeTestEncodingConfig()
|
|
|
|
db := dbm.NewMemDB()
|
2021-09-15 14:18:01 -07:00
|
|
|
app := NewSimappWithCustomOptions(t, false, SetupOptions{
|
|
|
|
Logger: log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
|
|
|
|
DB: db,
|
|
|
|
InvCheckPeriod: 0,
|
|
|
|
EncConfig: encCfg,
|
|
|
|
HomePath: DefaultNodeHome,
|
|
|
|
SkipUpgradeHeights: map[int64]bool{},
|
|
|
|
AppOpts: EmptyAppOptions{},
|
|
|
|
})
|
2021-03-19 15:01:29 -07:00
|
|
|
|
|
|
|
// make sure the upgrade keeper has version map in state
|
|
|
|
ctx := app.NewContext(false, tmproto.Header{})
|
|
|
|
vm := app.UpgradeKeeper.GetModuleVersionMap(ctx)
|
|
|
|
for v, i := range app.mm.Modules {
|
|
|
|
require.Equal(t, vm[v], i.ConsensusVersion())
|
|
|
|
}
|
|
|
|
}
|