-
Notifications
You must be signed in to change notification settings - Fork 126
/
test.go
561 lines (474 loc) · 20.9 KB
/
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
// Package conformance exposes a Test function
// that can be imported into other packages' tests.
//
// The exported Test function is intended to be a stable API
// that calls other Test* functions, which are not guaranteed
// to remain a stable API.
//
// External packages that intend to run IBC tests against their relayer implementation
// should define their own implementation of ibc.RelayerFactory,
// and in most cases should use an instance of ibc.BuiltinChainFactory.
//
// package myrelayer_test
//
// import (
// "testing"
//
// "github.com/strangelove-ventures/interchaintest/v8/conformance"
// "github.com/strangelove-ventures/interchaintest/v8/ibc"
// )
//
// func TestMyRelayer(t *testing.T) {
// conformance.Test(t, ibc.NewBuiltinChainFactory([]ibc.BuiltinChainFactoryEntry{
// {Name: "foo_bar" /* ... */},
// }, MyRelayerFactory(), getTestReporter())
// }
//
// Although the conformance package is made available as a convenience for other projects,
// the interchaintest project should be considered the canonical definition of tests and configuration.
package conformance
import (
"context"
"fmt"
"strings"
"testing"
"time"
"github.com/docker/docker/client"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
"cosmossdk.io/math"
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/dockerutil"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/relayer"
"github.com/strangelove-ventures/interchaintest/v8/testreporter"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
)
var (
userFaucetFund = math.NewInt(10_000_000_000)
testCoinAmount = math.NewInt(1_000_000)
pollHeightMax = int64(50)
)
type TxCache struct {
Src []ibc.Tx
Dst []ibc.Tx
}
type RelayerTestCase struct {
Config RelayerTestCaseConfig
// user on source chain
Users []ibc.Wallet
// temp storage in between test phases
TxCache TxCache
}
type RelayerTestCaseConfig struct {
Name string
// which relayer capabilities are required to run this test
RequiredRelayerCapabilities []relayer.Capability
// function to run after the chains are started but before the relayer is started
// e.g. send a transfer and wait for it to timeout so that the relayer will handle it once it is timed out
PreRelayerStart func(context.Context, *testing.T, *RelayerTestCase, ibc.Chain, ibc.Chain, []ibc.ChannelOutput)
// test after chains and relayers are started
Test func(context.Context, *testing.T, *RelayerTestCase, *testreporter.Reporter, ibc.Chain, ibc.Chain, []ibc.ChannelOutput)
}
var relayerTestCaseConfigs = [...]RelayerTestCaseConfig{
{
Name: "relay packet",
PreRelayerStart: preRelayerStartRelayPacket,
Test: testPacketRelaySuccess,
},
{
Name: "no timeout",
PreRelayerStart: preRelayerStartNoTimeout,
Test: testPacketRelaySuccess,
},
{
Name: "height timeout",
RequiredRelayerCapabilities: []relayer.Capability{relayer.HeightTimeout},
PreRelayerStart: preRelayerStartHeightTimeout,
Test: testPacketRelayFail,
},
{
Name: "timestamp timeout",
RequiredRelayerCapabilities: []relayer.Capability{relayer.TimestampTimeout},
PreRelayerStart: preRelayerStartTimestampTimeout,
Test: testPacketRelayFail,
},
}
// requireCapabilities tracks skipping t, if the relayer factory cannot satisfy the required capabilities.
func requireCapabilities(t *testing.T, rep *testreporter.Reporter, rf interchaintest.RelayerFactory, reqCaps ...relayer.Capability) {
t.Helper()
missing := missingCapabilities(rf, reqCaps...)
if len(missing) > 0 {
rep.TrackSkip(t, "skipping due to missing relayer capabilities +%s", missing)
}
}
func missingCapabilities(rf interchaintest.RelayerFactory, reqCaps ...relayer.Capability) []relayer.Capability {
caps := rf.Capabilities()
var missing []relayer.Capability
for _, c := range reqCaps {
if !caps[c] {
missing = append(missing, c)
}
}
return missing
}
func sendIBCTransfersFromBothChainsWithTimeout(
ctx context.Context,
t *testing.T,
testCase *RelayerTestCase,
srcChain ibc.Chain,
dstChain ibc.Chain,
channels []ibc.ChannelOutput,
timeout *ibc.IBCTimeout,
) {
t.Helper()
srcChainCfg := srcChain.Config()
srcUser := testCase.Users[0]
dstChainCfg := dstChain.Config()
dstUser := testCase.Users[1]
// will send ibc transfers from user wallet on both chains to their own respective wallet on the other chain
testCoinSrcToDst := ibc.WalletAmount{
Address: srcUser.(*cosmos.CosmosWallet).FormattedAddressWithPrefix(dstChainCfg.Bech32Prefix),
Denom: srcChainCfg.Denom,
Amount: testCoinAmount,
}
testCoinDstToSrc := ibc.WalletAmount{
Address: dstUser.(*cosmos.CosmosWallet).FormattedAddressWithPrefix(srcChainCfg.Bech32Prefix),
Denom: dstChainCfg.Denom,
Amount: testCoinAmount,
}
var eg errgroup.Group
srcTxs := make([]ibc.Tx, len(channels))
dstTxs := make([]ibc.Tx, len(channels))
eg.Go(func() (err error) {
for i, channel := range channels {
srcChannelID := channel.ChannelID
srcTxs[i], err = srcChain.SendIBCTransfer(ctx, srcChannelID, srcUser.KeyName(), testCoinSrcToDst, ibc.TransferOptions{Timeout: timeout})
if err != nil {
return fmt.Errorf("failed to send ibc transfer from source: %w", err)
}
if err := testutil.WaitForBlocks(ctx, 1, srcChain); err != nil {
return err
}
}
return nil
})
eg.Go(func() (err error) {
for i, channel := range channels {
dstChannelID := channel.Counterparty.ChannelID
dstTxs[i], err = dstChain.SendIBCTransfer(ctx, dstChannelID, dstUser.KeyName(), testCoinDstToSrc, ibc.TransferOptions{Timeout: timeout})
if err != nil {
return fmt.Errorf("failed to send ibc transfer from destination: %w", err)
}
if err := testutil.WaitForBlocks(ctx, 1, dstChain); err != nil {
return err
}
}
return nil
})
require.NoError(t, eg.Wait())
for _, srcTx := range srcTxs {
require.NoError(t, srcTx.Validate(), "source ibc transfer tx is invalid")
}
for _, dstTx := range dstTxs {
require.NoError(t, dstTx.Validate(), "destination ibc transfer tx is invalid")
}
testCase.TxCache = TxCache{
Src: srcTxs,
Dst: dstTxs,
}
}
// Test is the stable API exposed by the conformance package.
// This is intended to be used by Go unit tests.
//
// This function accepts the full set of chain factories and relayer factories to use,
// so that it can properly group subtests in a single invocation.
// If the subtest configuration does not meet your needs,
// you can directly call one of the other exported Test functions, such as TestChainPair.
func Test(t *testing.T, ctx context.Context, cfs []interchaintest.ChainFactory, rfs []interchaintest.RelayerFactory, rep *testreporter.Reporter) {
// Validate chain factory counts up front.
counts := make(map[int]bool)
for _, cf := range cfs {
switch count := cf.Count(); count {
case 2:
counts[count] = true
default:
panic(fmt.Errorf("cannot accept chain factory with count=%d", cf.Count()))
}
}
// Any chain pairs present?
if counts[2] {
t.Run("chain pairs", func(t *testing.T) {
for _, cf := range cfs {
if cf.Count() != 2 {
continue
}
t.Run(cf.Name(), func(t *testing.T) {
for _, rf := range rfs {
t.Run(rf.Name(), func(t *testing.T) {
// Record the labels for this nested test.
rep.TrackTest(t)
rep.TrackParallel(t)
t.Run("relayer setup", func(t *testing.T) {
rep.TrackTest(t)
rep.TrackParallel(t)
TestRelayerSetup(t, ctx, cf, rf, rep)
})
t.Run("conformance", func(t *testing.T) {
rep.TrackTest(t)
rep.TrackParallel(t)
chains, err := cf.Chains(t.Name())
if err != nil {
panic(fmt.Errorf("failed to get chains: %v", err))
}
client, network := interchaintest.DockerSetup(t)
TestChainPair(t, ctx, client, network, chains[0], chains[1], rf, rep, nil)
})
t.Run("flushing", func(t *testing.T) {
rep.TrackTest(t)
rep.TrackParallel(t)
TestRelayerFlushing(t, ctx, cf, rf, rep)
})
})
}
})
}
})
}
}
// TestChainPair runs the conformance tests for two chains and one relayer.
// This test asserts bidirectional behavior between both chains.
//
// Given 2 chains, Chain A and Chain B, this test asserts:
// 1. Successful IBC transfer from A -> B and B -> A.
// 2. Proper handling of no timeout from A -> B and B -> A.
// 3. Proper handling of height timeout from A -> B and B -> A.
// 4. Proper handling of timestamp timeout from A -> B and B -> A.
// If a non-nil relayerImpl is passed, it is assumed that the chains are already started.
func TestChainPair(
t *testing.T,
ctx context.Context,
client *client.Client,
network string,
srcChain, dstChain ibc.Chain,
rf interchaintest.RelayerFactory,
rep *testreporter.Reporter,
relayerImpl ibc.Relayer,
pathNames ...string,
) {
req := require.New(rep.TestifyT(t))
var (
preRelayerStartFuncs []func([]ibc.ChannelOutput)
testCases []*RelayerTestCase
err error
)
randomSuffix := dockerutil.RandLowerCaseLetterString(4)
for _, testCaseConfig := range relayerTestCaseConfigs {
testCase := RelayerTestCase{
Config: testCaseConfig,
}
testCases = append(testCases, &testCase)
if len(missingCapabilities(rf, testCaseConfig.RequiredRelayerCapabilities...)) > 0 {
// Do not add preRelayerStartFunc if capability missing.
// Adding all preRelayerStartFuncs appears to cause test pollution which is why this step is necessary.
continue
}
preRelayerStartFunc := func(channels []ibc.ChannelOutput) {
// fund a user wallet on both chains, save on test case
testCase.Users = interchaintest.GetAndFundTestUsers(t, ctx, strings.ReplaceAll(testCase.Config.Name, " ", "-")+"-"+randomSuffix, userFaucetFund, srcChain, dstChain)
// run test specific pre relayer start action
testCase.Config.PreRelayerStart(ctx, t, &testCase, srcChain, dstChain, channels)
}
preRelayerStartFuncs = append(preRelayerStartFuncs, preRelayerStartFunc)
}
if relayerImpl == nil {
t.Logf("creating relayer: %s", rf.Name())
// startup both chains.
// creates wallets in the relayer for src and dst chain.
// funds relayer src and dst wallets on respective chain in genesis.
// creates a faucet account on the both chains (separate fullnode).
// funds faucet accounts in genesis.
relayerImpl, err = interchaintest.StartChainPair(t, ctx, rep, client, network, srcChain, dstChain, rf, preRelayerStartFuncs)
req.NoError(err, "failed to StartChainPair")
}
// execute the pre relayer start functions, then start the relayer.
channels, err := interchaintest.StopStartRelayerWithPreStartFuncs(
t,
ctx,
srcChain.Config().ChainID,
relayerImpl,
rep.RelayerExecReporter(t),
preRelayerStartFuncs,
pathNames...,
)
req.NoError(err, "failed to StopStartRelayerWithPreStartFuncs")
t.Run("post_relayer_start", func(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.Config.Name, func(t *testing.T) {
rep.TrackTest(t)
requireCapabilities(t, rep, rf, testCase.Config.RequiredRelayerCapabilities...)
rep.TrackParallel(t)
testCase.Config.Test(ctx, t, testCase, rep, srcChain, dstChain, channels)
})
}
})
}
// PreRelayerStart methods for the RelayerTestCases
func preRelayerStartRelayPacket(ctx context.Context, t *testing.T, testCase *RelayerTestCase, srcChain ibc.Chain, dstChain ibc.Chain, channels []ibc.ChannelOutput) {
t.Helper()
sendIBCTransfersFromBothChainsWithTimeout(ctx, t, testCase, srcChain, dstChain, channels, nil)
}
func preRelayerStartNoTimeout(ctx context.Context, t *testing.T, testCase *RelayerTestCase, srcChain ibc.Chain, dstChain ibc.Chain, channels []ibc.ChannelOutput) {
t.Helper()
ibcTimeoutDisabled := ibc.IBCTimeout{Height: 0, NanoSeconds: 0}
sendIBCTransfersFromBothChainsWithTimeout(ctx, t, testCase, srcChain, dstChain, channels, &ibcTimeoutDisabled)
// TODO should we wait here to make sure it successfully relays a packet beyond the default timeout period?
// would need to shorten the chain default timeouts somehow to make that a feasible test
}
func preRelayerStartHeightTimeout(ctx context.Context, t *testing.T, testCase *RelayerTestCase, srcChain ibc.Chain, dstChain ibc.Chain, channels []ibc.ChannelOutput) {
t.Helper()
ibcTimeoutHeight := ibc.IBCTimeout{Height: 10}
sendIBCTransfersFromBothChainsWithTimeout(ctx, t, testCase, srcChain, dstChain, channels, &ibcTimeoutHeight)
// wait for both chains to produce 15 blocks to expire timeout
require.NoError(t, testutil.WaitForBlocks(ctx, 15, srcChain, dstChain), "failed to wait for blocks")
}
func preRelayerStartTimestampTimeout(ctx context.Context, t *testing.T, testCase *RelayerTestCase, srcChain ibc.Chain, dstChain ibc.Chain, channels []ibc.ChannelOutput) {
t.Helper()
ibcTimeoutTimestamp := ibc.IBCTimeout{NanoSeconds: uint64((1 * time.Second).Nanoseconds())}
sendIBCTransfersFromBothChainsWithTimeout(ctx, t, testCase, srcChain, dstChain, channels, &ibcTimeoutTimestamp)
// wait for 15 seconds to expire timeout
time.Sleep(15 * time.Second)
}
// Ensure that a queued packet is successfully relayed.
func testPacketRelaySuccess(
ctx context.Context,
t *testing.T,
testCase *RelayerTestCase,
rep *testreporter.Reporter,
srcChain ibc.Chain,
dstChain ibc.Chain,
channels []ibc.ChannelOutput,
) {
t.Helper()
req := require.New(rep.TestifyT(t))
srcChainCfg := srcChain.Config()
srcUser := testCase.Users[0]
srcDenom := srcChainCfg.Denom
dstChainCfg := dstChain.Config()
// [BEGIN] assert on source to destination transfer
for i, srcTx := range testCase.TxCache.Src {
t.Logf("Asserting %s to %s transfer", srcChainCfg.ChainID, dstChainCfg.ChainID)
// Assuming these values since the ibc transfers were sent in PreRelayerStart, so balances may have already changed by now
srcInitialBalance := userFaucetFund
dstInitialBalance := math.ZeroInt()
srcAck, err := testutil.PollForAck(ctx, srcChain, srcTx.Height, srcTx.Height+pollHeightMax, srcTx.Packet)
req.NoError(err, "failed to get acknowledgement on source chain")
req.NoError(srcAck.Validate(), "invalid acknowledgement on source chain")
// get ibc denom for src denom on dst chain
srcDenomTrace := transfertypes.ParseDenomTrace(transfertypes.GetPrefixedDenom(channels[i].Counterparty.PortID, channels[i].Counterparty.ChannelID, srcDenom))
dstIbcDenom := srcDenomTrace.IBCDenom()
srcFinalBalance, err := srcChain.GetBalance(ctx, srcUser.(*cosmos.CosmosWallet).FormattedAddressWithPrefix(srcChainCfg.Bech32Prefix), srcDenom)
req.NoError(err, "failed to get balance from source chain")
dstFinalBalance, err := dstChain.GetBalance(ctx, srcUser.(*cosmos.CosmosWallet).FormattedAddressWithPrefix(dstChainCfg.Bech32Prefix), dstIbcDenom)
req.NoError(err, "failed to get balance from dest chain")
totalFees := srcChain.GetGasFeesInNativeDenom(srcTx.GasSpent)
expectedDifference := testCoinAmount.AddRaw(totalFees)
req.True(srcFinalBalance.Equal(srcInitialBalance.Sub(expectedDifference)))
req.True(dstFinalBalance.Equal(dstInitialBalance.Add(testCoinAmount)))
}
// [END] assert on source to destination transfer
// [BEGIN] assert on destination to source transfer
for i, dstTx := range testCase.TxCache.Dst {
t.Logf("Asserting %s to %s transfer", dstChainCfg.ChainID, srcChainCfg.ChainID)
dstUser := testCase.Users[1]
dstDenom := dstChainCfg.Denom
// Assuming these values since the ibc transfers were sent in PreRelayerStart, so balances may have already changed by now
srcInitialBalance := math.ZeroInt()
dstInitialBalance := userFaucetFund
dstAck, err := testutil.PollForAck(ctx, dstChain, dstTx.Height, dstTx.Height+pollHeightMax, dstTx.Packet)
req.NoError(err, "failed to get acknowledgement on destination chain")
req.NoError(dstAck.Validate(), "invalid acknowledgement on destination chain")
// Even though we poll for the ack, there may be timing issues where balances are not fully reconciled yet.
// So we have a small buffer here.
require.NoError(t, testutil.WaitForBlocks(ctx, 5, srcChain, dstChain))
// get ibc denom for dst denom on src chain
dstDenomTrace := transfertypes.ParseDenomTrace(transfertypes.GetPrefixedDenom(channels[i].PortID, channels[i].ChannelID, dstDenom))
srcIbcDenom := dstDenomTrace.IBCDenom()
srcFinalBalance, err := srcChain.GetBalance(ctx, dstUser.(*cosmos.CosmosWallet).FormattedAddressWithPrefix(srcChainCfg.Bech32Prefix), srcIbcDenom)
req.NoError(err, "failed to get balance from source chain")
dstFinalBalance, err := dstChain.GetBalance(ctx, dstUser.(*cosmos.CosmosWallet).FormattedAddressWithPrefix(dstChainCfg.Bech32Prefix), dstDenom)
req.NoError(err, "failed to get balance from dest chain")
totalFees := dstChain.GetGasFeesInNativeDenom(dstTx.GasSpent)
expectedDifference := testCoinAmount.AddRaw(totalFees)
req.True(srcFinalBalance.Equal(srcInitialBalance.Add(testCoinAmount)))
req.True(dstFinalBalance.Equal(dstInitialBalance.Sub(expectedDifference)))
}
// [END] assert on destination to source transfer
}
// Ensure that a queued packet that should not be relayed is not relayed.
func testPacketRelayFail(
ctx context.Context,
t *testing.T,
testCase *RelayerTestCase,
rep *testreporter.Reporter,
srcChain ibc.Chain,
dstChain ibc.Chain,
channels []ibc.ChannelOutput,
) {
t.Helper()
req := require.New(rep.TestifyT(t))
srcChainCfg := srcChain.Config()
srcUser := testCase.Users[0]
srcDenom := srcChainCfg.Denom
dstChainCfg := dstChain.Config()
dstUser := testCase.Users[1]
dstDenom := dstChainCfg.Denom
// [BEGIN] assert on source to destination transfer
for i, srcTx := range testCase.TxCache.Src {
// Assuming these values since the ibc transfers were sent in PreRelayerStart, so balances may have already changed by now
srcInitialBalance := userFaucetFund
dstInitialBalance := math.ZeroInt()
timeout, err := testutil.PollForTimeout(ctx, srcChain, srcTx.Height, srcTx.Height+pollHeightMax, srcTx.Packet)
req.NoError(err, "failed to get timeout packet on source chain")
req.NoError(timeout.Validate(), "invalid timeout packet on source chain")
// Even though we poll for the timeout, there may be timing issues where balances are not fully reconciled yet.
// So we have a small buffer here.
require.NoError(t, testutil.WaitForBlocks(ctx, 5, srcChain, dstChain))
// get ibc denom for src denom on dst chain
srcDenomTrace := transfertypes.ParseDenomTrace(transfertypes.GetPrefixedDenom(channels[i].Counterparty.PortID, channels[i].Counterparty.ChannelID, srcDenom))
dstIbcDenom := srcDenomTrace.IBCDenom()
srcFinalBalance, err := srcChain.GetBalance(ctx, srcUser.(*cosmos.CosmosWallet).FormattedAddressWithPrefix(srcChainCfg.Bech32Prefix), srcDenom)
req.NoError(err, "failed to get balance from source chain")
dstFinalBalance, err := dstChain.GetBalance(ctx, srcUser.(*cosmos.CosmosWallet).FormattedAddressWithPrefix(dstChainCfg.Bech32Prefix), dstIbcDenom)
req.NoError(err, "failed to get balance from destination chain")
totalFees := srcChain.GetGasFeesInNativeDenom(srcTx.GasSpent)
req.True(srcFinalBalance.Equal(srcInitialBalance.SubRaw(totalFees)))
req.True(dstFinalBalance.Equal(dstInitialBalance))
}
// [END] assert on source to destination transfer
// [BEGIN] assert on destination to source transfer
for i, dstTx := range testCase.TxCache.Dst {
// Assuming these values since the ibc transfers were sent in PreRelayerStart, so balances may have already changed by now
srcInitialBalance := math.ZeroInt()
dstInitialBalance := userFaucetFund
timeout, err := testutil.PollForTimeout(ctx, dstChain, dstTx.Height, dstTx.Height+pollHeightMax, dstTx.Packet)
req.NoError(err, "failed to get timeout packet on destination chain")
req.NoError(timeout.Validate(), "invalid timeout packet on destination chain")
// Even though we poll for the timeout, there may be timing issues where balances are not fully reconciled yet.
// So we have a small buffer here.
require.NoError(t, testutil.WaitForBlocks(ctx, 5, srcChain, dstChain))
// get ibc denom for dst denom on src chain
dstDenomTrace := transfertypes.ParseDenomTrace(transfertypes.GetPrefixedDenom(channels[i].PortID, channels[i].ChannelID, dstDenom))
srcIbcDenom := dstDenomTrace.IBCDenom()
srcFinalBalance, err := srcChain.GetBalance(ctx, dstUser.(*cosmos.CosmosWallet).FormattedAddressWithPrefix(srcChainCfg.Bech32Prefix), srcIbcDenom)
req.NoError(err, "failed to get balance from source chain")
dstFinalBalance, err := dstChain.GetBalance(ctx, dstUser.(*cosmos.CosmosWallet).FormattedAddressWithPrefix(dstChainCfg.Bech32Prefix), dstDenom)
req.NoError(err, "failed to get balance from destination chain")
totalFees := dstChain.GetGasFeesInNativeDenom(dstTx.GasSpent)
req.True(srcFinalBalance.Equal(srcInitialBalance))
req.True(dstFinalBalance.Equal(dstInitialBalance.SubRaw(totalFees)))
}
// [END] assert on destination to source transfer
}