From c509966fb56120e17ced2c76f508cf4a78ba828e Mon Sep 17 00:00:00 2001 From: wadealexc Date: Thu, 16 Nov 2023 20:27:46 +0000 Subject: [PATCH] wip: example timewarp with modifier --- src/test/integration/IntegrationBase.t.sol | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/test/integration/IntegrationBase.t.sol b/src/test/integration/IntegrationBase.t.sol index a58bf488d..d9da50341 100644 --- a/src/test/integration/IntegrationBase.t.sol +++ b/src/test/integration/IntegrationBase.t.sol @@ -156,13 +156,9 @@ abstract contract IntegrationBase { uint[] memory removedShares, string memory err ) internal { - // Put current state on stack and revert to prior state to fetch - // previous operator shares - uint curState = global.warpToLast(); - uint[] memory prevShares = _getOperatorShares(operator, strategies); - global.warpToPresent(curState); // Snap back to reality - uint[] memory curShares = _getOperatorShares(operator, strategies); + // Use timewarp to get previous operator shares + uint[] memory prevShares = _getPrevOperatorShares(operator, strategies); // For each strategy, check (prev - removed == cur) for (uint i = 0; i < strategies.length; i++) { @@ -238,6 +234,19 @@ abstract contract IntegrationBase { return expectedShares; } + modifier timewarp() { + uint curState = global.warpToLast(); + _; + global.warpToPresent(curState); + } + + function _getPrevOperatorShares( + IUser operator, + IStrategy[] memory strategies + ) internal timewarp() view returns (uint[] memory) { + return _getOperatorShares(operator, strategies); + } + /// @dev Looks up each strategy and returns a list of the operator's shares function _getOperatorShares(IUser operator, IStrategy[] memory strategies) internal view returns (uint[] memory) { uint[] memory curShares = new uint[](strategies.length);