Refactor x/staking Validation and Delegation tests based on MsgCreateValidator.Pubkey type change. (#7526)

* testing: refactore Validation and Delegation handling of x/staking

This Changeset introduces set of improvements for writing tests.

The idea is to create a testing subpackage which will provide functions
to make tests more dev-friendly and wrap higher level use-cases.
Here is a show-up of of creating a service for staking module
for tests.

This PR also changes the `x/staking/types.MsgCreateValidator.Pubkey` from string
to types.Any. This change motivated the other change to show the pattern I'm describing here.

* add validator checks

* type change fixes

* use deprecated

* adding test slashing

* new network comment update

* working on tests

* Fix TestMsgPkDecode test

* Add UnpackInterfaces to MsgCreateValidator

* Fix tests

* Convert bech32 pubkey to proto

* Fix test

* fix v039/migrate_test/TestMigrate

* fix tests

* testslashing: rename Service to Helper

* file rename

* update TestMsgDecode

Co-authored-by: blushi <marie.gauthier63@gmail.com>
Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>
Co-authored-by: Cory Levinson <cjlevinson@gmail.com>
This commit is contained in:
Robert Zaremba
2020-10-19 13:04:55 +00:00
committed by GitHub
co-authored by blushi Amaury Martiny Cory Levinson
parent 0f8fdf60df
commit 8eaf2ececc
39 changed files with 778 additions and 1092 deletions
+4 -1
View File
@@ -148,7 +148,10 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k k
simtypes.RandomDecAmount(r, maxCommission),
)
msg := types.NewMsgCreateValidator(address, simAccount.ConsKey.PubKey(), selfDelegation, description, commission, sdk.OneInt())
msg, err := types.NewMsgCreateValidator(address, simAccount.ConsKey.PubKey(), selfDelegation, description, commission, sdk.OneInt())
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to create CreateValidator message"), nil, err
}
txGen := simappparams.MakeEncodingConfig().TxConfig
tx, err := helpers.GenTx(
+1 -1
View File
@@ -85,7 +85,7 @@ func TestSimulateMsgCreateValidator(t *testing.T) {
require.Equal(t, "0.660000000000000000", msg.Commission.MaxRate.String())
require.Equal(t, "0.047464127245687382", msg.Commission.Rate.String())
require.Equal(t, types.TypeMsgCreateValidator, msg.Type())
require.Equal(t, "cosmosvalconspub1zcjduepq280tm686ma80cva9z620dmknd9a858pd2zmq9ackfenfllecjxds0hg9n7", msg.Pubkey)
require.Equal(t, []byte{0xa, 0x20, 0x51, 0xde, 0xbd, 0xe8, 0xfa, 0xdf, 0x4e, 0xfc, 0x33, 0xa5, 0x16, 0x94, 0xf6, 0xee, 0xd3, 0x69, 0x7a, 0x7a, 0x1c, 0x2d, 0x50, 0xb6, 0x2, 0xf7, 0x16, 0x4e, 0x66, 0x9f, 0xff, 0x38, 0x91, 0x9b}, msg.Pubkey.Value)
require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress)
require.Equal(t, "cosmosvaloper1ghekyjucln7y67ntx7cf27m9dpuxxemnsvnaes", msg.ValidatorAddress)
require.Len(t, futureOperations, 0)