Skip to content

Commit

Permalink
Confirm build
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel committed Oct 26, 2022
1 parent bfc1ba9 commit 49e579d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 33 deletions.
7 changes: 4 additions & 3 deletions tests/difference/core/driver/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion testutil/keeper/unit_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions testutil/sample/sample.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}
34 changes: 5 additions & 29 deletions x/ccv/provider/keeper/keymap_test.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
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"
abci "github.com/tendermint/tendermint/abci/types"
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
Expand All @@ -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
Expand Down

0 comments on commit 49e579d

Please sign in to comment.