-
Notifications
You must be signed in to change notification settings - Fork 686
/
Copy pathupgrade_test.go
821 lines (629 loc) · 32.5 KB
/
upgrade_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
package upgrades
import (
"context"
"fmt"
"testing"
"time"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/gogoproto/proto"
// intertxtypes "github.com/cosmos/interchain-accounts/x/inter-tx/types"
interchaintest "github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
test "github.com/strangelove-ventures/interchaintest/v8/testutil"
testifysuite "github.com/stretchr/testify/suite"
sdkmath "cosmossdk.io/math"
upgradetypes "cosmossdk.io/x/upgrade/types"
sdk "github.com/cosmos/cosmos-sdk/types"
e2erelayer "github.com/cosmos/ibc-go/e2e/relayer"
"github.com/cosmos/ibc-go/e2e/testsuite"
"github.com/cosmos/ibc-go/e2e/testvalues"
v7migrations "github.com/cosmos/ibc-go/v8/modules/core/02-client/migrations/v7"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
"github.com/cosmos/ibc-go/v8/modules/core/exported"
solomachine "github.com/cosmos/ibc-go/v8/modules/light-clients/06-solomachine"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
)
const (
haltHeight = uint64(100)
blocksAfterUpgrade = uint64(10)
)
func TestUpgradeTestSuite(t *testing.T) {
testCfg := testsuite.LoadConfig()
if testCfg.UpgradeConfig.Tag == "" || testCfg.UpgradeConfig.PlanName == "" {
t.Fatalf("%s and %s must be set when running an upgrade test", testsuite.ChainUpgradeTagEnv, testsuite.ChainUpgradePlanEnv)
}
testifysuite.Run(t, new(UpgradeTestSuite))
}
type UpgradeTestSuite struct {
testsuite.E2ETestSuite
}
// UpgradeChain upgrades a chain to a specific version using the planName provided.
// The software upgrade proposal is broadcast by the provided wallet.
func (s *UpgradeTestSuite) UpgradeChain(ctx context.Context, chain *cosmos.CosmosChain, wallet ibc.Wallet, planName, currentVersion, upgradeVersion string) {
plan := upgradetypes.Plan{
Name: planName,
Height: int64(haltHeight),
Info: fmt.Sprintf("upgrade version test from %s to %s", currentVersion, upgradeVersion),
}
upgradeProposal := upgradetypes.NewSoftwareUpgradeProposal(fmt.Sprintf("upgrade from %s to %s", currentVersion, upgradeVersion), "upgrade chain E2E test", plan)
s.ExecuteGovV1Beta1Proposal(ctx, chain, wallet, upgradeProposal)
height, err := chain.Height(ctx)
s.Require().NoError(err, "error fetching height before upgrade")
timeoutCtx, timeoutCtxCancel := context.WithTimeout(ctx, time.Minute*2)
defer timeoutCtxCancel()
err = test.WaitForBlocks(timeoutCtx, int(haltHeight-height)+1, chain)
s.Require().Error(err, "chain did not halt at halt height")
err = chain.StopAllNodes(ctx)
s.Require().NoError(err, "error stopping node(s)")
chain.UpgradeVersion(ctx, s.DockerClient, getChainImage(chain), upgradeVersion)
err = chain.StartAllNodes(ctx)
s.Require().NoError(err, "error starting upgraded node(s)")
// we are reinitializing the clients because we need to update the hostGRPCAddress after
// the upgrade and subsequent restarting of nodes
s.InitGRPCClients(chain)
timeoutCtx, timeoutCtxCancel = context.WithTimeout(ctx, time.Minute*2)
defer timeoutCtxCancel()
err = test.WaitForBlocks(timeoutCtx, int(blocksAfterUpgrade), chain)
s.Require().NoError(err, "chain did not produce blocks after upgrade")
height, err = chain.Height(ctx)
s.Require().NoError(err, "error fetching height after upgrade")
s.Require().Greater(height, haltHeight, "height did not increment after upgrade")
}
func (s *UpgradeTestSuite) TestIBCChainUpgrade() {
t := s.T()
testCfg := testsuite.LoadConfig()
ctx := context.Background()
relayer, channelA := s.SetupChainsRelayerAndChannel(ctx)
chainA, chainB := s.GetChains()
var (
chainADenom = chainA.Config().Denom
chainBIBCToken = testsuite.GetIBCToken(chainADenom, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID) // IBC token sent to chainB
chainBDenom = chainB.Config().Denom
chainAIBCToken = testsuite.GetIBCToken(chainBDenom, channelA.PortID, channelA.ChannelID) // IBC token sent to chainA
)
// create separate user specifically for the upgrade proposal to more easily verify starting
// and end balances of the chainA users.
chainAUpgradeProposalWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
chainAAddress := chainAWallet.FormattedAddress()
chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)
chainBAddress := chainBWallet.FormattedAddress()
s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks")
t.Run("native IBC token transfer from chainA to chainB, sender is source of tokens", func(t *testing.T) {
transferTxResp := s.Transfer(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, testvalues.DefaultTransferAmount(chainADenom), chainAAddress, chainBAddress, s.GetTimeoutHeight(ctx, chainB), 0, "")
s.AssertTxSuccess(transferTxResp)
})
t.Run("tokens are escrowed", func(t *testing.T) {
actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet)
s.Require().NoError(err)
expected := testvalues.StartingTokenAmount - testvalues.IBCTransferAmount
s.Require().Equal(expected, actualBalance)
})
t.Run("start relayer", func(t *testing.T) {
s.StartRelayer(relayer)
})
t.Run("packets are relayed", func(t *testing.T) {
s.AssertPacketRelayed(ctx, chainA, channelA.PortID, channelA.ChannelID, 1)
actualBalance, err := chainB.GetBalance(ctx, chainBAddress, chainBIBCToken.IBCDenom())
s.Require().NoError(err)
expected := testvalues.IBCTransferAmount
s.Require().Equal(expected, actualBalance.Int64())
})
s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB), "failed to wait for blocks")
t.Run("upgrade chainA", func(t *testing.T) {
s.UpgradeChain(ctx, chainA, chainAUpgradeProposalWallet, testCfg.UpgradeConfig.PlanName, testCfg.ChainConfigs[0].Tag, testCfg.UpgradeConfig.Tag)
})
t.Run("restart relayer", func(t *testing.T) {
s.StopRelayer(ctx, relayer)
s.StartRelayer(relayer)
})
t.Run("native IBC token transfer from chainA to chainB, sender is source of tokens", func(t *testing.T) {
transferTxResp := s.Transfer(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, testvalues.DefaultTransferAmount(chainADenom), chainAAddress, chainBAddress, s.GetTimeoutHeight(ctx, chainB), 0, "")
s.AssertTxSuccess(transferTxResp)
})
s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB), "failed to wait for blocks")
t.Run("packets are relayed", func(t *testing.T) {
s.AssertPacketRelayed(ctx, chainA, channelA.PortID, channelA.ChannelID, 2)
actualBalance, err := chainB.GetBalance(ctx, chainBAddress, chainBIBCToken.IBCDenom())
s.Require().NoError(err)
expected := testvalues.IBCTransferAmount * 2
s.Require().Equal(expected, actualBalance.Int64())
})
t.Run("ensure packets can be received, send from chainB to chainA", func(t *testing.T) {
t.Run("send from chainB to chainA", func(t *testing.T) {
transferTxResp := s.Transfer(ctx, chainB, chainBWallet, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID, testvalues.DefaultTransferAmount(chainBDenom), chainBAddress, chainAAddress, s.GetTimeoutHeight(ctx, chainA), 0, "")
s.AssertTxSuccess(transferTxResp)
})
s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB), "failed to wait for blocks")
t.Run("packets are relayed", func(t *testing.T) {
s.AssertPacketRelayed(ctx, chainA, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID, 1)
actualBalance, err := chainA.GetBalance(ctx, chainAAddress, chainAIBCToken.IBCDenom())
s.Require().NoError(err)
expected := testvalues.IBCTransferAmount
s.Require().Equal(expected, actualBalance.Int64())
})
})
}
func (s *UpgradeTestSuite) TestChainUpgrade() {
t := s.T()
ctx := context.Background()
chain := s.SetupSingleChain(ctx)
userWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
userWalletAddr := userWallet.FormattedAddress()
s.Require().NoError(test.WaitForBlocks(ctx, 1, chain), "failed to wait for blocks")
t.Run("send funds to test wallet", func(t *testing.T) {
err := chain.SendFunds(ctx, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{
Address: userWalletAddr,
Amount: sdkmath.NewInt(testvalues.StartingTokenAmount),
Denom: chain.Config().Denom,
})
s.Require().NoError(err)
})
t.Run("verify tokens sent", func(t *testing.T) {
balance, err := chain.GetBalance(ctx, userWalletAddr, chain.Config().Denom)
s.Require().NoError(err)
expected := testvalues.StartingTokenAmount * 2
s.Require().Equal(expected, balance)
})
t.Run("upgrade chain", func(t *testing.T) {
testCfg := testsuite.LoadConfig()
proposerWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
s.UpgradeChain(ctx, chain, proposerWallet, testCfg.UpgradeConfig.PlanName, testCfg.ChainConfigs[0].Tag, testCfg.UpgradeConfig.Tag)
})
t.Run("send funds to test wallet", func(t *testing.T) {
err := chain.SendFunds(ctx, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{
Address: userWalletAddr,
Amount: sdkmath.NewInt(testvalues.StartingTokenAmount),
Denom: chain.Config().Denom,
})
s.Require().NoError(err)
})
t.Run("verify tokens sent", func(t *testing.T) {
balance, err := chain.GetBalance(ctx, userWalletAddr, chain.Config().Denom)
s.Require().NoError(err)
expected := testvalues.StartingTokenAmount * 3
s.Require().Equal(expected, balance)
})
}
// func (s *UpgradeTestSuite) TestV5ToV6ChainUpgrade() {
// t := s.T()
// testCfg := testsuite.LoadConfig()
// ctx := context.Background()
// relayer, _ := s.SetupChainsRelayerAndChannel(ctx)
// chainA, chainB := s.GetChains()
// // create separate user specifically for the upgrade proposal to more easily verify starting
// // and end balances of the chainA users.
// chainAUpgradeProposalWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
// s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks")
// // setup 2 accounts: controller account on chain A, a second chain B account.
// // host account will be created when the ICA is registered
// controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
// chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)
// var hostAccount string
// t.Run("register interchain account", func(t *testing.T) {
// // explicitly set the version string because intertx with ibfc-go v5 does not support incentivized channels.
// version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID)
// msgRegisterAccount := intertxtypes.NewMsgRegisterAccount(controllerAccount.FormattedAddress(), ibctesting.FirstConnectionID, version)
// s.RegisterInterchainAccount(ctx, chainA, controllerAccount, msgRegisterAccount)
// })
// t.Run("start relayer", func(t *testing.T) {
// s.StartRelayer(relayer)
// })
// t.Run("verify interchain account", func(t *testing.T) {
// var err error
// hostAccount, err = s.QueryInterchainAccount(ctx, chainA, controllerAccount.FormattedAddress(), ibctesting.FirstConnectionID)
// s.Require().NoError(err)
// s.Require().NotZero(len(hostAccount))
// channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID)
// s.Require().NoError(err)
// s.Require().Equal(len(channels), 2)
// })
// t.Run("interchain account executes a bank transfer on behalf of the corresponding owner account", func(t *testing.T) {
// t.Run("fund interchain account wallet", func(t *testing.T) {
// // fund the host account, so it has some $$ to send
// err := chainB.SendFunds(ctx, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{
// Address: hostAccount,
// Amount: sdkmath.NewInt(testvalues.StartingTokenAmount),
// Denom: chainB.Config().Denom,
// })
// s.Require().NoError(err)
// })
// t.Run("broadcast MsgSubmitTx (legacy)", func(t *testing.T) {
// // assemble bank transfer message from host account to user account on host chain
// msgSend := &banktypes.MsgSend{
// FromAddress: hostAccount,
// ToAddress: chainBAccount.FormattedAddress(),
// Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)),
// }
// // assemble submitMessage tx for intertx
// msgSubmitTx, err := intertxtypes.NewMsgSubmitTx(
// msgSend,
// ibctesting.FirstConnectionID,
// controllerAccount.FormattedAddress(),
// )
// s.Require().NoError(err)
// // broadcast submitMessage tx from controller account on chain A
// // this message should trigger the sending of an ICA packet over channel-1 (channel created between controller and host)
// // this ICA packet contains the assembled bank transfer message from above, which will be executed by the host account on the host chain.
// resp := s.BroadcastMessages(
// ctx,
// chainA,
// controllerAccount,
// msgSubmitTx,
// )
// s.AssertTxSuccess(resp)
// s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB))
// })
// t.Run("verify tokens transferred", func(t *testing.T) {
// balance, err := chainB.GetBalance(ctx, chainBAccount.FormattedAddress(), chainB.Config().Denom)
// s.Require().NoError(err)
// _, err = chainB.GetBalance(ctx, hostAccount, chainB.Config().Denom)
// s.Require().NoError(err)
// expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount
// s.Require().Equal(expected, balance)
// })
// })
// s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB), "failed to wait for blocks")
// t.Run("upgrade chainA", func(t *testing.T) {
// s.UpgradeChain(ctx, chainA, chainAUpgradeProposalWallet, testCfg.UpgradeConfig.PlanName, testCfg.ChainConfigs[0].Tag, testCfg.UpgradeConfig.Tag)
// })
// t.Run("restart relayer", func(t *testing.T) {
// s.StopRelayer(ctx, relayer)
// s.StartRelayer(relayer)
// })
// t.Run("broadcast MsgSubmitTx (legacy)", func(t *testing.T) {
// // assemble bank transfer message from host account to user account on host chain
// msgSend := &banktypes.MsgSend{
// FromAddress: hostAccount,
// ToAddress: chainBAccount.FormattedAddress(),
// Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)),
// }
// // assemble submitMessage tx for intertx
// msgSubmitTx, err := intertxtypes.NewMsgSubmitTx(
// msgSend,
// ibctesting.FirstConnectionID,
// controllerAccount.FormattedAddress(),
// )
// s.Require().NoError(err)
// // broadcast submitMessage tx from controller account on chain A
// // this message should trigger the sending of an ICA packet over channel-1 (channel created between controller and host)
// // this ICA packet contains the assembled bank transfer message from above, which will be executed by the host account on the host chain.
// resp := s.BroadcastMessages(
// ctx,
// chainA,
// controllerAccount,
// msgSubmitTx,
// )
// s.AssertTxSuccess(resp)
// s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB))
// })
// t.Run("verify tokens transferred", func(t *testing.T) {
// balance, err := chainB.GetBalance(ctx, chainBAccount.FormattedAddress(), chainB.Config().Denom)
// s.Require().NoError(err)
// _, err = chainB.GetBalance(ctx, hostAccount, chainB.Config().Denom)
// s.Require().NoError(err)
// expected := (testvalues.IBCTransferAmount * 2) + testvalues.StartingTokenAmount
// s.Require().Equal(expected, balance)
// })
// t.Run("broadcast MsgSendTx (MsgServer)", func(t *testing.T) {
// // assemble bank transfer message from host account to user account on host chain
// msgSend := &banktypes.MsgSend{
// FromAddress: hostAccount,
// ToAddress: chainBAccount.FormattedAddress(),
// Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)),
// }
// data, err := icatypes.SerializeCosmosTx(testsuite.Codec(), []proto.Message{msgSend}, icatypes.EncodingProtobuf)
// s.Require().NoError(err)
// icaPacketData := icatypes.InterchainAccountPacketData{
// Type: icatypes.EXECUTE_TX,
// Data: data,
// }
// relativeTimeoutTimestamp := uint64(time.Hour.Nanoseconds())
// msgSendTx := controllertypes.NewMsgSendTx(controllerAccount.FormattedAddress(), ibctesting.FirstConnectionID, relativeTimeoutTimestamp, icaPacketData)
// // broadcast MsgSendTx tx from controller account on chain A
// // this message should trigger the sending of an ICA packet over channel-1 (channel created between controller and host)
// // this ICA packet contains the assembled bank transfer message from above, which will be executed by the host account on the host chain.
// resp := s.BroadcastMessages(
// ctx,
// chainA,
// controllerAccount,
// msgSendTx,
// )
// s.AssertTxSuccess(resp)
// s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB))
// })
// t.Run("verify tokens transferred", func(t *testing.T) {
// balance, err := chainB.GetBalance(ctx, chainBAccount.FormattedAddress(), chainB.Config().Denom)
// s.Require().NoError(err)
// _, err = chainB.GetBalance(ctx, hostAccount, chainB.Config().Denom)
// s.Require().NoError(err)
// expected := (testvalues.IBCTransferAmount * 3) + testvalues.StartingTokenAmount
// s.Require().Equal(expected, balance)
// })
// }
// TestV6ToV7ChainUpgrade will test that an upgrade from a v6 ibc-go binary to a v7 ibc-go binary is successful
// and that the automatic migrations associated with the 02-client module are performed. Namely that the solo machine
// proto definition is migrated in state from the v2 to v3 definition. This is checked by creating a solo machine client
// before the upgrade and asserting that its TypeURL has been changed after the upgrade. The test also ensure packets
// can be sent before and after the upgrade without issue
func (s *UpgradeTestSuite) TestV6ToV7ChainUpgrade() {
t := s.T()
testCfg := testsuite.LoadConfig()
ctx := context.Background()
relayer, channelA := s.SetupChainsRelayerAndChannel(ctx)
chainA, chainB := s.GetChains()
var (
chainADenom = chainA.Config().Denom
chainBIBCToken = testsuite.GetIBCToken(chainADenom, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID) // IBC token sent to chainB
)
chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
chainAAddress := chainAWallet.FormattedAddress()
chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)
chainBAddress := chainBWallet.FormattedAddress()
// create second tendermint client
createClientOptions := ibc.CreateClientOptions{
TrustingPeriod: ibctesting.TrustingPeriod.String(),
}
s.SetupClients(ctx, relayer, createClientOptions)
s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks")
t.Run("check that both tendermint clients are active", func(t *testing.T) {
status, err := s.QueryClientStatus(ctx, chainA, testvalues.TendermintClientID(0))
s.Require().NoError(err)
s.Require().Equal(exported.Active.String(), status)
status, err = s.QueryClientStatus(ctx, chainA, testvalues.TendermintClientID(1))
s.Require().NoError(err)
s.Require().Equal(exported.Active.String(), status)
})
// create solo machine client using the solomachine implementation from ibctesting
// TODO: the solomachine clientID should be updated when after fix of this issue: https://github.com/cosmos/ibc-go/issues/2907
solo := ibctesting.NewSolomachine(t, testsuite.Codec(), "solomachine", "testing", 1)
legacyConsensusState := &v7migrations.ConsensusState{
PublicKey: solo.ConsensusState().PublicKey,
Diversifier: solo.ConsensusState().Diversifier,
Timestamp: solo.ConsensusState().Timestamp,
}
legacyClientState := &v7migrations.ClientState{
Sequence: solo.ClientState().Sequence,
IsFrozen: solo.ClientState().IsFrozen,
ConsensusState: legacyConsensusState,
AllowUpdateAfterProposal: true,
}
msgCreateSoloMachineClient, err := clienttypes.NewMsgCreateClient(legacyClientState, legacyConsensusState, chainAAddress)
s.Require().NoError(err)
resp := s.BroadcastMessages(
ctx,
chainA,
chainAWallet,
msgCreateSoloMachineClient,
)
s.AssertTxSuccess(resp)
t.Run("check that the solomachine is now active and that the clientstate is a pre-upgrade v2 solomachine clientstate", func(t *testing.T) {
status, err := s.QueryClientStatus(ctx, chainA, testvalues.SolomachineClientID(2))
s.Require().NoError(err)
s.Require().Equal(exported.Active.String(), status)
res, err := s.ClientState(ctx, chainA, testvalues.SolomachineClientID(2))
s.Require().NoError(err)
s.Require().Equal(fmt.Sprint("/", proto.MessageName(&v7migrations.ClientState{})), res.ClientState.TypeUrl)
})
s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks")
t.Run("IBC token transfer from chainA to chainB, sender is source of tokens", func(t *testing.T) {
transferTxResp := s.Transfer(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, testvalues.DefaultTransferAmount(chainADenom), chainAAddress, chainBAddress, s.GetTimeoutHeight(ctx, chainB), 0, "")
s.AssertTxSuccess(transferTxResp)
})
t.Run("tokens are escrowed", func(t *testing.T) {
actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet)
s.Require().NoError(err)
expected := testvalues.StartingTokenAmount - testvalues.IBCTransferAmount
s.Require().Equal(expected, actualBalance)
})
t.Run("start relayer", func(t *testing.T) {
s.StartRelayer(relayer)
})
t.Run("packets are relayed", func(t *testing.T) {
s.AssertPacketRelayed(ctx, chainA, channelA.PortID, channelA.ChannelID, 1)
actualBalance, err := chainB.GetBalance(ctx, chainBAddress, chainBIBCToken.IBCDenom())
s.Require().NoError(err)
expected := testvalues.IBCTransferAmount
s.Require().Equal(expected, actualBalance.Int64())
})
// create separate user specifically for the upgrade proposal to more easily verify starting
// and end balances of the chainA users.
chainAUpgradeProposalWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
t.Run("upgrade chainA", func(t *testing.T) {
s.UpgradeChain(ctx, chainA, chainAUpgradeProposalWallet, testCfg.UpgradeConfig.PlanName, testCfg.ChainConfigs[0].Tag, testCfg.UpgradeConfig.Tag)
})
// see this issue https://github.com/informalsystems/hermes/issues/3579
// this restart is a temporary workaround to a limitation in hermes requiring a restart
// in some cases after an upgrade.
tc := testsuite.LoadConfig()
if tc.RelayerConfig.Type == e2erelayer.Hermes {
s.RestartRelayer(ctx, relayer)
}
t.Run("check that the tendermint clients are active again after upgrade", func(t *testing.T) {
status, err := s.QueryClientStatus(ctx, chainA, testvalues.TendermintClientID(0))
s.Require().NoError(err)
s.Require().Equal(exported.Active.String(), status)
status, err = s.QueryClientStatus(ctx, chainA, testvalues.TendermintClientID(1))
s.Require().NoError(err)
s.Require().Equal(exported.Active.String(), status)
})
t.Run("IBC token transfer from chainA to chainB, to make sure the upgrade did not break the packet flow", func(t *testing.T) {
transferTxResp := s.Transfer(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, testvalues.DefaultTransferAmount(chainADenom), chainAAddress, chainBAddress, s.GetTimeoutHeight(ctx, chainB), 0, "")
s.AssertTxSuccess(transferTxResp)
})
t.Run("packets are relayed", func(t *testing.T) {
s.AssertPacketRelayed(ctx, chainA, channelA.PortID, channelA.ChannelID, 1)
actualBalance, err := chainB.GetBalance(ctx, chainBAddress, chainBIBCToken.IBCDenom())
s.Require().NoError(err)
expected := testvalues.IBCTransferAmount * 2
s.Require().Equal(expected, actualBalance.Int64())
})
t.Run("check that the v2 solo machine clientstate has been updated to the v3 solo machine clientstate", func(t *testing.T) {
res, err := s.ClientState(ctx, chainA, testvalues.SolomachineClientID(2))
s.Require().NoError(err)
s.Require().Equal(fmt.Sprint("/", proto.MessageName(&solomachine.ClientState{})), res.ClientState.TypeUrl)
})
}
func (s *UpgradeTestSuite) TestV7ToV7_1ChainUpgrade() {
t := s.T()
testCfg := testsuite.LoadConfig()
ctx := context.Background()
relayer, channelA := s.SetupChainsRelayerAndChannel(ctx)
chainA, chainB := s.GetChains()
chainADenom := chainA.Config().Denom
chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
chainAAddress := chainAWallet.FormattedAddress()
chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)
chainBAddress := chainBWallet.FormattedAddress()
s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks")
t.Run("transfer native tokens from chainA to chainB", func(t *testing.T) {
transferTxResp := s.Transfer(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, testvalues.DefaultTransferAmount(chainADenom), chainAAddress, chainBAddress, s.GetTimeoutHeight(ctx, chainB), 0, "")
s.AssertTxSuccess(transferTxResp)
})
t.Run("tokens are escrowed", func(t *testing.T) {
actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet)
s.Require().NoError(err)
expected := testvalues.StartingTokenAmount - testvalues.IBCTransferAmount
s.Require().Equal(expected, actualBalance)
})
t.Run("start relayer", func(t *testing.T) {
s.StartRelayer(relayer)
})
chainBIBCToken := testsuite.GetIBCToken(chainADenom, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID)
t.Run("packet is relayed", func(t *testing.T) {
s.AssertPacketRelayed(ctx, chainA, channelA.PortID, channelA.ChannelID, 1)
actualBalance, err := chainB.GetBalance(ctx, chainBAddress, chainBIBCToken.IBCDenom())
s.Require().NoError(err)
expected := testvalues.IBCTransferAmount
s.Require().Equal(expected, actualBalance.Int64())
})
s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA), "failed to wait for blocks")
t.Run("upgrade chain", func(t *testing.T) {
govProposalWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
s.UpgradeChain(ctx, chainA, govProposalWallet, testCfg.UpgradeConfig.PlanName, testCfg.ChainConfigs[0].Tag, testCfg.UpgradeConfig.Tag)
})
t.Run("ensure the localhost client is active and sentinel connection is stored in state", func(t *testing.T) {
status, err := s.QueryClientStatus(ctx, chainA, exported.LocalhostClientID)
s.Require().NoError(err)
s.Require().Equal(exported.Active.String(), status)
connectionEnd, err := s.QueryConnection(ctx, chainA, exported.LocalhostConnectionID)
s.Require().NoError(err)
s.Require().Equal(connectiontypes.OPEN, connectionEnd.State)
s.Require().Equal(exported.LocalhostClientID, connectionEnd.ClientId)
s.Require().Equal(exported.LocalhostClientID, connectionEnd.Counterparty.ClientId)
s.Require().Equal(exported.LocalhostConnectionID, connectionEnd.Counterparty.ConnectionId)
})
t.Run("ensure escrow amount for native denom is stored in state", func(t *testing.T) {
actualTotalEscrow, err := s.QueryTotalEscrowForDenom(ctx, chainA, chainADenom)
s.Require().NoError(err)
expectedTotalEscrow := sdk.NewCoin(chainADenom, sdkmath.NewInt(testvalues.IBCTransferAmount))
s.Require().Equal(expectedTotalEscrow, actualTotalEscrow) // migration has run and total escrow amount has been set
})
t.Run("IBC token transfer from chainA to chainB, to make sure the upgrade did not break the packet flow", func(t *testing.T) {
transferTxResp := s.Transfer(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, testvalues.DefaultTransferAmount(chainADenom), chainAAddress, chainBAddress, s.GetTimeoutHeight(ctx, chainB), 0, "")
s.AssertTxSuccess(transferTxResp)
})
t.Run("packets are relayed", func(t *testing.T) {
s.AssertPacketRelayed(ctx, chainA, channelA.PortID, channelA.ChannelID, 1)
actualBalance, err := chainB.GetBalance(ctx, chainBAddress, chainBIBCToken.IBCDenom())
s.Require().NoError(err)
expected := testvalues.IBCTransferAmount * 2
s.Require().Equal(expected, actualBalance.Int64())
})
}
func (s *UpgradeTestSuite) TestV7ToV8ChainUpgrade() {
t := s.T()
testCfg := testsuite.LoadConfig()
ctx := context.Background()
relayer, channelA := s.SetupChainsRelayerAndChannel(ctx)
chainA, chainB := s.GetChains()
chainADenom := chainA.Config().Denom
chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
chainAAddress := chainAWallet.FormattedAddress()
chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)
chainBAddress := chainBWallet.FormattedAddress()
s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks")
t.Run("transfer native tokens from chainA to chainB", func(t *testing.T) {
transferTxResp := s.Transfer(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, testvalues.DefaultTransferAmount(chainADenom), chainAAddress, chainBAddress, s.GetTimeoutHeight(ctx, chainB), 0, "")
s.AssertTxSuccess(transferTxResp)
})
t.Run("tokens are escrowed", func(t *testing.T) {
actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet)
s.Require().NoError(err)
expected := testvalues.StartingTokenAmount - testvalues.IBCTransferAmount
s.Require().Equal(expected, actualBalance)
})
t.Run("start relayer", func(t *testing.T) {
s.StartRelayer(relayer)
})
chainBIBCToken := testsuite.GetIBCToken(chainADenom, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID)
t.Run("packet is relayed", func(t *testing.T) {
s.AssertPacketRelayed(ctx, chainA, channelA.PortID, channelA.ChannelID, 1)
actualBalance, err := chainB.GetBalance(ctx, chainBAddress, chainBIBCToken.IBCDenom())
s.Require().NoError(err)
expected := testvalues.IBCTransferAmount
s.Require().Equal(expected, actualBalance.Int64())
})
s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA), "failed to wait for blocks")
t.Run("upgrade chain", func(t *testing.T) {
govProposalWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)
s.UpgradeChain(ctx, chainB, govProposalWallet, testCfg.UpgradeConfig.PlanName, testCfg.ChainConfigs[0].Tag, testCfg.UpgradeConfig.Tag)
})
t.Run("update params", func(t *testing.T) {
authority, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chainB)
s.Require().NoError(err)
s.Require().NotNil(authority)
msg := clienttypes.NewMsgUpdateParams(authority.String(), clienttypes.NewParams(exported.Tendermint, "some-client"))
s.ExecuteGovV1Proposal(ctx, msg, chainB, chainBWallet)
})
t.Run("query params", func(t *testing.T) {
clientParams, err := s.GetChainGRCPClients(chainB).ClientQueryClient.ClientParams(ctx, &clienttypes.QueryClientParamsRequest{})
s.Require().NoError(err)
allowedClients := clientParams.Params.AllowedClients
s.Require().Len(allowedClients, 2)
s.Require().Contains(allowedClients, exported.Tendermint)
s.Require().Contains(allowedClients, "some-client")
})
t.Run("query human readable ibc denom", func(t *testing.T) {
s.AssertHumanReadableDenom(ctx, chainB, chainADenom, channelA)
})
t.Run("IBC token transfer from chainA to chainB, to make sure the upgrade did not break the packet flow", func(t *testing.T) {
transferTxResp := s.Transfer(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, testvalues.DefaultTransferAmount(chainADenom), chainAAddress, chainBAddress, s.GetTimeoutHeight(ctx, chainB), 0, "")
s.AssertTxSuccess(transferTxResp)
})
t.Run("packets are relayed", func(t *testing.T) {
s.AssertPacketRelayed(ctx, chainA, channelA.PortID, channelA.ChannelID, 1)
actualBalance, err := chainB.GetBalance(ctx, chainBAddress, chainBIBCToken.IBCDenom())
s.Require().NoError(err)
expected := testvalues.IBCTransferAmount * 2
s.Require().Equal(expected, actualBalance.Int64())
})
}
// RegisterInterchainAccount will attempt to register an interchain account on the counterparty chain.
// func (s *UpgradeTestSuite) RegisterInterchainAccount(ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, msgRegisterAccount *intertxtypes.MsgRegisterAccount) {
// txResp := s.BroadcastMessages(ctx, chain, user, msgRegisterAccount)
// s.AssertTxSuccess(txResp)
// }
// ClientState queries the current ClientState by clientID
func (s *UpgradeTestSuite) ClientState(ctx context.Context, chain ibc.Chain, clientID string) (*clienttypes.QueryClientStateResponse, error) {
queryClient := s.GetChainGRCPClients(chain).ClientQueryClient
res, err := queryClient.ClientState(ctx, &clienttypes.QueryClientStateRequest{
ClientId: clientID,
})
if err != nil {
return res, err
}
return res, nil
}
// getChainImage returns the image of a given chain.
func getChainImage(chain *cosmos.CosmosChain) string {
tc := testsuite.LoadConfig()
for _, c := range tc.ChainConfigs {
if c.ChainID == chain.Config().ChainID {
return c.Image
}
}
panic(fmt.Errorf("unable to find image for chain: " + chain.Config().ChainID))
}