Skip to main content
Unit testing can prove to be challenging for a multichain setup with Foundry. Hence, we’ve provided a lightweight test environment MockHyperlaneEnvironment for you to unit test your cross-chain app while avoiding the need to fork multiple networks. Most multichain apps will be built on top of our Mailbox contract. So, we’ve abstracted away the details of a deployed mailbox with a MockMailbox and our environment contains an originMailbox and a destinationMailbox on the same chain. Internally, we store the messages arriving to the destination in the inboundMessages mapping on the destination mailbox. We simulate message delivery by enqueuing messages and increment the inboundProcessedNonce with MockMailbox.processNextInboundMessage(). The setup for the simple messaging forge test is as following:

Sending a message

Testing Router-based apps

Assuming you’re testing TestCrosschainApp which inherits from Router:
Call processNextPendingMessage() and processNextPendingMessageFromDestination() to process inbound messages for destination and origin mailboxes respectively. Now, you can make your cross-chain calls from origin to destination and vice-versa:
If you want to use your own ISM for your app, you can override the defaultIsm mailbox provides by passing it to the Router’s initialize method like following:
You can find examples of our unit testing setup here: InterchainAccountRouterTest.