Skip to content

Commit

Permalink
fix: minor fixes in credit account v3
Browse files Browse the repository at this point in the history
  • Loading branch information
lekhovitsky committed May 18, 2023
1 parent 4db84cd commit 1e2a5ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
8 changes: 5 additions & 3 deletions contracts/credit/CreditAccountV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ contract CreditAccountV3 is ICreditAccountV3 {
using Address for address;

/// @inheritdoc IVersion
uint256 public constant version = 3_00;
uint256 public constant override version = 3_00;

/// @inheritdoc ICreditAccountV3
address public immutable factory;
address public immutable override factory;

/// @inheritdoc ICreditAccountV3
address public immutable creditManager;
address public immutable override creditManager;

/// @dev Ensures that function caller is account factory
modifier factoryOnly() {
Expand Down Expand Up @@ -53,6 +53,7 @@ contract CreditAccountV3 is ICreditAccountV3 {
/// @inheritdoc ICreditAccountV3
function safeTransfer(address token, address to, uint256 amount)
external
override
creditManagerOnly // U:[CA-2]
{
IERC20(token).safeTransfer(to, amount); // U:[CA-3]
Expand All @@ -61,6 +62,7 @@ contract CreditAccountV3 is ICreditAccountV3 {
/// @inheritdoc ICreditAccountV3
function execute(address target, bytes memory data)
external
override
creditManagerOnly // U:[CA-2]
returns (bytes memory result)
{
Expand Down
33 changes: 9 additions & 24 deletions contracts/test/unit/credit/CreditAccountV3.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,36 +38,21 @@ contract CreditAccountV3UnitTest is TestHelper {
}

/// @notice U:[CA-2]: External functions have correct access
function test_U_CA_02_external_functions_have_correct_access(
address caller,
address factory_,
address creditManager_
) public {
vm.assume(factory_ != creditManager_);

vm.prank(factory_);
CreditAccountV3 creditAccount_ = new CreditAccountV3(creditManager_);

vm.mockCall(address(0), bytes(""), bytes(""));
vm.mockCall(address(0), abi.encodeCall(IERC20.transfer, (address(0), 0)), bytes(""));

if (caller != creditManager_) {
function test_U_CA_02_external_functions_have_correct_access(address caller) public {
vm.startPrank(caller);
if (caller != creditManager) {
vm.expectRevert(CallerNotCreditManagerException.selector);
creditAccount.safeTransfer({token: address(0), to: address(0), amount: 0});
}
vm.prank(caller);
creditAccount_.safeTransfer({token: address(0), to: address(0), amount: 0});

if (caller != creditManager_) {
if (caller != creditManager) {
vm.expectRevert(CallerNotCreditManagerException.selector);
creditAccount.execute({target: address(0), data: bytes("")});
}
vm.prank(caller);
creditAccount_.execute({target: address(0), data: bytes("")});

if (caller != factory_) {
if (caller != factory) {
vm.expectRevert(CallerNotAccountFactoryException.selector);
creditAccount.rescue({target: address(0), data: bytes("")});
}
vm.prank(caller);
creditAccount_.rescue({target: address(0), data: bytes("")});
vm.stopPrank();
}

/// @notice U:[CA-3]: `safeTransfer` works correctly
Expand Down

0 comments on commit 1e2a5ef

Please sign in to comment.