fix(cli): Resolve problem with assert-invariants cmd (#1624)

* remove no-op migrate command

* move assert-invariants from migrate -> cmd

* fix: don't modify validators for assert-invariants

Makes validator addition in TestApp initialization optional.

* update changelog
This commit is contained in:
Robert Pirtle 2023-06-09 16:52:52 -07:00 committed by GitHub
parent 230ad734a1
commit 49812b6e7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 89 deletions

View File

@ -55,6 +55,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
NOTE: no changes were made to existing Msg names (`MsgConvertCoinToERC20` & `MsgConvertERC20ToCoin`) NOTE: no changes were made to existing Msg names (`MsgConvertCoinToERC20` & `MsgConvertERC20ToCoin`)
- `convert-erc20-to-coin` -> `convert-evm-erc20-to-coin` - `convert-erc20-to-coin` -> `convert-evm-erc20-to-coin`
- `convert-coin-to-erc20` -> `convert-evm-erc20-from-coin` - `convert-coin-to-erc20` -> `convert-evm-erc20-from-coin`
- (cli) [#1624] Removes unused, no-op `migrate` CLI command.
### Bug Fixes
- (cli) [#1624] Fix `assert-invariants` CLI command.
## [v0.23.2] ## [v0.23.2]
@ -264,6 +268,7 @@ the [changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.38.4/CHANGELOG.md).
- [#257](https://github.com/Kava-Labs/kava/pulls/257) Include scripts to run - [#257](https://github.com/Kava-Labs/kava/pulls/257) Include scripts to run
large-scale simulations remotely using aws-batch large-scale simulations remotely using aws-batch
[#1624]: https://github.com/Kava-Labs/kava/pull/1624
[#1622]: https://github.com/Kava-Labs/kava/pull/1622 [#1622]: https://github.com/Kava-Labs/kava/pull/1622
[#1614]: https://github.com/Kava-Labs/kava/pull/1614 [#1614]: https://github.com/Kava-Labs/kava/pull/1614
[#1610]: https://github.com/Kava-Labs/kava/pull/1610 [#1610]: https://github.com/Kava-Labs/kava/pull/1610

View File

@ -275,19 +275,19 @@ func genesisStateWithValSet(
// InitializeFromGenesisStates calls InitChain on the app using the provided genesis states. // InitializeFromGenesisStates calls InitChain on the app using the provided genesis states.
// If any module genesis states are missing, defaults are used. // If any module genesis states are missing, defaults are used.
func (tApp TestApp) InitializeFromGenesisStates(genesisStates ...GenesisState) TestApp { func (tApp TestApp) InitializeFromGenesisStates(genesisStates ...GenesisState) TestApp {
return tApp.InitializeFromGenesisStatesWithTimeAndChainIDAndHeight(emptyTime, testChainID, defaultInitialHeight, genesisStates...) return tApp.InitializeFromGenesisStatesWithTimeAndChainIDAndHeight(emptyTime, testChainID, defaultInitialHeight, true, genesisStates...)
} }
// InitializeFromGenesisStatesWithTime calls InitChain on the app using the provided genesis states and time. // InitializeFromGenesisStatesWithTime calls InitChain on the app using the provided genesis states and time.
// If any module genesis states are missing, defaults are used. // If any module genesis states are missing, defaults are used.
func (tApp TestApp) InitializeFromGenesisStatesWithTime(genTime time.Time, genesisStates ...GenesisState) TestApp { func (tApp TestApp) InitializeFromGenesisStatesWithTime(genTime time.Time, genesisStates ...GenesisState) TestApp {
return tApp.InitializeFromGenesisStatesWithTimeAndChainIDAndHeight(genTime, testChainID, defaultInitialHeight, genesisStates...) return tApp.InitializeFromGenesisStatesWithTimeAndChainIDAndHeight(genTime, testChainID, defaultInitialHeight, true, genesisStates...)
} }
// InitializeFromGenesisStatesWithTimeAndChainID calls InitChain on the app using the provided genesis states, time, and chain id. // InitializeFromGenesisStatesWithTimeAndChainID calls InitChain on the app using the provided genesis states, time, and chain id.
// If any module genesis states are missing, defaults are used. // If any module genesis states are missing, defaults are used.
func (tApp TestApp) InitializeFromGenesisStatesWithTimeAndChainID(genTime time.Time, chainID string, genesisStates ...GenesisState) TestApp { func (tApp TestApp) InitializeFromGenesisStatesWithTimeAndChainID(genTime time.Time, chainID string, genesisStates ...GenesisState) TestApp {
return tApp.InitializeFromGenesisStatesWithTimeAndChainIDAndHeight(genTime, chainID, defaultInitialHeight, genesisStates...) return tApp.InitializeFromGenesisStatesWithTimeAndChainIDAndHeight(genTime, chainID, defaultInitialHeight, true, genesisStates...)
} }
// InitializeFromGenesisStatesWithTimeAndChainIDAndHeight calls InitChain on the app using the provided genesis states and other parameters. // InitializeFromGenesisStatesWithTimeAndChainIDAndHeight calls InitChain on the app using the provided genesis states and other parameters.
@ -296,6 +296,7 @@ func (tApp TestApp) InitializeFromGenesisStatesWithTimeAndChainIDAndHeight(
genTime time.Time, genTime time.Time,
chainID string, chainID string,
initialHeight int64, initialHeight int64,
addValidator bool,
genesisStates ...GenesisState, genesisStates ...GenesisState,
) TestApp { ) TestApp {
// Create a default genesis state and overwrite with provided values // Create a default genesis state and overwrite with provided values
@ -318,10 +319,12 @@ func (tApp TestApp) InitializeFromGenesisStatesWithTimeAndChainIDAndHeight(
} }
// Add default genesis states for at least 1 validator // Add default genesis states for at least 1 validator
genesisState = GenesisStateWithSingleValidator( if addValidator {
&tApp, genesisState = GenesisStateWithSingleValidator(
genesisState, &tApp,
) genesisState,
)
}
// Initialize the chain // Initialize the chain
stateBytes, err := json.Marshal(genesisState) stateBytes, err := json.Marshal(genesisState)

View File

@ -1,4 +1,4 @@
package migrate package cmd
import ( import (
"encoding/json" "encoding/json"
@ -13,46 +13,6 @@ import (
"github.com/kava-labs/kava/app/params" "github.com/kava-labs/kava/app/params"
) )
// MigrateGenesisCmd returns a command to execute genesis state migration.
func MigrateGenesisCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "migrate [genesis-file]",
Short: "Migrate genesis from v0.17 to v0.18",
Long: "Migrate the source genesis into v0.18 and print to STDOUT.",
Example: fmt.Sprintf(`%s migrate /path/to/genesis.json`, version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
// clientCtx := client.GetClientContextFromCmd(cmd)
// importGenesis := args[0]
// oldGenDoc, err := tmtypes.GenesisDocFromFile(importGenesis)
// if err != nil {
// return fmt.Errorf("failed to read genesis document from file %s: %w", importGenesis, err)
// }
// newGenDoc, err := v0_17.Migrate(oldGenDoc, clientCtx)
// if err != nil {
// return fmt.Errorf("failed to run migration: %w", err)
// }
// bz, err := tmjson.Marshal(newGenDoc)
// if err != nil {
// return fmt.Errorf("failed to marshal genesis doc: %w", err)
// }
// sortedBz, err := sdk.SortJSON(bz)
// if err != nil {
// return fmt.Errorf("failed to sort JSON genesis doc: %w", err)
// }
// fmt.Println(string(sortedBz))
return nil
},
}
return cmd
}
func AssertInvariantsCmd(config params.EncodingConfig) *cobra.Command { func AssertInvariantsCmd(config params.EncodingConfig) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "assert-invariants [genesis-file]", Use: "assert-invariants [genesis-file]",
@ -76,7 +36,13 @@ func AssertInvariantsCmd(config params.EncodingConfig) *cobra.Command {
if err != nil { if err != nil {
return fmt.Errorf("genesis doc did not pass validate genesis: %s: %w", importGenesis, err) return fmt.Errorf("genesis doc did not pass validate genesis: %s: %w", importGenesis, err)
} }
tApp.InitializeFromGenesisStatesWithTimeAndChainID(genDoc.GenesisTime, genDoc.ChainID, app.GenesisState(newAppState)) tApp.InitializeFromGenesisStatesWithTimeAndChainIDAndHeight(
genDoc.GenesisTime,
genDoc.ChainID,
genDoc.InitialHeight,
false,
app.GenesisState(newAppState),
)
fmt.Printf("successfully asserted all invariants for %s\n", importGenesis) fmt.Printf("successfully asserted all invariants for %s\n", importGenesis)
return nil return nil
@ -92,11 +58,7 @@ func AssertInvariantsCmd(config params.EncodingConfig) *cobra.Command {
func validateGenDoc(importGenesisFile string) (*tmtypes.GenesisDoc, error) { func validateGenDoc(importGenesisFile string) (*tmtypes.GenesisDoc, error) {
genDoc, err := tmtypes.GenesisDocFromFile(importGenesisFile) genDoc, err := tmtypes.GenesisDocFromFile(importGenesisFile)
if err != nil { if err != nil {
return nil, fmt.Errorf( return nil, fmt.Errorf("failed to validate CometBFT consensus params: %s", err)
"%s. Make sure that you have correctly migrated all Tendermint consensus params.",
err.Error(),
)
} }
return genDoc, nil return genDoc, nil
} }

View File

@ -23,7 +23,6 @@ import (
"github.com/kava-labs/kava/app" "github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/app/params" "github.com/kava-labs/kava/app/params"
kavaclient "github.com/kava-labs/kava/client" kavaclient "github.com/kava-labs/kava/client"
"github.com/kava-labs/kava/migrate"
) )
// EnvPrefix is the prefix environment variables must have to configure the app. // EnvPrefix is the prefix environment variables must have to configure the app.
@ -92,8 +91,7 @@ func addSubCmds(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, de
genutilcli.InitCmd(app.ModuleBasics, defaultNodeHome), genutilcli.InitCmd(app.ModuleBasics, defaultNodeHome),
), ),
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, defaultNodeHome), genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, defaultNodeHome),
migrate.MigrateGenesisCmd(), AssertInvariantsCmd(encodingConfig),
migrate.AssertInvariantsCmd(encodingConfig),
genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, defaultNodeHome), genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, defaultNodeHome),
genutilcli.ValidateGenesisCmd(app.ModuleBasics), genutilcli.ValidateGenesisCmd(app.ModuleBasics),
AddGenesisAccountCmd(defaultNodeHome), AddGenesisAccountCmd(defaultNodeHome),

View File

@ -1,32 +0,0 @@
package migrate_test
import (
"context"
"path/filepath"
"testing"
"github.com/cosmos/cosmos-sdk/client"
"github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/migrate"
"github.com/stretchr/testify/require"
)
func TestMigrateGenesisCmd_V17_Success(t *testing.T) {
ctx := newCmdContext()
cmd := migrate.MigrateGenesisCmd()
file := filepath.Join("v0_17", "testdata", "genesis-v16.json")
cmd.SetArgs([]string{file})
err := cmd.ExecuteContext(ctx)
require.NoError(t, err)
}
func newCmdContext() context.Context {
config := app.MakeEncodingConfig()
clientCtx := client.Context{}.
WithCodec(config.Marshaler).
WithLegacyAmino(config.Amino).
WithInterfaceRegistry(config.InterfaceRegistry)
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
return ctx
}