-
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.
Merge pull request #4 from BootNodeDev/inbound-transfer-tests
Inbound transfer tests
- Loading branch information
Showing
4 changed files
with
140 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.25 <0.9.0; | ||
|
||
import { Test } from "forge-std/Test.sol"; | ||
|
||
import { XERC20 } from "xerc20/contracts/XERC20.sol"; | ||
|
||
import { L1XERC20Adapter } from "src/L1XERC20Adapter.sol"; | ||
import { L1XERC20Gateway } from "src/L1XERC20Gateway.sol"; | ||
|
||
abstract contract L1XERC20BaseGatewayTest is Test { | ||
XERC20 internal xerc20; | ||
L1XERC20Adapter internal adapter; | ||
L1XERC20Gateway internal l1Gateway; | ||
address internal l1GatewayRouter; | ||
|
||
address internal l1Inbox; | ||
|
||
address internal _owner = makeAddr("owner"); | ||
address internal _user = makeAddr("user"); | ||
address internal _dest = makeAddr("dest"); | ||
|
||
uint256 internal amountToBridge = 25; | ||
|
||
function _setUp() internal { | ||
assert(l1GatewayRouter != address(0)); | ||
vm.label(l1GatewayRouter, "l1GatewayRouter"); | ||
assert(l1Inbox != address(0)); | ||
vm.label(l1Inbox, "l1Inbox"); | ||
|
||
l1Gateway = new L1XERC20Gateway(l1GatewayRouter, l1Inbox); | ||
|
||
xerc20 = new XERC20("NonArbitrumEnabled", "NON", _owner); | ||
vm.prank(_owner); | ||
xerc20.setLimits(address(l1Gateway), 420 ether, 69 ether); | ||
|
||
vm.prank(_owner); | ||
adapter = new L1XERC20Adapter(address(xerc20), address(l1Gateway)); | ||
} | ||
|
||
//// | ||
// Event declarations for assertions | ||
//// | ||
event Transfer(address indexed from, address indexed to, uint256 value); | ||
} |
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 |
---|---|---|
@@ -1,29 +1,56 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
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 { XERC20 } from "xerc20/contracts/XERC20.sol"; | ||
import { IInbox } from "@arbitrum/nitro-contracts/src/bridge/IInbox.sol"; | ||
import { InboxMock } from "@arbitrum/tokenbridge/test/InboxMock.sol"; | ||
|
||
import { L1XERC20Adapter } from "src/L1XERC20Adapter.sol"; | ||
import { L1XERC20Gateway } from "src/L1XERC20Gateway.sol"; | ||
|
||
contract L1XERC20GatewayTest is Test { | ||
XERC20 internal xerc20; | ||
L1XERC20Adapter internal adapter; | ||
L1XERC20Gateway internal gateway; | ||
|
||
address internal _owner = makeAddr("owner"); | ||
import { L1XERC20BaseGatewayTest } from "test/L1XERC20BaseGatewayTest.t.sol"; | ||
|
||
contract L1XERC20GatewayTest is L1XERC20BaseGatewayTest { | ||
function setUp() public { | ||
xerc20 = new XERC20("NonArbitrumEnabled", "NON", _owner); | ||
gateway = new L1XERC20Gateway(makeAddr("router"), makeAddr("inbox")); | ||
adapter = new L1XERC20Adapter(address(xerc20), address(gateway)); | ||
l1GatewayRouter = makeAddr("l1GatewayRouter"); | ||
l1Inbox = address(new InboxMock()); | ||
|
||
_setUp(); | ||
} | ||
|
||
function test_AddressIsAdapter() public view { | ||
assertEq(gateway.addressIsAdapter(address(xerc20)), false); | ||
assertEq(gateway.addressIsAdapter(address(adapter)), true); | ||
assertEq(l1Gateway.addressIsAdapter(address(xerc20)), false); | ||
assertEq(l1Gateway.addressIsAdapter(address(adapter)), true); | ||
} | ||
|
||
function test_FinalizeInboundTransfer() public { | ||
InboxMock(address(l1Inbox)).setL2ToL1Sender(l1Gateway.counterpartGateway()); | ||
|
||
uint256 exitNum = 7; | ||
bytes memory callHookData = ""; | ||
bytes memory data = abi.encode(exitNum, callHookData); | ||
|
||
vm.expectEmit(true, true, true, true, address(xerc20)); | ||
emit Transfer(address(0), _dest, amountToBridge); | ||
|
||
vm.expectEmit(true, true, true, true, address(l1Gateway)); | ||
emit WithdrawalFinalized(address(adapter), _user, _dest, exitNum, amountToBridge); | ||
|
||
uint256 balanceBefore = xerc20.balanceOf(_dest); | ||
|
||
vm.prank(address(IInbox(l1Gateway.inbox()).bridge())); | ||
l1Gateway.finalizeInboundTransfer(address(adapter), _user, _dest, amountToBridge, data); | ||
|
||
assertEq(adapter.balanceOf(_dest), xerc20.balanceOf(_dest)); | ||
assertEq(xerc20.balanceOf(_dest), balanceBefore + amountToBridge); | ||
} | ||
|
||
//// | ||
// Event declarations for assertions | ||
//// | ||
event WithdrawalFinalized( | ||
address l1Token, address indexed _from, address indexed _to, uint256 indexed _exitNum, uint256 _amount | ||
); | ||
} |
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