From 5a13210cc18fe01d6236c999e5f8bfe471d311d0 Mon Sep 17 00:00:00 2001 From: MSalopek Date: Mon, 4 Mar 2024 21:41:50 +0100 Subject: [PATCH] tests: update test setup; refactor key_assignment addr parser --- app/provider/app.go | 3 +-- app/provider/export.go | 5 ++++- go.mod | 17 +++++++---------- go.sum | 6 ------ tests/integration/setup.go | 16 +++++++--------- testutil/crypto/crypto.go | 2 +- testutil/ibc_testing/generic_setup.go | 4 ++-- x/ccv/provider/handler_test.go | 2 +- x/ccv/provider/keeper/consumer_equivocation.go | 3 +-- .../keeper/consumer_equivocation_test.go | 7 ++----- x/ccv/provider/keeper/key_assignment.go | 5 ++--- x/ccv/provider/keeper/key_assignment_test.go | 11 ++++------- 12 files changed, 32 insertions(+), 49 deletions(-) diff --git a/app/provider/app.go b/app/provider/app.go index e2d7320122..98d67fce72 100644 --- a/app/provider/app.go +++ b/app/provider/app.go @@ -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" @@ -158,7 +157,6 @@ var ( evidence.AppModuleBasic{}, transfer.AppModuleBasic{}, vesting.AppModuleBasic{}, - tendermint.AppModuleBasic{}, // router.AppModuleBasic{}, ibcprovider.AppModuleBasic{}, ) @@ -287,6 +285,7 @@ func New( evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, providertypes.StoreKey, + consensusparamtypes.StoreKey, ) // register streaming services diff --git a/app/provider/export.go b/app/provider/export.go index ce7158634c..a99ef9e83c 100644 --- a/app/provider/export.go +++ b/app/provider/export.go @@ -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) } @@ -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) diff --git a/go.mod b/go.mod index d173e26405..de8ccbce45 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 3d8cda3a73..1b3a707ec1 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= diff --git a/tests/integration/setup.go b/tests/integration/setup.go index 1f2ba15883..f9239330ab 100644 --- a/tests/integration/setup.go +++ b/tests/integration/setup.go @@ -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" ) @@ -126,12 +125,6 @@ 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) @@ -139,6 +132,11 @@ func (suite *CCVTestSuite) SetupTest() { 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 @@ -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 { diff --git a/testutil/crypto/crypto.go b/testutil/crypto/crypto.go index 8b755d6a7f..cad27a9a02 100644 --- a/testutil/crypto/crypto.go +++ b/testutil/crypto/crypto.go @@ -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 { diff --git a/testutil/ibc_testing/generic_setup.go b/testutil/ibc_testing/generic_setup.go index deb13482ef..7048f31853 100644 --- a/testutil/ibc_testing/generic_setup.go +++ b/testutil/ibc_testing/generic_setup.go @@ -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) @@ -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, diff --git a/x/ccv/provider/handler_test.go b/x/ccv/provider/handler_test.go index f795e823d2..96cd896a08 100644 --- a/x/ccv/provider/handler_test.go +++ b/x/ccv/provider/handler_test.go @@ -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() diff --git a/x/ccv/provider/keeper/consumer_equivocation.go b/x/ccv/provider/keeper/consumer_equivocation.go index 8d6191ad72..f89bc59129 100644 --- a/x/ccv/provider/keeper/consumer_equivocation.go +++ b/x/ccv/provider/keeper/consumer_equivocation.go @@ -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 cosmos-sdk@v0.50 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 } diff --git a/x/ccv/provider/keeper/consumer_equivocation_test.go b/x/ccv/provider/keeper/consumer_equivocation_test.go index 9b62285038..4d16d3b2d9 100644 --- a/x/ccv/provider/keeper/consumer_equivocation_test.go +++ b/x/ccv/provider/keeper/consumer_equivocation_test.go @@ -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("", "", "", "", ""), ) @@ -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{ diff --git a/x/ccv/provider/keeper/key_assignment.go b/x/ccv/provider/keeper/key_assignment.go index a986181688..c6d5261547 100644 --- a/x/ccv/provider/keeper/key_assignment.go +++ b/x/ccv/provider/keeper/key_assignment.go @@ -455,14 +455,13 @@ func (k Keeper) AssignConsumerKey( oldConsumerKey = providerKey } - // NOTE: on cosmos-sdk@v0.50 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 } diff --git a/x/ccv/provider/keeper/key_assignment_test.go b/x/ccv/provider/keeper/key_assignment_test.go index 77a5eae039..bdb281d450 100644 --- a/x/ccv/provider/keeper/key_assignment_test.go +++ b/x/ccv/provider/keeper/key_assignment_test.go @@ -2,7 +2,6 @@ package keeper_test import ( "bytes" - "fmt" "math/rand" "sort" "testing" @@ -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] } }