Skip to content

Commit

Permalink
Fix useMultipleSetup (#17)
Browse files Browse the repository at this point in the history
Reverting to the first snapshot in the list, also implicitly resets the array of snapShotIds to Only have one member
  • Loading branch information
tom2o17 authored Feb 5, 2024
1 parent 71d0d47 commit 65b1f01
Showing 2 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/FraxTest.sol
Original file line number Diff line number Diff line change
@@ -12,16 +12,17 @@ abstract contract FraxTest is VmHelper, Test {
modifier useMultipleSetupFunctions() {
if (snapShotIds.length == 0) _;
for (uint256 i = 0; i < snapShotIds.length; i++) {
uint256 _originalSnapshotId = vm.snapshot();
if (!vm.revertTo(snapShotIds[i])) {
revert VmDidNotRevert(snapShotIds[i]);
}
_;
vm.clearMockedCalls();
vm.revertTo(_originalSnapshotId);
}
}

function addSetupFunctions(function()[] memory _setupFunctions) internal {
uint256 _originalSnapshotId = vm.snapshot();
for (uint256 i = 0; i < _setupFunctions.length; i++) {
_setupFunctions[i]();
snapShotIds.push(vm.snapshot());
31 changes: 31 additions & 0 deletions test/TestMultipleSetup.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: ISC
pragma solidity >=0.8.0;

import "../src/FraxTest.sol";

contract TestMultipleSetup is FraxTest {
uint256 value;

function initializeValueOne() public {
value = 25;
}

function initializeValueTwo() public {
value = 5;
}

function initializeValueThree() public {
value = 10;
}

function setUp() public {
setupFunctions.push(initializeValueOne);
setupFunctions.push(initializeValueTwo);
setupFunctions.push(initializeValueThree);
addSetupFunctions(setupFunctions);
}

function testFailAssertValue() public useMultipleSetupFunctions {

This comment has been minimized.

Copy link
@pegahcarter

pegahcarter Feb 5, 2024

Contributor

What should value be equal to in this test?

This comment has been minimized.

Copy link
@tom2o17

tom2o17 Feb 6, 2024

Author Collaborator

25, 5, and 10 via the useMultipleSetupFunctions modifier

Consequently this test case should fail assuming that the alternative states are being accessed correctly.

assertEq(value, 5);
}
}

0 comments on commit 65b1f01

Please sign in to comment.