Skip to content

Commit

Permalink
fix: added base test
Browse files Browse the repository at this point in the history
  • Loading branch information
sendra committed Mar 6, 2024
1 parent fc4d295 commit 4d2ae8f
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@
pragma solidity ^0.8.0;

import {AaveV3Arbitrum} from 'aave-address-book/AaveV3Arbitrum.sol';

import 'forge-std/Test.sol';
import {ProtocolV3TestBase} from 'aave-helpers/ProtocolV3TestBase.sol';
import {AaveV3Arbitrum_ADIAndBridgeAdaptersUpdate_20240305} from './AaveV3Arbitrum_ADIAndBridgeAdaptersUpdate_20240305.sol';
import {ICrossChainReceiver} from 'aave-address-book/common/ICrossChainController.sol';
import {ChainIds} from 'aave-helpers/ChainIds.sol';
import {ProxyAdmin} from 'solidity-utils/contracts/transparent-proxy/ProxyAdmin.sol';
import {MiscArbitrum} from 'aave-address-book/MiscArbitrum.sol';
import {GovernanceV3Arbitrum} from 'aave-address-book/GovernanceV3Arbitrum.sol';
import {TransparentUpgradeableProxy} from 'solidity-utils/contracts/transparent-proxy/TransparentUpgradeableProxy.sol';
import './BaseTest.sol';

