Skip to content

Commit

Permalink
Add staking validator helper to test validator
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel committed Nov 2, 2022
1 parent 0a73df1 commit f4ac5b4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions testutil/crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (

cryptoEd25519 "crypto/ed25519"

"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"

sdkcryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdkcryptokeys "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
sdkcryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdktypes "github.com/cosmos/cosmos-sdk/types"
sdkstakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

tmcrypto "github.com/tendermint/tendermint/crypto"
tmprotocrypto "github.com/tendermint/tendermint/proto/tendermint/crypto"
Expand All @@ -24,7 +24,7 @@ type Validator struct {

func NewValidatorFromBytesSeed(seed []byte) Validator {
//lint:ignore SA1019 We don't care because this is only a test.
privKey := mock.PV{PrivKey: &ed25519.PrivKey{Key: cryptoEd25519.NewKeyFromSeed(seed)}}
privKey := mock.PV{PrivKey: &sdkcryptokeys.PrivKey{Key: cryptoEd25519.NewKeyFromSeed(seed)}}
return Validator{PV: privKey}
}

Expand Down Expand Up @@ -55,6 +55,14 @@ func (v *Validator) TMCryptoPubKey() tmcrypto.PubKey {
return ret
}

func (v *Validator) SDKStakingValidator() sdkstakingtypes.Validator {
ret, err := sdkstakingtypes.NewValidator(v.SDKValAddress(), v.SDKPubKey(), sdkstakingtypes.Description{})
if err != nil {
panic(err)
}
return ret
}

func (v *Validator) SDKPubKey() sdkcryptotypes.PubKey {
tmcryptoPubKey := v.TMCryptoPubKey()
ret, err := sdkcryptocodec.FromTmPubKeyInterface(tmcryptoPubKey)
Expand Down

0 comments on commit f4ac5b4

Please sign in to comment.