Unit Testing
Recommended Telepathy testing patterns.
Testing
To test cross-chain contracts, we leverage mocking patterns. MockTelepathy
simulates the behavior of TelepathyRouter
without the overhead of generating and relaying proofs. An example is below.
We specify our router
and receiver
to be MockTelepathy
contracts that simulate the behavior of TelepathyRouter
on the source and destination chain, respectively. We then specify our counter contracts on the source and contract chains with source
and target
.
To test source
and target
, we use source.increment()...
to increment. Then, we must call router.executeNextMessage()
to make our MockTelepathy
routers relay the call to target
. In doing so, we implicitly call target.handleTelepathyImpl(...)
! Without calls to router.executeNextMessage()
, our messages would be in a queue on the mock source chain, waiting to be relayed to the specified destination chain.
MockTelepathy Methods
These are methods unique to MockTelepathy
that don't exist in TelepathyRouter
.
addTelepathyReceiver(uint32 _chainId, MockTelepathy _receiver)
: This method tells a source chain router whichMockTelepathy
instance to route messages to that are sent to_chainId
.executeNextMessage()
: Broadcast next message in queue to receiverMockTelepathy
instance
MockTelepathy
can be used with forge
testing. Examples can be found below:
Last updated