Skip to content

Commit

Permalink
fix: added test to check only changes on specified forwarders
Browse files Browse the repository at this point in the history
  • Loading branch information
sendra committed Mar 13, 2024
1 parent 5c5d694 commit 529e3c5
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,4 @@ contract AaveV3Avalanche_UpdateADIImplementationAndCCIPAdapters_20240313_Test is
42801819
)
{}

// function _getForwarderAdaptersByChain(
// bool afterExecution
// ) internal view override returns (ForwarderAdapters[] memory) {
// ForwarderAdapters[] memory forwarderAdapters = new ForwarderAdapters[](1);
//
// ICrossChainForwarder.ChainIdBridgeConfig[]
// memory adapters = new ICrossChainForwarder.ChainIdBridgeConfig[](1);
// adapters[0].currentChainBridgeAdapter = payload.CCIP_ADAPTER_TO_REMOVE();
//
// if (afterExecution) {
// adapters[0].currentChainBridgeAdapter = payload.CCIP_NEW_ADAPTER();
// adapters[0].destinationBridgeAdapter = payload.DESTINATION_CCIP_NEW_ADAPTER();
// }
// forwarderAdapters[0].adapters = adapters;
// forwarderAdapters[0].chainId = ChainIds.MAINNET;
//
// return forwarderAdapters;
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,4 @@ contract AaveV3Ethereum_UpdateADIImplementationAndCCIPAdapters_20240313_Test is
19418547
)
{}

// function _getForwarderAdaptersByChain(
// bool afterExecution
// ) internal view override returns (ForwarderAdapters[] memory) {
// ForwarderAdapters[] memory forwarderAdapters = new ForwarderAdapters[](3);
//
// ICrossChainForwarder.ChainIdBridgeConfig[]
// memory polygonAdapters = new ICrossChainForwarder.ChainIdBridgeConfig[](1);
// ICrossChainForwarder.ChainIdBridgeConfig[]
// memory avalancheAdapters = new ICrossChainForwarder.ChainIdBridgeConfig[](1);
// ICrossChainForwarder.ChainIdBridgeConfig[]
// memory binanceAdapters = new ICrossChainForwarder.ChainIdBridgeConfig[](1);
//
// // polygon
// polygonAdapters[0].currentChainBridgeAdapter = payload.CCIP_ADAPTER_TO_REMOVE();
// // avalanche
// avalancheAdapters[0].currentChainBridgeAdapter = payload.CCIP_ADAPTER_TO_REMOVE();
// // binance
// binanceAdapters[0].currentChainBridgeAdapter = payload.CCIP_ADAPTER_TO_REMOVE();
//
// if (afterExecution) {
// // polygon
// polygonAdapters[0].currentChainBridgeAdapter = payload.CCIP_NEW_ADAPTER();
// polygonAdapters[0].destinationBridgeAdapter = payload.DESTINATION_CCIP_NEW_ADAPTER_POLYGON();
// // avalanche
// avalancheAdapters[0].currentChainBridgeAdapter = payload.CCIP_NEW_ADAPTER();
// avalancheAdapters[0].destinationBridgeAdapter = payload
// .DESTINATION_CCIP_NEW_ADAPTER_AVALANCHE();
// // binance
// binanceAdapters[0].currentChainBridgeAdapter = payload.CCIP_NEW_ADAPTER();
// binanceAdapters[0].destinationBridgeAdapter = payload.DESTINATION_CCIP_NEW_ADAPTER_BNB();
// }
// forwarderAdapters[0].adapters = polygonAdapters;
// forwarderAdapters[0].chainId = ChainIds.POLYGON;
// forwarderAdapters[1].adapters = avalancheAdapters;
// forwarderAdapters[1].chainId = ChainIds.AVALANCHE;
// forwarderAdapters[2].adapters = binanceAdapters;
// forwarderAdapters[2].chainId = ChainIds.BNB;
//
// return forwarderAdapters;
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,4 @@ contract AaveV3Polygon_UpdateADIImplementationAndCCIPAdapters_20240313_Test is B
54566890
)
{}

// function _getForwarderAdaptersByChain(
// bool afterExecution
// ) internal view override returns (ForwarderAdapters[] memory) {
// ForwarderAdapters[] memory forwarderAdapters = new ForwarderAdapters[](1);
//
// ICrossChainForwarder.ChainIdBridgeConfig[]
// memory adapters = new ICrossChainForwarder.ChainIdBridgeConfig[](1);
// adapters[0].currentChainBridgeAdapter = payload.CCIP_ADAPTER_TO_REMOVE();
//
// if (afterExecution) {
// adapters[0].currentChainBridgeAdapter = payload.CCIP_NEW_ADAPTER();
// adapters[0].destinationBridgeAdapter = payload.DESTINATION_CCIP_NEW_ADAPTER();
// }
// forwarderAdapters[0].adapters = adapters;
// forwarderAdapters[0].chainId = ChainIds.MAINNET;
//
// return forwarderAdapters;
// }
}
133 changes: 75 additions & 58 deletions src/20240313_Multi_UpdateADIImplementationAndCCIPAdapters/BaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -250,75 +250,92 @@ abstract contract BaseTest is BaseCCCImplementationUpdatePayloadTest {
}
}

