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

Feat: StrategyManager Unit testing #224

Merged
merged 9 commits into from
Oct 12, 2023
6 changes: 3 additions & 3 deletions .github/workflows/certora-prover.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ jobs:
python-version: '3.10'
cache: 'pip'
- name: Install java
uses: actions/setup-java@v1
uses: actions/setup-java@v2
with:
java-version: '11'
java-package: 'jre'
distribution: temurin
ChaoticWalrus marked this conversation as resolved.
Show resolved Hide resolved
java-version: '17'
- name: Install certora
run: pip install certora-cli
- name: Install solc
Expand Down
2 changes: 1 addition & 1 deletion certora/scripts/strategies/verifyStrategyBase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ then
RULE="--rule $2"
fi

solc-select use 0.8.12
solc-select use 0.8.12

certoraRun certora/munged/strategies/StrategyBase.sol \
lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol \
Expand Down
34 changes: 16 additions & 18 deletions script/whitelist/Whitelister.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,17 @@ contract Whitelister is IWhitelister, Ownable {

function queueWithdrawal(
address staker,
uint256[] calldata strategyIndexes,
IStrategy[] calldata strategies,
uint256[] calldata shares,
address withdrawer
) public onlyOwner returns (bytes memory) {
// bytes memory data = abi.encodeWithSelector(
// IStrategyManager.queueWithdrawal.selector,
// strategyIndexes,
// strategies,
// shares,
// withdrawer
// );
// return Staker(staker).callAddress(address(strategyManager), data);
bytes memory data = abi.encodeWithSelector(
IDelegationManager.queueWithdrawal.selector,
strategies,
shares,
withdrawer
);
return Staker(staker).callAddress(address(delegation), data);
}

function completeQueuedWithdrawal(
Expand All @@ -133,15 +131,15 @@ contract Whitelister is IWhitelister, Ownable {
uint256 middlewareTimesIndex,
bool receiveAsTokens
) public onlyOwner returns (bytes memory) {
// bytes memory data = abi.encodeWithSelector(
// IStrategyManager.completeQueuedWithdrawal.selector,
// queuedWithdrawal,
// tokens,
// middlewareTimesIndex,
// receiveAsTokens
// );

// return Staker(staker).callAddress(address(strategyManager), data);
bytes memory data = abi.encodeWithSelector(
IDelegationManager.completeQueuedWithdrawal.selector,
queuedWithdrawal,
tokens,
middlewareTimesIndex,
receiveAsTokens
);

return Staker(staker).callAddress(address(delegation), data);
}

function transfer(
Expand Down
1 change: 0 additions & 1 deletion src/contracts/interfaces/IWhitelister.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ interface IWhitelister {

function queueWithdrawal(
address staker,
uint256[] calldata strategyIndexes,
IStrategy[] calldata strategies,
uint256[] calldata shares,
address withdrawer
Expand Down
25 changes: 5 additions & 20 deletions src/test/DelegationFaucet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ contract DelegationFaucetTests is EigenLayerTestHelper {
address owner = cheats.addr(1000);

/// @notice Emitted when a queued withdrawal is completed
event WithdrawalCompleted(
address indexed depositor,
uint256 nonce,
address indexed withdrawer,
bytes32 withdrawalRoot
);
event WithdrawalCompleted(bytes32 withdrawalRoot);

function setUp() public virtual override {
EigenLayerDeployer.setUp();
Expand Down Expand Up @@ -346,13 +341,8 @@ contract DelegationFaucetTests is EigenLayerTestHelper {
delegatedTo: strategyManager.delegation().delegatedTo(stakerContract)
});
}
cheats.expectEmit(true, true, true, true, address(strategyManager));
emit WithdrawalCompleted(
queuedWithdrawal.staker,
queuedWithdrawal.nonce,
queuedWithdrawal.withdrawer,
delegation.calculateWithdrawalRoot(queuedWithdrawal)
);
cheats.expectEmit(true, true, true, true, address(delegation));
emit WithdrawalCompleted(delegation.calculateWithdrawalRoot(queuedWithdrawal));
uint256 middlewareTimesIndex = 0;
bool receiveAsTokens = false;
delegationFaucet.completeQueuedWithdrawal(
Expand Down Expand Up @@ -412,13 +402,8 @@ contract DelegationFaucetTests is EigenLayerTestHelper {
delegatedTo: strategyManager.delegation().delegatedTo(stakerContract)
});
}
cheats.expectEmit(true, true, true, true, address(strategyManager));
emit WithdrawalCompleted(
queuedWithdrawal.staker,
queuedWithdrawal.nonce,
queuedWithdrawal.withdrawer,
delegation.calculateWithdrawalRoot(queuedWithdrawal)
);
cheats.expectEmit(true, true, true, true, address(delegation));
emit WithdrawalCompleted(delegation.calculateWithdrawalRoot(queuedWithdrawal));
uint256 middlewareTimesIndex = 0;
bool receiveAsTokens = true;
delegationFaucet.completeQueuedWithdrawal(
Expand Down
4 changes: 2 additions & 2 deletions src/test/DepositWithdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ contract DepositWithdrawTests is EigenLayerTestHelper {

{
uint256 correctMiddlewareTimesIndex = 4;
cheats.expectRevert("StrategyManager.completeQueuedWithdrawal: shares pending withdrawal are still slashable");
cheats.expectRevert("DelegationManager.completeQueuedAction: pending action is still slashable");
delegation.completeQueuedWithdrawal(queuedWithdrawal, tokensArray, correctMiddlewareTimesIndex, false);
}

//When called with a stale index the call should also revert.
{
uint256 staleMiddlewareTimesIndex = 2;
cheats.expectRevert("StrategyManager.completeQueuedWithdrawal: shares pending withdrawal are still slashable");
cheats.expectRevert("DelegationManager.completeQueuedAction: pending action is still slashable");
delegation.completeQueuedWithdrawal(queuedWithdrawal, tokensArray, staleMiddlewareTimesIndex, false);
}

Expand Down
15 changes: 4 additions & 11 deletions src/test/Whitelister.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,13 @@ contract WhitelisterTests is EigenLayerTestHelper {
emit log_named_uint("expectedTokensOut", expectedTokensOut);
}

uint256[] memory strategyIndexes = new uint256[](1);
IERC20[] memory tokensArray = new IERC20[](1);
{
// hardcoded values
strategyIndexes[0] = 0;
tokensArray[0] = dummyToken;
}
// hardcoded values
tokensArray[0] = dummyToken;
_testQueueWithdrawal(
staker,
dataForTestWithdrawal.delegatorStrategies,
dataForTestWithdrawal.delegatorShares,
strategyIndexes
dataForTestWithdrawal.delegatorShares
);
{
uint256 balanceBeforeWithdrawal = dummyToken.balanceOf(staker);
Expand All @@ -279,15 +274,13 @@ contract WhitelisterTests is EigenLayerTestHelper {
function _testQueueWithdrawal(
address staker,
IStrategy[] memory strategyArray,
uint256[] memory shareAmounts,
uint256[] memory strategyIndexes
uint256[] memory shareAmounts
)
internal
{
cheats.startPrank(theMultiSig);
whiteLister.queueWithdrawal(
staker,
strategyIndexes,
strategyArray,
shareAmounts,
staker
Expand Down
Loading
Loading