diff --git a/tests/difference/core/driver/setup.go b/tests/difference/core/driver/setup.go index 23739a44f2..e0fc219ea1 100644 --- a/tests/difference/core/driver/setup.go +++ b/tests/difference/core/driver/setup.go @@ -14,21 +14,16 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/crypto" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/types" - "github.com/cosmos/ibc-go/v3/testing/mock" - ibctesting "github.com/cosmos/ibc-go/v3/testing" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" simapp "github.com/cosmos/interchain-security/testutil/simapp" - cryptoEd25519 "crypto/ed25519" - - cosmosEd25519 "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + testcrypto "github.com/cosmos/interchain-security/testutil/crypto" clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" @@ -60,24 +55,6 @@ type Builder struct { initState InitState } -type ValidatorKeyData struct { - signer mock.PV - address sdk.ValAddress - pubKey crypto.PubKey -} - -func (b *Builder) getValidatorKeyData(seedIx int) ValidatorKeyData { - ret := ValidatorKeyData{} - ret.signer = b.getValidatorPK(seedIx) - pubKey, err := ret.signer.GetPubKey() - require.NoError(b.suite.T(), err) - ret.pubKey = pubKey - addr, err := sdk.ValAddressFromHex(ret.pubKey.Address().String()) - require.NoError(b.suite.T(), err) - ret.address = addr - return ret -} - func (b *Builder) ctx(chain string) sdk.Context { return b.chain(chain).GetContext() } @@ -135,10 +112,8 @@ func (b *Builder) consAddr(i int64) sdk.ConsAddress { } // getValidatorPK returns the validator private key using the given seed index -func (b *Builder) getValidatorPK(seedIx int) mock.PV { - seed := []byte(b.initState.PKSeeds[seedIx]) - //lint:ignore SA1019 We don't care because this is only a test. - return mock.PV{PrivKey: &cosmosEd25519.PrivKey{Key: cryptoEd25519.NewKeyFromSeed(seed)}} +func (b *Builder) getValidatorPK(seedIx int) testcrypto.Validator { + return testcrypto.NewValidatorFromBytesSeed([]byte(b.initState.PKSeeds[seedIx])) } func (b *Builder) getAppBytesAndSenders(chainID string, app ibctesting.TestingApp, genesis map[string]json.RawMessage, @@ -335,10 +310,10 @@ func (b *Builder) createValidators() (*tmtypes.ValidatorSet, map[string]tmtypes. continue } - validatorKeyData := b.getValidatorKeyData(i) - signers[validatorKeyData.pubKey.Address().String()] = validatorKeyData.signer - addresses = append(addresses, validatorKeyData.address) - validators = append(validators, tmtypes.NewValidator(validatorKeyData.pubKey, int64(power))) + testVal := b.getValidatorPK(i) + signers[testVal.SDKValAddressString()] = testVal + addresses = append(addresses, testVal.SDKValAddress()) + validators = append(validators, testVal.TMValidator(int64(power))) } return tmtypes.NewValidatorSet(validators), signers, addresses diff --git a/testutil/crypto/crypto.go b/testutil/crypto/crypto.go index 0a7702d36c..9aeae3e277 100644 --- a/testutil/crypto/crypto.go +++ b/testutil/crypto/crypto.go @@ -11,9 +11,11 @@ import ( sdkcryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdkcryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdktypes "github.com/cosmos/cosmos-sdk/types" tmcrypto "github.com/tendermint/tendermint/crypto" tmprotocrypto "github.com/tendermint/tendermint/proto/tendermint/crypto" + tmtypes "github.com/tendermint/tendermint/types" ) type Validator struct { @@ -33,6 +35,10 @@ func NewValidatorFromIntSeed(i int) Validator { return NewValidatorFromBytesSeed(seed) } +func (v *Validator) TMValidator(power int64) *tmtypes.Validator { + return tmtypes.NewValidator(v.TMCryptoPubKey(), power) +} + func (v *Validator) TMProtoCryptoPublicKey() tmprotocrypto.PublicKey { ret, err := sdkcryptocodec.ToTmProtoPublicKey(v.SDKPubKey()) if err != nil { @@ -57,3 +63,15 @@ func (v *Validator) SDKPubKey() sdkcryptotypes.PubKey { } return ret } + +func (v *Validator) SDKValAddressString() string { + return v.TMCryptoPubKey().Address().String() +} + +func (v *Validator) SDKValAddress() sdktypes.ValAddress { + ret, err := sdktypes.ValAddressFromHex(v.SDKValAddressString()) + if err != nil { + panic(err) + } + return ret +}