forked from noble-assets/noble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ibc_client_expire_substitute_test.go
181 lines (139 loc) · 5.24 KB
/
ibc_client_expire_substitute_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
package interchaintest_test
import (
"context"
"testing"
"github.com/strangelove-ventures/interchaintest/v4"
"github.com/strangelove-ventures/interchaintest/v4/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v4/ibc"
"github.com/strangelove-ventures/interchaintest/v4/testreporter"
"github.com/strangelove-ventures/interchaintest/v4/testutil"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
)
// run `make local-image`to rebuild updated binary before running test
func TestClientSubstitution(t *testing.T) {
if testing.Short() {
t.Skip()
}
t.Log("hi")
t.Parallel()
ctx := context.Background()
rep := testreporter.NewNopReporter()
eRep := rep.RelayerExecReporter(t)
client, network := interchaintest.DockerSetup(t)
var gw genesisWrapper
nv := 1
nf := 0
cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{
nobleChainSpec(ctx, &gw, "noble-1", nv, nf, true, true, true, true),
{
Name: "gaia",
Version: "v10.0.2",
NumValidators: &nv,
NumFullNodes: &nf,
},
})
chains, err := cf.Chains(t.Name())
require.NoError(t, err)
gw.chain = chains[0].(*cosmos.CosmosChain)
noble := gw.chain
gaia := chains[1].(*cosmos.CosmosChain)
r := interchaintest.NewBuiltinRelayerFactory(
ibc.CosmosRly,
zaptest.NewLogger(t),
relayerImage,
).Build(t, client, network)
pathName := "noble-gaia"
ic := interchaintest.NewInterchain().
AddChain(noble).
AddChain(gaia).
AddRelayer(r, "r").
AddLink(interchaintest.InterchainLink{
Chain1: noble,
Chain2: gaia,
Relayer: r,
Path: pathName,
})
require.NoError(t, ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
SkipPathCreation: true,
}))
t.Cleanup(func() {
_ = ic.Close()
})
nobleChainID := noble.Config().ChainID
gaiaChainID := gaia.Config().ChainID
err = r.GeneratePath(ctx, eRep, nobleChainID, gaiaChainID, pathName)
require.NoError(t, err)
// create client on noble with short trusting period which will expire.
res := r.Exec(ctx, eRep, []string{"rly", "tx", "client", nobleChainID, gaiaChainID, pathName, "--client-tp", "20s", "--home", "/home/relayer"}, nil)
require.NoError(t, res.Err)
// create client on gaia with longer trusting period so it won't expire for this test.
res = r.Exec(ctx, eRep, []string{"rly", "tx", "client", gaiaChainID, nobleChainID, pathName, "--home", "/home/relayer"}, nil)
require.NoError(t, res.Err)
err = testutil.WaitForBlocks(ctx, 2, noble, gaia)
require.NoError(t, err)
err = r.CreateConnections(ctx, eRep, pathName)
require.NoError(t, err)
err = testutil.WaitForBlocks(ctx, 2, noble, gaia)
require.NoError(t, err)
err = r.CreateChannel(ctx, eRep, pathName, ibc.CreateChannelOptions{
SourcePortName: "transfer",
DestPortName: "transfer",
Order: ibc.Unordered,
Version: "ics20-1",
})
require.NoError(t, err)
const userFunds = int64(10_000_000_000)
users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), userFunds, noble, gaia)
nobleClients, err := r.GetClients(ctx, eRep, nobleChainID)
require.NoError(t, err)
require.Len(t, nobleClients, 1)
nobleClient := nobleClients[0]
nobleChannels, err := r.GetChannels(ctx, eRep, nobleChainID)
require.NoError(t, err)
require.Len(t, nobleChannels, 1)
nobleChannel := nobleChannels[0]
err = testutil.WaitForBlocks(ctx, 20, noble)
require.NoError(t, err)
// client should now be expired, no relayer was running to update the clients during the 20s trusting period.
_, err = noble.SendIBCTransfer(ctx, nobleChannel.ChannelID, users[0].KeyName(), ibc.WalletAmount{
Address: users[1].FormattedAddress(),
Amount: 1000000,
Denom: noble.Config().Denom,
}, ibc.TransferOptions{})
require.Error(t, err)
require.ErrorContains(t, err, "status Expired: client is not active")
// create new client on noble
res = r.Exec(ctx, eRep, []string{"rly", "tx", "client", nobleChainID, gaiaChainID, pathName, "--override", "--home", "/home/relayer"}, nil)
require.NoError(t, res.Err)
nobleClients, err = r.GetClients(ctx, eRep, nobleChainID)
require.NoError(t, err)
require.Len(t, nobleClients, 2)
newNobleClient := nobleClients[1]
// substitute new client state into old client
_, err = noble.Validators[0].ExecTx(ctx, gw.paramAuthority.KeyName(), "ibc-authority", "update-client", nobleClient.ClientID, newNobleClient.ClientID)
require.NoError(t, err)
// update config to old client ID
res = r.Exec(ctx, eRep, []string{"rly", "paths", "update", pathName, "--src-client-id", nobleClient.ClientID, "--home", "/home/relayer"}, nil)
require.NoError(t, res.Err)
// start up relayer and test a transfer
err = r.StartRelayer(ctx, eRep, pathName)
require.NoError(t, err)
t.Cleanup(func() {
_ = r.StopRelayer(ctx, eRep)
})
nobleHeight, err := noble.Height(ctx)
require.NoError(t, err)
// send a packet on the same channel with new client, should succeed.
tx, err := noble.SendIBCTransfer(ctx, nobleChannel.ChannelID, users[0].KeyName(), ibc.WalletAmount{
Address: users[1].FormattedAddress(),
Amount: 1000000,
Denom: noble.Config().Denom,
}, ibc.TransferOptions{})
require.NoError(t, err)
_, err = testutil.PollForAck(ctx, noble, nobleHeight, nobleHeight+10, tx.Packet)
require.NoError(t, err)
}