Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Assume on tests failing due to low addresses #2

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 78 additions & 75 deletions tests/adapters/HyperLaneAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ contract HyperLaneAdapterTest is BaseAdapterTest {
uint256 baseGasLimit,
uint256 originChainId
) {
vm.assume(mailBox > address(65536));
vm.assume(originForwarder > address(65536));
vm.assume(crossChainController > address(65536));
vm.assume(baseGasLimit < 1e7);
_assumeSafeAddress(crossChainController);
_assumeSafeAddress(mailBox);
Expand Down Expand Up @@ -105,54 +108,54 @@ contract HyperLaneAdapterTest is BaseAdapterTest {
assertEq(hlAdapter.infraToNativeChainId(ChainIds.POLYGON), uint32(ChainIds.POLYGON));
}

// function testForwardMessage(
// address crossChainController,
// address mailBox,
// address originForwarder,
// uint256 baseGasLimit,
// uint256 dstGasLimit,
// address receiver,
// address caller
// )
// public
// setHLAdapter(crossChainController, mailBox, originForwarder, baseGasLimit, ChainIds.POLYGON)
// {
// vm.assume(caller != address(0));
// vm.assume(dstGasLimit < 1 ether);
// vm.assume(receiver != address(0));
function testForwardMessage(
address crossChainController,
address mailBox,
address originForwarder,
uint256 baseGasLimit,
uint256 dstGasLimit,
address receiver,
address caller
)
public
setHLAdapter(crossChainController, mailBox, originForwarder, baseGasLimit, ChainIds.POLYGON)
{
vm.assume(caller > address(65536));
vm.assume(dstGasLimit < 1 ether);
vm.assume(receiver > address(65536));

// _testForwardMessage(mailBox, receiver, dstGasLimit, baseGasLimit, caller);
// }
_testForwardMessage(mailBox, receiver, dstGasLimit, baseGasLimit, caller);
}

// function testForwardMessageWithNoValue(
// address crossChainController,
// address mailBox,
// address originForwarder,
// uint256 baseGasLimit,
// uint256 dstGasLimit,
// address receiver
// )
// public
// setHLAdapter(crossChainController, mailBox, originForwarder, baseGasLimit, ChainIds.POLYGON)
// {
// vm.assume(dstGasLimit > 200000 && dstGasLimit < 1 ether);
// vm.assume(receiver != address(0));
function testForwardMessageWithNoValue(
address crossChainController,
address mailBox,
address originForwarder,
uint256 baseGasLimit,
uint256 dstGasLimit,
address receiver
)
public
setHLAdapter(crossChainController, mailBox, originForwarder, baseGasLimit, ChainIds.POLYGON)
{
vm.assume(dstGasLimit > 200000 && dstGasLimit < 1 ether);
vm.assume(receiver != address(0));

// bytes memory message = abi.encode('test message');
bytes memory message = abi.encode('test message');

// vm.mockCall(mailBox, abi.encodeWithSelector(IMailbox.quoteDispatch.selector), abi.encode(1e4));
// vm.expectRevert(bytes(Errors.NOT_ENOUGH_VALUE_TO_PAY_BRIDGE_FEES));
// (bool success, ) = address(hlAdapter).delegatecall(
// abi.encodeWithSelector(
// IBaseAdapter.forwardMessage.selector,
// receiver,
// dstGasLimit,
// ChainIds.POLYGON,
// message
// )
// );
// assertEq(success, false);
// }
vm.mockCall(mailBox, abi.encodeWithSelector(IMailbox.quoteDispatch.selector), abi.encode(1e4));
vm.expectRevert(bytes(Errors.NOT_ENOUGH_VALUE_TO_PAY_BRIDGE_FEES));
(bool success, ) = address(hlAdapter).delegatecall(
abi.encodeWithSelector(
IBaseAdapter.forwardMessage.selector,
receiver,
dstGasLimit,
ChainIds.POLYGON,
message
)
);
assertEq(success, false);
}

function testForwardMessageWhenWrongReceiver(
address crossChainController,
Expand All @@ -176,38 +179,38 @@ contract HyperLaneAdapterTest is BaseAdapterTest {
);
}

// function testHandle(
// address crossChainController,
// address mailBox,
// address originForwarder,
// uint256 baseGasLimit
// )
// public
// setHLAdapter(crossChainController, mailBox, originForwarder, baseGasLimit, ChainIds.ETHEREUM)
// {
// bytes memory message = abi.encode('some message');
function testHandle(
address crossChainController,
address mailBox,
address originForwarder,
uint256 baseGasLimit
)
public
setHLAdapter(crossChainController, mailBox, originForwarder, baseGasLimit, ChainIds.ETHEREUM)
{
bytes memory message = abi.encode('some message');

// hoax(mailBox);
// vm.mockCall(
// crossChainController,
// abi.encodeWithSelector(ICrossChainReceiver.receiveCrossChainMessage.selector),
// abi.encode()
// );
// vm.expectCall(
// crossChainController,
// 0,
// abi.encodeWithSelector(
// ICrossChainReceiver.receiveCrossChainMessage.selector,
// message,
// ChainIds.ETHEREUM
// )
// );
// HyperLaneAdapter(address(hlAdapter)).handle(
// uint32(ChainIds.ETHEREUM),
// TypeCasts.addressToBytes32(originForwarder),
// message
// );
// }
hoax(mailBox);
vm.mockCall(
crossChainController,
abi.encodeWithSelector(ICrossChainReceiver.receiveCrossChainMessage.selector),
abi.encode()
);
vm.expectCall(
crossChainController,
0,
abi.encodeWithSelector(
ICrossChainReceiver.receiveCrossChainMessage.selector,
message,
ChainIds.ETHEREUM
)
);
HyperLaneAdapter(address(hlAdapter)).handle(
uint32(ChainIds.ETHEREUM),
TypeCasts.addressToBytes32(originForwarder),
message
);
}

function testHandleWhenCallerNotMailBox(
address crossChainController,
Expand Down
65 changes: 34 additions & 31 deletions tests/adapters/LayerZeroAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ contract LayerZeroAdapterTest is BaseAdapterTest {
uint256 baseGasLimit,
uint256 originChainId
) {
vm.assume(lzEndpoint > address(65536));
vm.assume(originForwarder > address(65536));
vm.assume(crossChainController > address(65536));
vm.assume(baseGasLimit < 1 ether);
_assumeSafeAddress(crossChainController);
_assumeSafeAddress(lzEndpoint);
Expand Down Expand Up @@ -212,39 +215,39 @@ contract LayerZeroAdapterTest is BaseAdapterTest {
// _testForwardMessage(lzEndpoint, receiver, dstGasLimit, caller);
// }

// function testForwardPayloadWithNoValue(
// address crossChainController,
// address lzEndpoint,
// address originForwarder,
// uint256 baseGasLimit,
// uint256 dstGasLimit,
// address receiver
// )
// public
// setLZAdapter(crossChainController, lzEndpoint, originForwarder, baseGasLimit, ChainIds.ETHEREUM)
// {
// vm.assume(dstGasLimit > 200000 && dstGasLimit < 1 ether);
// vm.assume(receiver != address(0));
function testForwardPayloadWithNoValue(
address crossChainController,
address lzEndpoint,
address originForwarder,
uint256 baseGasLimit,
uint256 dstGasLimit,
address receiver
)
public
setLZAdapter(crossChainController, lzEndpoint, originForwarder, baseGasLimit, ChainIds.ETHEREUM)
{
vm.assume(dstGasLimit > 200000 && dstGasLimit < 1 ether);
vm.assume(receiver != address(0));

// bytes memory payload = abi.encode('test message');
bytes memory payload = abi.encode('test message');

// vm.mockCall(
// lzEndpoint,
// abi.encodeWithSelector(ILayerZeroEndpointV2.quote.selector),
// abi.encode(MessagingFee({nativeFee: 10, lzTokenFee: 0}))
// );
// vm.expectRevert(bytes(Errors.NOT_ENOUGH_VALUE_TO_PAY_BRIDGE_FEES));
// (bool success, ) = address(layerZeroAdapter).delegatecall(
// abi.encodeWithSelector(
// IBaseAdapter.forwardMessage.selector,
// receiver,
// dstGasLimit,
// ChainIds.POLYGON,
// payload
// )
// );
// assertEq(success, false);
// }
vm.mockCall(
lzEndpoint,
abi.encodeWithSelector(ILayerZeroEndpointV2.quote.selector),
abi.encode(MessagingFee({nativeFee: 10, lzTokenFee: 0}))
);
vm.expectRevert(bytes(Errors.NOT_ENOUGH_VALUE_TO_PAY_BRIDGE_FEES));
(bool success, ) = address(layerZeroAdapter).delegatecall(
abi.encodeWithSelector(
IBaseAdapter.forwardMessage.selector,
receiver,
dstGasLimit,
ChainIds.POLYGON,
payload
)
);
assertEq(success, false);
}

function testForwardPayloadWhenNoChainSet(
address crossChainController,
Expand Down
Loading