Skip to content

Commit b3a2781

Browse files
authored
test: fix key assignment in testing (#2344)
fix key assignment in testing
1 parent 6532a88 commit b3a2781

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

tests/integration/setup.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,15 @@ import (
99
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
1010
ibctmtypes "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
1111
ibctesting "github.com/cosmos/ibc-go/v8/testing"
12-
"github.com/cosmos/ibc-go/v8/testing/mock"
1312
"github.com/stretchr/testify/suite"
1413

1514
store "cosmossdk.io/store/types"
1615

17-
sdk "github.com/cosmos/cosmos-sdk/types"
18-
1916
abci "github.com/cometbft/cometbft/abci/types"
20-
tmencoding "github.com/cometbft/cometbft/crypto/encoding"
2117

2218
icstestingutils "github.com/cosmos/interchain-security/v6/testutil/ibc_testing"
2319
testutil "github.com/cosmos/interchain-security/v6/testutil/integration"
2420
consumertypes "github.com/cosmos/interchain-security/v6/x/ccv/consumer/types"
25-
providertypes "github.com/cosmos/interchain-security/v6/x/ccv/provider/types"
2621
ccv "github.com/cosmos/interchain-security/v6/x/ccv/types"
2722
)
2823

@@ -145,14 +140,6 @@ func (suite *CCVTestSuite) SetupTest() {
145140
params.BlocksPerEpoch = 10
146141
providerKeeper.SetParams(suite.providerCtx(), params)
147142

148-
// re-assign all validator keys for the first consumer chain
149-
// this has to be done before:
150-
// 1. the consumer chain is added to the coordinator
151-
// 2. MakeGenesis is called on the provider chain
152-
// 3. ibc/testing sets the tendermint header for the consumer chain app
153-
providerKeeper.SetConsumerPhase(suite.providerCtx(), icstestingutils.FirstConsumerID, providertypes.CONSUMER_PHASE_INITIALIZED)
154-
preProposalKeyAssignment(suite, icstestingutils.FirstConsumerID)
155-
156143
// start consumer chains
157144
suite.consumerBundles = make(map[string]*icstestingutils.ConsumerBundle)
158145
for i := 0; i < icstestingutils.NumConsumers; i++ {
@@ -416,34 +403,6 @@ func (s *CCVTestSuite) validateEndpointsClientConfig(consumerBundle icstestingut
416403
)
417404
}
418405

419-
// preProposalKeyAssignment assigns keys to all provider validators for
420-
// the consumer with consumerId before the chain is registered, i.e.,
421-
// before a client to the consumer is created
422-
func preProposalKeyAssignment(s *CCVTestSuite, consumerId string) {
423-
providerKeeper := s.providerApp.GetProviderKeeper()
424-
425-
for _, val := range s.providerChain.Vals.Validators {
426-
// get SDK validator
427-
valAddr, err := sdk.ValAddressFromHex(val.Address.String())
428-
s.Require().NoError(err)
429-
validator := s.getVal(s.providerCtx(), valAddr)
430-
431-
// generate new PrivValidator
432-
privVal := mock.NewPV()
433-
tmPubKey, err := privVal.GetPubKey()
434-
s.Require().NoError(err)
435-
consumerKey, err := tmencoding.PubKeyToProto(tmPubKey)
436-
s.Require().NoError(err)
437-
438-
// add Signer to the provider chain as there is no consumer chain to add it;
439-
// as a result, NewTestChainWithValSet in AddConsumer uses providerChain.Signers
440-
s.providerChain.Signers[tmPubKey.Address().String()] = privVal
441-
442-
err = providerKeeper.AssignConsumerKey(s.providerCtx(), consumerId, validator, consumerKey)
443-
s.Require().NoError(err)
444-
}
445-
}
446-
447406
// packetSniffer implements the StreamingService interface.
448407
// Implements ListenEndBlock to record packets from events.
449408
type packetSniffer struct {

testutil/ibc_testing/generic_setup.go

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
99
ibctesting "github.com/cosmos/ibc-go/v8/testing"
10+
"github.com/cosmos/ibc-go/v8/testing/mock"
1011
"github.com/stretchr/testify/require"
1112
"github.com/stretchr/testify/suite"
1213

@@ -19,6 +20,7 @@ import (
1920
testutil "github.com/cosmos/interchain-security/v6/testutil/integration"
2021
testkeeper "github.com/cosmos/interchain-security/v6/testutil/keeper"
2122
consumerkeeper "github.com/cosmos/interchain-security/v6/x/ccv/consumer/keeper"
23+
providerkeeper "github.com/cosmos/interchain-security/v6/x/ccv/provider/keeper"
2224
providertypes "github.com/cosmos/interchain-security/v6/x/ccv/provider/types"
2325
)
2426

@@ -155,9 +157,6 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp](
155157
powerShapingParameters.Top_N = consumerTopNParams[index] // isn't used in CreateConsumerClient
156158

157159
consumerId := providerKeeper.FetchAndIncrementConsumerId(providerChain.GetContext())
158-
if chainID == firstConsumerChainID {
159-
FirstConsumerID = consumerId
160-
}
161160
providerKeeper.SetConsumerChainId(providerChain.GetContext(), consumerId, chainID)
162161
err := providerKeeper.SetConsumerMetadata(providerChain.GetContext(), consumerId, consumerMetadata)
163162
s.Require().NoError(err)
@@ -166,6 +165,15 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp](
166165
err = providerKeeper.SetConsumerPowerShapingParameters(providerChain.GetContext(), consumerId, powerShapingParameters)
167166
s.Require().NoError(err)
168167
providerKeeper.SetConsumerPhase(providerChain.GetContext(), consumerId, providertypes.CONSUMER_PHASE_INITIALIZED)
168+
if chainID == firstConsumerChainID {
169+
FirstConsumerID = consumerId
170+
// re-assign all validator keys for the first consumer chain
171+
// this has to be done before:
172+
// 1. the consumer chain is added to the coordinator
173+
// 2. MakeGenesis is called on the provider chain
174+
// 3. ibc/testing sets the tendermint header for the consumer chain app
175+
preProposalKeyAssignment(s, *providerChain, providerKeeper, providerApp, FirstConsumerID)
176+
}
169177
err = providerKeeper.AppendConsumerToBeLaunched(providerChain.GetContext(), consumerId, coordinator.CurrentTime)
170178
s.Require().NoError(err)
171179

@@ -228,3 +236,36 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp](
228236
TopN: powerShapingParameters.Top_N,
229237
}
230238
}
239+
240+
// preProposalKeyAssignment assigns keys to all provider validators for
241+
// the consumer with consumerId before the chain is registered, i.e.,
242+
// before a client to the consumer is created
243+
func preProposalKeyAssignment(
244+
s *suite.Suite,
245+
providerChain ibctesting.TestChain,
246+
providerKeeper providerkeeper.Keeper,
247+
providerApp testutil.ProviderApp,
248+
consumerId string,
249+
) {
250+
for _, val := range providerChain.Vals.Validators {
251+
// get SDK validator
252+
valAddr, err := sdk.ValAddressFromHex(val.Address.String())
253+
s.Require().NoError(err)
254+
validator, err := providerApp.GetTestStakingKeeper().GetValidator(providerChain.GetContext(), valAddr)
255+
s.Require().NoError(err)
256+
257+
// generate new PrivValidator
258+
privVal := mock.NewPV()
259+
tmPubKey, err := privVal.GetPubKey()
260+
s.Require().NoError(err)
261+
consumerKey, err := tmencoding.PubKeyToProto(tmPubKey)
262+
s.Require().NoError(err)
263+
264+
// add Signer to the provider chain as there is no consumer chain to add it;
265+
// as a result, NewTestChainWithValSet in AddConsumer uses providerChain.Signers
266+
providerChain.Signers[tmPubKey.Address().String()] = privVal
267+
268+
err = providerKeeper.AssignConsumerKey(providerChain.GetContext(), consumerId, validator, consumerKey)
269+
s.Require().NoError(err)
270+
}
271+
}

0 commit comments

Comments
 (0)