-
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.
- Loading branch information
1 parent
e347ef6
commit 6c3e3f0
Showing
7 changed files
with
212 additions
and
25 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 @@ | ||
solady/=lib/solady/src/ |
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,63 @@ | ||
pragma solidity ^0.8.28; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
|
||
import {HyperlaneMailboxMock} from "./mocks/HyperlaneMailboxMock.sol"; | ||
import {OpBridgeMock} from "./mocks/OpBridgeMock.sol"; | ||
import {OpReceiverProxy} from "../src/OpReceiverProxy.sol"; | ||
import {IHyperlaneMailbox} from "../src/interfaces/IHyperlaneMailbox.sol"; | ||
import {IOpBridge} from "../src/interfaces/IOpBridge.sol"; | ||
|
||
contract OpReceiverProxyTest is Test { | ||
address public user; | ||
|
||
IOpBridge public opBridge; | ||
IHyperlaneMailbox public hyperlaneMailbox; | ||
|
||
uint32 public senderChainId; | ||
uint256 public feeBps; | ||
address public opSenderProxy; | ||
|
||
OpReceiverProxy public opReceiverProxy; | ||
|
||
function setUp() public { | ||
user = address(1); | ||
vm.deal(user, 1000 ether); | ||
|
||
opBridge = new OpBridgeMock(); | ||
hyperlaneMailbox = new HyperlaneMailboxMock(); | ||
|
||
senderChainId = 1; | ||
feeBps = 5e15; | ||
opSenderProxy = address(2); | ||
|
||
opReceiverProxy = new OpReceiverProxy( | ||
senderChainId, | ||
address(hyperlaneMailbox), | ||
feeBps, | ||
opSenderProxy | ||
); | ||
} | ||
|
||
function test_handle() public { | ||
uint256 amount = 1 ether; | ||
|
||
vm.deal(address(opReceiverProxy), 10 ether); | ||
|
||
uint256 balanceBefore = user.balance; | ||
|
||
vm.prank(address(hyperlaneMailbox)); | ||
opReceiverProxy.handle( | ||
senderChainId, | ||
bytes32(uint256(uint160(opSenderProxy))), | ||
abi.encode(0, user, amount) | ||
); | ||
|
||
uint256 balanceAfter = user.balance; | ||
|
||
assertEq( | ||
balanceAfter - balanceBefore, | ||
amount - (amount * opReceiverProxy.FEE_BPS()) / 1e18 | ||
); | ||
} | ||
} |
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,46 @@ | ||
pragma solidity ^0.8.28; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
|
||
import {HyperlaneMailboxMock} from "./mocks/HyperlaneMailboxMock.sol"; | ||
import {OpBridgeMock} from "./mocks/OpBridgeMock.sol"; | ||
import {OpSenderProxy} from "../src/OpSenderProxy.sol"; | ||
import {IHyperlaneMailbox} from "../src/interfaces/IHyperlaneMailbox.sol"; | ||
import {IOpBridge} from "../src/interfaces/IOpBridge.sol"; | ||
|
||
contract OpSenderProxyTest is Test { | ||
address public user; | ||
|
||
IOpBridge public opBridge; | ||
IHyperlaneMailbox public hyperlaneMailbox; | ||
|
||
uint32 public receiverChainId; | ||
address public opReceiverProxy; | ||
|
||
OpSenderProxy public opSenderProxy; | ||
|
||
function setUp() public { | ||
user = address(1); | ||
vm.deal(user, 1000 ether); | ||
|
||
opBridge = new OpBridgeMock(); | ||
hyperlaneMailbox = new HyperlaneMailboxMock(); | ||
|
||
receiverChainId = 1; | ||
opReceiverProxy = address(2); | ||
|
||
opSenderProxy = new OpSenderProxy( | ||
address(opBridge), | ||
receiverChainId, | ||
address(hyperlaneMailbox), | ||
opReceiverProxy | ||
); | ||
} | ||
|
||
function test_withdraw() public { | ||
uint256 amount = 1 ether; | ||
|
||
vm.prank(user); | ||
opSenderProxy.withdraw{value: amount}(user); | ||
} | ||
} |
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,22 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.28; | ||
|
||
import {IHyperlaneMailbox} from "../../src/interfaces/IHyperlaneMailbox.sol"; | ||
|
||
contract HyperlaneMailboxMock is IHyperlaneMailbox { | ||
function dispatch( | ||
uint32, // receiverChainId | ||
bytes32, // receiverAddress | ||
bytes calldata // data | ||
) external payable returns (bytes32 id) { | ||
return bytes32(block.number); | ||
} | ||
|
||
function quoteDispatch( | ||
uint32, // receiverChainId | ||
bytes32, // receiverAddress | ||
bytes calldata // data | ||
) external pure returns (uint256 fee) { | ||
return 0.001 ether; | ||
} | ||
} |
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,16 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.28; | ||
|
||
import {IOpBridge} from "../../src/interfaces/IOpBridge.sol"; | ||
|
||
contract OpBridgeMock is IOpBridge { | ||
function withdrawTo( | ||
address, // l2Token | ||
address, // to | ||
uint256, // amount | ||
uint32, // minGasLimit | ||
bytes calldata // extraData | ||
) external payable { | ||
// Do nothing | ||
} | ||
} |