Skip to content

Instantly share code, notes, and snippets.

@ecmendenhall
Created April 5, 2022 18:16
Show Gist options
  • Save ecmendenhall/abd66ddbbb797f286e0bcd45317b22b5 to your computer and use it in GitHub Desktop.
Save ecmendenhall/abd66ddbbb797f286e0bcd45317b22b5 to your computer and use it in GitHub Desktop.
Fuzz test without error message
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.10;
import "ds-test/test.sol";
contract ExampleTest is DSTest {
function test_fuzz_reverts_with_message(uint256 n) public {
revert("message");
assertEq(n, 1);
}
function test_fuzz_reverts_without_message(uint256 n) public {
revert();
assertEq(n, 1);
}
function test_unit_reverts_with_message() public {
revert("message");
uint256 two = 2;
assertEq(two, 1);
}
function test_unit_reverts_without_message() public {
revert();
uint256 two = 2;
assertEq(two, 1);
}
}
Running 4 tests for src/test/Example.t.sol:ExampleTest
[FAIL. Reason: message. Counterexample: calldata=0x13f37b520000000000000000000000000000000000000000000000000000000000000000, args=[0]] test_fuzz_reverts_with_message(uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Counterexample: calldata=0x3d4a65530000000000000000000000000000000000000000000000000000000000000000, args=[0]] test_fuzz_reverts_without_message(uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: message] test_unit_reverts_with_message() (gas: 290)
[FAIL. Reason: Revert] test_unit_reverts_without_message() (gas: 151)
Test result: FAILED. 0 passed; 4 failed; finished in 173.83µs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment