From 49e579d388884bed28060bf812ec96659704276c Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 26 Oct 2022 16:47:01 +0100 Subject: [PATCH] Confirm build --- tests/difference/core/driver/core_test.go | 7 +++-- testutil/keeper/unit_test_helpers.go | 3 +- testutil/sample/sample.go | 34 +++++++++++++++++++++++ x/ccv/provider/keeper/keymap_test.go | 34 ++++------------------- 4 files changed, 45 insertions(+), 33 deletions(-) diff --git a/tests/difference/core/driver/core_test.go b/tests/difference/core/driver/core_test.go index 08d2326e69..fc90298f3a 100644 --- a/tests/difference/core/driver/core_test.go +++ b/tests/difference/core/driver/core_test.go @@ -24,6 +24,7 @@ import ( "math/rand" slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + testutil "github.com/cosmos/interchain-security/testutil/sample" consumerkeeper "github.com/cosmos/interchain-security/x/ccv/consumer/keeper" providerkeeper "github.com/cosmos/interchain-security/x/ccv/provider/keeper" ) @@ -345,9 +346,9 @@ func (s *CoreSuite) executeTrace() { // TODO: j := rand.Intn(initState.NumValidators) pk := s.providerValidatorPubKey(int64(j)) - ck := - s.providerKeeper().KeyMap(s.ctx(P), s.chainID(C)).SetProviderPubKeyToConsumerPubKey() - + k := rand.Intn(50) + ck := testutil.GetTMCryptoPublicKeyFromSeed(uint64(k)) + s.providerKeeper().KeyMap(s.ctx(P), s.chainID(C)).SetProviderPubKeyToConsumerPubKey(pk, ck) } switch a.Kind { diff --git a/testutil/keeper/unit_test_helpers.go b/testutil/keeper/unit_test_helpers.go index 203f1750fe..61ce0ce713 100644 --- a/testutil/keeper/unit_test_helpers.go +++ b/testutil/keeper/unit_test_helpers.go @@ -22,13 +22,14 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmdb "github.com/tendermint/tm-db" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" + + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" ) // Parameters needed to instantiate an in-memory keeper diff --git a/testutil/sample/sample.go b/testutil/sample/sample.go index 98f2153ed4..d4f6e9ad6b 100644 --- a/testutil/sample/sample.go +++ b/testutil/sample/sample.go @@ -1,8 +1,17 @@ package sample import ( + "encoding/binary" + + cryptoEd25519 "crypto/ed25519" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ibc-go/v3/testing/mock" + + tmprotocrypto "github.com/tendermint/tendermint/proto/tendermint/crypto" ) // AccAddress returns a sample account address @@ -11,3 +20,28 @@ func AccAddress() string { addr := pk.Address() return sdk.AccAddress(addr).String() } + +func GetTMCryptoPublicKeyFromSeed(i uint64) tmprotocrypto.PublicKey { + + fromSeed := func(seed []byte) tmprotocrypto.PublicKey { + //lint:ignore SA1019 We don't care because this is only a test. + privKey := mock.PV{PrivKey: &ed25519.PrivKey{Key: cryptoEd25519.NewKeyFromSeed(seed)}} + pubKey, err := privKey.GetPubKey() + if err != nil { + panic(err) + } + sdkVer, err := cryptocodec.FromTmPubKeyInterface(pubKey) + if err != nil { + panic(err) + } + pk, err := cryptocodec.ToTmProtoPublicKey(sdkVer) + if err != nil { + panic(err) + } + return pk + } + + seed := []byte("AAAAAAAAabcdefghijklmnopqrstuvwx") // 8+24 bytes + binary.LittleEndian.PutUint64(seed[:8], i) + return fromSeed(seed) +} diff --git a/x/ccv/provider/keeper/keymap_test.go b/x/ccv/provider/keeper/keymap_test.go index d296818b84..f18fed6b69 100644 --- a/x/ccv/provider/keeper/keymap_test.go +++ b/x/ccv/provider/keeper/keymap_test.go @@ -1,17 +1,13 @@ package keeper_test import ( - cryptoEd25519 "crypto/ed25519" - "encoding/binary" "math/rand" "testing" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - cosmosEd25519 "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/ibc-go/v3/testing/mock" testkeeper "github.com/cosmos/interchain-security/testutil/keeper" + testutil "github.com/cosmos/interchain-security/testutil/sample" "github.com/cosmos/interchain-security/x/ccv/provider/keeper" ccvtypes "github.com/cosmos/interchain-security/x/ccv/types" "github.com/stretchr/testify/require" @@ -19,6 +15,10 @@ import ( crypto "github.com/tendermint/tendermint/proto/tendermint/crypto" ) +func key(k uint64) crypto.PublicKey { + return testutil.GetTMCryptoPublicKeyFromSeed(k) +} + // TODO: all the map lookups are probably gonna fail because the objects are different // Num traces to run for heuristic testing @@ -35,30 +35,6 @@ const NUM_VALS = 4 // (This is constrained to ensure overlap edge cases are tested) const NUM_CKS = 50 -func fromSeed(seed []byte) crypto.PublicKey { - //lint:ignore SA1019 We don't care because this is only a test. - privKey := mock.PV{PrivKey: &cosmosEd25519.PrivKey{Key: cryptoEd25519.NewKeyFromSeed(seed)}} - pubKey, err := privKey.GetPubKey() - if err != nil { - panic(err) - } - sdkVer, err := cryptocodec.FromTmPubKeyInterface(pubKey) - if err != nil { - panic(err) - } - pk, err := cryptocodec.ToTmProtoPublicKey(sdkVer) - if err != nil { - panic(err) - } - return pk -} - -func key(i uint64) crypto.PublicKey { - seed := []byte("AAAAAAAAabcdefghijklmnopqrstuvwx") // 8+24 bytes - binary.LittleEndian.PutUint64(seed[:8], i) - return fromSeed(seed) -} - type keyMapEntry struct { pk keeper.ProviderPubKey ck keeper.ConsumerPubKey