/**
* @dev executes the generic test suite including e2e and config snapshots
*/
function test_defaultProposalExecution() public {
// _checkAllForwarderAdaptersAreRepresented(false);

//
// AdaptersByChain[] memory receiversBeforeExecution = _getCurrentReceiverAdaptersByChain();
//
function test_onlyChangedNeededForwarders() public {
ForwarderAdapters[]
memory forwardersBridgeAdaptersByChainBefore = _getCurrentForwarderAdaptersByChain();

ICrossChainForwarder.BridgeAdapterToDisable[]
memory adaptersToRemove = BaseAdaptersUpdatePayload(payloadAddress)
.getForwarderBridgeAdaptersToRemove();

executePayload(vm, payloadAddress);
//
// AdaptersByChain[] memory afterBeforeExecution = _getCurrentReceiverAdaptersByChain();
// // _checkAllForwarderAdaptersAreRepresented(true);
}

// -------------- virtual methods --------------------------
ForwarderAdapters[]
memory forwardersBridgeAdaptersByChainAfter = _getCurrentForwarderAdaptersByChain();

function _getForwarderAdaptersByChain(
bool afterExecution
) internal view virtual returns (ForwarderAdapters[] memory) {
ForwarderAdapters[] memory forwarderAdapters = new ForwarderAdapters[](0);
return forwarderAdapters;
}
assertEq(
forwardersBridgeAdaptersByChainAfter.length,
forwardersBridgeAdaptersByChainBefore.length
);

// ------------------------ checks -------------
// function _checkAllForwarderAdaptersAreRepresented(bool afterExecution) internal {
// ForwarderAdapters[] memory forwarderAdapters = _getForwarderAdaptersByChain(afterExecution);
//
// for (uint256 i = 0; i < forwarderAdapters.length; i++) {
// _testForwarderAdapterCorrectness(
// forwarderAdapters[i].chainId,
// forwarderAdapters[i].adapters,
// afterExecution
// );
// }
// }

//-----------------------------------------------------------------

function _testForwarderAdapterCorrectness(
uint256 chainId,
ICrossChainForwarder.ChainIdBridgeConfig[] memory adapters,
bool checkDestination
) internal {
ICrossChainForwarder.ChainIdBridgeConfig[]
memory forwarderBridgeAdapters = ICrossChainForwarder(CROSS_CHAIN_CONTROLLER)
.getForwarderBridgeAdaptersByChain(chainId);

uint256 adaptersCount;
for (uint256 i = 0; i < forwarderBridgeAdapters.length; i++) {
for (uint256 j = 0; j < adapters.length; j++) {
for (uint256 l = 0; l < forwardersBridgeAdaptersByChainBefore.length; l++) {
for (uint256 j = 0; j < forwardersBridgeAdaptersByChainAfter.length; j++) {
if (
forwarderBridgeAdapters[i].currentChainBridgeAdapter ==
adapters[j].currentChainBridgeAdapter
forwardersBridgeAdaptersByChainBefore[l].chainId ==
forwardersBridgeAdaptersByChainAfter[j].chainId
) {
if (checkDestination) {
if (
forwarderBridgeAdapters[i].destinationBridgeAdapter ==
adapters[j].destinationBridgeAdapter
) {
adaptersCount++;
for (uint256 i = 0; i < forwardersBridgeAdaptersByChainBefore[l].adapters.length; i++) {
bool forwarderFound;
for (uint256 m = 0; m < forwardersBridgeAdaptersByChainAfter[j].adapters.length; m++) {
if (
forwardersBridgeAdaptersByChainBefore[l].adapters[i].destinationBridgeAdapter ==
forwardersBridgeAdaptersByChainAfter[j].adapters[m].destinationBridgeAdapter &&
forwardersBridgeAdaptersByChainBefore[l].adapters[i].currentChainBridgeAdapter ==
forwardersBridgeAdaptersByChainAfter[j].adapters[m].currentChainBridgeAdapter
) {
forwarderFound = true;
break;
}
}
if (!forwarderFound) {
bool isAdapterToBeRemoved;
for (uint256 k = 0; k < adaptersToRemove.length; k++) {
if (
forwardersBridgeAdaptersByChainBefore[l].adapters[i].currentChainBridgeAdapter ==
adaptersToRemove[k].bridgeAdapter
) {
for (uint256 n = 0; n < adaptersToRemove[k].chainIds.length; n++) {
if (
forwardersBridgeAdaptersByChainBefore[l].chainId ==
adaptersToRemove[k].chainIds[n]
) {
isAdapterToBeRemoved = true;
break;
}
}
}
}
assertEq(isAdapterToBeRemoved, true);
}
} else {
adaptersCount++;
}
}
}
}
assertEq(adaptersCount, adapters.length);
}

function _getCurrentForwarderAdaptersByChain() internal returns (ForwarderAdapters[] memory) {
uint256[] memory supportedChains = new uint256[](10);
supportedChains[0] = ChainIds.POLYGON;
supportedChains[1] = ChainIds.AVALANCHE;
supportedChains[2] = ChainIds.BNB;
supportedChains[3] = ChainIds.GNOSIS;
supportedChains[4] = ChainIds.ARBITRUM;
supportedChains[5] = ChainIds.OPTIMISM;
supportedChains[6] = ChainIds.METIS;
supportedChains[7] = ChainIds.BASE;
supportedChains[8] = ChainIds.SCROLL;
supportedChains[9] = ChainIds.MAINNET;

ForwarderAdapters[] memory forwarderAdapters = new ForwarderAdapters[](supportedChains.length);

for (uint256 i = 0; i < supportedChains.length; i++) {
ICrossChainForwarder.ChainIdBridgeConfig[] memory forwarders = ICrossChainForwarder(
CROSS_CHAIN_CONTROLLER
).getForwarderBridgeAdaptersByChain(supportedChains[i]);

forwarderAdapters[i] = ForwarderAdapters({adapters: forwarders, chainId: supportedChains[i]});
}
return forwarderAdapters;
}

function _getCurrentReceiverAdaptersByChain() internal returns (AdaptersByChain[] memory) {
Expand Down

0 comments on commit 529e3c5

Please sign in to comment.