Skip to content

Commit

Permalink
Use any as validator pubkey (cosmos#7597)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
4 people authored Oct 23, 2020
1 parent 46c20cd commit f5aabb5
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 15 deletions.
6 changes: 3 additions & 3 deletions encoding.go
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
9 changes: 6 additions & 3 deletions export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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. */

Expand Down
9 changes: 4 additions & 5 deletions params/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
2 changes: 2 additions & 0 deletions sim_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -261,6 +264,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
SimulationOperations(newApp, newApp.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
app.AppCodec(),
)
require.NoError(t, err)
}
Expand Down Expand Up @@ -311,6 +315,7 @@ func TestAppStateDeterminism(t *testing.T) {
SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
app.AppCodec(),
)
require.NoError(t, err)

Expand Down
6 changes: 3 additions & 3 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)) },
)

Expand Down
10 changes: 9 additions & 1 deletion test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f5aabb5

Please sign in to comment.