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: correct addresss ranges #9

Merged
merged 1 commit into from
Apr 24, 2024
Merged
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
282 changes: 141 additions & 141 deletions tests/CrossChainForwarder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import {Transaction, EncodedTransaction, Envelope} from '../src/contracts/libs/E
import {BaseTest} from './BaseTest.sol';

contract CrossChainForwarderTest is BaseTest {
address public constant OWNER = address(123);
address public constant GUARDIAN = address(12);
address public constant OWNER = address(65536 + 123);
address public constant GUARDIAN = address(65536 + 12);
// mock addresses
address public constant DESTINATION_BRIDGE_ADAPTER = address(12345);
address public constant DESTINATION_BRIDGE_ADAPTER = address(65536 + 12345);
address public constant SENDER = address(123456);

uint256 public constant ORIGIN_LZ_CHAIN_ID = ChainIds.ETHEREUM;
Expand Down Expand Up @@ -180,76 +180,76 @@ contract CrossChainForwarderTest is BaseTest {
crossChainForwarder.enableBridgeAdapters(newBridgeAdaptersToEnable);
}

// function testAllowBridgeAdapters() public {
// ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[]
// memory newBridgeAdaptersToEnable = new ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[](
// 3
// );

// address NEW_BRIDGE_ADAPTER_1 = address(201);
// address NEW_BRIDGE_ADAPTER_2 = address(202);
// address NEW_DESTINATION_BRIDGE_ADAPTER_A = address(203);

// // this one overwrites
// newBridgeAdaptersToEnable[0] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
// currentChainBridgeAdapter: address(lzAdapter),
// destinationBridgeAdapter: DESTINATION_BRIDGE_ADAPTER,
// destinationChainId: ChainIds.POLYGON
// });
// // new one on same network
// newBridgeAdaptersToEnable[1] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
// currentChainBridgeAdapter: NEW_BRIDGE_ADAPTER_1,
// destinationBridgeAdapter: DESTINATION_BRIDGE_ADAPTER,
// destinationChainId: ChainIds.POLYGON
// });
// // new one on different network but same bridge adapter
// newBridgeAdaptersToEnable[2] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
// currentChainBridgeAdapter: NEW_BRIDGE_ADAPTER_2,
// destinationBridgeAdapter: NEW_DESTINATION_BRIDGE_ADAPTER_A,
// destinationChainId: ChainIds.AVALANCHE
// });

// hoax(OWNER);
// vm.expectEmit(true, true, true, true);
// emit BridgeAdapterUpdated(
// ChainIds.POLYGON,
// NEW_BRIDGE_ADAPTER_1,
// DESTINATION_BRIDGE_ADAPTER,
// true
// );
// emit BridgeAdapterUpdated(
// ChainIds.AVALANCHE,
// NEW_BRIDGE_ADAPTER_2,
// NEW_DESTINATION_BRIDGE_ADAPTER_A,
// true
// );
// vm.mockCall(
// NEW_BRIDGE_ADAPTER_1,
// abi.encodeWithSelector(IBaseAdapter.setupPayments.selector),
// abi.encode()
// );
// vm.mockCall(
// NEW_BRIDGE_ADAPTER_2,
// abi.encodeWithSelector(IBaseAdapter.setupPayments.selector),
// abi.encode()
// );
// crossChainForwarder.enableBridgeAdapters(newBridgeAdaptersToEnable);

// ICrossChainForwarder.ChainIdBridgeConfig[] memory configsPolygon = crossChainForwarder
// .getForwarderBridgeAdaptersByChain(ChainIds.POLYGON);
// assertEq(configsPolygon.length, 2);
// assertEq(configsPolygon[0].destinationBridgeAdapter, DESTINATION_BRIDGE_ADAPTER);
// assertEq(configsPolygon[0].currentChainBridgeAdapter, address(lzAdapter));

// assertEq(configsPolygon[1].destinationBridgeAdapter, DESTINATION_BRIDGE_ADAPTER);
// assertEq(configsPolygon[1].currentChainBridgeAdapter, NEW_BRIDGE_ADAPTER_1);

// ICrossChainForwarder.ChainIdBridgeConfig[] memory configsAvalanche = crossChainForwarder
// .getForwarderBridgeAdaptersByChain(ChainIds.AVALANCHE);
// assertEq(configsAvalanche.length, 1);
// assertEq(configsAvalanche[0].destinationBridgeAdapter, NEW_DESTINATION_BRIDGE_ADAPTER_A);
// assertEq(configsAvalanche[0].currentChainBridgeAdapter, NEW_BRIDGE_ADAPTER_2);
// }
function testAllowBridgeAdapters() public {
ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[]
memory newBridgeAdaptersToEnable = new ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[](
3
);

address NEW_BRIDGE_ADAPTER_1 = address(65536 + 201);
address NEW_BRIDGE_ADAPTER_2 = address(65536 + 202);
address NEW_DESTINATION_BRIDGE_ADAPTER_A = address(65536 + 203);

// this one overwrites
newBridgeAdaptersToEnable[0] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
currentChainBridgeAdapter: address(lzAdapter),
destinationBridgeAdapter: DESTINATION_BRIDGE_ADAPTER,
destinationChainId: ChainIds.POLYGON
});
// new one on same network
newBridgeAdaptersToEnable[1] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
currentChainBridgeAdapter: NEW_BRIDGE_ADAPTER_1,
destinationBridgeAdapter: DESTINATION_BRIDGE_ADAPTER,
destinationChainId: ChainIds.POLYGON
});
// new one on different network but same bridge adapter
newBridgeAdaptersToEnable[2] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
currentChainBridgeAdapter: NEW_BRIDGE_ADAPTER_2,
destinationBridgeAdapter: NEW_DESTINATION_BRIDGE_ADAPTER_A,
destinationChainId: ChainIds.AVALANCHE
});

