Skip to content

Commit

Permalink
lint: run lint
Browse files Browse the repository at this point in the history
  • Loading branch information
QEDK committed Apr 30, 2024
1 parent 93d1b6e commit ea2db92
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 67 deletions.
5 changes: 4 additions & 1 deletion src/AvailDepository.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ contract AvailDepository is AccessControlDefaultAdminRulesUpgradeable, IAvailDep
external
initializer
{
if (governance == address(0) || address(newBridge) == address(0) || newDepositor == address(0) || newDepository == bytes32(0)) {
if (
governance == address(0) || address(newBridge) == address(0) || newDepositor == address(0)
|| newDepository == bytes32(0)
) {
revert ZeroAddress();
}
bridge = newBridge;
Expand Down
18 changes: 15 additions & 3 deletions test/AvailDepositoryTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,28 @@ contract AvailDepositoryTest is Test {
function testRevert_constructor() external {
vm.expectRevert(IAvailDepository.ZeroAddress.selector);
new AvailDepository(IERC20(address(0)));
}
}

function test_constructor(address rand) external {
vm.assume(rand != address(0));
AvailDepository newDepository = new AvailDepository(IERC20(rand));
assertEq(address(newDepository.avail()), rand);
}

function testRevert_Initialize(address rand, address newGovernance, address newBridge, address newDepositor, bytes32 newAvailDepositoryAddr) external {
vm.assume(rand != address(0) && (newGovernance == address(0) || newBridge == address(0) || newDepositor == address(0) || newAvailDepositoryAddr == bytes32(0)));
function testRevert_Initialize(
address rand,
address newGovernance,
address newBridge,
address newDepositor,
bytes32 newAvailDepositoryAddr
) external {
vm.assume(
rand != address(0)
&& (
newGovernance == address(0) || newBridge == address(0) || newDepositor == address(0)
|| newAvailDepositoryAddr == bytes32(0)
)
);
AvailDepository newDepository = new AvailDepository(IERC20(rand));
assertEq(address(newDepository.avail()), rand);
vm.expectRevert(IAvailDepository.ZeroAddress.selector);
Expand Down
6 changes: 4 additions & 2 deletions test/AvailWithdrawalHelperTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ contract AvailWithdrawalHelperTest is Test {
assertEq(address(newWithdrawalHelper.avail()), rand);
}

function testRevert_initialize(address rand, address newGovernance, address newStakedAvail, uint256 amount) external {
function testRevert_initialize(address rand, address newGovernance, address newStakedAvail, uint256 amount)
external
{
vm.assume(rand != address(0));
AvailWithdrawalHelper newWithdrawalHelper = new AvailWithdrawalHelper(IERC20(rand));
assertEq(address(newWithdrawalHelper.avail()), rand);
vm.assume(newGovernance == address(0) || newStakedAvail == address(0));
vm.expectRevert(IAvailWithdrawalHelper.ZeroAddress.selector);
newWithdrawalHelper.initialize(newGovernance,IStakedAvail(newStakedAvail), amount);
newWithdrawalHelper.initialize(newGovernance, IStakedAvail(newStakedAvail), amount);
}

function test_initialize() external view {
Expand Down
43 changes: 13 additions & 30 deletions test/DeqRouterTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,22 @@ contract DeqRouterTest is Test {
vm.startPrank(from);
tokenIn.approve(address(deqRouter), amountIn);
bytes memory data = abi.encodeWithSelector(
rand,
tokenIn,
address(avail),
amountIn,
minAmountOut,
new IDeqRouter.Transformation[](0)
rand, tokenIn, address(avail), amountIn, minAmountOut, new IDeqRouter.Transformation[](0)
);
avail.mint(address(deqRouter), amountOut);
vm.mockCall(
swapRouter,
data,
abi.encode(amountOut)
);
vm.mockCall(swapRouter, data, abi.encode(amountOut));
deqRouter.swapERC20ToStAvail(makeAddr("rand"), data);
assertEq(stakedAvail.balanceOf(from), amountOut);
assertEq(avail.balanceOf(address(deqRouter)), 0);
}

function test_swapERC20ToStAvailWithPermit(bytes4 rand, uint256 amountIn, uint256 amountOut, uint256 minAmountOut, uint256 deadline) external {
function test_swapERC20ToStAvailWithPermit(
bytes4 rand,
uint256 amountIn,
uint256 amountOut,
uint256 minAmountOut,
uint256 deadline
) external {
vm.assume(amountIn > 0 && amountOut > 0 && minAmountOut > 0 && minAmountOut <= amountOut && deadline != 0);
MockERC20 tokenIn = new MockERC20("TokenIn", "TKNIN");
(address from, uint256 key) = makeAddrAndKey("from");
Expand All @@ -100,26 +97,17 @@ contract DeqRouterTest is Test {

(uint8 v, bytes32 r, bytes32 s) = vm.sign(key, digest);
bytes memory data = abi.encodeWithSelector(
rand,
tokenIn,
address(avail),
amountIn,
minAmountOut,
new IDeqRouter.Transformation[](0)
rand, tokenIn, address(avail), amountIn, minAmountOut, new IDeqRouter.Transformation[](0)
);
avail.mint(address(deqRouter), amountOut);
vm.mockCall(
swapRouter,
data,
abi.encode(amountOut)
);
vm.mockCall(swapRouter, data, abi.encode(amountOut));
deqRouter.swapERC20ToStAvailWithPermit(makeAddr("rand"), data, deadline, v, r, s);
assertEq(stakedAvail.balanceOf(from), amountOut);
assertEq(avail.balanceOf(address(deqRouter)), 0);
}

function test_swapETHToStAvail(bytes4 rand, uint256 amountIn, uint256 amountOut, uint256 minAmountOut) external {
vm.assume(amountIn > 0 && amountOut > 0 && minAmountOut > 0 && minAmountOut <= amountOut);
vm.assume(amountIn > 0 && amountOut > 0 && minAmountOut > 0 && minAmountOut <= amountOut);
address from = makeAddr("from");
vm.deal(from, amountIn);
vm.startPrank(from);
Expand All @@ -132,12 +120,7 @@ contract DeqRouterTest is Test {
new IDeqRouter.Transformation[](0)
);
avail.mint(address(deqRouter), amountOut);
vm.mockCall(
swapRouter,
amountIn,
data,
abi.encode(amountOut)
);
vm.mockCall(swapRouter, amountIn, data, abi.encode(amountOut));
deqRouter.swapETHtoStAvail{value: amountIn}(data);
assertEq(stakedAvail.balanceOf(from), amountOut);
assertEq(avail.balanceOf(address(deqRouter)), 0);
Expand Down
38 changes: 7 additions & 31 deletions test/helpers/SigUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ contract SigUtils {
}

// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
bytes32 public constant PERMIT_TYPEHASH =
0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;

struct Permit {
address owner;
Expand All @@ -22,37 +21,14 @@ contract SigUtils {
}

// computes the hash of a permit
function getStructHash(Permit memory _permit)
internal
pure
returns (bytes32)
{
return
keccak256(
abi.encode(
PERMIT_TYPEHASH,
_permit.owner,
_permit.spender,
_permit.value,
_permit.nonce,
_permit.deadline
)
);
function getStructHash(Permit memory _permit) internal pure returns (bytes32) {
return keccak256(
abi.encode(PERMIT_TYPEHASH, _permit.owner, _permit.spender, _permit.value, _permit.nonce, _permit.deadline)
);
}

// computes the hash of the fully encoded EIP-712 message for the domain, which can be used to recover the signer
function getTypedDataHash(Permit memory _permit)
public
view
returns (bytes32)
{
return
keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR,
getStructHash(_permit)
)
);
function getTypedDataHash(Permit memory _permit) public view returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR, getStructHash(_permit)));
}
}

0 comments on commit ea2db92

Please sign in to comment.