Skip to content

Commit

Permalink
Revert EscrowOperationsTest base to EscrowAccountingTest
Browse files Browse the repository at this point in the history
  • Loading branch information
qian-hu committed Jul 23, 2024
1 parent 05baf70 commit 6baf163
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
5 changes: 4 additions & 1 deletion test/kontrol/EscrowAccounting.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pragma solidity 0.8.23;

import "@openzeppelin/contracts/proxy/Clones.sol";

import "contracts/Configuration.sol";
import "contracts/DualGovernance.sol";
import "contracts/EmergencyProtectedTimelock.sol";
Expand Down Expand Up @@ -35,7 +37,8 @@ contract EscrowAccountingTest is EscrowInvariants {

config = new Configuration(adminExecutor, emergencyGovernance, new address[](0));

escrow = new Escrow(address(stEth), address(wstEth), address(withdrawalQueue), address(config));
Escrow escrowMasterCopy = new Escrow(address(stEth), address(wstEth), address(withdrawalQueue), address(config));
escrow = Escrow(payable(Clones.clone(address(escrowMasterCopy))));
escrow.initialize(dualGovernanceAddress);

// ?STORAGE
Expand Down
40 changes: 22 additions & 18 deletions test/kontrol/EscrowOperations.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ pragma solidity 0.8.23;
import {Duration, Durations} from "contracts/types/Duration.sol";
import {Timestamp, Timestamps} from "contracts/types/Timestamp.sol";

import "test/kontrol/EscrowLockUnlock.t.sol";
import "test/kontrol/EscrowAccounting.t.sol";

contract EscrowOperationsTest is EscrowLockUnlockTest {
contract EscrowOperationsTest is EscrowAccountingTest {
function _tryLockStETH(uint256 amount) internal returns (bool) {
try signallingEscrow.lockStETH(amount) {
try escrow.lockStETH(amount) {
return true;
} catch {
return false;
}
}

function _tryUnlockStETH() internal returns (bool) {
try signallingEscrow.unlockStETH() {
try escrow.unlockStETH() {
return true;
} catch {
return false;
Expand All @@ -26,12 +26,14 @@ contract EscrowOperationsTest is EscrowLockUnlockTest {
* Test that a staker cannot unlock funds from the escrow until SignallingEscrowMinLockTime has passed since the last time that user has locked tokens.
*/
function testCannotUnlockBeforeMinLockTime() external {
_setUpGenericState();

// Placeholder address to avoid complications with keccak of symbolic addresses
address sender = address(uint160(uint256(keccak256("sender"))));
vm.assume(stEth.sharesOf(sender) < ethUpperBound);
vm.assume(_getLastAssetsLockTimestamp(signallingEscrow, sender) < timeUpperBound);
vm.assume(_getLastAssetsLockTimestamp(escrow, sender) < timeUpperBound);

AccountingRecord memory pre = _saveAccountingRecord(sender, signallingEscrow);
AccountingRecord memory pre = _saveAccountingRecord(sender, escrow);
vm.assume(pre.escrowState == EscrowState.SignallingEscrow);
vm.assume(pre.userSharesLocked <= pre.totalSharesLocked);

Expand All @@ -40,20 +42,22 @@ contract EscrowOperationsTest is EscrowLockUnlockTest {
if (Timestamps.now() < lockPeriod) {
vm.prank(sender);
vm.expectRevert(abi.encodeWithSelector(AssetsAccounting.AssetsUnlockDelayNotPassed.selector, lockPeriod));
signallingEscrow.unlockStETH();
escrow.unlockStETH();
}
}

/**
* Test that funds cannot be locked and unlocked if the escrow is in the RageQuitEscrow state.
*/
function testCannotLockUnlockInRageQuitEscrowState(uint256 amount) external {
_setUpGenericState();

// Placeholder address to avoid complications with keccak of symbolic addresses
address sender = address(uint160(uint256(keccak256("sender"))));
vm.assume(stEth.sharesOf(sender) < ethUpperBound);
vm.assume(stEth.balanceOf(sender) < ethUpperBound);

AccountingRecord memory pre = _saveAccountingRecord(sender, signallingEscrow);
AccountingRecord memory pre = _saveAccountingRecord(sender, escrow);
vm.assume(0 < amount);
vm.assume(amount <= pre.userBalance);
vm.assume(amount <= pre.allowance);
Expand All @@ -62,9 +66,9 @@ contract EscrowOperationsTest is EscrowLockUnlockTest {
_assumeNoOverflow(pre.userSharesLocked, amountInShares);
_assumeNoOverflow(pre.totalSharesLocked, amountInShares);

_escrowInvariants(Mode.Assume, signallingEscrow);
_signallingEscrowInvariants(Mode.Assume, signallingEscrow);
_escrowUserInvariants(Mode.Assume, signallingEscrow, sender);
_escrowInvariants(Mode.Assume, escrow);
_signallingEscrowInvariants(Mode.Assume, escrow);
_escrowUserInvariants(Mode.Assume, escrow, sender);

if (pre.escrowState == EscrowState.RageQuitEscrow) {
vm.startPrank(sender);
Expand All @@ -80,22 +84,22 @@ contract EscrowOperationsTest is EscrowLockUnlockTest {
vm.stopPrank;
} else {
vm.prank(sender);
signallingEscrow.lockStETH(amount);
escrow.lockStETH(amount);

AccountingRecord memory afterLock = _saveAccountingRecord(sender, signallingEscrow);
AccountingRecord memory afterLock = _saveAccountingRecord(sender, escrow);
vm.assume(afterLock.userShares < ethUpperBound);
//vm.assume(afterLock.userLastLockedTime < timeUpperBound);
vm.assume(afterLock.userSharesLocked <= afterLock.totalSharesLocked);
vm.assume(Timestamps.now() >= addTo(config.SIGNALLING_ESCROW_MIN_LOCK_TIME(), afterLock.userLastLockedTime));

vm.prank(sender);
signallingEscrow.unlockStETH();
escrow.unlockStETH();

_escrowInvariants(Mode.Assert, signallingEscrow);
_signallingEscrowInvariants(Mode.Assert, signallingEscrow);
_escrowUserInvariants(Mode.Assert, signallingEscrow, sender);
_escrowInvariants(Mode.Assert, escrow);
_signallingEscrowInvariants(Mode.Assert, escrow);
_escrowUserInvariants(Mode.Assert, escrow, sender);

AccountingRecord memory post = _saveAccountingRecord(sender, signallingEscrow);
AccountingRecord memory post = _saveAccountingRecord(sender, escrow);
assert(post.escrowState == EscrowState.SignallingEscrow);
assert(post.userShares == pre.userShares);
assert(post.escrowShares == pre.escrowShares);
Expand Down

0 comments on commit 6baf163

Please sign in to comment.