|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +pragma solidity ^0.8.4; |
| 3 | + |
| 4 | +import "forge-std/Test.sol"; |
| 5 | +import "./util/TestUtil.sol"; |
| 6 | +import "../../src/bridge/IERC20Bridge.sol"; |
| 7 | +import "../../src/bridge/ERC20Bridge.sol"; |
| 8 | +import "../../src/bridge/extra/ERC20MigrationOutbox.sol"; |
| 9 | +import {NoZeroTransferToken} from "./util/NoZeroTransferToken.sol"; |
| 10 | + |
| 11 | +contract ERC20MigrationOutboxTest is Test { |
| 12 | + IERC20Bridge public bridge; |
| 13 | + |
| 14 | + IERC20MigrationOutbox public erc20MigrationOutbox; |
| 15 | + IERC20Bridge public erc20Bridge; |
| 16 | + IERC20 public nativeToken; |
| 17 | + |
| 18 | + address public user = address(100); |
| 19 | + address public rollup = address(1000); |
| 20 | + address public seqInbox = address(1001); |
| 21 | + address public constant dst = address(1337); |
| 22 | + |
| 23 | + function setUp() public { |
| 24 | + // deploy token, bridge and erc20MigrationOutbox |
| 25 | + nativeToken = new NoZeroTransferToken("Appchain Token", "App", 1_000_000, address(this)); |
| 26 | + bridge = IERC20Bridge(TestUtil.deployProxy(address(new ERC20Bridge()))); |
| 27 | + erc20Bridge = IERC20Bridge(address(bridge)); |
| 28 | + |
| 29 | + // init bridge |
| 30 | + erc20Bridge.initialize(IOwnable(rollup), address(nativeToken)); |
| 31 | + |
| 32 | + // deploy erc20MigrationOutbox |
| 33 | + erc20MigrationOutbox = new ERC20MigrationOutbox(bridge, dst); |
| 34 | + |
| 35 | + // set outbox |
| 36 | + vm.prank(rollup); |
| 37 | + bridge.setOutbox(address(erc20MigrationOutbox), true); |
| 38 | + } |
| 39 | + |
| 40 | + function test_invalid_destination() public { |
| 41 | + vm.expectRevert(IERC20MigrationOutbox.InvalidDestination.selector); |
| 42 | + new ERC20MigrationOutbox(bridge, address(0)); |
| 43 | + } |
| 44 | + |
| 45 | + function test_migrate() public { |
| 46 | + nativeToken.transfer(address(bridge), 1000); |
| 47 | + |
| 48 | + vm.prank(user); |
| 49 | + erc20MigrationOutbox.migrate(); |
| 50 | + |
| 51 | + assertEq(nativeToken.balanceOf(dst), 1000); |
| 52 | + } |
| 53 | + |
| 54 | + function test_migrate_no_balance() public { |
| 55 | + vm.expectRevert(IERC20MigrationOutbox.NoBalanceToMigrate.selector); |
| 56 | + vm.prank(user); |
| 57 | + erc20MigrationOutbox.migrate(); |
| 58 | + } |
| 59 | +} |
0 commit comments