7
7
8
8
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
9
9
ibctesting "github.com/cosmos/ibc-go/v8/testing"
10
+ "github.com/cosmos/ibc-go/v8/testing/mock"
10
11
"github.com/stretchr/testify/require"
11
12
"github.com/stretchr/testify/suite"
12
13
@@ -19,6 +20,7 @@ import (
19
20
testutil "github.com/cosmos/interchain-security/v6/testutil/integration"
20
21
testkeeper "github.com/cosmos/interchain-security/v6/testutil/keeper"
21
22
consumerkeeper "github.com/cosmos/interchain-security/v6/x/ccv/consumer/keeper"
23
+ providerkeeper "github.com/cosmos/interchain-security/v6/x/ccv/provider/keeper"
22
24
providertypes "github.com/cosmos/interchain-security/v6/x/ccv/provider/types"
23
25
)
24
26
@@ -155,9 +157,6 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp](
155
157
powerShapingParameters .Top_N = consumerTopNParams [index ] // isn't used in CreateConsumerClient
156
158
157
159
consumerId := providerKeeper .FetchAndIncrementConsumerId (providerChain .GetContext ())
158
- if chainID == firstConsumerChainID {
159
- FirstConsumerID = consumerId
160
- }
161
160
providerKeeper .SetConsumerChainId (providerChain .GetContext (), consumerId , chainID )
162
161
err := providerKeeper .SetConsumerMetadata (providerChain .GetContext (), consumerId , consumerMetadata )
163
162
s .Require ().NoError (err )
@@ -166,6 +165,15 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp](
166
165
err = providerKeeper .SetConsumerPowerShapingParameters (providerChain .GetContext (), consumerId , powerShapingParameters )
167
166
s .Require ().NoError (err )
168
167
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
+ }
169
177
err = providerKeeper .AppendConsumerToBeLaunched (providerChain .GetContext (), consumerId , coordinator .CurrentTime )
170
178
s .Require ().NoError (err )
171
179
@@ -228,3 +236,36 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp](
228
236
TopN : powerShapingParameters .Top_N ,
229
237
}
230
238
}
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