From 9380a65608ac58a693ea93e9b95699f83df875ad Mon Sep 17 00:00:00 2001 From: j75689 Date: Fri, 7 Jul 2023 12:48:44 +0800 Subject: [PATCH] chore: fix testcase --- testutil/sims/address_helpers.go | 14 -------------- x/slashing/abci_test.go | 6 +++--- x/staking/testutil/helpers.go | 11 ++++++----- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/testutil/sims/address_helpers.go b/testutil/sims/address_helpers.go index 9aa0dc93b3..742bcfca72 100644 --- a/testutil/sims/address_helpers.go +++ b/testutil/sims/address_helpers.go @@ -8,7 +8,6 @@ import ( "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - "github.com/cosmos/cosmos-sdk/crypto/keys/eth/ethsecp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/errors" @@ -145,19 +144,6 @@ func CreateTestPubKeys(numPubKeys int) []cryptotypes.PubKey { return publicKeys } -// CreateTestAccounts returns number of PubKey, PrivKey -func CreateTestAccounts(num int) ([]cryptotypes.PubKey, []cryptotypes.PrivKey) { - var publicKeys = make([]cryptotypes.PubKey, 0, num) - var privateKeys = make([]cryptotypes.PrivKey, 0, num) - for i := 0; i < num; i++ { - privKey, _ := ethsecp256k1.GenPrivKey() - publicKeys = append(publicKeys, privKey.PubKey()) - privateKeys = append(privateKeys, privKey) - } - - return publicKeys, privateKeys -} - // NewPubKeyFromHex returns a PubKey from a hex string. func NewPubKeyFromHex(pk string) (res cryptotypes.PubKey) { pkBytes, err := hex.DecodeString(pk) diff --git a/x/slashing/abci_test.go b/x/slashing/abci_test.go index 62785223e4..36ed0ba9c0 100644 --- a/x/slashing/abci_test.go +++ b/x/slashing/abci_test.go @@ -38,14 +38,14 @@ func TestBeginBlocker(t *testing.T) { ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - pks, pvs := simtestutil.CreateTestAccounts(1) + pks := simtestutil.CreateTestPubKeys(1) simtestutil.AddTestAddrsFromPubKeys(bankKeeper, stakingKeeper, ctx, pks, stakingKeeper.TokensFromConsensusPower(ctx, 200)) - addr, pk, pv := sdk.AccAddress(pks[0].Address()), pks[0], pvs[0] + addr, pk := sdk.AccAddress(pks[0].Address()), pks[0] tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper) // bond the validator power := int64(100) - amt := tstaking.CreateValidatorWithValPower(addr, pk, pv, power, true) + amt := tstaking.CreateValidatorWithValPower(addr, pk, power, true) staking.EndBlocker(ctx, stakingKeeper) require.Equal( t, bankKeeper.GetAllBalances(ctx, addr), diff --git a/x/staking/testutil/helpers.go b/x/staking/testutil/helpers.go index aedd44d59f..51cd002d1a 100644 --- a/x/staking/testutil/helpers.go +++ b/x/staking/testutil/helpers.go @@ -39,20 +39,20 @@ func NewHelper(t *testing.T, ctx sdk.Context, k *keeper.Keeper) *Helper { // CreateValidator calls staking module `MsgServer/CreateValidator` to create a new validator func (sh *Helper) CreateValidator(addr sdk.AccAddress, pk cryptotypes.PubKey, pv cryptotypes.PrivKey, stakeAmount math.Int, ok bool) { coin := sdk.NewCoin(sh.Denom, stakeAmount) - sh.createValidator(addr, pk, pv, coin, ok) + sh.createValidator(addr, pk, coin, ok) } // CreateValidatorWithValPower calls staking module `MsgServer/CreateValidator` to create a new validator with zero // commission -func (sh *Helper) CreateValidatorWithValPower(addr sdk.AccAddress, pk cryptotypes.PubKey, pv cryptotypes.PrivKey, valPower int64, ok bool) math.Int { +func (sh *Helper) CreateValidatorWithValPower(addr sdk.AccAddress, pk cryptotypes.PubKey, valPower int64, ok bool) math.Int { amount := sh.k.TokensFromConsensusPower(sh.Ctx, valPower) coin := sdk.NewCoin(sh.Denom, amount) - sh.createValidator(addr, pk, pv, coin, ok) + sh.createValidator(addr, pk, coin, ok) return amount } // CreateValidatorMsg returns a message used to create validator in this service. -func (sh *Helper) CreateValidatorMsg(addr sdk.AccAddress, pk cryptotypes.PubKey, pv cryptotypes.PrivKey, stakeAmount math.Int) *stakingtypes.MsgCreateValidator { +func (sh *Helper) CreateValidatorMsg(addr sdk.AccAddress, pk cryptotypes.PubKey, stakeAmount math.Int) *stakingtypes.MsgCreateValidator { coin := sdk.NewCoin(sh.Denom, stakeAmount) blsSecretKey, _ := bls.RandKey() blsPk := hex.EncodeToString(blsSecretKey.PublicKey().Marshal()) @@ -72,11 +72,12 @@ func (sh *Helper) CreateValidatorWithMsg(ctx context.Context, msg *stakingtypes. return sh.msgSrvr.CreateValidator(ctx, msg) } -func (sh *Helper) createValidator(addr sdk.AccAddress, pk cryptotypes.PubKey, pv cryptotypes.PrivKey, coin sdk.Coin, ok bool) { +func (sh *Helper) createValidator(addr sdk.AccAddress, pk cryptotypes.PubKey, coin sdk.Coin, ok bool) { blsSecretKey, _ := bls.RandKey() blsPk := hex.EncodeToString(blsSecretKey.PublicKey().Marshal()) blsProofBuf := blsSecretKey.Sign(tmhash.Sum(blsSecretKey.PublicKey().Marshal())) blsProof := hex.EncodeToString(blsProofBuf.Marshal()) + msg, err := stakingtypes.NewMsgCreateValidator( addr, pk, coin, stakingtypes.Description{}, sh.Commission, sdk.OneInt(),