Skip to content

Commit

Permalink
In UniStaker tests, remember depositors and surrogates and prevent ov…
Browse files Browse the repository at this point in the history
…erlap

Due to a recent, undocumented change in the Foundry fuzzer implementation, we are now
seeing test failures where the address of a yet-to-be-deployed DelegationSurrogate is
selected as a depositor. This breaks our tests. This is occuring despite the include_storage
flag being set to false, which previously was sufficient for preventing this edge case.

To accomodate this, we implement a test helper that remembers each depositor and surrogate as
they're chosen and deployed respectively, and assures there is no overlap between the two
groups of addresses.
  • Loading branch information
apbendi committed Mar 22, 2024
1 parent 489f4d6 commit 1573451
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/UniStaker.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ contract UniStakerTest is Test, PercentAssertions {
event RewardNotifierSet(address indexed account, bool isEnabled);
event AdminSet(address indexed oldAdmin, address indexed newAdmin);

mapping(DelegationSurrogate surrogate => bool isKnown) isKnownSurrogate;
mapping(address depositor => bool isKnown) isKnownDepositor;

function setUp() public {
// Set the block timestamp to an arbitrary value to avoid introducing assumptions into tests
// based on a starting timestamp of 0, which is the default.
Expand Down Expand Up @@ -75,6 +78,20 @@ contract UniStakerTest is Test, PercentAssertions {
_boundedStakeAmount = bound(_stakeAmount, 0.1e18, 25_000_000e18);
}

// Remember each depositor and surrogate (as they're deployed) and ensure that there is
// no overlap between them. This is to prevent the fuzzer from selecting a surrogate as a
// depositor or vice versa.
function _assumeSafeDepositorAndSurrogate(address _depositor, address _delegatee) internal {
DelegationSurrogate _surrogate = uniStaker.surrogates(_delegatee);
isKnownDepositor[_depositor] = true;
isKnownSurrogate[_surrogate] = true;

vm.assume(
(!isKnownSurrogate[DelegationSurrogate(_depositor)])
&& (!isKnownDepositor[address(_surrogate)])
);
}

function _stake(address _depositor, uint256 _amount, address _delegatee)
internal
returns (UniStaker.DepositIdentifier _depositId)
Expand All @@ -85,6 +102,9 @@ contract UniStakerTest is Test, PercentAssertions {
govToken.approve(address(uniStaker), _amount);
_depositId = uniStaker.stake(_amount, _delegatee);
vm.stopPrank();

// Called after the stake so the surrogate will exist
_assumeSafeDepositorAndSurrogate(_depositor, _delegatee);
}

function _stake(address _depositor, uint256 _amount, address _delegatee, address _beneficiary)
Expand All @@ -97,6 +117,9 @@ contract UniStakerTest is Test, PercentAssertions {
govToken.approve(address(uniStaker), _amount);
_depositId = uniStaker.stake(_amount, _delegatee, _beneficiary);
vm.stopPrank();

// Called after the stake so the surrogate will exist
_assumeSafeDepositorAndSurrogate(_depositor, _delegatee);
}

function _fetchDeposit(UniStaker.DepositIdentifier _depositId)
Expand Down

0 comments on commit 1573451

Please sign in to comment.