Skip to content

Commit

Permalink
Put interface in tpyes
Browse files Browse the repository at this point in the history
  • Loading branch information
amaury1093 committed Sep 18, 2020
1 parent 5fe532c commit 7a423d8
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 33 deletions.
13 changes: 3 additions & 10 deletions crypto/keys/ed25519/ed25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import (
"fmt"
"io"

"golang.org/x/crypto/ed25519"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/tendermint/tendermint/crypto"
tmed25519 "github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/tmhash"
"golang.org/x/crypto/ed25519"

"github.com/cosmos/cosmos-sdk/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)

Expand Down Expand Up @@ -151,14 +150,8 @@ func GenPrivKeyFromSecret(secret []byte) *PrivKey {
var _ cryptotypes.PubKey = &PubKey{}
var _ codec.AminoMarshaler = &PubKey{}

// IntoTmPubKey allows our own PubKey types be converted into Tendermint's
// pubkey types.
type IntoTmPubKey interface {
AsTmPubKey() crypto.PubKey
}

var _ crypto.PubKey = &PubKey{}
var _ IntoTmPubKey = &PubKey{}
var _ cryptotypes.IntoTmPubKey = &PubKey{}

// Address is the SHA256-20 of the raw pubkey bytes.
func (pubKey *PubKey) Address() crypto.Address {
Expand Down
6 changes: 6 additions & 0 deletions crypto/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ type PrivKey interface {
type (
Address = tmcrypto.Address
)

// IntoTmPubKey allows our own PubKey types be converted into Tendermint's
// pubkey types.
type IntoTmPubKey interface {
AsTmPubKey() tmcrypto.PubKey
}
4 changes: 2 additions & 2 deletions x/ibc/02-client/keeper/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
Expand Down Expand Up @@ -256,7 +256,7 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() {
altPrivVal := ibctestingmock.NewPV()
altPubKey, err := altPrivVal.GetPubKey()
suite.Require().NoError(err)
altVal := tmtypes.NewValidator(altPubKey.(ed25519.IntoTmPubKey).AsTmPubKey(), 4)
altVal := tmtypes.NewValidator(altPubKey.(cryptotypes.IntoTmPubKey).AsTmPubKey(), 4)

// Set valSet here with suite.valSet so it doesn't get reset on each testcase
valSet := suite.valSet
Expand Down
4 changes: 2 additions & 2 deletions x/ibc/02-client/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/keeper"
Expand Down Expand Up @@ -88,7 +88,7 @@ func (suite *KeeperTestSuite) SetupTest() {

testClientHeightMinus1 := types.NewHeight(0, height-1)

validator := tmtypes.NewValidator(pubKey.(ed25519.IntoTmPubKey).AsTmPubKey(), 1)
validator := tmtypes.NewValidator(pubKey.(cryptotypes.IntoTmPubKey).AsTmPubKey(), 1)
suite.valSet = tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})
suite.valSetHash = suite.valSet.Hash()
suite.header = ibctmtypes.CreateTestHeader(testChainID, testClientHeight, testClientHeightMinus1, now2, suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal})
Expand Down
4 changes: 2 additions & 2 deletions x/ibc/02-client/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/require"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
client "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
Expand Down Expand Up @@ -51,7 +51,7 @@ func TestValidateGenesis(t *testing.T) {

now := time.Now().UTC()

val := tmtypes.NewValidator(pubKey.(ed25519.IntoTmPubKey).AsTmPubKey(), 10)
val := tmtypes.NewValidator(pubKey.(cryptotypes.IntoTmPubKey).AsTmPubKey(), 10)
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{val})

heightMinus1 := types.NewHeight(0, height-1)
Expand Down
4 changes: 2 additions & 2 deletions x/ibc/07-tendermint/types/misbehaviour_handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/tendermint/tendermint/crypto/tmhash"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/simapp"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
"github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
Expand All @@ -21,7 +21,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() {
altPubKey, err := altPrivVal.GetPubKey()
suite.Require().NoError(err)

altVal := tmtypes.NewValidator(altPubKey.(ed25519.IntoTmPubKey).AsTmPubKey(), 4)
altVal := tmtypes.NewValidator(altPubKey.(cryptotypes.IntoTmPubKey).AsTmPubKey(), 4)

// Create bothValSet with both suite validator and altVal
bothValSet := tmtypes.NewValidatorSet(append(suite.valSet.Validators, altVal))
Expand Down
4 changes: 2 additions & 2 deletions x/ibc/07-tendermint/types/misbehaviour_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
"github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
"github.com/cosmos/cosmos-sdk/x/ibc/exported"
Expand Down Expand Up @@ -37,7 +37,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() {

epochHeight := int64(height.EpochHeight)

altVal := tmtypes.NewValidator(altPubKey.(ed25519.IntoTmPubKey).AsTmPubKey(), epochHeight)
altVal := tmtypes.NewValidator(altPubKey.(cryptotypes.IntoTmPubKey).AsTmPubKey(), epochHeight)

// Create bothValSet with both suite validator and altVal
bothValSet := tmtypes.NewValidatorSet(append(suite.valSet.Validators, altVal))
Expand Down
4 changes: 2 additions & 2 deletions x/ibc/07-tendermint/types/tendermint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
Expand Down Expand Up @@ -77,7 +77,7 @@ func (suite *TendermintTestSuite) SetupTest() {

heightMinus1 := clienttypes.NewHeight(0, height.EpochHeight-1)

val := tmtypes.NewValidator(pubKey.(ed25519.IntoTmPubKey).AsTmPubKey(), 10)
val := tmtypes.NewValidator(pubKey.(cryptotypes.IntoTmPubKey).AsTmPubKey(), 10)
suite.valSet = tmtypes.NewValidatorSet([]*tmtypes.Validator{val})
suite.valsHash = suite.valSet.Hash()
suite.header = ibctmtypes.CreateTestHeader(chainID, height, heightMinus1, suite.now, suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal})
Expand Down
4 changes: 2 additions & 2 deletions x/ibc/07-tendermint/types/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
types "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
Expand Down Expand Up @@ -34,7 +34,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() {
heightMinus3 := clienttypes.NewHeight(height.EpochNumber, height.EpochHeight-3)
heightPlus5 := clienttypes.NewHeight(height.EpochNumber, height.EpochHeight+5)

altVal := tmtypes.NewValidator(altPubKey.(ed25519.IntoTmPubKey).AsTmPubKey(), epochHeight)
altVal := tmtypes.NewValidator(altPubKey.(cryptotypes.IntoTmPubKey).AsTmPubKey(), epochHeight)

// Create bothValSet with both suite validator and altVal. Would be valid update
bothValSet := tmtypes.NewValidatorSet(append(suite.valSet.Validators, altVal))
Expand Down
4 changes: 2 additions & 2 deletions x/ibc/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
Expand Down Expand Up @@ -61,7 +61,7 @@ func (suite *IBCTestSuite) SetupTest() {

now := time.Now().UTC()

val := tmtypes.NewValidator(pubKey.(ed25519.IntoTmPubKey).AsTmPubKey(), 10)
val := tmtypes.NewValidator(pubKey.(cryptotypes.IntoTmPubKey).AsTmPubKey(), 10)
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{val})

clientHeightMinus1 := clienttypes.NewHeight(0, height-1)
Expand Down
4 changes: 2 additions & 2 deletions x/ibc/testing/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -111,7 +111,7 @@ func NewTestChain(t *testing.T, chainID string) *TestChain {
require.NoError(t, err)

// create validator set with single validator
validator := tmtypes.NewValidator(pubKey.(ed25519.IntoTmPubKey).AsTmPubKey(), 1)
validator := tmtypes.NewValidator(pubKey.(cryptotypes.IntoTmPubKey).AsTmPubKey(), 1)
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})
signers := []tmtypes.PrivValidator{privVal}

Expand Down
5 changes: 3 additions & 2 deletions x/staking/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -153,7 +154,7 @@ func TestDuplicatesMsgCreateValidator(t *testing.T) {
require.True(t, found)
assert.Equal(t, sdk.Bonded, validator.Status)
assert.Equal(t, addr1, validator.OperatorAddress)
assert.Equal(t, pk1, validator.GetConsPubKey())
assert.Equal(t, pk1.(cryptotypes.IntoTmPubKey).AsTmPubKey(), validator.GetConsPubKey())
assert.Equal(t, valTokens, validator.BondedTokens())
assert.Equal(t, valTokens.ToDec(), validator.DelegatorShares)
assert.Equal(t, types.Description{}, validator.Description)
Expand Down Expand Up @@ -185,7 +186,7 @@ func TestDuplicatesMsgCreateValidator(t *testing.T) {
require.True(t, found)
assert.Equal(t, sdk.Bonded, validator.Status)
assert.Equal(t, addr2, validator.OperatorAddress)
assert.Equal(t, pk2, validator.GetConsPubKey())
assert.Equal(t, pk2.(cryptotypes.IntoTmPubKey).AsTmPubKey(), validator.GetConsPubKey())
assert.True(sdk.IntEq(t, valTokens, validator.Tokens))
assert.True(sdk.DecEq(t, valTokens.ToDec(), validator.DelegatorShares))
assert.Equal(t, types.Description{}, validator.Description)
Expand Down
4 changes: 2 additions & 2 deletions x/staking/types/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"gopkg.in/yaml.v2"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/staking/exported"
Expand Down Expand Up @@ -429,7 +429,7 @@ func (v Validator) GetConsPubKey() crypto.PubKey {
// pubkey will be passed into TM.
pk := sdk.MustGetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, v.ConsensusPubkey)

if intoTmPk, ok := pk.(ed25519.IntoTmPubKey); ok {
if intoTmPk, ok := pk.(cryptotypes.IntoTmPubKey); ok {
return intoTmPk.AsTmPubKey()
}

Expand Down
3 changes: 2 additions & 1 deletion x/staking/types/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand Down Expand Up @@ -317,7 +318,7 @@ func TestValidatorToTm(t *testing.T) {
val.Status = sdk.Bonded
val.Tokens = sdk.NewInt(rand.Int63())
vals[i] = val
expected[i] = tmtypes.NewValidator(pk.(ed25519.IntoTmPubKey).AsTmPubKey(), val.ConsensusPower())
expected[i] = tmtypes.NewValidator(pk.(cryptotypes.IntoTmPubKey).AsTmPubKey(), val.ConsensusPower())
}

require.Equal(t, expected, vals.ToTmValidators())
Expand Down

0 comments on commit 7a423d8

Please sign in to comment.