Use any as validator pubkey (#7597)
* protobuf pubkey type update * wip2 * wip3 * solving types.NewValidator issues * remove bech32 from validator type assignment * update Validator interface * Changelog update * wip4 * update genutil * fix simapp & x/ibc/testing tests * update staking * changelog update * fix import cycle in tests * fix amino panic on TestValidatorMarshalUnmarshalJSON * fix TestValidatorMarshalUnmarshalJSON consensus_pubkey check * Add UnpackInterfaces to HistoricalInfo * fix TestHistoricalInfo * update todos * fix: Expecting ed25519.PubKey to implement proto.Message * fix linter issues * Fix migrate test * Update CHANGELOG.md Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * review comments * cosmetic changes * add UnpackInterfaces got GenesisRandomized test * Validator.Equal reuses Validator.MinEqual * fix test * use Validator.Equal in tests * Fix staking simulation TestRandomizedGenState * Remove TODO * use HistoricalInfo.Equal * use proto.Equal * rename Validator.GetConsPubKey to TmConsPubKey * prefer require.Equal over reflect.DeepEqual * SetHistoricalInfo using a pointer * Fix TestQueryDelegation test * Fix TestQueryValidators test * Fix TestSimulateMsgUnjail test * experiement with LegacyAmino instances * Register codecs in all simapp tests * Fix cli_test compilation problems * fix typo sdk -> std * fix typo * fix TestPlanStringer * Rename to MakeEncodingConfig * Remove RegisterCodecsTests * Use gRPC in GetCmdQueryValidators * Empty status * fix info log check * linter fixes * rename simapparams to simappparams * Update simapp/test_helpers.go Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * comments updates * use valAddr1 instead of sdk.ValAddress(pk1.Address().Bytes()) Co-authored-by: Cory Levinson <cjlevinson@gmail.com> Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com>
This commit is contained in:
co-authored by
Marie Gauthier
Cory Levinson
Amaury Martiny
parent
5bebf2bd39
commit
6bc8ff2dfe
+3
-3
@@ -1,13 +1,13 @@
|
||||
package simapp
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/simapp/params"
|
||||
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
|
||||
"github.com/cosmos/cosmos-sdk/std"
|
||||
)
|
||||
|
||||
// MakeEncodingConfig creates an EncodingConfig for testing
|
||||
func MakeEncodingConfig() params.EncodingConfig {
|
||||
encodingConfig := params.MakeEncodingConfig()
|
||||
func MakeEncodingConfig() simappparams.EncodingConfig {
|
||||
encodingConfig := simappparams.MakeEncodingConfig()
|
||||
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
|
||||
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
|
||||
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
|
||||
|
||||
+6
-3
@@ -35,13 +35,13 @@ func (app *SimApp) ExportAppStateAndValidators(
|
||||
return servertypes.ExportedApp{}, err
|
||||
}
|
||||
|
||||
validators := staking.WriteValidators(ctx, app.StakingKeeper)
|
||||
validators, err := staking.WriteValidators(ctx, app.StakingKeeper)
|
||||
return servertypes.ExportedApp{
|
||||
AppState: appState,
|
||||
Validators: validators,
|
||||
Height: height,
|
||||
ConsensusParams: app.BaseApp.GetConsensusParams(ctx),
|
||||
}, nil
|
||||
}, err
|
||||
}
|
||||
|
||||
// prepare for fresh start at zero height
|
||||
@@ -174,7 +174,10 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
|
||||
|
||||
iter.Close()
|
||||
|
||||
_ = app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||
_, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
/* Handle slashing state. */
|
||||
|
||||
|
||||
@@ -8,17 +8,16 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/tx"
|
||||
)
|
||||
|
||||
// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.
|
||||
// MakeEncodingConfig creates an EncodingConfig for a non-amino based test configuration.
|
||||
func MakeEncodingConfig() EncodingConfig {
|
||||
amino := codec.NewLegacyAmino()
|
||||
cdc := codec.NewLegacyAmino()
|
||||
interfaceRegistry := types.NewInterfaceRegistry()
|
||||
marshaler := codec.NewProtoCodec(interfaceRegistry)
|
||||
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes)
|
||||
|
||||
return EncodingConfig{
|
||||
InterfaceRegistry: interfaceRegistry,
|
||||
Marshaler: marshaler,
|
||||
TxConfig: txCfg,
|
||||
Amino: amino,
|
||||
TxConfig: tx.NewTxConfig(marshaler, tx.DefaultSignModes),
|
||||
Amino: cdc,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ func BenchmarkFullAppSimulation(b *testing.B) {
|
||||
SimulationOperations(app, app.AppCodec(), config),
|
||||
app.ModuleAccountAddrs(),
|
||||
config,
|
||||
app.AppCodec(),
|
||||
)
|
||||
|
||||
// export state and simParams before the simulation error is checked
|
||||
@@ -83,6 +84,7 @@ func BenchmarkInvariants(b *testing.B) {
|
||||
SimulationOperations(app, app.AppCodec(), config),
|
||||
app.ModuleAccountAddrs(),
|
||||
config,
|
||||
app.AppCodec(),
|
||||
)
|
||||
|
||||
// export state and simParams before the simulation error is checked
|
||||
|
||||
@@ -81,6 +81,7 @@ func TestFullAppSimulation(t *testing.T) {
|
||||
SimulationOperations(app, app.AppCodec(), config),
|
||||
app.ModuleAccountAddrs(),
|
||||
config,
|
||||
app.AppCodec(),
|
||||
)
|
||||
|
||||
// export state and simParams before the simulation error is checked
|
||||
@@ -118,6 +119,7 @@ func TestAppImportExport(t *testing.T) {
|
||||
SimulationOperations(app, app.AppCodec(), config),
|
||||
app.ModuleAccountAddrs(),
|
||||
config,
|
||||
app.AppCodec(),
|
||||
)
|
||||
|
||||
// export state and simParams before the simulation error is checked
|
||||
@@ -214,6 +216,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
|
||||
SimulationOperations(app, app.AppCodec(), config),
|
||||
app.ModuleAccountAddrs(),
|
||||
config,
|
||||
app.AppCodec(),
|
||||
)
|
||||
|
||||
// export state and simParams before the simulation error is checked
|
||||
@@ -261,6 +264,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
|
||||
SimulationOperations(newApp, newApp.AppCodec(), config),
|
||||
app.ModuleAccountAddrs(),
|
||||
config,
|
||||
app.AppCodec(),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
@@ -311,6 +315,7 @@ func TestAppStateDeterminism(t *testing.T) {
|
||||
SimulationOperations(app, app.AppCodec(), config),
|
||||
app.ModuleAccountAddrs(),
|
||||
config,
|
||||
app.AppCodec(),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
+3
-3
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
simapparams "github.com/cosmos/cosmos-sdk/simapp/params"
|
||||
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
@@ -85,11 +85,11 @@ func AppStateRandomizedFn(
|
||||
// number of bonded accounts
|
||||
var initialStake, numInitiallyBonded int64
|
||||
appParams.GetOrGenerate(
|
||||
cdc, simapparams.StakePerAccount, &initialStake, r,
|
||||
cdc, simappparams.StakePerAccount, &initialStake, r,
|
||||
func(r *rand.Rand) { initialStake = r.Int63n(1e12) },
|
||||
)
|
||||
appParams.GetOrGenerate(
|
||||
cdc, simapparams.InitiallyBondedValidators, &numInitiallyBonded, r,
|
||||
cdc, simappparams.InitiallyBondedValidators, &numInitiallyBonded, r,
|
||||
func(r *rand.Rand) { numInitiallyBonded = int64(r.Intn(300)) },
|
||||
)
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
|
||||
bam "github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/simapp/helpers"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -92,9 +93,16 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
|
||||
bondAmt := sdk.NewInt(1000000)
|
||||
|
||||
for _, val := range valSet.Validators {
|
||||
// Currently validator requires tmcrypto.ed25519 keys, which don't support
|
||||
// our Marshaling interfaces, so we need to pack them into our version of ed25519.
|
||||
// There is ongoing work to add secp256k1 keys (https://github.com/cosmos/cosmos-sdk/pull/7604).
|
||||
pk, err := ed25519.FromTmEd25519(val.PubKey)
|
||||
require.NoError(t, err)
|
||||
pkAny, err := codectypes.PackAny(pk)
|
||||
require.NoError(t, err)
|
||||
validator := stakingtypes.Validator{
|
||||
OperatorAddress: sdk.ValAddress(val.Address).String(),
|
||||
ConsensusPubkey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, val.PubKey),
|
||||
ConsensusPubkey: pkAny,
|
||||
Jailed: false,
|
||||
Status: stakingtypes.Bonded,
|
||||
Tokens: bondAmt,
|
||||
|
||||
Reference in New Issue
Block a user