Skip to content

Commit

Permalink
Add test with chainlink CCIP simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
rya-sge committed Apr 30, 2024
1 parent b6ac90b commit 71ba229
Show file tree
Hide file tree
Showing 58 changed files with 483 additions and 368 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/chainlink-local"]
path = lib/chainlink-local
url = https://github.com/smartcontractkit/chainlink-local
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

Please follow <https://changelog.md/> conventions.



## 1.0.1 - 20240429

In the version 1.0.0, when fees are paid in native tokens, the function ccipSend from the CCIP router was called without the `value`argument.

Old version

**new version**

```solidity
if(_paymentMethodId == 0){ // Native token
messageId = router.ccipSend{value: fees}(_destinationChainSelector, message);
} else{
messageId = router.ccipSend(_destinationChainSelector, message);
}
```



## 1.0.0 - 20240423

- 🎉 First release !
6 changes: 3 additions & 3 deletions doc/test/coverage/bridge/CCIPBaseSender.sol.func-sort-c.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</tr>
<tr>
<td class="headerItem">Date:</td>
<td class="headerValue">2024-04-26 14:53:42</td>
<td class="headerValue">2024-04-30 10:51:06</td>
<td></td>
<td class="headerItem">Functions:</td>
<td class="headerCovTableEntry">3</td>
Expand Down Expand Up @@ -74,11 +74,11 @@
</tr>
<tr>
<td class="coverFn"><a href="CCIPBaseSender.sol.gcov.html#113">CCIPBaseSender._buildEndSend</a></td>
<td class="coverFnHi">12</td>
<td class="coverFnHi">13</td>
</tr>
<tr>
<td class="coverFn"><a href="CCIPBaseSender.sol.gcov.html#38">CCIPBaseSender.transferTokens</a></td>
<td class="coverFnHi">12</td>
<td class="coverFnHi">13</td>
</tr>
</table>
<br>
Expand Down
6 changes: 3 additions & 3 deletions doc/test/coverage/bridge/CCIPBaseSender.sol.func.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</tr>
<tr>
<td class="headerItem">Date:</td>
<td class="headerValue">2024-04-26 14:53:42</td>
<td class="headerValue">2024-04-30 10:51:06</td>
<td></td>
<td class="headerItem">Functions:</td>
<td class="headerCovTableEntry">3</td>
Expand Down Expand Up @@ -70,11 +70,11 @@
</tr>
<tr>
<td class="coverFn"><a href="CCIPBaseSender.sol.gcov.html#113">CCIPBaseSender._buildEndSend</a></td>
<td class="coverFnHi">12</td>
<td class="coverFnHi">13</td>
</tr>
<tr>
<td class="coverFn"><a href="CCIPBaseSender.sol.gcov.html#38">CCIPBaseSender.transferTokens</a></td>
<td class="coverFnHi">12</td>
<td class="coverFnHi">13</td>
</tr>
<tr>
<td class="coverFn"><a href="CCIPBaseSender.sol.gcov.html#78">CCIPBaseSender.transferTokensBatch</a></td>
Expand Down
32 changes: 16 additions & 16 deletions doc/test/coverage/bridge/CCIPBaseSender.sol.gcov.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</tr>
<tr>
<td class="headerItem">Date:</td>
<td class="headerValue">2024-04-26 14:53:42</td>
<td class="headerValue">2024-04-30 10:51:06</td>
<td></td>
<td class="headerItem">Functions:</td>
<td class="headerCovTableEntry">3</td>
Expand Down Expand Up @@ -120,18 +120,18 @@
<a name="49"><span class="lineNum"> 49 </span> : : onlyAllowlistedDestinationChain(_destinationChainSelector)</a>
<a name="50"><span class="lineNum"> 50 </span> : : returns (bytes32 messageId) </a>
<a name="51"><span class="lineNum"> 51 </span> : : {</a>
<a name="52"><span class="lineNum"> 52 </span> :<span class="lineCov"> 20 : Client.EVMTokenAmount[]</span></a>
<a name="53"><span class="lineNum"> 53 </span> :<span class="lineCov"> 20 : memory tokenAmounts = new Client.EVMTokenAmount[](1);</span></a>
<a name="54"><span class="lineNum"> 54 </span> :<span class="lineCov"> 30 : Client.EVMTokenAmount memory tokenAmount = Client.EVMTokenAmount({</span></a>
<a name="52"><span class="lineNum"> 52 </span> :<span class="lineCov"> 22 : Client.EVMTokenAmount[]</span></a>
<a name="53"><span class="lineNum"> 53 </span> :<span class="lineCov"> 22 : memory tokenAmounts = new Client.EVMTokenAmount[](1);</span></a>
<a name="54"><span class="lineNum"> 54 </span> :<span class="lineCov"> 33 : Client.EVMTokenAmount memory tokenAmount = Client.EVMTokenAmount({</span></a>
<a name="55"><span class="lineNum"> 55 </span> : : token: _token,</a>
<a name="56"><span class="lineNum"> 56 </span> : : amount: _amount</a>
<a name="57"><span class="lineNum"> 57 </span> : : });</a>
<a name="58"><span class="lineNum"> 58 </span> :<span class="lineCov"> 20 : tokenAmounts[0] = tokenAmount;</span></a>
<a name="59"><span class="lineNum"> 59 </span> :<span class="lineCov"> 20 : uint256 fees;</span></a>
<a name="58"><span class="lineNum"> 58 </span> :<span class="lineCov"> 22 : tokenAmounts[0] = tokenAmount;</span></a>
<a name="59"><span class="lineNum"> 59 </span> :<span class="lineCov"> 22 : uint256 fees;</span></a>
<a name="60"><span class="lineNum"> 60 </span> : : </a>
<a name="61"><span class="lineNum"> 61 </span> :<span class="lineCov"> 20 : (fees, messageId) = _buildEndSend(_destinationChainSelector, _receiver, _paymentMethodId, tokenAmounts);</span></a>
<a name="61"><span class="lineNum"> 61 </span> :<span class="lineCov"> 22 : (fees, messageId) = _buildEndSend(_destinationChainSelector, _receiver, _paymentMethodId, tokenAmounts);</span></a>
<a name="62"><span class="lineNum"> 62 </span> : : </a>
<a name="63"><span class="lineNum"> 63 </span> :<span class="lineCov"> 4 : emit TokenSingleTransferred(</span></a>
<a name="63"><span class="lineNum"> 63 </span> :<span class="lineCov"> 6 : emit TokenSingleTransferred(</span></a>
<a name="64"><span class="lineNum"> 64 </span> : : messageId,</a>
<a name="65"><span class="lineNum"> 65 </span> : : _destinationChainSelector,</a>
<a name="66"><span class="lineNum"> 66 </span> : : _receiver,</a>
Expand Down Expand Up @@ -185,20 +185,20 @@
<a name="114"><span class="lineNum"> 114 </span> : : */</a>
<a name="115"><span class="lineNum"> 115 </span> : : function _buildEndSend(uint64 _destinationChainSelector, address _receiver, uint256 _paymentMethodId, Client.EVMTokenAmount[] memory tokenAmounts) internal returns(uint256 fees, bytes32 messageId){</a>
<a name="116"><span class="lineNum"> 116 </span> : : // Build the CCIP Message</a>
<a name="117"><span class="lineNum"> 117 </span> :<span class="lineCov"> 36 : Client.EVM2AnyMessage memory message = CCIPSenderBuild._buildCCIPTransferMessage(_receiver, tokenAmounts, _paymentMethodId );</span></a>
<a name="117"><span class="lineNum"> 117 </span> :<span class="lineCov"> 39 : Client.EVM2AnyMessage memory message = CCIPSenderBuild._buildCCIPTransferMessage(_receiver, tokenAmounts, _paymentMethodId );</span></a>
<a name="118"><span class="lineNum"> 118 </span> : : // Initialize a router client instance to interact with cross-chain router</a>
<a name="119"><span class="lineNum"> 119 </span> :<span class="lineCov"> 30 : IRouterClient router = IRouterClient(CCIPRouterManage.getRouter());</span></a>
<a name="119"><span class="lineNum"> 119 </span> :<span class="lineCov"> 33 : IRouterClient router = IRouterClient(CCIPRouterManage.getRouter());</span></a>
<a name="120"><span class="lineNum"> 120 </span> : : // CCIP Fees Management</a>
<a name="121"><span class="lineNum"> 121 </span> :<span class="lineCov"> 20 : fees = CCIPSenderPayment._computeAndApproveFee(_destinationChainSelector, message, router, _paymentMethodId);</span></a>
<a name="122"><span class="lineNum"> 122 </span> :<span class="lineCov"> 36 : for(uint256 i = 0; i &lt; tokenAmounts.length; ++i){</span></a>
<a name="121"><span class="lineNum"> 121 </span> :<span class="lineCov"> 22 : fees = CCIPSenderPayment._computeAndApproveFee(_destinationChainSelector, message, router, _paymentMethodId);</span></a>
<a name="122"><span class="lineNum"> 122 </span> :<span class="lineCov"> 41 : for(uint256 i = 0; i &lt; tokenAmounts.length; ++i){</span></a>
<a name="123"><span class="lineNum"> 123 </span> : : // transfer tokens to the contract</a>
<a name="124"><span class="lineNum"> 124 </span> :<span class="lineCov"> 20 : IERC20(tokenAmounts[i].token).safeTransferFrom(_msgSender(), address(this), tokenAmounts[i].amount);</span></a>
<a name="124"><span class="lineNum"> 124 </span> :<span class="lineCov"> 22 : IERC20(tokenAmounts[i].token).safeTransferFrom(_msgSender(), address(this), tokenAmounts[i].amount);</span></a>
<a name="125"><span class="lineNum"> 125 </span> : : // approve the Router to spend tokens on contract's behalf. It will spend the amount of the given token</a>
<a name="126"><span class="lineNum"> 126 </span> :<span class="lineCov"> 12 : IERC20(tokenAmounts[i].token).safeIncreaseAllowance(address(router), tokenAmounts[i].amount);</span></a>
<a name="126"><span class="lineNum"> 126 </span> :<span class="lineCov"> 14 : IERC20(tokenAmounts[i].token).safeIncreaseAllowance(address(router), tokenAmounts[i].amount);</span></a>
<a name="127"><span class="lineNum"> 127 </span> : : }</a>
<a name="128"><span class="lineNum"> 128 </span> : : // Send CCIP Message</a>
<a name="129"><span class="lineNum"> 129 </span> [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span>]:<span class="lineCov"> 8 : if(_paymentMethodId == 0){ // Native token</span></a>
<a name="130"><span class="lineNum"> 130 </span> :<span class="lineCov"> 4 : messageId = router.ccipSend{value: fees}(_destinationChainSelector, message); </span></a>
<a name="129"><span class="lineNum"> 129 </span> [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov"> 10 : if(_paymentMethodId == 0){ // Native token</span></a>
<a name="130"><span class="lineNum"> 130 </span> :<span class="lineCov"> 6 : messageId = router.ccipSend{value: fees}(_destinationChainSelector, message); </span></a>
<a name="131"><span class="lineNum"> 131 </span> : : } else{</a>
<a name="132"><span class="lineNum"> 132 </span> :<span class="lineCov"> 4 : messageId = router.ccipSend(_destinationChainSelector, message); </span></a>
<a name="133"><span class="lineNum"> 133 </span> : : }</a>
Expand Down
2 changes: 1 addition & 1 deletion doc/test/coverage/bridge/index-sort-b.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</tr>
<tr>
<td class="headerItem">Date:</td>
<td class="headerValue">2024-04-26 14:53:42</td>
<td class="headerValue">2024-04-30 10:51:06</td>
<td></td>
<td class="headerItem">Functions:</td>
<td class="headerCovTableEntry">3</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/test/coverage/bridge/index-sort-f.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</tr>
<tr>
<td class="headerItem">Date:</td>
<td class="headerValue">2024-04-26 14:53:42</td>
<td class="headerValue">2024-04-30 10:51:06</td>
<td></td>
<td class="headerItem">Functions:</td>
<td class="headerCovTableEntry">3</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/test/coverage/bridge/index-sort-l.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</tr>
<tr>
<td class="headerItem">Date:</td>
<td class="headerValue">2024-04-26 14:53:42</td>
<td class="headerValue">2024-04-30 10:51:06</td>
<td></td>
<td class="headerItem">Functions:</td>
<td class="headerCovTableEntry">3</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/test/coverage/bridge/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</tr>
<tr>
<td class="headerItem">Date:</td>
<td class="headerValue">2024-04-26 14:53:42</td>
<td class="headerValue">2024-04-30 10:51:06</td>
<td></td>
<td class="headerItem">Functions:</td>
<td class="headerCovTableEntry">3</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</tr>
<tr>
<td class="headerItem">Date:</td>
<td class="headerValue">2024-04-26 14:53:42</td>
<td class="headerValue">2024-04-30 10:51:06</td>
<td></td>
<td class="headerItem">Functions:</td>
<td class="headerCovTableEntry">1</td>
Expand Down Expand Up @@ -70,7 +70,7 @@
</tr>
<tr>
<td class="coverFn"><a href="CCIPAllowlistedChain.sol.gcov.html#36">CCIPAllowlistedChain.setAllowlistChain</a></td>
<td class="coverFnHi">17</td>
<td class="coverFnHi">18</td>
</tr>
</table>
<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</tr>
<tr>
<td class="headerItem">Date:</td>
<td class="headerValue">2024-04-26 14:53:42</td>
<td class="headerValue">2024-04-30 10:51:06</td>
<td></td>
<td class="headerItem">Functions:</td>
<td class="headerCovTableEntry">1</td>
Expand Down Expand Up @@ -70,7 +70,7 @@
</tr>
<tr>
<td class="coverFn"><a href="CCIPAllowlistedChain.sol.gcov.html#36">CCIPAllowlistedChain.setAllowlistChain</a></td>
<td class="coverFnHi">17</td>
<td class="coverFnHi">18</td>
</tr>
</table>
<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</tr>
<tr>
<td class="headerItem">Date:</td>
<td class="headerValue">2024-04-26 14:53:42</td>
<td class="headerValue">2024-04-30 10:51:06</td>
<td></td>
<td class="headerItem">Functions:</td>
<td class="headerCovTableEntry">1</td>
Expand Down Expand Up @@ -111,11 +111,11 @@
<a name="40"><span class="lineNum"> 40 </span> : : bool allowedSourceChain,</a>
<a name="41"><span class="lineNum"> 41 </span> : : bool allowedDestinationChain</a>
<a name="42"><span class="lineNum"> 42 </span> : : ) external onlyRole(BRIDGE_ALLOWLISTED_CHAIN_MANAGER_ROLE) {</a>
<a name="43"><span class="lineNum"> 43 </span> [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchCov" title="Branch 1 was taken 15 times"> + </span>]:<span class="lineCov"> 30 : if(allowlistedSourceChains[_chainSelector] != allowedSourceChain){</span></a>
<a name="43"><span class="lineNum"> 43 </span> [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchCov" title="Branch 1 was taken 16 times"> + </span>]:<span class="lineCov"> 32 : if(allowlistedSourceChains[_chainSelector] != allowedSourceChain){</span></a>
<a name="44"><span class="lineNum"> 44 </span> :<span class="lineCov"> 6 : allowlistedSourceChains[_chainSelector] = allowedSourceChain;</span></a>
<a name="45"><span class="lineNum"> 45 </span> : : }</a>
<a name="46"><span class="lineNum"> 46 </span> [<span class="branchCov" title="Branch 0 was taken 15 times"> + </span><span class="branchCov" title="Branch 1 was taken 15 times"> + </span>]:<span class="lineCov"> 30 : if( allowlistedDestinationChains[_chainSelector] != allowedDestinationChain){</span></a>
<a name="47"><span class="lineNum"> 47 </span> :<span class="lineCov"> 30 : allowlistedDestinationChains[_chainSelector] = allowedDestinationChain;</span></a>
<a name="46"><span class="lineNum"> 46 </span> [<span class="branchCov" title="Branch 0 was taken 16 times"> + </span><span class="branchCov" title="Branch 1 was taken 16 times"> + </span>]:<span class="lineCov"> 32 : if( allowlistedDestinationChains[_chainSelector] != allowedDestinationChain){</span></a>
<a name="47"><span class="lineNum"> 47 </span> :<span class="lineCov"> 32 : allowlistedDestinationChains[_chainSelector] = allowedDestinationChain;</span></a>
<a name="48"><span class="lineNum"> 48 </span> : : }</a>
<a name="49"><span class="lineNum"> 49 </span> : : }</a>
<a name="50"><span class="lineNum"> 50 </span> : : }</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</tr>
<tr>
<td class="headerItem">Date:</td>
<td class="headerValue">2024-04-26 14:53:42</td>
<td class="headerValue">2024-04-30 10:51:06</td>
<td></td>
<td class="headerItem">Functions:</td>
<td class="headerCovTableEntry">3</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</tr>
<tr>
<td class="headerItem">Date:</td>
<td class="headerValue">2024-04-26 14:53:42</td>
<td class="headerValue">2024-04-30 10:51:06</td>
<td></td>
<td class="headerItem">Functions:</td>
<td class="headerCovTableEntry">3</td>
Expand Down
Loading

0 comments on commit 71ba229

Please sign in to comment.