Skip to content

Commit

Permalink
chore: fix testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed Jul 7, 2023
1 parent 8885e18 commit 9380a65
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 22 deletions.
14 changes: 0 additions & 14 deletions testutil/sims/address_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions x/slashing/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
11 changes: 6 additions & 5 deletions x/staking/testutil/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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(),
Expand Down

0 comments on commit 9380a65

Please sign in to comment.