Skip to content

Commit

Permalink
fix: add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sendra committed Dec 21, 2023
1 parent 4c73aaf commit c78f581
Show file tree
Hide file tree
Showing 5 changed files with 333 additions and 22 deletions.
2 changes: 1 addition & 1 deletion scripts/access_control/Deploy_Granular_CCC_Guardian.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract contract BaseDeployGranularGuardian is BaseScript {
function CROSS_CHAIN_CONTROLLER() public view virtual returns (address);

function _execute(DeployerHelpers.Addresses memory addresses) internal override {
address granularCCCGuardian = (
address granularCCCGuardian = address(
new GranularGuardianAccessControl(
AAVE_GUARDIAN(),
RETRY_GUARDIAN(),
Expand Down
29 changes: 29 additions & 0 deletions tests/BaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
pragma solidity ^0.8.0;

import 'forge-std/Test.sol';
import {ChainIds} from '../src/contracts/libs/ChainIds.sol';
import {Transaction, EncodedTransaction, Envelope, EncodedEnvelope} from '../src/contracts/libs/EncodingUtils.sol';
import {ICrossChainForwarder} from '../src/contracts/interfaces/ICrossChainForwarder.sol';
import {ICrossChainReceiver} from '../src/contracts/interfaces/ICrossChainReceiver.sol';
import {CrossChainController, ICrossChainController} from '../src/contracts/CrossChainController.sol';
import {CrossChainControllerWithEmergencyMode, ICrossChainControllerWithEmergencyMode} from '../src/contracts/CrossChainControllerWithEmergencyMode.sol';

contract BaseTest is Test {
bytes internal constant MESSAGE = bytes('this is the message to send');
Expand Down Expand Up @@ -42,6 +47,30 @@ contract BaseTest is Test {
uint256 envelopeNonce;
}

modifier generateEmergencyState() {
_;
}

modifier generateRetryTxState(
address cccOwner,
address ccc,
uint256 destinationChainId,
address destination,
uint256 gasLimit
) {
// set caller as an approved sender
address[] memory senders = new address[](1);
senders[0] = address(this);

vm.startPrank(cccOwner);
ICrossChainForwarder(ccc).approveSenders(senders);
vm.stopPrank();

// call forward message
ICrossChainForwarder(ccc).forwardMessage(destinationChainId, destination, gasLimit, MESSAGE);
_;
}

function _generateExtendedTransaction(
TestParams memory testParams
) internal pure returns (ExtendedTransaction memory) {
Expand Down
56 changes: 35 additions & 21 deletions tests/access_control/GranularGuardianAccessControl.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,32 @@
pragma solidity ^0.8.0;

import 'forge-std/Test.sol';
import {TestUtils} from '../utils/TestUtils.sol';
import '../../src/contracts/access_control/GranularGuardianAccessControl.sol';
import {GovernanceV3Ethereum} from 'aave-address-book/GovernanceV3Ethereum.sol';
import {OwnableWithGuardian, IWithGuardian} from 'solidity-utils/contracts/access-control/OwnableWithGuardian.sol';

contract GranularGuardianAccessControlTest is Test {
address public constant RETRY_USER = address(123);
address public constant SOLVE_EMERGENCY_USER = address(1234);
address public constant CROSS_CHAIN_CONTROLLER = address(12345);

address public constant BGD_GUARDIAN = 0xb812d0944f8F581DfAA3a93Dda0d22EcEf51A9CF;
address public constant AAVE_GUARDIAN = 0xCA76Ebd8617a03126B6FB84F9b1c1A0fB71C2633;
address public constant BGD_GUARDIAN = address(1956);
address public constant AAVE_GUARDIAN = address(1238975);
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

GranularGuardianAccessControl public control;

function setUp() public {
vm.createSelectFork('ethereum', 18826980);

control = new GranularGuardianAccessControl(
AAVE_GUARDIAN,
RETRY_USER,
SOLVE_EMERGENCY_USER,
GovernanceV3Ethereum.CROSS_CHAIN_CONTROLLER
);

hoax(BGD_GUARDIAN);
OwnableWithGuardian(GovernanceV3Ethereum.CROSS_CHAIN_CONTROLLER).updateGuardian(
address(control)
CROSS_CHAIN_CONTROLLER
);
}

function test_initialization() public {
assertEq(control.CROSS_CHAIN_CONTROLLER(), GovernanceV3Ethereum.CROSS_CHAIN_CONTROLLER);
assertEq(control.CROSS_CHAIN_CONTROLLER(), CROSS_CHAIN_CONTROLLER);
assertEq(control.hasRole(DEFAULT_ADMIN_ROLE, AAVE_GUARDIAN), true);
assertEq(control.getRoleAdmin(control.RETRY_ROLE()), DEFAULT_ADMIN_ROLE);
assertEq(control.getRoleAdmin(control.SOLVE_EMERGENCY_ROLE()), DEFAULT_ADMIN_ROLE);
Expand All @@ -52,7 +46,11 @@ contract GranularGuardianAccessControlTest is Test {
function test_retryTxWhenWrongCaller() public {
vm.expectRevert(
bytes(
'AccessControl: account 0x7fa9385be102ac3eac297483dd6233d62b3e1496 is missing role 0xc448b9502bbdf9850cc39823b6ea40cfe96d3ac63008e89edd2b8e98c6cc0af3'
string.concat(
'AccessControl: account 0x',
TestUtils.toAsciiString(address(this)),
' is missing role 0xc448b9502bbdf9850cc39823b6ea40cfe96d3ac63008e89edd2b8e98c6cc0af3'
)
)
);
_retryTx();
Expand All @@ -69,7 +67,11 @@ contract GranularGuardianAccessControlTest is Test {
function test_retryEnvelopeWhenWrongCaller(bytes32 mockEnvId) public {
vm.expectRevert(
bytes(
'AccessControl: account 0x7fa9385be102ac3eac297483dd6233d62b3e1496 is missing role 0xc448b9502bbdf9850cc39823b6ea40cfe96d3ac63008e89edd2b8e98c6cc0af3'
string.concat(
'AccessControl: account 0x',
TestUtils.toAsciiString(address(this)),
' is missing role 0xc448b9502bbdf9850cc39823b6ea40cfe96d3ac63008e89edd2b8e98c6cc0af3'
)
)
);
_retryEnvelope(mockEnvId);
Expand All @@ -84,23 +86,35 @@ contract GranularGuardianAccessControlTest is Test {
function test_solveEmergencyWhenWrongCaller() public {
vm.expectRevert(
bytes(
'AccessControl: account 0x7fa9385be102ac3eac297483dd6233d62b3e1496 is missing role 0xf4cdc679c22cbf47d6de8e836ce79ffdae51f38408dcde3f0645de7634fa607d'
string.concat(
'AccessControl: account 0x',
TestUtils.toAsciiString(address(this)),
' is missing role 0xf4cdc679c22cbf47d6de8e836ce79ffdae51f38408dcde3f0645de7634fa607d'
)
)
);
_solveEmergency();
}

function test_updateGuardian(address newGuardian) public {
vm.startPrank(AAVE_GUARDIAN);
vm.mockCall(
CROSS_CHAIN_CONTROLLER,
abi.encodeWithSelector(IWithGuardian.updateGuardian.selector, newGuardian),
abi.encode()
);
control.updateGuardian(newGuardian);
assertEq(IWithGuardian(GovernanceV3Ethereum.CROSS_CHAIN_CONTROLLER).guardian(), newGuardian);
vm.stopPrank();
}

function test_solveEmergencyWhenWrongCaller(address newGuardian) public {
function test_updateGuardianWhenWrongCaller(address newGuardian) public {
vm.expectRevert(
bytes(
'AccessControl: account 0x7fa9385be102ac3eac297483dd6233d62b3e1496 is missing role 0x0000000000000000000000000000000000000000000000000000000000000000'
string.concat(
'AccessControl: account 0x',
TestUtils.toAsciiString(address(this)),
' is missing role 0x0000000000000000000000000000000000000000000000000000000000000000'
)
)
);
control.updateGuardian(newGuardian);
Expand Down Expand Up @@ -131,7 +145,7 @@ contract GranularGuardianAccessControlTest is Test {
);

vm.mockCall(
GovernanceV3Ethereum.CROSS_CHAIN_CONTROLLER,
CROSS_CHAIN_CONTROLLER,
abi.encodeWithSelector(
ICrossChainControllerWithEmergencyMode.solveEmergency.selector,
newConfirmations,
Expand Down Expand Up @@ -170,7 +184,7 @@ contract GranularGuardianAccessControlTest is Test {
uint256 gasLimit = 300_000;

vm.mockCall(
GovernanceV3Ethereum.CROSS_CHAIN_CONTROLLER,
CROSS_CHAIN_CONTROLLER,
abi.encodeWithSelector(ICrossChainForwarder.retryEnvelope.selector, envelope, gasLimit),
abi.encode(mockEnvId)
);
Expand All @@ -183,7 +197,7 @@ contract GranularGuardianAccessControlTest is Test {
address[] memory bridgeAdaptersToRetry = new address[](0);

vm.mockCall(
GovernanceV3Ethereum.CROSS_CHAIN_CONTROLLER,
CROSS_CHAIN_CONTROLLER,
abi.encodeWithSelector(
ICrossChainForwarder.retryTransaction.selector,
encodedTransaction,
Expand Down
Loading

0 comments on commit c78f581

Please sign in to comment.