Skip to content

Commit

Permalink
test: add transfer admin tests
Browse files Browse the repository at this point in the history
test: add noDelegateCall tests
  • Loading branch information
andreivladbrg committed Jan 9, 2025
1 parent 84d4e15 commit e2c1af4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
4 changes: 3 additions & 1 deletion tests/mocks/NoDelegateCallMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ import { NoDelegateCall } from "src/NoDelegateCall.sol";

contract NoDelegateCallMock is NoDelegateCall {
/// @dev An empty function that uses the `noDelegateCall` modifier.
function foo() public noDelegateCall { }
function foo() public view noDelegateCall returns (uint256) {
return 420;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pragma solidity >=0.8.22 <0.9.0;
import { IAdminable } from "src/interfaces/IAdminable.sol";
import { Errors } from "src/libraries/Errors.sol";

import { CommonBase } from "../../../Base.t.sol";
import { AdminableMock } from "../../../mocks/AdminableMock.sol";
import { CommonBase } from "../../Base.t.sol";
import { AdminableMock } from "../../mocks/AdminableMock.sol";

contract TransferAdmin_Unit_Concrete_Test is CommonBase {
AdminableMock internal adminableMock;
Expand Down
File renamed without changes.
30 changes: 30 additions & 0 deletions tests/unit/no-delegate-call/noDelegateCall.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.22;

import { Errors } from "src/libraries/Errors.sol";

import { CommonBase } from "../../Base.t.sol";
import { NoDelegateCallMock } from "../../mocks/NoDelegateCallMock.sol";

contract NoDelegateCall_Unit_Concrete_Test is CommonBase {
NoDelegateCallMock internal noDelegateCallMock;

function setUp() public virtual override {
CommonBase.setUp();

noDelegateCallMock = new NoDelegateCallMock();
}

function test_RevertWhen_DelegateCall() external {
bytes memory callData = abi.encodeCall(noDelegateCallMock.foo, ());
(bool success, bytes memory returnData) = address(noDelegateCallMock).delegatecall(callData);
assertFalse(success, "delegatecall success");
assertEq(returnData, abi.encodeWithSelector(Errors.DelegateCall.selector), "delegatecall return data");
}

function test_WhenNoDelegateCall() external view {
uint256 actual = noDelegateCallMock.foo();
uint256 expected = 420;
assertEq(actual, expected, "foo");
}
}
5 changes: 5 additions & 0 deletions tests/unit/no-delegate-call/noDelegateCall.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
NoDelegateCall_Unit_Concrete_Test
β”œβ”€β”€ when delegate call
β”‚ └── it should revert
└── when no delegate call
└── it should execute the function

0 comments on commit e2c1af4

Please sign in to comment.