@@ -80,13 +80,13 @@ func (suite *KeeperTestSuite) TestTrySendTx() {
80
80
suite .Run (tc .name , func () {
81
81
suite .SetupTest () // reset
82
82
path = NewICAPath (suite .chainA , suite .chainB )
83
- owner := TestOwnerAddress
84
83
suite .coordinator .SetupConnections (path )
85
84
86
- err := suite .SetupICAPath (path , owner )
85
+ err := suite .SetupICAPath (path , TestOwnerAddress )
87
86
suite .Require ().NoError (err )
88
87
89
88
portID = path .EndpointA .ChannelConfig .PortID
89
+
90
90
tc .malleate ()
91
91
92
92
_ , err = suite .chainA .GetSimApp ().ICAKeeper .TrySendTx (suite .chainA .GetContext (), portID , msg )
@@ -106,6 +106,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
106
106
msg sdk.Msg
107
107
txBytes []byte
108
108
packetData []byte
109
+ sourcePort string
109
110
)
110
111
111
112
testCases := []struct {
@@ -119,6 +120,10 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
119
120
amount , _ := sdk .ParseCoinsNormalized ("100stake" )
120
121
interchainAccountAddr , _ := suite .chainB .GetSimApp ().ICAKeeper .GetInterchainAccountAddress (suite .chainB .GetContext (), path .EndpointA .ChannelConfig .PortID )
121
122
msg = & banktypes.MsgSend {FromAddress : interchainAccountAddr , ToAddress : suite .chainB .SenderAccount .GetAddress ().String (), Amount : amount }
123
+ // build packet data
124
+ txBytes , err := suite .chainA .GetSimApp ().ICAKeeper .SerializeCosmosTx (suite .chainA .Codec , msg )
125
+ suite .Require ().NoError (err )
126
+
122
127
data := types.IBCAccountPacketData {Type : types .EXECUTE_TX ,
123
128
Data : txBytes }
124
129
packetData = data .GetBytes ()
@@ -146,18 +151,39 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
146
151
}, false ,
147
152
},
148
153
{
149
- "Wrong data type" , func () {
154
+ "Invalid packet type" , func () {
150
155
txBytes = []byte {}
156
+ // Type here is an ENUM
157
+ // Valid type is types.EXECUTE_TX
151
158
data := types.IBCAccountPacketData {Type : 100 ,
152
159
Data : txBytes }
153
160
packetData = data .GetBytes ()
154
161
}, false ,
155
162
},
156
163
{
157
- "Cannot unmarshal interchain account packet data" , func () {
164
+ "Cannot unmarshal interchain account packet data into types.IBCAccountPacketData " , func () {
158
165
packetData = []byte {}
159
166
}, false ,
160
167
},
168
+ {
169
+ "Unauthorised: Interchain account not found for given source portID" , func () {
170
+ sourcePort = "invalid-port-id"
171
+ }, false ,
172
+ },
173
+ {
174
+ "Unauthorised: Signer of message is not the interchain account associated with sourcePortID" , func () {
175
+ // build MsgSend
176
+ amount , _ := sdk .ParseCoinsNormalized ("100stake" )
177
+ // Incorrect FromAddress
178
+ msg = & banktypes.MsgSend {FromAddress : suite .chainB .SenderAccount .GetAddress ().String (), ToAddress : suite .chainB .SenderAccount .GetAddress ().String (), Amount : amount }
179
+ // build packet data
180
+ txBytes , err := suite .chainA .GetSimApp ().ICAKeeper .SerializeCosmosTx (suite .chainA .Codec , msg )
181
+ suite .Require ().NoError (err )
182
+ data := types.IBCAccountPacketData {Type : types .EXECUTE_TX ,
183
+ Data : txBytes }
184
+ packetData = data .GetBytes ()
185
+ }, false ,
186
+ },
161
187
}
162
188
163
189
for _ , tc := range testCases {
@@ -166,26 +192,27 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
166
192
suite .Run (fmt .Sprintf ("Case %s" , tc .msg ), func () {
167
193
suite .SetupTest () // reset
168
194
169
- // setup interchain account
170
- owner := suite .chainA .SenderAccount .GetAddress ().String ()
171
195
path = NewICAPath (suite .chainA , suite .chainB )
172
196
suite .coordinator .SetupConnections (path )
173
- err := suite .SetupICAPath (path , owner )
197
+ err := suite .SetupICAPath (path , TestOwnerAddress )
174
198
suite .Require ().NoError (err )
175
199
176
200
// send 100stake to interchain account wallet
177
201
amount , _ := sdk .ParseCoinsNormalized ("100stake" )
178
202
interchainAccountAddr , _ := suite .chainB .GetSimApp ().ICAKeeper .GetInterchainAccountAddress (suite .chainB .GetContext (), path .EndpointA .ChannelConfig .PortID )
179
203
bankMsg := & banktypes.MsgSend {FromAddress : suite .chainB .SenderAccount .GetAddress ().String (), ToAddress : interchainAccountAddr , Amount : amount }
204
+
180
205
_ , err = suite .chainB .SendMsgs (bankMsg )
206
+ suite .Require ().NoError (err )
181
207
182
- txBytes , err = suite .chainA .GetSimApp ().ICAKeeper .SerializeCosmosTx (suite .chainA .Codec , msg )
183
- // Next we need to define the packet/data to pass into OnRecvPacket
184
- seq := uint64 (1 )
208
+ // valid source port
209
+ sourcePort = path .EndpointA .ChannelConfig .PortID
185
210
211
+ // malleate packetData for test cases
186
212
tc .malleate ()
187
213
188
- packet := channeltypes .NewPacket (packetData , seq , path .EndpointA .ChannelConfig .PortID , path .EndpointA .ChannelID , path .EndpointB .ChannelConfig .PortID , path .EndpointB .ChannelID , clienttypes .NewHeight (0 , 100 ), 0 )
214
+ seq := uint64 (1 )
215
+ packet := channeltypes .NewPacket (packetData , seq , sourcePort , path .EndpointA .ChannelID , path .EndpointB .ChannelConfig .PortID , path .EndpointB .ChannelID , clienttypes .NewHeight (0 , 100 ), 0 )
189
216
190
217
// Pass it in here
191
218
err = suite .chainB .GetSimApp ().ICAKeeper .OnRecvPacket (suite .chainB .GetContext (), packet )
0 commit comments