Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escrow contract unit tests #101

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions contracts/interfaces/IEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
pragma solidity 0.8.26;

import {Duration} from "../types/Duration.sol";
import {Timestamp} from "../types/Timestamp.sol";
import {PercentD16} from "../types/PercentD16.sol";

interface IEscrow {
function initialize(Duration minAssetsLockDuration) external;

function startRageQuit(Duration rageQuitExtraTimelock, Duration rageQuitWithdrawalsTimelock) external;
function requestNextWithdrawalsBatch(uint256 batchSize) external;
function claimNextWithdrawalsBatch(uint256 maxUnstETHIdsCount) external;
function claimNextWithdrawalsBatch(uint256 fromUnstETHId, uint256[] calldata hints) external;
function startRageQuitExtensionDelay() external;

function isRageQuitFinalized() external view returns (bool);
function getRageQuitSupport() external view returns (PercentD16 rageQuitSupport);
function setMinAssetsLockDuration(Duration newMinAssetsLockDuration) external;
function isRageQuitExtensionDelayStarted() external view returns (bool);
function getRageQuitExtensionDelayStartedAt() external view returns (Timestamp);
}
2 changes: 1 addition & 1 deletion contracts/libraries/WithdrawalBatchesQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";

/// @notice The state of the WithdrawalBatchesQueue
/// @param Empty The initial (uninitialized) state of the WithdrawalBatchesQueue
/// @param Absent The initial (uninitialized) state of the WithdrawalBatchesQueue
/// @param Opened In this state, the WithdrawalBatchesQueue allows the addition of new batches of unstETH ids
/// @param Closed The terminal state of the queue. In this state, the addition of new batches is forbidden
enum State {
Expand Down
58 changes: 58 additions & 0 deletions test/mocks/DualGovernanceMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import {IDualGovernance} from "contracts/interfaces/IDualGovernance.sol";
import {ExternalCall} from "contracts/libraries/ExternalCalls.sol";
import {IEscrow} from "contracts/interfaces/IEscrow.sol";
import {Duration} from "contracts/types/Duration.sol";

/* solhint-disable no-unused-vars,custom-errors */
contract DualGovernanceMock is IDualGovernance {
function submitProposal(ExternalCall[] calldata calls) external returns (uint256 proposalId) {
revert("Not Implemented");
}

function scheduleProposal(uint256 proposalId) external {
revert("Not Implemented");
}

function cancelAllPendingProposals() external {
revert("Not Implemented");
}

function canScheduleProposal(uint256 proposalId) external view returns (bool) {
revert("Not Implemented");
}

function activateNextState() external {
revert("Not Implemented");
}

function resealSealable(address sealables) external {
revert("Not Implemented");
}

function tiebreakerScheduleProposal(uint256 proposalId) external {
revert("Not Implemented");
}

function tiebreakerResumeSealable(address sealable) external {
revert("Not Implemented");
}

function initializeEscrow(IEscrow instance, Duration minAssetsLockDuration) external {
instance.initialize(minAssetsLockDuration);
}

function startRageQuitForEscrow(
IEscrow instance,
Duration rageQuitExtensionDelay,
Duration rageQuitWithdrawalsTimelock
) external {
instance.startRageQuit(rageQuitExtensionDelay, rageQuitWithdrawalsTimelock);
}

function setMinAssetsLockDurationForEscrow(IEscrow instance, Duration newMinAssetsLockDuration) external {
instance.setMinAssetsLockDuration(newMinAssetsLockDuration);
}
}
28 changes: 28 additions & 0 deletions test/mocks/StETHMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import {ERC20Mock} from "@openzeppelin/contracts/mocks/token/ERC20Mock.sol";
import {IStETH} from "contracts/interfaces/IStETH.sol";

/* solhint-disable no-unused-vars,custom-errors */
contract StETHMock is ERC20Mock, IStETH {
function getSharesByPooledEth(uint256 ethAmount) external view returns (uint256) {
revert("Not Implemented");
}

function getPooledEthByShares(uint256 sharesAmount) external view returns (uint256) {
revert("Not Implemented");
}

function transferShares(address to, uint256 amount) external {
revert("Not Implemented");
}

function transferSharesFrom(
address _sender,
address _recipient,
uint256 _sharesAmount
) external returns (uint256) {
revert("Not Implemented");
}
}
135 changes: 135 additions & 0 deletions test/mocks/WithdrawalQueueMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

// import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; /*, ERC721("test", "test")*/
import {IWithdrawalQueue, WithdrawalRequestStatus} from "contracts/interfaces/IWithdrawalQueue.sol";

/* solhint-disable no-unused-vars,custom-errors */
contract WithdrawalQueueMock is IWithdrawalQueue {
uint256 private _lastRequestId;
uint256 private _lastFinalizedRequestId;
uint256 private _minStETHWithdrawalAmount;
uint256 private _maxStETHWithdrawalAmount;
uint256[] private _requestWithdrawalsResult;

constructor() {}

function MIN_STETH_WITHDRAWAL_AMOUNT() external view returns (uint256) {
return _minStETHWithdrawalAmount;
}

function MAX_STETH_WITHDRAWAL_AMOUNT() external view returns (uint256) {
return _maxStETHWithdrawalAmount;
}

function claimWithdrawals(uint256[] calldata requestIds, uint256[] calldata hints) external {
revert("Not Implemented");
}

function getLastRequestId() external view returns (uint256) {
return _lastRequestId;
}

function getLastFinalizedRequestId() external view returns (uint256) {
return _lastFinalizedRequestId;
}

function getWithdrawalStatus(uint256[] calldata _requestIds)
external
view
returns (WithdrawalRequestStatus[] memory statuses)
{
revert("Not Implemented");
}

/// @notice Returns amount of ether available for claim for each provided request id
/// @param _requestIds array of request ids
/// @param _hints checkpoint hints. can be found with `findCheckpointHints(_requestIds, 1, getLastCheckpointIndex())`
/// @return claimableEthValues amount of claimable ether for each request, amount is equal to 0 if request
/// is not finalized or already claimed
function getClaimableEther(
uint256[] calldata _requestIds,
uint256[] calldata _hints
) external view returns (uint256[] memory claimableEthValues) {
revert("Not Implemented");
}

function findCheckpointHints(
uint256[] calldata _requestIds,
uint256 _firstIndex,
uint256 _lastIndex
) external view returns (uint256[] memory hintIds) {
revert("Not Implemented");
}

function getLastCheckpointIndex() external view returns (uint256) {
revert("Not Implemented");
}

function requestWithdrawals(
uint256[] calldata _amounts,
address _owner
) external returns (uint256[] memory requestIds) {
return _requestWithdrawalsResult;
}

function balanceOf(address owner) external view returns (uint256 balance) {
revert("Not Implemented");
}

function ownerOf(uint256 tokenId) external view returns (address owner) {
revert("Not Implemented");
}

function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external {
revert("Not Implemented");
}

function safeTransferFrom(address from, address to, uint256 tokenId) external {
revert("Not Implemented");
}

function transferFrom(address from, address to, uint256 tokenId) external {
revert("Not Implemented");
}

function approve(address to, uint256 tokenId) external {
revert("Not Implemented");
}

function setApprovalForAll(address operator, bool approved) external {
revert("Not Implemented");
}

function getApproved(uint256 tokenId) external view returns (address operator) {
revert("Not Implemented");
}

function isApprovedForAll(address owner, address operator) external view returns (bool) {
revert("Not Implemented");
}

function supportsInterface(bytes4 interfaceId) external view returns (bool) {
revert("Not Implemented");
}

function setLastRequestId(uint256 id) public {
_lastRequestId = id;
}

function setLastFinalizedRequestId(uint256 id) public {
_lastFinalizedRequestId = id;
}

function setMinStETHWithdrawalAmount(uint256 amount) public {
_minStETHWithdrawalAmount = amount;
}

function setMaxStETHWithdrawalAmount(uint256 amount) public {
_maxStETHWithdrawalAmount = amount;
}

function setRequestWithdrawalsResult(uint256[] memory requestIds) public {
_requestWithdrawalsResult = requestIds;
}
}
20 changes: 20 additions & 0 deletions test/mocks/WstETHMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import {ERC20Mock} from "@openzeppelin/contracts/mocks/token/ERC20Mock.sol";
import {IWstETH} from "contracts/interfaces/IWstETH.sol";

/* solhint-disable no-unused-vars,custom-errors */
contract WstETHMock is ERC20Mock, IWstETH {
function wrap(uint256 stETHAmount) external returns (uint256) {
revert("Not Implemented");
}

function unwrap(uint256 wstETHAmount) external returns (uint256) {
revert("Not Implemented");
}

function getStETHByWstETH(uint256 wstethAmount) external view returns (uint256) {
revert("Not Implemented");
}
}
2 changes: 1 addition & 1 deletion test/scenario/escrow.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ contract EscrowHappyPath is ScenarioTestBlueprint {

escrow.requestNextWithdrawalsBatch(96);

vm.expectRevert();
vm.expectRevert(WithdrawalsBatchesQueue.EmptyBatch.selector);
escrow.claimNextWithdrawalsBatch(0, new uint256[](0));

escrow.startRageQuitExtensionDelay();
Expand Down
Loading