From 6baf16391e24f15dc86b518c1ec4134724accefe Mon Sep 17 00:00:00 2001 From: qian-hu <88806138+qian-hu@users.noreply.github.com> Date: Tue, 23 Jul 2024 19:19:00 -0400 Subject: [PATCH] Revert EscrowOperationsTest base to EscrowAccountingTest --- test/kontrol/EscrowAccounting.t.sol | 5 +++- test/kontrol/EscrowOperations.t.sol | 40 ++++++++++++++++------------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/test/kontrol/EscrowAccounting.t.sol b/test/kontrol/EscrowAccounting.t.sol index cbe616ee..b289ecae 100644 --- a/test/kontrol/EscrowAccounting.t.sol +++ b/test/kontrol/EscrowAccounting.t.sol @@ -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"; @@ -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 diff --git a/test/kontrol/EscrowOperations.t.sol b/test/kontrol/EscrowOperations.t.sol index f12c5763..c9dd24dc 100644 --- a/test/kontrol/EscrowOperations.t.sol +++ b/test/kontrol/EscrowOperations.t.sol @@ -3,11 +3,11 @@ 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; @@ -15,7 +15,7 @@ contract EscrowOperationsTest is EscrowLockUnlockTest { } function _tryUnlockStETH() internal returns (bool) { - try signallingEscrow.unlockStETH() { + try escrow.unlockStETH() { return true; } catch { return false; @@ -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); @@ -40,7 +42,7 @@ contract EscrowOperationsTest is EscrowLockUnlockTest { if (Timestamps.now() < lockPeriod) { vm.prank(sender); vm.expectRevert(abi.encodeWithSelector(AssetsAccounting.AssetsUnlockDelayNotPassed.selector, lockPeriod)); - signallingEscrow.unlockStETH(); + escrow.unlockStETH(); } } @@ -48,12 +50,14 @@ contract EscrowOperationsTest is EscrowLockUnlockTest { * 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); @@ -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); @@ -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);