forked from cosmos/interchain-security
-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel_init.go
96 lines (86 loc) · 2.59 KB
/
channel_init.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
package integration
// TestInitTimeout tests the init timeout
func (suite *CCVTestSuite) TestInitTimeout() {
testCases := []struct {
name string
handshake func()
removed bool
}{
{
"init times out before INIT", func() {}, true,
},
{
"init times out before TRY", func() {
// send ChanOpenInit
err := suite.path.EndpointA.ChanOpenInit()
suite.Require().NoError(err)
}, true,
},
{
"init times out before ACK", func() {
// send ChanOpenInit
err := suite.path.EndpointA.ChanOpenInit()
suite.Require().NoError(err)
// send ChanOpenTry
err = suite.path.EndpointB.ChanOpenTry()
suite.Require().NoError(err)
}, true,
},
{
"init times out before CONFIRM", func() {
// send ChanOpenInit
err := suite.path.EndpointA.ChanOpenInit()
suite.Require().NoError(err)
// send ChanOpenTry
err = suite.path.EndpointB.ChanOpenTry()
suite.Require().NoError(err)
// send ChanOpenAck
err = suite.path.EndpointA.ChanOpenAck()
suite.Require().NoError(err)
}, true,
},
{
"init completes before timeout", func() {
// send ChanOpenInit
err := suite.path.EndpointA.ChanOpenInit()
suite.Require().NoError(err)
// send ChanOpenTry
err = suite.path.EndpointB.ChanOpenTry()
suite.Require().NoError(err)
// send ChanOpenAck
err = suite.path.EndpointA.ChanOpenAck()
suite.Require().NoError(err)
// send ChanOpenConfirm
err = suite.path.EndpointB.ChanOpenConfirm()
suite.Require().NoError(err)
}, false,
},
}
for i, tc := range testCases {
providerKeeper := suite.providerApp.GetProviderKeeper()
initTimeout := providerKeeper.GetParams(suite.providerCtx()).InitTimeoutPeriod
chainID := suite.consumerChain.ChainID
// check that the init timeout timestamp is set
_, found := providerKeeper.GetInitTimeoutTimestamp(suite.providerCtx(), chainID)
suite.Require().True(found, "cannot find init timeout timestamp; test: %s", tc.name)
// create connection
suite.coordinator.CreateConnections(suite.path)
// channel opening handshake
tc.handshake()
// call NextBlock
suite.providerChain.NextBlock()
// increment time
incrementTime(suite, initTimeout)
// check whether the chain was removed
_, found = providerKeeper.GetConsumerClientId(suite.providerCtx(), chainID)
suite.Require().Equal(!tc.removed, found, "unexpected outcome; test: %s", tc.name)
if tc.removed {
// check if the chain was properly removed
suite.checkConsumerChainIsRemoved(chainID, false)
}
if i+1 < len(testCases) {
// reset suite to reset provider client
suite.SetupTest()
}
}
}