Skip to content

Commit

Permalink
Reach milestone in factoring out test keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel committed Nov 2, 2022
1 parent 80cb85a commit 6b4fc4b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
4 changes: 4 additions & 0 deletions testutil/crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func NewValidatorFromIntSeed(i int) Validator {
return NewValidatorFromBytesSeed(seed)
}

func (v *Validator) ABCIAddressBytes() []byte {
return v.SDKPubKey().Address()
}

func (v *Validator) TMValidator(power int64) *tmtypes.Validator {
return tmtypes.NewValidator(v.TMCryptoPubKey(), power)
}
Expand Down
24 changes: 5 additions & 19 deletions x/ccv/provider/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
tmprotocrypto "github.com/tendermint/tendermint/proto/tendermint/crypto"

testcrypto "github.com/cosmos/interchain-security/testutil/crypto"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/ed25519"
)

// TestValsetUpdateBlockHeight tests the getter, setter, and deletion methods for valset updates mapped to block height
Expand Down Expand Up @@ -197,24 +197,10 @@ func TestHandleSlashPacketDoubleSigning(t *testing.T) {
keeperParams := testkeeper.NewInMemKeeperParams(t)
ctx := keeperParams.Ctx

//~~~~~~~~~~~~
// TODO: tidyup
var pubKey tmprotocrypto.PublicKey
pk := ed25519.GenPrivKey().PubKey()

sdkVer, err := cryptocodec.FromTmPubKeyInterface(pk)
if err != nil {
panic(err)
}
pubKey, err = cryptocodec.ToTmProtoPublicKey(sdkVer)
if err != nil {
panic(err)
}
// TODO: tidyup
//~~~~~~~~~~~~
testVal := testcrypto.NewValidatorFromIntSeed(0)

slashPacket := ccv.NewSlashPacketData(
abci.Validator{Address: pk.Address(),
abci.Validator{Address: testVal.ABCIAddressBytes(),
Power: int64(0)},
uint64(0),
stakingtypes.DoubleSign,
Expand Down Expand Up @@ -260,8 +246,8 @@ func TestHandleSlashPacketDoubleSigning(t *testing.T) {
providerKeeper := testkeeper.NewInMemProviderKeeper(keeperParams, mocks)

providerKeeper.SetInitChainHeight(ctx, chainId, uint64(infractionHeight))
providerKeeper.KeyMap(ctx, chainId).SetProviderPubKeyToConsumerPubKey(pubKey, pubKey)
providerKeeper.KeyMap(ctx, chainId).ComputeUpdates(0, []abci.ValidatorUpdate{{PubKey: pubKey, Power: 1}})
providerKeeper.KeyMap(ctx, chainId).SetProviderPubKeyToConsumerPubKey(testVal.TMProtoCryptoPublicKey(), testVal.TMProtoCryptoPublicKey())
providerKeeper.KeyMap(ctx, chainId).ComputeUpdates(0, []abci.ValidatorUpdate{{PubKey: testVal.TMProtoCryptoPublicKey(), Power: 1}})

success, err := providerKeeper.HandleSlashPacket(ctx, chainId, slashPacket)
require.NoError(t, err)
Expand Down

0 comments on commit 6b4fc4b

Please sign in to comment.