Skip to content

Commit

Permalink
tests: update test setup; refactor key_assignment addr parser
Browse files Browse the repository at this point in the history
  • Loading branch information
MSalopek committed Mar 4, 2024
1 parent 08ff58e commit 5a13210
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 49 deletions.
3 changes: 1 addition & 2 deletions app/provider/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
tendermint "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
ibctestingtypes "github.com/cosmos/ibc-go/v8/testing/types"
"github.com/spf13/cast"
Expand Down Expand Up @@ -158,7 +157,6 @@ var (
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
tendermint.AppModuleBasic{},
// router.AppModuleBasic{},
ibcprovider.AppModuleBasic{},
)
Expand Down Expand Up @@ -287,6 +285,7 @@ func New(
evidencetypes.StoreKey, ibctransfertypes.StoreKey,
capabilitytypes.StoreKey,
providertypes.StoreKey,
consensusparamtypes.StoreKey,
)

// register streaming services
Expand Down
5 changes: 4 additions & 1 deletion app/provider/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str

// withdraw all validator commission
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
valAddr, err := sdk.ValAddressFromHex(val.GetOperator())
valAddr, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -132,6 +132,9 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
}

scraps, err := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, valAddr)
if err != nil {
panic(err)
}
feePool, err := app.DistrKeeper.FeePool.Get(ctx)
if err != nil {
panic(err)
Expand Down
17 changes: 7 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
cosmossdk.io/errors v1.0.1
cosmossdk.io/math v1.2.0
github.com/cometbft/cometbft v0.38.5
github.com/cometbft/cometbft-db v0.10.0
github.com/cometbft/cometbft-db v0.10.0 // indirect
github.com/cosmos/cosmos-sdk v0.50.4
github.com/cosmos/gogoproto v1.4.11
github.com/cosmos/ics23/go v0.10.0
Expand Down Expand Up @@ -39,9 +39,8 @@ require (
cloud.google.com/go/iam v1.1.5 // indirect
cloud.google.com/go/storage v1.36.0 // indirect
cosmossdk.io/api v0.7.3
cosmossdk.io/core v0.11.0 // indirect
cosmossdk.io/core v0.11.0
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/tools/rosetta v0.2.1
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
Expand All @@ -55,14 +54,12 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cockroachdb/apd/v2 v2.0.2 // indirect
github.com/coinbase/rosetta-sdk-go/types v1.0.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.4
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v1.0.1 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/cosmos/rosetta-sdk-go v0.10.0 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
Expand Down Expand Up @@ -155,11 +152,16 @@ require (
)

require (
cosmossdk.io/client/v2 v2.0.0-beta.1
cosmossdk.io/collections v0.4.0
cosmossdk.io/log v1.3.1
cosmossdk.io/store v1.0.2
cosmossdk.io/tools/confix v0.1.1
cosmossdk.io/x/evidence v0.1.0
cosmossdk.io/x/feegrant v0.1.0
cosmossdk.io/x/tx v0.13.0
cosmossdk.io/x/upgrade v0.1.1
github.com/cosmos/cosmos-db v1.0.0
github.com/cosmos/ibc-go/modules/capability v1.0.0
github.com/cosmos/ibc-go/v8 v8.1.0
github.com/informalsystems/itf-go v0.0.1
Expand All @@ -169,11 +171,7 @@ require (
)

require (
cosmossdk.io/client/v2 v2.0.0-beta.1 // indirect
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/tools/confix v0.1.1 // indirect
cosmossdk.io/x/circuit v0.1.0 // indirect
cosmossdk.io/x/tx v0.13.0 // indirect
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/bits-and-blooms/bitset v1.8.0 // indirect
Expand All @@ -182,7 +180,6 @@ require (
github.com/cockroachdb/pebble v1.1.0 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cosmos/cosmos-db v1.0.0 // indirect
github.com/creachadair/atomicfile v0.3.1 // indirect
github.com/creachadair/tomledit v0.0.24 // indirect
github.com/emicklei/dot v1.6.1 // indirect
Expand Down
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@ cosmossdk.io/store v1.0.2 h1:lSg5BTvJBHUDwswNNyeh4K/CbqiHER73VU4nDNb8uk0=
cosmossdk.io/store v1.0.2/go.mod h1:EFtENTqVTuWwitGW1VwaBct+yDagk7oG/axBMPH+FXs=
cosmossdk.io/tools/confix v0.1.1 h1:aexyRv9+y15veH3Qw16lxQwo+ki7r2I+g0yNTEFEQM8=
cosmossdk.io/tools/confix v0.1.1/go.mod h1:nQVvP1tHsGXS83PonPVWJtSbddIqyjEw99L4M3rPJyQ=
cosmossdk.io/tools/rosetta v0.2.1 h1:ddOMatOH+pbxWbrGJKRAawdBkPYLfKXutK9IETnjYxw=
cosmossdk.io/tools/rosetta v0.2.1/go.mod h1:Pqdc1FdvkNV3LcNIkYWt2RQY6IP1ge6YWZk8MhhO9Hw=
cosmossdk.io/x/circuit v0.1.0 h1:IAej8aRYeuOMritczqTlljbUVHq1E85CpBqaCTwYgXs=
cosmossdk.io/x/circuit v0.1.0/go.mod h1:YDzblVE8+E+urPYQq5kq5foRY/IzhXovSYXb4nwd39w=
cosmossdk.io/x/evidence v0.1.0 h1:J6OEyDl1rbykksdGynzPKG5R/zm6TacwW2fbLTW4nCk=
Expand Down Expand Up @@ -337,8 +335,6 @@ github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZ
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo=
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/coinbase/rosetta-sdk-go/types v1.0.0 h1:jpVIwLcPoOeCR6o1tU+Xv7r5bMONNbHU7MuEHboiFuA=
github.com/coinbase/rosetta-sdk-go/types v1.0.0/go.mod h1:eq7W2TMRH22GTW0N0beDnN931DW0/WOI1R2sdHNHG4c=
github.com/cometbft/cometbft v0.38.5 h1:4lOcK5VTPrfbLOhNHmPYe6c7eDXHtBdMCQuKbAfFJdU=
github.com/cometbft/cometbft v0.38.5/go.mod h1:0tqKin+KQs8zDwzYD8rPHzSBIDNPuB4NrwwGDNb/hUg=
github.com/cometbft/cometbft-db v0.10.0 h1:VMBQh88zXn64jXVvj39tlu/IgsGR84T7ImjS523DCiU=
Expand Down Expand Up @@ -376,8 +372,6 @@ github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZD
github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0=
github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM=
github.com/cosmos/ledger-cosmos-go v0.13.3/go.mod h1:HENcEP+VtahZFw38HZ3+LS3Iv5XV6svsnkk9vdJtLr8=
github.com/cosmos/rosetta-sdk-go v0.10.0 h1:E5RhTruuoA7KTIXUcMicL76cffyeoyvNybzUGSKFTcM=
github.com/cosmos/rosetta-sdk-go v0.10.0/go.mod h1:SImAZkb96YbwvoRkzSMQB6noNJXFgWl/ENIznEoYQI4=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand Down
16 changes: 7 additions & 9 deletions tests/integration/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
icstestingutils "github.com/cosmos/interchain-security/v4/testutil/ibc_testing"
testutil "github.com/cosmos/interchain-security/v4/testutil/integration"
consumertypes "github.com/cosmos/interchain-security/v4/x/ccv/consumer/types"
"github.com/cosmos/interchain-security/v4/x/ccv/provider/types"
ccv "github.com/cosmos/interchain-security/v4/x/ccv/types"
)

Expand Down Expand Up @@ -126,19 +125,18 @@ func (suite *CCVTestSuite) SetupTest() {
suite.registerPacketSniffer(suite.providerChain)
providerKeeper := suite.providerApp.GetProviderKeeper()

// re-assign all validator keys for the first consumer chain
providerKeeper.SetPendingConsumerAdditionProp(suite.providerCtx(), &types.ConsumerAdditionProposal{
ChainId: icstestingutils.FirstConsumerChainID,
})
preProposalKeyAssignment(suite, icstestingutils.FirstConsumerChainID)

// start consumer chains
numConsumers := 5
suite.consumerBundles = make(map[string]*icstestingutils.ConsumerBundle)
for i := 0; i < numConsumers; i++ {
bundle := suite.setupConsumerCallback(&suite.Suite, suite.coordinator, i)
suite.consumerBundles[bundle.Chain.ChainID] = bundle
suite.registerPacketSniffer(bundle.Chain)

// re-assign all validator keys for the first consumer chain
if i == 0 {
consumerKeyAssignment(suite, icstestingutils.FirstConsumerChainID)
}
}

// initialize each consumer chain with it's corresponding genesis state
Expand Down Expand Up @@ -355,10 +353,10 @@ func (s CCVTestSuite) validateEndpointsClientConfig(consumerBundle icstestinguti
)
}

// preProposalKeyAssignment assigns keys to all provider validators for
// consumerKeyAssignmentt assigns keys to all provider validators for
// the consumer with chainID before the chain is registered, i.e.,
// before a client to the consumer is created
func preProposalKeyAssignment(s *CCVTestSuite, chainID string) {
func consumerKeyAssignment(s *CCVTestSuite, chainID string) {
providerKeeper := s.providerApp.GetProviderKeeper()

for _, val := range s.providerChain.Vals.Validators {
Expand Down
2 changes: 1 addition & 1 deletion testutil/crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (v *CryptoIdentity) SDKStakingValidator() sdkstakingtypes.Validator {
}

func (v *CryptoIdentity) SDKValOpAddressString() string {
return v.OperatorSDKPubKey().Address().String()
return sdktypes.ValAddress(v.OperatorSDKPubKey().Address()).String()
}

func (v *CryptoIdentity) ConsensusSDKPubKey() sdkcryptotypes.PubKey {
Expand Down
4 changes: 2 additions & 2 deletions testutil/ibc_testing/generic_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp](

providerKeeper.SetPendingConsumerAdditionProp(providerChain.GetContext(), &prop)
propsToExecute := providerKeeper.GetConsumerAdditionPropsToExecute(providerChain.GetContext())
s.Require().Len(propsToExecute, 1)
s.Require().Len(propsToExecute, 1, "props to execute is incorrect length")

// commit the state on the provider chain
coordinator.CommitBlock(providerChain)
Expand All @@ -163,7 +163,7 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp](
for _, update := range consumerGenesisState.Provider.InitialValSet {
// tmPubKey update.PubKey
tmPubKey, err := tmencoding.PubKeyFromProto(update.PubKey)
s.Require().NoError(err)
s.Require().NoError(err, "failed to convert tendermint pubkey")
valz = append(valz, &tmtypes.Validator{
PubKey: tmPubKey,
VotingPower: update.Power,
Expand Down
2 changes: 1 addition & 1 deletion x/ccv/provider/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestInvalidMsg(t *testing.T) {
require.True(t, strings.Contains(err.Error(), "unrecognized provider message type"))
}

func TestAssignConsensusKeyForConsumerChain(t *testing.T) {
func TestAssignConsensusKeyMsgHandling(t *testing.T) {
providerCryptoId := testcrypto.NewCryptoIdentityFromIntSeed(0)
providerConsAddr := providerCryptoId.ProviderConsAddress()

Expand Down
3 changes: 1 addition & 2 deletions x/ccv/provider/keeper/consumer_equivocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,7 @@ func (k Keeper) SlashValidator(ctx sdk.Context, providerAddr types.ProviderConsA
return fmt.Errorf("validator is tombstoned. provider consensus address: %s", providerAddr.String())
}

// NOTE: on [email protected] validator.GetOperator() now returns a Hex string instead of sdk.ValAddress
valAddr, err := sdk.ValAddressFromHex(validator.GetOperator())
valAddr, err := k.ValidatorAddressCodec().StringToBytes(validator.GetOperator())
if err != nil {
return err
}
Expand Down
7 changes: 2 additions & 5 deletions x/ccv/provider/keeper/consumer_equivocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,13 +649,10 @@ func TestSlashValidator(t *testing.T) {
// undelegation or redelegation entries with completion time one hour in the future have not yet matured
nowPlus1Hour := now.Add(time.Hour)

keeperParams := testkeeper.NewInMemKeeperParams(t)
testkeeper.NewInMemProviderKeeper(keeperParams, mocks)

pubKey, _ := cryptocodec.FromTmPubKeyInterface(tmtypes.NewMockPV().PrivKey.PubKey())

validator, err := stakingtypes.NewValidator(
pubKey.Address().String(),
sdk.ValAddress(pubKey.Address()).String(),
pubKey,
stakingtypes.NewDescription("", "", "", "", ""),
)
Expand Down Expand Up @@ -687,7 +684,7 @@ func TestSlashValidator(t *testing.T) {
expectedInfractionHeight := int64(0)
expectedSlashPower := int64(3750)

expectedValoperAddr, err := sdk.ValAddressFromHex(validator.GetOperator())
expectedValoperAddr, err := keeper.ValidatorAddressCodec().StringToBytes(validator.GetOperator())
require.NoError(t, err)

expectedCalls := []*gomock.Call{
Expand Down
5 changes: 2 additions & 3 deletions x/ccv/provider/keeper/key_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,14 +455,13 @@ func (k Keeper) AssignConsumerKey(
oldConsumerKey = providerKey
}

// NOTE: on [email protected] validator.GetOperator() now returns a Hex string instead of sdk.ValAddress
valAddrBech32, err := sdk.ValAddressFromHex(validator.GetOperator())
valAddr, err := k.ValidatorAddressCodec().StringToBytes(validator.GetOperator())
if err != nil {
return err
}

// check whether the validator is valid, i.e., its power is positive
power, err := k.stakingKeeper.GetLastValidatorPower(ctx, valAddrBech32)
power, err := k.stakingKeeper.GetLastValidatorPower(ctx, valAddr)
if err != nil {
return err
}
Expand Down
11 changes: 4 additions & 7 deletions x/ccv/provider/keeper/key_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper_test

import (
"bytes"
"fmt"
"math/rand"
"sort"
"testing"
Expand Down Expand Up @@ -803,12 +802,10 @@ func TestSimulatedAssignmentsAndUpdateApplication(t *testing.T) {
// When the mocked method is called, locate the appropriate validator
// in the provider valset and return its power.
for i, id := range providerIDS {
// TODO: @MSalopek -> double check
valAddrFromHex, err := sdk.ValAddressFromHex(id.SDKStakingValidator().GetOperator())
if err != nil {
panic(fmt.Sprintf("could not get val address from hex: %s", err))
}
if valAddrFromHex.String() == valAddr.String() {
decodeValAddr, err := k.ValidatorAddressCodec().StringToBytes(id.SDKStakingValidator().GetOperator())
require.NoError(t, err)

if string(decodeValAddr) == valAddr.String() {
return providerValset.power[i]
}
}
Expand Down

0 comments on commit 5a13210

Please sign in to comment.