@@ -32,6 +32,8 @@ type Chain struct {
32
32
ValidatorWallets []ValidatorWallet
33
33
RelayerWallet ibc.Wallet
34
34
TestWallets []ibc.Wallet
35
+ walletMtx sync.Mutex
36
+ walletsInUse map [int ]bool
35
37
}
36
38
37
39
type ValidatorWallet struct {
@@ -49,6 +51,7 @@ func chainFromCosmosChain(cosmos *cosmos.CosmosChain, relayerWallet ibc.Wallet,
49
51
c .ValidatorWallets = wallets
50
52
c .RelayerWallet = relayerWallet
51
53
c .TestWallets = testWallets
54
+ c .walletsInUse = make (map [int ]bool )
52
55
return c , nil
53
56
}
54
57
@@ -88,7 +91,7 @@ func CreateChain(ctx context.Context, testName interchaintest.TestName, spec *in
88
91
}
89
92
90
93
// build test wallets
91
- testWallets , err := setupTestWallets (ctx , cosmosChain , TestWalletsNumber )
94
+ testWallets , err := SetupTestWallets (ctx , cosmosChain , TestWalletsNumber )
92
95
if err != nil {
93
96
return nil , err
94
97
}
@@ -100,7 +103,7 @@ func CreateChain(ctx context.Context, testName interchaintest.TestName, spec *in
100
103
return chain , nil
101
104
}
102
105
103
- func setupTestWallets (ctx context.Context , cosmosChain * cosmos.CosmosChain , walletCount int ) ([]ibc.Wallet , error ) {
106
+ func SetupTestWallets (ctx context.Context , cosmosChain * cosmos.CosmosChain , walletCount int ) ([]ibc.Wallet , error ) {
104
107
wallets := make ([]ibc.Wallet , walletCount )
105
108
eg := new (errgroup.Group )
106
109
for i := 0 ; i < walletCount ; i ++ {
@@ -159,6 +162,85 @@ func getValidatorWallets(ctx context.Context, chain *Chain) ([]ValidatorWallet,
159
162
return wallets , nil
160
163
}
161
164
165
+ func (p * Chain ) AddConsumerChain (ctx context.Context , relayer * Relayer , spec * interchaintest.ChainSpec ) (* Chain , error ) {
166
+ dockerClient , dockerNetwork := GetDockerContext (ctx )
167
+
168
+ cf := interchaintest .NewBuiltinChainFactory (
169
+ GetLogger (ctx ),
170
+ []* interchaintest.ChainSpec {spec },
171
+ )
172
+
173
+ chains , err := cf .Chains (p .GetNode ().TestName )
174
+ if err != nil {
175
+ return nil , err
176
+ }
177
+ consumer := chains [0 ].(* cosmos.CosmosChain )
178
+
179
+ // We can't use AddProviderConsumerLink here because the provider chain is already built; we'll have to do everything by hand.
180
+ p .Consumers = append (p .Consumers , consumer )
181
+ consumer .Provider = p .CosmosChain
182
+ relayerWallet , err := consumer .BuildRelayerWallet (ctx , "relayer-" + consumer .Config ().ChainID )
183
+ if err != nil {
184
+ return nil , err
185
+ }
186
+ wallets := make ([]ibc.Wallet , len (p .Validators )+ 1 )
187
+ wallets [0 ] = relayerWallet
188
+ // This is a hack, but we need to create wallets for the validators that have the right moniker.
189
+ for i := 1 ; i <= len (p .Validators ); i ++ {
190
+ wallets [i ], err = consumer .BuildRelayerWallet (ctx , ValidatorMoniker )
191
+ if err != nil {
192
+ return nil , err
193
+ }
194
+ }
195
+ walletAmounts := make ([]ibc.WalletAmount , len (wallets ))
196
+ for i , wallet := range wallets {
197
+ walletAmounts [i ] = ibc.WalletAmount {
198
+ Address : wallet .FormattedAddress (),
199
+ Denom : consumer .Config ().Denom ,
200
+ Amount : sdkmath .NewInt (TotalValidatorFunds ),
201
+ }
202
+ }
203
+
204
+ ic := interchaintest .NewInterchain ().
205
+ AddChain (consumer , walletAmounts ... ).
206
+ AddRelayer (relayer , "relayer" )
207
+
208
+ if err := ic .Build (ctx , GetRelayerExecReporter (ctx ), interchaintest.InterchainBuildOptions {
209
+ Client : dockerClient ,
210
+ NetworkID : dockerNetwork ,
211
+ TestName : p .GetNode ().TestName ,
212
+ }); err != nil {
213
+ return nil , err
214
+ }
215
+
216
+ for i , val := range consumer .Validators {
217
+ if err := val .RecoverKey (ctx , ValidatorMoniker , wallets [i + 1 ].Mnemonic ()); err != nil {
218
+ return nil , err
219
+ }
220
+ }
221
+ consumerChain , err := chainFromCosmosChain (consumer , relayerWallet , p .TestWallets )
222
+ if err != nil {
223
+ return nil , err
224
+ }
225
+
226
+ return consumerChain , nil
227
+ }
228
+
229
+ // GetUnusedTestingAddresss retrieves an unused wallet address and its key name safely
230
+ func (p * Chain ) GetUnusedTestingAddresss () (formattedAddress string , keyName string , err error ) {
231
+ p .walletMtx .Lock ()
232
+ defer p .walletMtx .Unlock ()
233
+
234
+ for i , wallet := range p .TestWallets {
235
+ if ! p .walletsInUse [i ] {
236
+ p .walletsInUse [i ] = true
237
+ return wallet .FormattedAddress (), wallet .KeyName (), nil
238
+ }
239
+ }
240
+
241
+ return "" , "" , fmt .Errorf ("no unused wallets available" )
242
+ }
243
+
162
244
// UpdateAndVerifyStakeChange updates the staking amount on the provider chain and verifies that the change is reflected on the consumer side
163
245
func (p * Chain ) UpdateAndVerifyStakeChange (ctx context.Context , consumer * Chain , relayer * Relayer , amount , valIdx int ) error {
164
246
@@ -552,6 +634,36 @@ func (c *Chain) GetCcvConsumerParams(ctx context.Context) (ConsumerParamsRespons
552
634
return queryResponse , nil
553
635
}
554
636
637
+ func (c * Chain ) GetProviderInfo (ctx context.Context ) (ProviderInfoResponse , error ) {
638
+ queryRes , _ , err := c .GetNode ().ExecQuery (
639
+ ctx ,
640
+ "ccvconsumer" , "provider-info" ,
641
+ )
642
+ if err != nil {
643
+ return ProviderInfoResponse {}, err
644
+ }
645
+
646
+ var queryResponse ProviderInfoResponse
647
+ err = json .Unmarshal ([]byte (queryRes ), & queryResponse )
648
+ if err != nil {
649
+ return ProviderInfoResponse {}, err
650
+ }
651
+
652
+ return queryResponse , nil
653
+ }
654
+
655
+ func (c * Chain ) QueryJSON (ctx context.Context , jsonPath string , query ... string ) (gjson.Result , error ) {
656
+ stdout , _ , err := c .GetNode ().ExecQuery (ctx , query ... )
657
+ if err != nil {
658
+ return gjson.Result {}, err
659
+ }
660
+ retval := gjson .GetBytes (stdout , jsonPath )
661
+ if ! retval .Exists () {
662
+ return gjson.Result {}, fmt .Errorf ("json path %s not found in query result %s" , jsonPath , stdout )
663
+ }
664
+ return retval , nil
665
+ }
666
+
555
667
func getEvtAttribute (events []abci.Event , evtType string , key string ) (string , bool ) {
556
668
for _ , evt := range events {
557
669
if evt .GetType () == evtType {
0 commit comments