|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity 0.8.26; |
| 3 | + |
| 4 | +import {Test} from "forge-std/Test.sol"; |
| 5 | +import {CCIPLocalSimulator, IRouterClient, LinkToken} from "@chainlink/local/src/ccip/CCIPLocalSimulator.sol"; |
| 6 | +import {SepoliaSender} from "src/SepoliaSender.sol"; |
| 7 | +import {AmoyReceiver} from "src/AmoyReceiver.sol"; |
| 8 | + |
| 9 | +contract MessageTransferTest is Test { |
| 10 | + CCIPLocalSimulator public ccipLocalSimulator; |
| 11 | + uint64 public destinationChainSelector; |
| 12 | + |
| 13 | + SepoliaSender public sepoliaSender; |
| 14 | + AmoyReceiver public amoyReceiver; |
| 15 | + |
| 16 | + address public USER = makeAddr("USER"); |
| 17 | + |
| 18 | + function setUp() public { |
| 19 | + ccipLocalSimulator = new CCIPLocalSimulator(); |
| 20 | + |
| 21 | + ( |
| 22 | + uint64 chainSelector, |
| 23 | + IRouterClient sourceRouter, |
| 24 | + IRouterClient destinationRouter, |
| 25 | + , |
| 26 | + LinkToken link, |
| 27 | + , |
| 28 | + |
| 29 | + ) = ccipLocalSimulator.configuration(); |
| 30 | + |
| 31 | + destinationChainSelector = chainSelector; |
| 32 | + |
| 33 | + sepoliaSender = new SepoliaSender(address(sourceRouter), address(link)); |
| 34 | + amoyReceiver = new AmoyReceiver(address(destinationRouter)); |
| 35 | + } |
| 36 | + |
| 37 | + function testMessageTransferWithLinkTokenPaid() public { |
| 38 | + ccipLocalSimulator.requestLinkFromFaucet( |
| 39 | + address(sepoliaSender), |
| 40 | + 5 ether |
| 41 | + ); |
| 42 | + |
| 43 | + bytes memory signedMessage = abi.encodePacked("Hello, Amoy!"); |
| 44 | + |
| 45 | + bytes32 messageId = sepoliaSender.sendMessage( |
| 46 | + destinationChainSelector, |
| 47 | + address(amoyReceiver), |
| 48 | + signedMessage |
| 49 | + ); |
| 50 | + |
| 51 | + bytes memory receivedMessage = amoyReceiver.getSignedMessage(); |
| 52 | + bytes32 lastMessageId = amoyReceiver.getMessageId(); |
| 53 | + |
| 54 | + string memory expectedMessage = "Hello, Amoy!"; |
| 55 | + string memory actualMessage = abi.decode(receivedMessage, (string)); |
| 56 | + |
| 57 | + assertEq(messageId, lastMessageId); |
| 58 | + assertEq(expectedMessage, actualMessage); |
| 59 | + } |
| 60 | +} |
0 commit comments