Skip to content

Commit

Permalink
added test for rate limits
Browse files Browse the repository at this point in the history
  • Loading branch information
dan13ram committed Sep 4, 2024
1 parent 664725f commit 5df9ace
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions test/OFT.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ contract OFTTest is TestHelper {
super.setUp();
setUpEndpoints(3, LibraryType.UltraLightNode);
RateLimiter.RateLimitConfig[] memory _rateLimitConfigs = new RateLimiter.RateLimitConfig[](3);
_rateLimitConfigs[0] = RateLimiter.RateLimitConfig({dstEid: 1, limit: 1000000 ether, window: 1 days});
_rateLimitConfigs[1] = RateLimiter.RateLimitConfig({dstEid: 2, limit: 1000000 ether, window: 1 days});
_rateLimitConfigs[2] = RateLimiter.RateLimitConfig({dstEid: 3, limit: 1000000 ether, window: 1 days});
_rateLimitConfigs[0] = RateLimiter.RateLimitConfig({dstEid: 1, limit: 10 ether, window: 1 days});
_rateLimitConfigs[1] = RateLimiter.RateLimitConfig({dstEid: 2, limit: 10 ether, window: 1 days});
_rateLimitConfigs[2] = RateLimiter.RateLimitConfig({dstEid: 3, limit: 10 ether, window: 1 days});

{
aERC20 = new ERC20Mock("aToken", "aToken");
Expand Down Expand Up @@ -171,6 +171,23 @@ contract OFTTest is TestHelper {
assertEq(bERC20.balanceOf(userB), 0 + tokensToSend);
}

function test_send_oft_rate_limited() public {
uint256 tokensToSend = 20 ether;
bytes memory options = OptionsBuilder.newOptions().addExecutorLzReceiveOption(200000, 0);
SendParam memory sendParam =
SendParam(bEid, addressToBytes32(userB), tokensToSend, tokensToSend, options, "", "");
MessagingFee memory fee = aOFTAdapter.quoteSend(sendParam, false);

assertEq(aERC20.balanceOf(userA), initialBalance);
assertEq(bERC20.balanceOf(userB), 0);

vm.startPrank(userA);
aERC20.approve(address(aOFTAdapter), tokensToSend);
vm.expectRevert(RateLimiter.RateLimitExceeded.selector);
aOFTAdapter.send{value: fee.nativeFee}(sendParam, fee, payable(address(this)));
vm.stopPrank();
}

function test_send_oft_and_receive() public {
uint256 tokensToSend = 1 ether;
bytes memory options = OptionsBuilder.newOptions().addExecutorLzReceiveOption(200000, 0);
Expand Down

0 comments on commit 5df9ace

Please sign in to comment.