/**
* @dev Test for AaveV3Arbitrum_ADIAndBridgeAdaptersUpdate_20240305
* command: make test-contract filter=AaveV3Arbitrum_ADIAndBridgeAdaptersUpdate_20240305
*/
contract AaveV3Arbitrum_ADIAndBridgeAdaptersUpdate_20240305_Test is ProtocolV3TestBase {
contract AaveV3Arbitrum_ADIAndBridgeAdaptersUpdate_20240305_Test is ProtocolV3TestBase, BaseTest {
AaveV3Arbitrum_ADIAndBridgeAdaptersUpdate_20240305 internal proposal;

function setUp() public {
Expand Down Expand Up @@ -50,11 +46,7 @@ contract AaveV3Arbitrum_ADIAndBridgeAdaptersUpdate_20240305_Test is ProtocolV3Te

assertEq(cccImplementation != proposal.NEW_CROSS_CHAIN_CONTROLLER_IMPLEMENTATION(), true);

defaultTest(
'AaveV3Arbitrum_ADIAndBridgeAdaptersUpdate_20240305',
AaveV3Arbitrum.POOL,
address(proposal)
);
executePayload(vm, address(proposal));

address[] memory receiverAdaptersAfter = ICrossChainReceiver(
GovernanceV3Arbitrum.CROSS_CHAIN_CONTROLLER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@
pragma solidity ^0.8.0;

import {AaveV3Avalanche} from 'aave-address-book/AaveV3Avalanche.sol';

import 'forge-std/Test.sol';
import {ProtocolV3TestBase} from 'aave-helpers/ProtocolV3TestBase.sol';
import {AaveV3Avalanche_ADIAndBridgeAdaptersUpdate_20240305} from './AaveV3Avalanche_ADIAndBridgeAdaptersUpdate_20240305.sol';
import {ChainIds} from 'aave-helpers/ChainIds.sol';
import {ProxyAdmin} from 'solidity-utils/contracts/transparent-proxy/ProxyAdmin.sol';
import {MiscAvalanche} from 'aave-address-book/MiscAvalanche.sol';
import {TransparentUpgradeableProxy} from 'solidity-utils/contracts/transparent-proxy/TransparentUpgradeableProxy.sol';
import {ICrossChainReceiver, ICrossChainForwarder} from 'aave-address-book/common/ICrossChainController.sol';
import {GovernanceV3Avalanche} from 'aave-address-book/GovernanceV3Avalanche.sol';
import './BaseTest.sol';

/**
* @dev Test for AaveV3Avalanche_ADIAndBridgeAdaptersUpdate_20240305
* command: make test-contract filter=AaveV3Avalanche_ADIAndBridgeAdaptersUpdate_20240305
*/
contract AaveV3Avalanche_ADIAndBridgeAdaptersUpdate_20240305_Test is ProtocolV3TestBase {
contract AaveV3Avalanche_ADIAndBridgeAdaptersUpdate_20240305_Test is ProtocolV3TestBase, BaseTest {
AaveV3Avalanche_ADIAndBridgeAdaptersUpdate_20240305 internal proposal;

function setUp() public {
Expand Down Expand Up @@ -91,11 +86,7 @@ contract AaveV3Avalanche_ADIAndBridgeAdaptersUpdate_20240305_Test is ProtocolV3T

assertEq(cccImplementation != proposal.NEW_CROSS_CHAIN_CONTROLLER_IMPLEMENTATION(), true);

defaultTest(
'AaveV3Avalanche_ADIAndBridgeAdaptersUpdate_20240305',
AaveV3Avalanche.POOL,
address(proposal)
);
executePayload(vm, address(proposal));

assertEq(
ICrossChainReceiver(GovernanceV3Avalanche.CROSS_CHAIN_CONTROLLER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@
pragma solidity ^0.8.0;

import {AaveV3BNB} from 'aave-address-book/AaveV3BNB.sol';

import 'forge-std/Test.sol';
import {ProtocolV3TestBase} from 'aave-helpers/ProtocolV3TestBase.sol';
import {AaveV3BNB_ADIAndBridgeAdaptersUpdate_20240305} from './AaveV3BNB_ADIAndBridgeAdaptersUpdate_20240305.sol';
import {ChainIds} from 'aave-helpers/ChainIds.sol';
import {ProxyAdmin} from 'solidity-utils/contracts/transparent-proxy/ProxyAdmin.sol';
import {MiscBNB} from 'aave-address-book/MiscBNB.sol';
import {TransparentUpgradeableProxy} from 'solidity-utils/contracts/transparent-proxy/TransparentUpgradeableProxy.sol';
import {ICrossChainReceiver, ICrossChainForwarder} from 'aave-address-book/common/ICrossChainController.sol';
import {GovernanceV3BNB} from 'aave-address-book/GovernanceV3BNB.sol';
import './BaseTest.sol';

/**
* @dev Test for AaveV3BNB_ADIAndBridgeAdaptersUpdate_20240305
* command: make test-contract filter=AaveV3BNB_ADIAndBridgeAdaptersUpdate_20240305
*/
contract AaveV3BNB_ADIAndBridgeAdaptersUpdate_20240305_Test is ProtocolV3TestBase {
contract AaveV3BNB_ADIAndBridgeAdaptersUpdate_20240305_Test is ProtocolV3TestBase, BaseTest {
AaveV3BNB_ADIAndBridgeAdaptersUpdate_20240305 internal proposal;

function setUp() public {
Expand Down Expand Up @@ -75,7 +70,7 @@ contract AaveV3BNB_ADIAndBridgeAdaptersUpdate_20240305_Test is ProtocolV3TestBas

assertEq(cccImplementation != proposal.NEW_CROSS_CHAIN_CONTROLLER_IMPLEMENTATION(), true);

defaultTest('AaveV3BNB_ADIAndBridgeAdaptersUpdate_20240305', AaveV3BNB.POOL, address(proposal));
executePayload(vm, address(proposal));

assertEq(
ICrossChainReceiver(GovernanceV3BNB.CROSS_CHAIN_CONTROLLER).isReceiverBridgeAdapterAllowed(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@
pragma solidity ^0.8.0;

import {AaveV3Base} from 'aave-address-book/AaveV3Base.sol';
import 'forge-std/Test.sol';
import {ProtocolV3TestBase} from 'aave-helpers/ProtocolV3TestBase.sol';
import {AaveV3Base_ADIAndBridgeAdaptersUpdate_20240305} from './AaveV3Base_ADIAndBridgeAdaptersUpdate_20240305.sol';
import {ChainIds} from 'aave-helpers/ChainIds.sol';
import {ProxyAdmin} from 'solidity-utils/contracts/transparent-proxy/ProxyAdmin.sol';
import {MiscBase} from 'aave-address-book/MiscBase.sol';
import {TransparentUpgradeableProxy} from 'solidity-utils/contracts/transparent-proxy/TransparentUpgradeableProxy.sol';
import {ICrossChainReceiver} from 'aave-address-book/common/ICrossChainController.sol';
import {GovernanceV3Base} from 'aave-address-book/GovernanceV3Base.sol';
import './BaseTest.sol';

/**
* @dev Test for AaveV3Base_ADIAndBridgeAdaptersUpdate_20240305
* command: make test-contract filter=AaveV3Base_ADIAndBridgeAdaptersUpdate_20240305
*/
contract AaveV3Base_ADIAndBridgeAdaptersUpdate_20240305_Test is ProtocolV3TestBase {
contract AaveV3Base_ADIAndBridgeAdaptersUpdate_20240305_Test is ProtocolV3TestBase, BaseTest {
AaveV3Base_ADIAndBridgeAdaptersUpdate_20240305 internal proposal;

function setUp() public {
Expand Down Expand Up @@ -50,11 +46,7 @@ contract AaveV3Base_ADIAndBridgeAdaptersUpdate_20240305_Test is ProtocolV3TestBa

assertEq(cccImplementation != proposal.NEW_CROSS_CHAIN_CONTROLLER_IMPLEMENTATION(), true);

defaultTest(
'AaveV3Base_ADIAndBridgeAdaptersUpdate_20240305',
AaveV3Base.POOL,
address(proposal)
);
executePayload(vm, address(proposal));

address[] memory receiverAdaptersAfter = ICrossChainReceiver(
GovernanceV3Base.CROSS_CHAIN_CONTROLLER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@
pragma solidity ^0.8.0;

import {AaveV3Ethereum} from 'aave-address-book/AaveV3Ethereum.sol';

import 'forge-std/Test.sol';
import {ProtocolV3TestBase, ReserveConfig} from 'aave-helpers/ProtocolV3TestBase.sol';
import {AaveV3Ethereum_ADIAndBridgeAdaptersUpdate_20240305} from './AaveV3Ethereum_ADIAndBridgeAdaptersUpdate_20240305.sol';
import {ChainIds} from 'aave-helpers/ChainIds.sol';
import {ProxyAdmin} from 'solidity-utils/contracts/transparent-proxy/ProxyAdmin.sol';
import {MiscEthereum} from 'aave-address-book/MiscEthereum.sol';
import {TransparentUpgradeableProxy} from 'solidity-utils/contracts/transparent-proxy/TransparentUpgradeableProxy.sol';
import {ICrossChainReceiver, ICrossChainForwarder} from 'aave-address-book/common/ICrossChainController.sol';
import {GovernanceV3Ethereum} from 'aave-address-book/GovernanceV3Ethereum.sol';
import './BaseTest.sol';

/**
* @dev Test for AaveV3Ethereum_ADIAndBridgeAdaptersUpdate_20240305
* command: make test-contract filter=AaveV3Ethereum_ADIAndBridgeAdaptersUpdate_20240305
*/
contract AaveV3Ethereum_ADIAndBridgeAdaptersUpdate_20240305_Test is ProtocolV3TestBase {
contract AaveV3Ethereum_ADIAndBridgeAdaptersUpdate_20240305_Test is ProtocolV3TestBase, BaseTest {
AaveV3Ethereum_ADIAndBridgeAdaptersUpdate_20240305 internal proposal;

function setUp() public {
ccc = GovernanceV3Ethereum.CROSS_CHAIN_CONTROLLER;
proxyAdmin = MiscEthereum.PROXY_ADMIN;

vm.createSelectFork(vm.rpcUrl('mainnet'), 19367957);
proposal = new AaveV3Ethereum_ADIAndBridgeAdaptersUpdate_20240305();
}
Expand All @@ -31,40 +29,13 @@ contract AaveV3Ethereum_ADIAndBridgeAdaptersUpdate_20240305_Test is ProtocolV3Te
function test_defaultProposalExecution() public {
_testCurrentReceiversAreAllowed();
_testCurrentForwarders();
_testImplementationAddress(proposal.NEW_CROSS_CHAIN_CONTROLLER_IMPLEMENTATION(), false);

// get proxy information
address cccImplementation = ProxyAdmin(MiscEthereum.PROXY_ADMIN).getProxyImplementation(
TransparentUpgradeableProxy(payable(GovernanceV3Ethereum.CROSS_CHAIN_CONTROLLER))
);
assertEq(cccImplementation != proposal.NEW_CROSS_CHAIN_CONTROLLER_IMPLEMENTATION(), true);

defaultTest(
'AaveV3Ethereum_ADIAndBridgeAdaptersUpdate_20240305',
AaveV3Ethereum.POOL,
address(proposal)
);
executePayload(vm, address(proposal));

_testAfterReceiversAreAllowed();
_testAfterForwarders();
}

function _checkAdapterCorrectness(uint256 chainId, address[] memory adapters) internal {
ICrossChainForwarder.ChainIdBridgeConfig[]
memory forwarderBridgeAdapters = ICrossChainForwarder(
GovernanceV3Ethereum.CROSS_CHAIN_CONTROLLER
).getForwarderBridgeAdaptersByChain(chainId);

assertEq(adapters.length, forwarderBridgeAdapters.length);

uint256 adaptersCount;
for (uint256 i = 0; i < forwarderBridgeAdapters.length; i++) {
for (uint256 j = 0; j < adapters.length; j++) {
if (forwarderBridgeAdapters[i].currentChainBridgeAdapter == adapters[j]) {
adaptersCount++;
}
}
}
assertEq(adaptersCount, forwarderBridgeAdapters.length);
_testImplementationAddress(proposal.NEW_CROSS_CHAIN_CONTROLLER_IMPLEMENTATION(), true);
}

function _testCurrentForwarders() internal {
Expand Down Expand Up @@ -220,14 +191,6 @@ contract AaveV3Ethereum_ADIAndBridgeAdaptersUpdate_20240305_Test is ProtocolV3Te
_testReceiverAdapterAllowed(proposal.POL_ADAPTER_TO_REMOVE(), ChainIds.POLYGON, true);
}

function _testReceiverAdapterAllowed(address adapter, uint256 chainId, bool allowed) internal {
assertEq(
ICrossChainReceiver(GovernanceV3Ethereum.CROSS_CHAIN_CONTROLLER)
.isReceiverBridgeAdapterAllowed(adapter, chainId),
allowed
);
}

function _testAfterReceiversAreAllowed() internal {
// check that old bridges are no longer allowed
_testReceiverAdapterAllowed(proposal.CCIP_ADAPTER_TO_REMOVE(), ChainIds.AVALANCHE, false);
Expand Down
43 changes: 43 additions & 0 deletions src/20240305_Multi_ADIAndBridgeAdaptersUpdate/BaseTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import 'forge-std/Test.sol';
import {ICrossChainReceiver, ICrossChainForwarder} from 'aave-address-book/common/ICrossChainController.sol';
import {TransparentUpgradeableProxy} from 'solidity-utils/contracts/transparent-proxy/TransparentUpgradeableProxy.sol';
import {ChainIds} from 'aave-helpers/ChainIds.sol';
import {ProxyAdmin} from 'solidity-utils/contracts/transparent-proxy/ProxyAdmin.sol';

contract BaseTest is Test {
address public ccc;
address public proxyAdmin;

function _checkAdapterCorrectness(uint256 chainId, address[] memory adapters) internal {
ICrossChainForwarder.ChainIdBridgeConfig[]
memory forwarderBridgeAdapters = ICrossChainForwarder(ccc).getForwarderBridgeAdaptersByChain(
chainId
);

assertEq(adapters.length, forwarderBridgeAdapters.length);

uint256 adaptersCount;
for (uint256 i = 0; i < forwarderBridgeAdapters.length; i++) {
for (uint256 j = 0; j < adapters.length; j++) {
if (forwarderBridgeAdapters[i].currentChainBridgeAdapter == adapters[j]) {
adaptersCount++;
}
}
}
assertEq(adaptersCount, forwarderBridgeAdapters.length);
}

function _testReceiverAdapterAllowed(address adapter, uint256 chainId, bool allowed) internal {
assertEq(ICrossChainReceiver(ccc).isReceiverBridgeAdapterAllowed(adapter, chainId), allowed);
}

function _testImplementationAddress(address implementation, bool equal) internal {
address cccImplementation = ProxyAdmin(proxyAdmin).getProxyImplementation(
TransparentUpgradeableProxy(payable(ccc))
);
assertEq(cccImplementation == implementation, equal);
}
}

0 comments on commit 4d2ae8f

Please sign in to comment.