hoax(OWNER);
vm.expectEmit(true, true, true, true);
emit BridgeAdapterUpdated(
ChainIds.POLYGON,
NEW_BRIDGE_ADAPTER_1,
DESTINATION_BRIDGE_ADAPTER,
true
);
emit BridgeAdapterUpdated(
ChainIds.AVALANCHE,
NEW_BRIDGE_ADAPTER_2,
NEW_DESTINATION_BRIDGE_ADAPTER_A,
true
);
vm.mockCall(
NEW_BRIDGE_ADAPTER_1,
abi.encodeWithSelector(IBaseAdapter.setupPayments.selector),
abi.encode()
);
vm.mockCall(
NEW_BRIDGE_ADAPTER_2,
abi.encodeWithSelector(IBaseAdapter.setupPayments.selector),
abi.encode()
);
crossChainForwarder.enableBridgeAdapters(newBridgeAdaptersToEnable);

ICrossChainForwarder.ChainIdBridgeConfig[] memory configsPolygon = crossChainForwarder
.getForwarderBridgeAdaptersByChain(ChainIds.POLYGON);
assertEq(configsPolygon.length, 2);
assertEq(configsPolygon[0].destinationBridgeAdapter, DESTINATION_BRIDGE_ADAPTER);
assertEq(configsPolygon[0].currentChainBridgeAdapter, address(lzAdapter));

assertEq(configsPolygon[1].destinationBridgeAdapter, DESTINATION_BRIDGE_ADAPTER);
assertEq(configsPolygon[1].currentChainBridgeAdapter, NEW_BRIDGE_ADAPTER_1);

ICrossChainForwarder.ChainIdBridgeConfig[] memory configsAvalanche = crossChainForwarder
.getForwarderBridgeAdaptersByChain(ChainIds.AVALANCHE);
assertEq(configsAvalanche.length, 1);
assertEq(configsAvalanche[0].destinationBridgeAdapter, NEW_DESTINATION_BRIDGE_ADAPTER_A);
assertEq(configsAvalanche[0].currentChainBridgeAdapter, NEW_BRIDGE_ADAPTER_2);
}

