-
Notifications
You must be signed in to change notification settings - Fork 126
/
flush.go
105 lines (78 loc) · 2.78 KB
/
flush.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
package conformance
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/require"
"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/types"
"github.com/strangelove-ventures/interchaintest/v8"
"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"
)
func TestRelayerFlushing(t *testing.T, ctx context.Context, cf interchaintest.ChainFactory, rf interchaintest.RelayerFactory, rep *testreporter.Reporter) {
rep.TrackTest(t)
// FlushPackets will be exercised in a subtest,
// but check that capability first in case we can avoid setup.
requireCapabilities(t, rep, rf, relayer.Flush)
client, network := interchaintest.DockerSetup(t)
req := require.New(rep.TestifyT(t))
chains, err := cf.Chains(t.Name())
req.NoError(err, "failed to get chains")
if len(chains) != 2 {
panic(fmt.Errorf("expected 2 chains, got %d", len(chains)))
}
c0, c1 := chains[0], chains[1]
r := rf.Build(t, client, network)
const pathName = "p"
ic := interchaintest.NewInterchain().
AddChain(c0).
AddChain(c1).
AddRelayer(r, "r").
AddLink(interchaintest.InterchainLink{
Chain1: c0,
Chain2: c1,
Relayer: r,
Path: pathName,
CreateChannelOpts: ibc.DefaultChannelOpts(),
})
eRep := rep.RelayerExecReporter(t)
req.NoError(ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
}))
defer ic.Close()
// Get faucet address on destination chain for ibc transfer.
c1FaucetAddrBytes, err := c1.GetAddress(ctx, interchaintest.FaucetAccountKeyName)
req.NoError(err)
c1FaucetAddr, err := types.Bech32ifyAddressBytes(c1.Config().Bech32Prefix, c1FaucetAddrBytes)
req.NoError(err)
channels, err := r.GetChannels(ctx, eRep, c0.Config().ChainID)
req.NoError(err)
req.Len(channels, 1)
c0ChannelID := channels[0].ChannelID
beforeTransferHeight, err := c0.Height(ctx)
req.NoError(err)
const txAmount = 112233 // Arbitrary amount that is easy to find in logs.
tx, err := c0.SendIBCTransfer(ctx, c0ChannelID, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{
Address: c1FaucetAddr,
Denom: c0.Config().Denom,
Amount: math.NewInt(txAmount),
}, ibc.TransferOptions{})
req.NoError(err)
req.NoError(tx.Validate())
t.Run("flush", func(t *testing.T) {
rep.TrackTest(t)
eRep := rep.RelayerExecReporter(t)
req := require.New(rep.TestifyT(t))
// Should trigger MsgRecvPacket.
req.NoError(r.Flush(ctx, eRep, pathName, c0ChannelID))
afterFlushHeight, err := c0.Height(ctx)
req.NoError(err)
_, err = testutil.PollForAck(ctx, c0, beforeTransferHeight, afterFlushHeight+5, tx.Packet)
req.NoError(err)
})
}