-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add checkValue modifier to L1XERC20Adapter and ArbitrumEnabledXER20 * Add L1 fix tests * Lint * Update test/L1ArbitrumEnabledXERC20.t.sol Co-authored-by: Tomas Rojas <tmsrjs@gmail.com> --------- Co-authored-by: Tomas Rojas <tmsrjs@gmail.com>
- Loading branch information
1 parent
6d9f114
commit fbb173e
Showing
9 changed files
with
161 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.25 <0.9.0; | ||
|
||
import { Test } from "forge-std/Test.sol"; | ||
|
||
// solhint-disable-next-line | ||
import { console2 } from "forge-std/console2.sol"; | ||
|
||
import { L1ArbitrumEnabledXERC20 } from "src/L1ArbitrumEnabledXERC20.sol"; | ||
import { L1ArbitrumEnabled } from "src/libraries/L1ArbitrumEnabled.sol"; | ||
|
||
import { GatewayMock } from "test/mocks/GatewayMock.sol"; | ||
import { RouterMock } from "test/mocks/RouterMock.sol"; | ||
|
||
contract L1ArbitrumEnabledXERC20Test is Test { | ||
GatewayMock internal gateway; | ||
L1ArbitrumEnabledXERC20 internal arbEnabledToken; | ||
address internal _owner = makeAddr("owner"); | ||
|
||
function setUp() public { | ||
gateway = new GatewayMock(); | ||
|
||
arbEnabledToken = new L1ArbitrumEnabledXERC20("ArbitrumEnabledToken", "AET", _owner, address(gateway)); | ||
} | ||
|
||
function test_IsArbitrumEnabled() public view { | ||
assertEq(arbEnabledToken.isArbitrumEnabled(), uint8(0xb1)); | ||
} | ||
|
||
function test_registerTokenOnL2_WrongValue(uint256 valueForGateway, uint256 valueForRouter) public { | ||
// bound to avoid overflow or underflow | ||
valueForGateway = bound(valueForGateway, 1, 1e36); | ||
valueForRouter = bound(valueForRouter, 1, 1e36); | ||
|
||
deal(_owner, valueForGateway + valueForRouter + 1); | ||
|
||
vm.prank(_owner); | ||
vm.expectRevert(L1ArbitrumEnabled.WrongValue.selector); | ||
arbEnabledToken.registerTokenOnL2{ value: valueForGateway + valueForRouter - 1 }( | ||
makeAddr("l2Token"), 0, 0, 0, 0, 0, valueForGateway, valueForRouter, makeAddr("creditBack") | ||
); | ||
|
||
vm.prank(_owner); | ||
vm.expectRevert(L1ArbitrumEnabled.WrongValue.selector); | ||
arbEnabledToken.registerTokenOnL2{ value: valueForGateway + valueForRouter + 1 }( | ||
makeAddr("l2Token"), 0, 0, 0, 0, 0, valueForGateway, valueForRouter, makeAddr("creditBack") | ||
); | ||
} | ||
|
||
function test_registerTokenOnL2_works(uint256 valueForGateway, uint256 valueForRouter) public { | ||
// bound to avoid overflow or underflow | ||
valueForGateway = bound(valueForGateway, 1, 1e36); | ||
valueForRouter = bound(valueForRouter, 1, 1e36); | ||
|
||
deal(_owner, valueForGateway + valueForRouter); | ||
|
||
address router = gateway.router(); | ||
|
||
vm.prank(_owner); | ||
vm.expectCall(address(gateway), valueForGateway, abi.encodePacked(GatewayMock.registerTokenToL2.selector)); | ||
vm.expectCall(address(gateway), abi.encodePacked(GatewayMock.router.selector)); | ||
vm.expectCall(router, valueForRouter, abi.encodePacked(RouterMock.setGateway.selector)); | ||
arbEnabledToken.registerTokenOnL2{ value: valueForGateway + valueForRouter }( | ||
makeAddr("l2Token"), 0, 0, 0, 0, 0, valueForGateway, valueForRouter, makeAddr("creditBack") | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.25 <0.9.0; | ||
|
||
import { RouterMock } from "./RouterMock.sol"; | ||
|
||
contract GatewayMock { | ||
RouterMock internal routerContract; | ||
|
||
constructor() { | ||
routerContract = new RouterMock(); | ||
} | ||
|
||
function registerTokenToL2(address, uint256, uint256, uint256, address) public payable returns (uint256) { | ||
return 1; | ||
} | ||
|
||
function router() public view returns (address) { | ||
return address(routerContract); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.25 <0.9.0; | ||
|
||
import { IL1CustomGateway } from "src/interfaces/IL1CustomGateway.sol"; | ||
|
||
contract RouterMock { | ||
function setGateway(IL1CustomGateway, uint256, uint256, uint256, address) public payable returns (uint256) { | ||
return 1; | ||
} | ||
} |