Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/petar/external-functions-in-setu…
Browse files Browse the repository at this point in the history
…p' into tests-on-client-code
  • Loading branch information
PetarMax committed Jul 26, 2024
2 parents 6baf163 + 83e85fa commit b6c977d
Show file tree
Hide file tree
Showing 9 changed files with 377 additions and 236 deletions.
65 changes: 26 additions & 39 deletions test/kontrol/ActivateNextState.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,30 @@ import {State} from "contracts/libraries/DualGovernanceState.sol";
import "test/kontrol/DualGovernanceSetUp.sol";

contract ActivateNextStateMock is StorageSetup {
StorageSetup public immutable STORAGE_SETUP;

constructor(address storageSetup) {
STORAGE_SETUP = StorageSetup(storageSetup);
}

function activateNextState() external {
DualGovernance dualGovernance = DualGovernance(address(this));
IConfiguration config = dualGovernance.CONFIG();
Escrow signallingEscrow = Escrow(payable(dualGovernance.getVetoSignallingEscrow()));
Escrow rageQuitEscrow = Escrow(payable(dualGovernance.getRageQuitEscrow()));
address sender = address(uint160(uint256(keccak256("sender"))));
AccountingRecord memory pre = _saveAccountingRecord(sender, signallingEscrow);

_dualGovernanceStorageInvariants(Mode.Assert, dualGovernance);
_escrowStorageInvariants(Mode.Assert, signallingEscrow);
_signallingEscrowStorageInvariants(Mode.Assert, signallingEscrow);
_escrowStorageInvariants(Mode.Assert, rageQuitEscrow);
_rageQuitEscrowStorageInvariants(Mode.Assert, rageQuitEscrow);

State initialState = dualGovernance.getCurrentState();
uint256 rageQuitSupport = signallingEscrow.getRageQuitSupport();
(,, Timestamp vetoSignallingActivationTime,) = dualGovernance.getVetoSignallingState();

if (
(initialState == State.VetoSignalling || initialState == State.VetoSignallingDeactivation)
&& rageQuitSupport > config.SECOND_SEAL_RAGE_QUIT_SUPPORT()
&& Timestamps.now() > config.DYNAMIC_TIMELOCK_MAX_DURATION().addTo(vetoSignallingActivationTime)
) {
address escrowMasterCopy = signallingEscrow.MASTER_COPY();
IEscrow newSignallingEscrow = IEscrow(Clones.clone(escrowMasterCopy));
STORAGE_SETUP.dualGovernanceStorageInvariants(Mode.Assert, dualGovernance);
STORAGE_SETUP.escrowStorageInvariants(Mode.Assert, signallingEscrow);
STORAGE_SETUP.signallingEscrowStorageInvariants(Mode.Assert, signallingEscrow);
STORAGE_SETUP.escrowStorageInvariants(Mode.Assert, rageQuitEscrow);
STORAGE_SETUP.rageQuitEscrowStorageInvariants(Mode.Assert, rageQuitEscrow);

_dualGovernanceInitializeStorage(dualGovernance, newSignallingEscrow, signallingEscrow);
_signallingEscrowInitializeStorage(newSignallingEscrow, dualGovernance);
_rageQuitEscrowInitializeStorage(signallingEscrow, dualGovernance);
} else {
_dualGovernanceInitializeStorage(dualGovernance, signallingEscrow, rageQuitEscrow);
_signallingEscrowInitializeStorage(signallingEscrow, dualGovernance);
_rageQuitEscrowInitializeStorage(rageQuitEscrow, dualGovernance);
}
address escrowMasterCopy = signallingEscrow.MASTER_COPY();
IEscrow newSignallingEscrow = IEscrow(Clones.clone(escrowMasterCopy));
IEscrow newRageQuitEscrow = IEscrow(Clones.clone(escrowMasterCopy));

AccountingRecord memory post = _saveAccountingRecord(sender, signallingEscrow);
_establishEqualAccountingRecords(Mode.Assume, pre, post);
STORAGE_SETUP.dualGovernanceInitializeStorage(dualGovernance, newSignallingEscrow, newRageQuitEscrow);
STORAGE_SETUP.signallingEscrowInitializeStorage(newSignallingEscrow, dualGovernance);
STORAGE_SETUP.rageQuitEscrowInitializeStorage(newRageQuitEscrow, dualGovernance);
}
}