function testAllowBridgeAdaptersWhenNoCurrentBridgeAdapter() public {
ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[]
Expand Down Expand Up @@ -321,74 +321,74 @@ contract CrossChainForwarderTest is BaseTest {
assertEq(configsPolygon[0].currentChainBridgeAdapter, address(lzAdapter));
}

// function testDisallowBridgeAdapters() public {
// ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[]
// memory newBridgeAdaptersToEnable = new ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[](
// 2
// );

// address NEW_BRIDGE_ADAPTER_1 = address(201);
// address NEW_DESTINATION_BRIDGE_ADAPTER_A = address(203);

// // new one on same network
// newBridgeAdaptersToEnable[0] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
// currentChainBridgeAdapter: NEW_BRIDGE_ADAPTER_1,
// destinationBridgeAdapter: DESTINATION_BRIDGE_ADAPTER,
// destinationChainId: ChainIds.POLYGON
// });
// // new one on different network but same bridge adapter
// newBridgeAdaptersToEnable[1] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
// currentChainBridgeAdapter: address(lzAdapter),
// destinationBridgeAdapter: NEW_DESTINATION_BRIDGE_ADAPTER_A,
// destinationChainId: ChainIds.AVALANCHE
// });

// vm.mockCall(
// NEW_BRIDGE_ADAPTER_1,
// abi.encodeWithSelector(IBaseAdapter.setupPayments.selector),
// abi.encode()
// );
// hoax(OWNER);
// crossChainForwarder.enableBridgeAdapters(newBridgeAdaptersToEnable);

// ICrossChainForwarder.BridgeAdapterToDisable[]
// memory bridgeAdaptersToDisable = new ICrossChainForwarder.BridgeAdapterToDisable[](1);

// uint256[] memory chainIdsAdapter = new uint256[](2);
// chainIdsAdapter[0] = ChainIds.POLYGON;
// chainIdsAdapter[1] = ChainIds.AVALANCHE;

// bridgeAdaptersToDisable[0] = ICrossChainForwarder.BridgeAdapterToDisable({
// bridgeAdapter: address(lzAdapter),
// chainIds: chainIdsAdapter
// });

// hoax(OWNER);
// vm.expectEmit(true, true, false, true);
// emit BridgeAdapterUpdated(
// ChainIds.POLYGON,
// address(lzAdapter),
// DESTINATION_BRIDGE_ADAPTER,
// false
// );
// emit BridgeAdapterUpdated(
// ChainIds.AVALANCHE,
// address(lzAdapter),
// NEW_DESTINATION_BRIDGE_ADAPTER_A,
// false
// );
// crossChainForwarder.disableBridgeAdapters(bridgeAdaptersToDisable);

// ICrossChainForwarder.ChainIdBridgeConfig[] memory configsPolygon = crossChainForwarder
// .getForwarderBridgeAdaptersByChain(ChainIds.POLYGON);
// assertEq(configsPolygon.length, 1);
// assertEq(configsPolygon[0].destinationBridgeAdapter, DESTINATION_BRIDGE_ADAPTER);
// assertEq(configsPolygon[0].currentChainBridgeAdapter, NEW_BRIDGE_ADAPTER_1);

// ICrossChainForwarder.ChainIdBridgeConfig[] memory configsAvalanche = crossChainForwarder
// .getForwarderBridgeAdaptersByChain(ChainIds.AVALANCHE);
// assertEq(configsAvalanche.length, 0);
// }
function testDisallowBridgeAdapters() public {
ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[]
memory newBridgeAdaptersToEnable = new ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[](
2
);

address NEW_BRIDGE_ADAPTER_1 = address(65536 + 201);
address NEW_DESTINATION_BRIDGE_ADAPTER_A = address(65536 + 203);

// new one on same network
newBridgeAdaptersToEnable[0] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
currentChainBridgeAdapter: NEW_BRIDGE_ADAPTER_1,
destinationBridgeAdapter: DESTINATION_BRIDGE_ADAPTER,
destinationChainId: ChainIds.POLYGON
});
// new one on different network but same bridge adapter
newBridgeAdaptersToEnable[1] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
currentChainBridgeAdapter: address(lzAdapter),
destinationBridgeAdapter: NEW_DESTINATION_BRIDGE_ADAPTER_A,
destinationChainId: ChainIds.AVALANCHE
});

vm.mockCall(
NEW_BRIDGE_ADAPTER_1,
abi.encodeWithSelector(IBaseAdapter.setupPayments.selector),
abi.encode()
);
hoax(OWNER);
crossChainForwarder.enableBridgeAdapters(newBridgeAdaptersToEnable);

ICrossChainForwarder.BridgeAdapterToDisable[]
memory bridgeAdaptersToDisable = new ICrossChainForwarder.BridgeAdapterToDisable[](1);

uint256[] memory chainIdsAdapter = new uint256[](2);
chainIdsAdapter[0] = ChainIds.POLYGON;
chainIdsAdapter[1] = ChainIds.AVALANCHE;

bridgeAdaptersToDisable[0] = ICrossChainForwarder.BridgeAdapterToDisable({
bridgeAdapter: address(lzAdapter),
chainIds: chainIdsAdapter
});

hoax(OWNER);
vm.expectEmit(true, true, false, true);
emit BridgeAdapterUpdated(
ChainIds.POLYGON,
address(lzAdapter),
DESTINATION_BRIDGE_ADAPTER,
false
);
emit BridgeAdapterUpdated(
ChainIds.AVALANCHE,
address(lzAdapter),
NEW_DESTINATION_BRIDGE_ADAPTER_A,
false
);
crossChainForwarder.disableBridgeAdapters(bridgeAdaptersToDisable);

ICrossChainForwarder.ChainIdBridgeConfig[] memory configsPolygon = crossChainForwarder
.getForwarderBridgeAdaptersByChain(ChainIds.POLYGON);
assertEq(configsPolygon.length, 1);
assertEq(configsPolygon[0].destinationBridgeAdapter, DESTINATION_BRIDGE_ADAPTER);
assertEq(configsPolygon[0].currentChainBridgeAdapter, NEW_BRIDGE_ADAPTER_1);

ICrossChainForwarder.ChainIdBridgeConfig[] memory configsAvalanche = crossChainForwarder
.getForwarderBridgeAdaptersByChain(ChainIds.AVALANCHE);
assertEq(configsAvalanche.length, 0);
}

function testDisallowBridgeAdaptersWhenNotOwner() public {
ICrossChainForwarder.BridgeAdapterToDisable[]
Expand Down