Unit Testing
Recommended Telepathy testing patterns.
Last updated
Recommended Telepathy testing patterns.
Last updated
To test cross-chain contracts, we leverage mocking patterns. 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.
addTelepathyReceiver(uint32 _chainId, MockTelepathy _receiver)
: This method tells a source chain router which MockTelepathy
instance to route messages to that are sent to _chainId
.
executeNextMessage()
: Broadcast next message in queue to receiver MockTelepathy
instance
MockTelepathy
can be used with forge
testing. Examples can be found below:
These are methods unique to that don't exist in TelepathyRouter
.