Expand All @@ -51,7 +38,7 @@ contract ActivateNextStateTest is DualGovernanceSetUp {
uint256 rageQuitSupport = signallingEscrow.getRageQuitSupport();
(,, Timestamp vetoSignallingActivationTime,) = dualGovernance.getVetoSignallingState();
address sender = address(uint160(uint256(keccak256("sender"))));
AccountingRecord memory pre = _saveAccountingRecord(sender, signallingEscrow);
AccountingRecord memory pre = this.saveAccountingRecord(sender, signallingEscrow);

dualGovernance.activateNextState();

Expand All @@ -64,19 +51,19 @@ contract ActivateNextStateTest is DualGovernanceSetUp {

assert(dualGovernance.getRageQuitEscrow() == address(signallingEscrow));
assert(EscrowState(_getCurrentState(signallingEscrow)) == EscrowState.RageQuitEscrow);
_dualGovernanceStorageInvariants(Mode.Assert, dualGovernance);
_signallingEscrowStorageInvariants(Mode.Assert, newSignallingEscrow);
_rageQuitEscrowStorageInvariants(Mode.Assert, signallingEscrow);
this.dualGovernanceStorageInvariants(Mode.Assert, dualGovernance);
this.signallingEscrowStorageInvariants(Mode.Assert, newSignallingEscrow);
this.rageQuitEscrowStorageInvariants(Mode.Assert, signallingEscrow);
} else {
assert(dualGovernance.getVetoSignallingEscrow() == address(signallingEscrow));
assert(dualGovernance.getRageQuitEscrow() == address(rageQuitEscrow));
assert(EscrowState(_getCurrentState(signallingEscrow)) == EscrowState.SignallingEscrow);
_dualGovernanceStorageInvariants(Mode.Assert, dualGovernance);
_signallingEscrowStorageInvariants(Mode.Assert, signallingEscrow);
_rageQuitEscrowStorageInvariants(Mode.Assert, rageQuitEscrow);
this.dualGovernanceStorageInvariants(Mode.Assert, dualGovernance);
this.signallingEscrowStorageInvariants(Mode.Assert, signallingEscrow);
this.rageQuitEscrowStorageInvariants(Mode.Assert, rageQuitEscrow);
}

AccountingRecord memory post = _saveAccountingRecord(sender, signallingEscrow);
_establishEqualAccountingRecords(Mode.Assert, pre, post);
AccountingRecord memory post = this.saveAccountingRecord(sender, signallingEscrow);
this.establishEqualAccountingRecords(Mode.Assert, pre, post);
}
}
8 changes: 4 additions & 4 deletions test/kontrol/DualGovernanceSetUp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ contract DualGovernanceSetUp is StorageSetup {
// ?WORD: totalPooledEther
// ?WORD0: totalShares
// ?WORD1: shares[signallingEscrow]
_stEthStorageSetup(stEth, signallingEscrow);
this.stEthStorageSetup(stEth, signallingEscrow);

// ?STORAGE0
// ?WORD2: currentState
Expand All @@ -58,7 +58,7 @@ contract DualGovernanceSetUp is StorageSetup {
// ?WORD5: vetoSignallingReactivationTime
// ?WORD6: lastAdoptableStaateExitedAt
// ?WORD7: rageQuitRound
_dualGovernanceInitializeStorage(dualGovernance, signallingEscrow, rageQuitEscrow);
this.dualGovernanceInitializeStorage(dualGovernance, signallingEscrow, rageQuitEscrow);

// ?STORAGE1
// ?WORD8: lockedShares
Expand All @@ -69,7 +69,7 @@ contract DualGovernanceSetUp is StorageSetup {
// ?WORD13: rageQuitExtensionDelay
// ?WORD14: rageQuitWithdrawalsTimelock
// ?WORD15: rageQuitTimelockStartedAt
_signallingEscrowInitializeStorage(signallingEscrow, dualGovernance);
this.signallingEscrowInitializeStorage(signallingEscrow, dualGovernance);

// ?STORAGE2
// ?WORD16: lockedShares
Expand All @@ -80,7 +80,7 @@ contract DualGovernanceSetUp is StorageSetup {
// ?WORD21: rageQuitExtensionDelay
// ?WORD22: rageQuitWithdrawalsTimelock
// ?WORD23: rageQuitTimelockStartedAt
_rageQuitEscrowInitializeStorage(rageQuitEscrow, dualGovernance);
this.rageQuitEscrowInitializeStorage(rageQuitEscrow, dualGovernance);

// ?STORAGE3
kevm.symbolicStorage(address(timelock));
Expand Down
34 changes: 17 additions & 17 deletions test/kontrol/EscrowAccounting.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract EscrowAccountingTest is EscrowInvariants {
// ?WORD: totalPooledEther
// ?WORD0: totalShares
// ?WORD1: shares[escrow]
_stEthStorageSetup(stEth, escrow);
this.stEthStorageSetup(stEth, escrow);
}

function _setUpGenericState() public {
Expand All @@ -64,7 +64,7 @@ contract EscrowAccountingTest is EscrowInvariants {
// ?WORD9: rageQuitExtensionDelay
// ?WORD10: rageQuitWithdrawalsTimelock
// ?WORD11: rageQuitTimelockStartedAt
_escrowStorageSetup(escrow, DualGovernance(dualGovernanceAddress), EscrowState(currentState));
this.escrowStorageSetup(escrow, DualGovernance(dualGovernanceAddress), EscrowState(currentState));
}

function testRageQuitSupport() public {
Expand All @@ -82,9 +82,9 @@ contract EscrowAccountingTest is EscrowInvariants {

// Placeholder address to avoid complications with keccak of symbolic addresses
address sender = address(uint160(uint256(keccak256("sender"))));
_escrowInvariants(Mode.Assert, escrow);
_signallingEscrowInvariants(Mode.Assert, escrow);
_escrowUserInvariants(Mode.Assert, escrow, sender);
this.escrowInvariants(Mode.Assert, escrow);
this.signallingEscrowInvariants(Mode.Assert, escrow);
this.escrowUserInvariants(Mode.Assert, escrow, sender);
}

function testRequestWithdrawals(uint256 stEthAmount) public {
Expand All @@ -94,10 +94,10 @@ contract EscrowAccountingTest is EscrowInvariants {
address sender = address(uint160(uint256(keccak256("sender"))));
vm.assume(stEth.sharesOf(sender) < ethUpperBound);

AccountingRecord memory pre = _saveAccountingRecord(sender, escrow);
AccountingRecord memory pre = this.saveAccountingRecord(sender, escrow);

_escrowInvariants(Mode.Assume, escrow);
_escrowUserInvariants(Mode.Assume, escrow, sender);
this.escrowInvariants(Mode.Assume, escrow);
this.escrowUserInvariants(Mode.Assume, escrow, sender);

// Only request one withdrawal for simplicity
uint256[] memory stEthAmounts = new uint256[](1);
Expand All @@ -107,10 +107,10 @@ contract EscrowAccountingTest is EscrowInvariants {
escrow.requestWithdrawals(stEthAmounts);
vm.stopPrank();

_escrowInvariants(Mode.Assert, escrow);
_escrowUserInvariants(Mode.Assert, escrow, sender);
this.escrowInvariants(Mode.Assert, escrow);
this.escrowUserInvariants(Mode.Assert, escrow, sender);

AccountingRecord memory post = _saveAccountingRecord(sender, escrow);
AccountingRecord memory post = this.saveAccountingRecord(sender, escrow);
assert(post.userSharesLocked == pre.userSharesLocked - stEthAmount);
assert(post.totalSharesLocked == pre.totalSharesLocked - stEthAmount);
assert(post.userLastLockedTime == Timestamps.now());
Expand All @@ -123,11 +123,11 @@ contract EscrowAccountingTest is EscrowInvariants {

vm.assume(EscrowState(_getCurrentState(escrow)) == EscrowState.RageQuitEscrow);

_escrowInvariants(Mode.Assume, escrow);
this.escrowInvariants(Mode.Assume, escrow);

escrow.requestNextWithdrawalsBatch(maxBatchSize);

_escrowInvariants(Mode.Assert, escrow);
this.escrowInvariants(Mode.Assert, escrow);
}

function testClaimNextWithdrawalsBatch() public {
Expand All @@ -139,8 +139,8 @@ contract EscrowAccountingTest is EscrowInvariants {

vm.assume(EscrowState(_getCurrentState(escrow)) == EscrowState.RageQuitEscrow);

_escrowInvariants(Mode.Assume, escrow);
_escrowUserInvariants(Mode.Assume, escrow, sender);
this.escrowInvariants(Mode.Assume, escrow);
this.escrowUserInvariants(Mode.Assume, escrow, sender);

// Only claim one unstETH for simplicity
uint256 maxUnstETHIdsCount = 1;
Expand All @@ -149,7 +149,7 @@ contract EscrowAccountingTest is EscrowInvariants {
escrow.claimNextWithdrawalsBatch(maxUnstETHIdsCount);
vm.stopPrank();

_escrowInvariants(Mode.Assert, escrow);
_escrowUserInvariants(Mode.Assert, escrow, sender);
this.escrowInvariants(Mode.Assert, escrow);
this.escrowUserInvariants(Mode.Assert, escrow, sender);
}
}
6 changes: 3 additions & 3 deletions test/kontrol/EscrowInvariants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import "contracts/model/WstETHAdapted.sol";
import {StorageSetup} from "test/kontrol/StorageSetup.sol";

contract EscrowInvariants is StorageSetup {
function _escrowInvariants(Mode mode, Escrow escrow) internal view {
function escrowInvariants(Mode mode, Escrow escrow) external view {
IStETH stEth = escrow.ST_ETH();
LockedAssetsTotals memory totals = escrow.getLockedAssetsTotals();
_establish(mode, totals.stETHLockedShares <= stEth.sharesOf(address(escrow)));
Expand All @@ -32,7 +32,7 @@ contract EscrowInvariants is StorageSetup {
_establish(mode, uint8(currentState) < 3);
}

function _signallingEscrowInvariants(Mode mode, Escrow escrow) internal view {
function signallingEscrowInvariants(Mode mode, Escrow escrow) external view {
// TODO: Adapt to updated code
/*
if (_getCurrentState(escrow) == EscrowState.SignallingEscrow) {
Expand All @@ -44,7 +44,7 @@ contract EscrowInvariants is StorageSetup {
*/
}

function _escrowUserInvariants(Mode mode, Escrow escrow, address user) internal view {
function escrowUserInvariants(Mode mode, Escrow escrow, address user) external view {
_establish(
mode, escrow.getVetoerState(user).stETHLockedShares <= escrow.getLockedAssetsTotals().stETHLockedShares
);
Expand Down
Loading

0 comments on commit b6c977d

Please sign in to comment.