github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/core/ante/ante_test.go (about) 1 package ante_test 2 3 import ( 4 "math/big" 5 "testing" 6 7 appante "github.com/fibonacci-chain/fbc/app/ante" 8 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/simapp/helpers" 9 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 10 ibcmsg "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/ibc-adapter" 11 clienttypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/02-client/types" 12 channeltypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/04-channel/types" 13 ibctesting "github.com/fibonacci-chain/fbc/libs/ibc-go/testing" 14 "github.com/fibonacci-chain/fbc/libs/ibc-go/testing/mock" 15 helpers2 "github.com/fibonacci-chain/fbc/libs/ibc-go/testing/simapp/helpers" 16 evmtypes "github.com/fibonacci-chain/fbc/x/evm/types" 17 "github.com/fibonacci-chain/fbc/x/order" 18 "github.com/stretchr/testify/suite" 19 ) 20 21 type AnteTestSuite struct { 22 suite.Suite 23 24 coordinator *ibctesting.Coordinator 25 26 // testing chains used for convenience and readability 27 chainA ibctesting.TestChainI 28 chainB ibctesting.TestChainI 29 30 path *ibctesting.Path 31 } 32 33 // SetupTest creates a coordinator with 2 test chains. 34 func (suite *AnteTestSuite) SetupTest() { 35 suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) 36 suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(0)) 37 suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(1)) 38 // commit some blocks so that QueryProof returns valid proof (cannot return valid query if height <= 1) 39 suite.coordinator.CommitNBlocks(suite.chainA, 2) 40 suite.coordinator.CommitNBlocks(suite.chainB, 2) 41 suite.path = ibctesting.NewPath(suite.chainA, suite.chainB) 42 suite.coordinator.Setup(suite.path) 43 } 44 45 // TestAnteTestSuite runs all the tests within this package. 46 func TestAnteTestSuite(t *testing.T) { 47 suite.Run(t, new(AnteTestSuite)) 48 } 49 50 func (suite *AnteTestSuite) TestAnteDecorator() { 51 testCases := []struct { 52 name string 53 malleate func(suite *AnteTestSuite) []ibcmsg.Msg 54 expPass bool 55 }{ 56 { 57 "success on single msg", 58 func(suite *AnteTestSuite) []ibcmsg.Msg { 59 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), 1, 60 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 61 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 62 clienttypes.NewHeight(1, 0), 0) 63 64 return []ibcmsg.Msg{channeltypes.NewMsgRecvPacket(packet, []byte("proof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())} 65 }, 66 true, 67 }, 68 { 69 "success on multiple msgs", 70 func(suite *AnteTestSuite) []ibcmsg.Msg { 71 var msgs []ibcmsg.Msg 72 73 for i := 1; i <= 5; i++ { 74 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), uint64(i), 75 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 76 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 77 clienttypes.NewHeight(1, 0), 0) 78 79 msgs = append(msgs, channeltypes.NewMsgRecvPacket(packet, []byte("proof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 80 } 81 return msgs 82 }, 83 true, 84 }, 85 { 86 "success on multiple msgs: 1 fresh recv packet", 87 func(suite *AnteTestSuite) []ibcmsg.Msg { 88 var msgs []ibcmsg.Msg 89 90 for i := 1; i <= 5; i++ { 91 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), uint64(i), 92 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 93 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 94 clienttypes.NewHeight(1, 0), 0) 95 96 err := suite.path.EndpointA.SendPacket(packet) 97 suite.Require().NoError(err) 98 99 // receive all sequences except packet 3 100 if i != 3 { 101 err = suite.path.EndpointB.RecvPacket(packet) 102 suite.Require().NoError(err) 103 } 104 105 msgs = append(msgs, channeltypes.NewMsgRecvPacket(packet, []byte("proof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 106 } 107 108 return msgs 109 }, 110 true, 111 }, 112 { 113 "success on multiple mixed msgs", 114 func(suite *AnteTestSuite) []ibcmsg.Msg { 115 var msgs []ibcmsg.Msg 116 117 for i := 1; i <= 3; i++ { 118 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), uint64(i), 119 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 120 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 121 clienttypes.NewHeight(1, 0), 0) 122 err := suite.path.EndpointA.SendPacket(packet) 123 suite.Require().NoError(err) 124 125 msgs = append(msgs, channeltypes.NewMsgRecvPacket(packet, []byte("proof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 126 } 127 for i := 1; i <= 3; i++ { 128 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), uint64(i), 129 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 130 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 131 clienttypes.NewHeight(1, 0), 0) 132 err := suite.path.EndpointB.SendPacket(packet) 133 suite.Require().NoError(err) 134 135 msgs = append(msgs, channeltypes.NewMsgAcknowledgement(packet, []byte("ack"), []byte("proof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 136 } 137 for i := 4; i <= 6; i++ { 138 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), uint64(i), 139 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 140 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 141 clienttypes.NewHeight(1, 0), 0) 142 err := suite.path.EndpointB.SendPacket(packet) 143 suite.Require().NoError(err) 144 145 msgs = append(msgs, channeltypes.NewMsgTimeout(packet, uint64(i), []byte("proof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 146 } 147 return msgs 148 }, 149 true, 150 }, 151 { 152 "success on multiple mixed msgs: 1 fresh packet of each type", 153 func(suite *AnteTestSuite) []ibcmsg.Msg { 154 var msgs []ibcmsg.Msg 155 156 for i := 1; i <= 3; i++ { 157 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), uint64(i), 158 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 159 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 160 clienttypes.NewHeight(1, 0), 0) 161 err := suite.path.EndpointA.SendPacket(packet) 162 suite.Require().NoError(err) 163 164 // receive all sequences except packet 3 165 if i != 3 { 166 167 err := suite.path.EndpointB.RecvPacket(packet) 168 suite.Require().NoError(err) 169 } 170 171 msgs = append(msgs, channeltypes.NewMsgRecvPacket(packet, []byte("proof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 172 } 173 for i := 1; i <= 3; i++ { 174 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), uint64(i), 175 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 176 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 177 clienttypes.NewHeight(1, 0), 0) 178 err := suite.path.EndpointB.SendPacket(packet) 179 suite.Require().NoError(err) 180 181 // receive all acks except ack 2 182 if i != 2 { 183 err = suite.path.EndpointA.RecvPacket(packet) 184 suite.Require().NoError(err) 185 err = suite.path.EndpointB.AcknowledgePacket(packet, mock.MockAcknowledgement.Acknowledgement()) 186 suite.Require().NoError(err) 187 } 188 189 msgs = append(msgs, channeltypes.NewMsgAcknowledgement(packet, []byte("ack"), []byte("proof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 190 } 191 for i := 4; i <= 6; i++ { 192 height := suite.chainA.LastHeader().GetHeight() 193 timeoutHeight := clienttypes.NewHeight(height.GetRevisionNumber(), height.GetRevisionHeight()+1) 194 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), uint64(i), 195 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 196 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 197 timeoutHeight, 0) 198 err := suite.path.EndpointB.SendPacket(packet) 199 suite.Require().NoError(err) 200 201 // timeout packet 202 suite.coordinator.CommitNBlocks(suite.chainA, 3) 203 204 // timeout packets except sequence 5 205 if i != 5 { 206 suite.path.EndpointB.UpdateClient() 207 err = suite.path.EndpointB.TimeoutPacket(packet) 208 suite.Require().NoError(err) 209 } 210 211 msgs = append(msgs, channeltypes.NewMsgTimeout(packet, uint64(i), []byte("proof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 212 } 213 return msgs 214 }, 215 true, 216 }, 217 { 218 "success on multiple mixed msgs: only 1 fresh msg in total", 219 func(suite *AnteTestSuite) []ibcmsg.Msg { 220 var msgs []ibcmsg.Msg 221 222 for i := 1; i <= 3; i++ { 223 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), uint64(i), 224 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 225 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 226 clienttypes.NewHeight(1, 0), 0) 227 228 // receive all packets 229 suite.path.EndpointA.SendPacket(packet) 230 suite.path.EndpointB.RecvPacket(packet) 231 232 msgs = append(msgs, channeltypes.NewMsgRecvPacket(packet, []byte("proof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 233 } 234 for i := 1; i <= 3; i++ { 235 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), uint64(i), 236 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 237 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 238 clienttypes.NewHeight(1, 0), 0) 239 240 // receive all acks 241 suite.path.EndpointB.SendPacket(packet) 242 suite.path.EndpointA.RecvPacket(packet) 243 suite.path.EndpointB.AcknowledgePacket(packet, mock.MockAcknowledgement.Acknowledgement()) 244 245 msgs = append(msgs, channeltypes.NewMsgAcknowledgement(packet, []byte("ack"), []byte("proof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 246 } 247 for i := 4; i < 5; i++ { 248 height := suite.chainA.LastHeader().GetHeight() 249 timeoutHeight := clienttypes.NewHeight(height.GetRevisionNumber(), height.GetRevisionHeight()+1) 250 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), uint64(i), 251 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 252 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 253 timeoutHeight, 0) 254 255 // do not timeout packet, timeout msg is fresh 256 suite.path.EndpointB.SendPacket(packet) 257 258 msgs = append(msgs, channeltypes.NewMsgTimeout(packet, uint64(i), []byte("proof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 259 } 260 return msgs 261 }, 262 true, 263 }, 264 { 265 "success on single update client msg", 266 func(suite *AnteTestSuite) []ibcmsg.Msg { 267 return []ibcmsg.Msg{&clienttypes.MsgUpdateClient{ 268 suite.chainB.ChainID(), 269 nil, 270 suite.chainB.SenderAccount().GetAddress().String(), 271 }} 272 }, 273 true, 274 }, 275 { 276 "success on multiple update clients", 277 func(suite *AnteTestSuite) []ibcmsg.Msg { 278 return []ibcmsg.Msg{ 279 &clienttypes.MsgUpdateClient{suite.chainB.ChainID(), nil, suite.chainB.SenderAccount().GetAddress().String()}, 280 &clienttypes.MsgUpdateClient{suite.chainB.ChainID(), nil, suite.chainB.SenderAccount().GetAddress().String()}, 281 &clienttypes.MsgUpdateClient{suite.chainB.ChainID(), nil, suite.chainB.SenderAccount().GetAddress().String()}} 282 }, 283 true, 284 }, 285 { 286 "success on multiple update clients and fresh packet message", 287 func(suite *AnteTestSuite) []ibcmsg.Msg { 288 msgs := []ibcmsg.Msg{ 289 &clienttypes.MsgUpdateClient{suite.chainB.ChainID(), nil, suite.chainB.SenderAccount().GetAddress().String()}, 290 &clienttypes.MsgUpdateClient{suite.chainB.ChainID(), nil, suite.chainB.SenderAccount().GetAddress().String()}, 291 &clienttypes.MsgUpdateClient{suite.chainB.ChainID(), nil, suite.chainB.SenderAccount().GetAddress().String()}, 292 } 293 294 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), 1, 295 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 296 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 297 clienttypes.NewHeight(1, 0), 0) 298 299 return append(msgs, channeltypes.NewMsgRecvPacket(packet, []byte("proof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 300 }, 301 true, 302 }, 303 { 304 "success of tx with different msg type even if all packet messages are redundant", 305 func(suite *AnteTestSuite) []ibcmsg.Msg { 306 msgs := []ibcmsg.Msg{&clienttypes.MsgUpdateClient{suite.chainB.ChainID(), nil, suite.chainB.SenderAccount().GetAddress().String()}} 307 308 for i := 1; i <= 3; i++ { 309 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), uint64(i), 310 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 311 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 312 clienttypes.NewHeight(1, 0), 0) 313 314 // receive all packets 315 suite.path.EndpointA.SendPacket(packet) 316 suite.path.EndpointB.RecvPacket(packet) 317 318 msgs = append(msgs, channeltypes.NewMsgRecvPacket(packet, []byte("proof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 319 } 320 for i := 1; i <= 3; i++ { 321 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), uint64(i), 322 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 323 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 324 clienttypes.NewHeight(1, 0), 0) 325 326 // receive all acks 327 suite.path.EndpointB.SendPacket(packet) 328 suite.path.EndpointA.RecvPacket(packet) 329 suite.path.EndpointB.AcknowledgePacket(packet, mock.MockAcknowledgement.Acknowledgement()) 330 331 msgs = append(msgs, channeltypes.NewMsgAcknowledgement(packet, []byte("ack"), []byte("proof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 332 } 333 for i := 4; i < 6; i++ { 334 height := suite.chainA.LastHeader().GetHeight() 335 timeoutHeight := clienttypes.NewHeight(height.GetRevisionNumber(), height.GetRevisionHeight()+1) 336 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), uint64(i), 337 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 338 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 339 timeoutHeight, 0) 340 341 err := suite.path.EndpointB.SendPacket(packet) 342 suite.Require().NoError(err) 343 344 // timeout packet 345 suite.coordinator.CommitNBlocks(suite.chainA, 3) 346 347 suite.path.EndpointB.UpdateClient() 348 suite.path.EndpointB.TimeoutPacket(packet) 349 350 msgs = append(msgs, channeltypes.NewMsgTimeoutOnClose(packet, uint64(i), []byte("proof"), []byte("channelProof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 351 } 352 353 // append non packet and update message to msgs to ensure multimsg tx should pass 354 msgs = append(msgs, &clienttypes.MsgSubmitMisbehaviour{suite.chainB.ChainID(), nil, suite.chainB.SenderAccount().GetAddress().String()}) 355 356 return msgs 357 }, 358 true, 359 }, 360 { 361 "no success on multiple mixed message: all are redundant", 362 func(suite *AnteTestSuite) []ibcmsg.Msg { 363 var msgs []ibcmsg.Msg 364 365 for i := 1; i <= 3; i++ { 366 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), uint64(i), 367 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 368 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 369 clienttypes.NewHeight(1, 0), 0) 370 371 // receive all packets 372 suite.path.EndpointA.SendPacket(packet) 373 suite.path.EndpointB.RecvPacket(packet) 374 375 msgs = append(msgs, channeltypes.NewMsgRecvPacket(packet, []byte("proof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 376 } 377 for i := 1; i <= 3; i++ { 378 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), uint64(i), 379 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 380 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 381 clienttypes.NewHeight(1, 0), 0) 382 383 // receive all acks 384 suite.path.EndpointB.SendPacket(packet) 385 suite.path.EndpointA.RecvPacket(packet) 386 suite.path.EndpointB.AcknowledgePacket(packet, mock.MockAcknowledgement.Acknowledgement()) 387 388 msgs = append(msgs, channeltypes.NewMsgAcknowledgement(packet, []byte("ack"), []byte("proof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 389 } 390 for i := 4; i < 6; i++ { 391 height := suite.chainA.LastHeader().GetHeight() 392 timeoutHeight := clienttypes.NewHeight(height.GetRevisionNumber(), height.GetRevisionHeight()+1) 393 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), uint64(i), 394 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 395 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 396 timeoutHeight, 0) 397 398 err := suite.path.EndpointB.SendPacket(packet) 399 suite.Require().NoError(err) 400 401 // timeout packet 402 suite.coordinator.CommitNBlocks(suite.chainA, 3) 403 404 suite.path.EndpointB.UpdateClient() 405 suite.path.EndpointB.TimeoutPacket(packet) 406 407 msgs = append(msgs, channeltypes.NewMsgTimeoutOnClose(packet, uint64(i), []byte("proof"), []byte("channelProof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 408 } 409 return msgs 410 }, 411 false, 412 }, 413 { 414 "no success if msgs contain update clients and redundant packet messages", 415 func(suite *AnteTestSuite) []ibcmsg.Msg { 416 msgs := []ibcmsg.Msg{&clienttypes.MsgUpdateClient{Signer: "fb1gjfgxzpe2k908udw9kw8zfpdc66edcqh5alez2"}, &clienttypes.MsgUpdateClient{Signer: "fb1gjfgxzpe2k908udw9kw8zfpdc66edcqh5alez2"}, &clienttypes.MsgUpdateClient{Signer: "fb1gjfgxzpe2k908udw9kw8zfpdc66edcqh5alez2"}} 417 418 for i := 1; i <= 3; i++ { 419 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), uint64(i), 420 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 421 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 422 clienttypes.NewHeight(1, 0), 0) 423 424 // receive all packets 425 suite.path.EndpointA.SendPacket(packet) 426 suite.path.EndpointB.RecvPacket(packet) 427 428 msgs = append(msgs, channeltypes.NewMsgRecvPacket(packet, []byte("proof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 429 } 430 for i := 1; i <= 3; i++ { 431 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), uint64(i), 432 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 433 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 434 clienttypes.NewHeight(1, 0), 0) 435 436 // receive all acks 437 suite.path.EndpointB.SendPacket(packet) 438 suite.path.EndpointA.RecvPacket(packet) 439 suite.path.EndpointB.AcknowledgePacket(packet, mock.MockAcknowledgement.Acknowledgement()) 440 441 msgs = append(msgs, channeltypes.NewMsgAcknowledgement(packet, []byte("ack"), []byte("proof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 442 } 443 for i := 4; i < 6; i++ { 444 height := suite.chainA.LastHeader().GetHeight() 445 timeoutHeight := clienttypes.NewHeight(height.GetRevisionNumber(), height.GetRevisionHeight()+1) 446 packet := channeltypes.NewPacket([]byte(mock.MockPacketData), uint64(i), 447 suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 448 suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 449 timeoutHeight, 0) 450 451 err := suite.path.EndpointB.SendPacket(packet) 452 suite.Require().NoError(err) 453 454 // timeout packet 455 suite.coordinator.CommitNBlocks(suite.chainA, 3) 456 457 suite.path.EndpointB.UpdateClient() 458 suite.path.EndpointB.TimeoutPacket(packet) 459 460 msgs = append(msgs, channeltypes.NewMsgTimeoutOnClose(packet, uint64(i), []byte("proof"), []byte("channelProof"), clienttypes.NewHeight(0, 1), suite.chainB.SenderAccount().GetAddress().String())) 461 } 462 return msgs 463 }, 464 false, 465 }, 466 } 467 468 for _, tc := range testCases { 469 tc := tc 470 471 suite.Run(tc.name, func() { 472 // reset suite 473 suite.SetupTest() 474 475 k := suite.chainB.App().GetFacadedKeeper() 476 //decorator := ante.NewAnteDecorator(k) 477 app := suite.chainB.GetSimApp() 478 msgs := tc.malleate(suite) 479 480 deliverCtx := suite.chainB.GetContext().WithIsCheckTx(false) 481 checkCtx := suite.chainB.GetContext().WithIsCheckTx(true) 482 483 // create multimsg tx 484 txBuilder := suite.chainB.TxConfig().NewTxBuilder() 485 err := txBuilder.SetMsgs(msgs...) 486 ibcTx, err := helpers2.GenTx( 487 suite.chainB.TxConfig(), 488 msgs, 489 sdk.CoinAdapters{sdk.NewCoinAdapter(sdk.DefaultIbcWei, sdk.NewIntFromBigInt(big.NewInt(0)))}, 490 helpers.DefaultGenTxGas, 491 suite.chainB.ChainID(), 492 []uint64{suite.chainB.SenderAccount().GetAccountNumber()}, 493 []uint64{suite.chainB.SenderAccount().GetSequence()}, 494 1, 495 suite.chainB.SenderAccountPV(), 496 ) 497 antehandler := appante.NewAnteHandler(app.AccountKeeper, app.EvmKeeper, app.SupplyKeeper, validateMsgHook(app.OrderKeeper), app.WasmHandler, k, app.StakingKeeper, app.ParamsKeeper) 498 antehandler(deliverCtx, ibcTx, false) 499 //_, err = decorator.AnteHandle(deliverCtx, ibcTx, false, next) 500 suite.Require().NoError(err, "antedecorator should not error on DeliverTx") 501 ibcTx, err = helpers2.GenTx( 502 suite.chainB.TxConfig(), 503 msgs, 504 sdk.CoinAdapters{sdk.NewCoinAdapter(sdk.DefaultIbcWei, sdk.NewIntFromBigInt(big.NewInt(0)))}, 505 helpers.DefaultGenTxGas, 506 suite.chainB.ChainID(), 507 []uint64{suite.chainB.SenderAccount().GetAccountNumber()}, 508 []uint64{suite.chainB.SenderAccount().GetSequence() + uint64(1)}, 509 1, 510 suite.chainB.SenderAccountPV(), 511 ) 512 //_, err = decorator.AnteHandle(checkCtx, ibcTx, false, next) 513 _, err = antehandler(checkCtx, ibcTx, false) 514 if tc.expPass { 515 suite.Require().NoError(err, "non-strict decorator did not pass as expected") 516 } else { 517 suite.Require().Error(err, "non-strict antehandler did not return error as expected") 518 } 519 }) 520 } 521 } 522 523 func validateMsgHook(orderKeeper order.Keeper) appante.ValidateMsgHandler { 524 return func(newCtx sdk.Context, msgs []sdk.Msg) error { 525 526 wrongMsgErr := sdk.ErrUnknownRequest( 527 "It is not allowed that a transaction with more than one message contains order or evm message") 528 var err error 529 530 for _, msg := range msgs { 531 switch assertedMsg := msg.(type) { 532 case order.MsgNewOrders: 533 if len(msgs) > 1 { 534 return wrongMsgErr 535 } 536 _, err = order.ValidateMsgNewOrders(newCtx, orderKeeper, assertedMsg) 537 case order.MsgCancelOrders: 538 if len(msgs) > 1 { 539 return wrongMsgErr 540 } 541 err = order.ValidateMsgCancelOrders(newCtx, orderKeeper, assertedMsg) 542 case *evmtypes.MsgEthereumTx: 543 if len(msgs) > 1 { 544 return wrongMsgErr 545 } 546 } 547 548 if err != nil { 549 return err 550 } 551 } 552 return nil 553 } 554 }