Skip to content

Commit

Permalink
remove unnecessary tests from both test_cmd and AssumeNoRevert.t.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
emo-eth committed Nov 2, 2024
1 parent 9df03fc commit 3800b7a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 110 deletions.
55 changes: 1 addition & 54 deletions crates/forge/tests/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2393,7 +2393,7 @@ contract Dummy {
assert!(dump_path.exists());
});

forgetest_init!(assume_no_revert_tests, |prj, cmd| {
forgetest_init!(test_assume_no_revert_with_data, |prj, cmd| {
prj.wipe_contracts();
let config = Config {
fuzz: { FuzzConfig { runs: 256, seed: Some(U256::from(100)), ..Default::default() } },
Expand Down Expand Up @@ -2475,52 +2475,6 @@ forgetest_init!(assume_no_revert_tests, |prj, cmd| {
reverter = new Reverter();
}
/// @dev Test that `assumeNoRevert` anticipates and correctly rejects a specific error selector
function testAssumeSelector(uint256 x) public view {
_vm.assumeNoRevert(Reverter.MyRevert.selector);
reverter.revertIf2(x);
}
/// @dev Test that `assumeNoRevert` anticipates and correctly rejects a specific error selector and data
function testAssumeWithDataSingle(uint256 x) public view {
_vm.assumeNoRevert(abi.encodeWithSelector(Reverter.RevertWithData.selector, 2));
reverter.revertWithDataIf2(x);
}
/// @dev Test that `assumeNoPartialRevert` anticipates and correctly rejects a specific error selector with any extra data
function testAssumeWithDataPartial(uint256 x) public view {
_vm.assumeNoPartialRevert(Reverter.RevertWithData.selector);
reverter.revertWithDataIf2(x);
}
/// @dev Test that `assumeNoRevert` assumptions are not cleared after a cheatcode call
function testAssumeNotClearedAfterCheatcodeCall(uint256 x) public {
_vm.assumeNoRevert(Reverter.MyRevert.selector);
_vm.warp(block.timestamp + 1000);
reverter.revertIf2(x);
}
/// @dev Test that `assumeNoRevert` correctly rejects two different error selectors
function testMultipleAssumesPasses(uint256 x) public view {
_vm.assumeNoRevert(abi.encodeWithSelector(Reverter.MyRevert.selector), address(reverter));
_vm.assumeNoRevert(abi.encodeWithSelector(Reverter.RevertWithData.selector, 3), address(reverter));
reverter.twoPossibleReverts(x);
}
/// @dev Test that `assumeNoPartialRevert` correctly interacts with `assumeNoRevert`
function testMultipleAssumes_Partial(uint256 x) public view {
_vm.assumeNoPartialRevert(Reverter.RevertWithData.selector);
_vm.assumeNoRevert(Reverter.MyRevert.selector);
reverter.twoPossibleReverts(x);
}
/// @dev Test that calling `assumeNoRevert` after `expectRevert` results in an error
function testExpectThenAssumeFails() public {
_vm._expectCheatcodeRevert();
_vm.assumeNoRevert();
reverter.revertIf2(1);
}
/// @dev Test that `assumeNoRevert` does not reject an unanticipated error selector
function testAssume_wrongSelector_fails(uint256 x) public view {
_vm.assumeNoRevert(Reverter.UnusedError.selector);
Expand Down Expand Up @@ -2598,13 +2552,6 @@ forgetest_init!(assume_no_revert_tests, |prj, cmd| {
);
}

match_test(&mut cmd, "testAssumeSelector").assert_success();
match_test(&mut cmd, "testAssumeWithDataSingle").assert_success();
match_test(&mut cmd, "testAssumeWithDataPartial").assert_success();
match_test(&mut cmd, "testMultipleAssumesPasses").assert_success();
match_test(&mut cmd, "testMultipleAssumes_Partial").assert_success();
match_test(&mut cmd, "testAssumeNotClearedAfterCheatcodeCall").assert_success();
match_test(&mut cmd, "testExpectThenAssumeFails");
assert_failure_contains(
&mut cmd,
"testAssume_wrongSelector_fails",
Expand Down
56 changes: 0 additions & 56 deletions testdata/default/cheats/AssumeNoRevert.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,60 +113,4 @@ contract ReverterTest is Test {
_vm.assumeNoRevert();
reverter.revertIf2(1);
}

/// @dev Test that `assumeNoRevert` does not reject an unanticipated error selector
function testAssume_wrongSelector_fails(uint256 x) public view {
_vm.assumeNoRevert(Reverter.UnusedError.selector);
reverter.revertIf2(x);
}

/// @dev Test that `assumeNoRevert` does not reject an unanticipated error with extra data
function testAssume_wrongData_fails(uint256 x) public view {
_vm.assumeNoRevert(abi.encodeWithSelector(Reverter.RevertWithData.selector, 3));
reverter.revertWithDataIf2(x);
}

/// @dev Test that `assumeNoRevert` correctly rejects an error selector from a different contract
function testAssumeWithReverter_fails(uint256 x) public view {
ReverterB subReverter = (reverter.subReverter());
_vm.assumeNoRevert(abi.encodeWithSelector(Reverter.MyRevert.selector), address(reverter));
subReverter.revertIf2(x);
}

/// @dev Test that `assumeNoRevert` correctly rejects one of two different error selectors when supplying a specific reverter
function testMultipleAssumes_OneWrong_fails(uint256 x) public view {
_vm.assumeNoRevert(abi.encodeWithSelector(Reverter.MyRevert.selector), address(reverter));
_vm.assumeNoRevert(abi.encodeWithSelector(Reverter.RevertWithData.selector, 4), address(reverter));
reverter.twoPossibleReverts(x);
}

/// @dev Test that `assumeNoRevert` assumptions are cleared after the first non-cheatcode external call
function testMultipleAssumesClearAfterCall_fails(uint256 x) public view {
_vm.assumeNoRevert(Reverter.MyRevert.selector);
_vm.assumeNoPartialRevert(Reverter.RevertWithData.selector, address(reverter));
reverter.twoPossibleReverts(x);

reverter.twoPossibleReverts(2);
}

// /// @dev Test that `assumeNoRevert` correctly rejects any error selector when no selector is provided
// function testMultipleAssumes_ThrowOnGenericNoRevert_fails(bytes4 selector) public view {
// _vm.assumeNoRevert();
// _vm.assumeNoRevert(selector);
// reverter.twoPossibleReverts(2);
// }

/// @dev Test that `assumeNoRevert` correctly rejects a generic assumeNoRevert call after any specific reason is provided
function testMultipleAssumes_ThrowOnGenericNoRevert_AfterSpecific_fails(bytes4 selector) public view {
_vm.assumeNoRevert(selector);
_vm.assumeNoRevert();
reverter.twoPossibleReverts(2);
}

/// @dev Test that calling `expectRevert` after `assumeNoRevert` results in an error
function testAssumeThenExpect_fails(uint256) public {
_vm.assumeNoRevert(Reverter.MyRevert.selector);
_vm.expectRevert();
reverter.revertIf2(1);
}
}

0 comments on commit 3800b7a

Please sign in to comment.