Skip to content

Commit

Permalink
test: halmos stress test
Browse files Browse the repository at this point in the history
  • Loading branch information
wei3erHase committed Jul 5, 2024
1 parent fe45a5b commit a4ba28e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ yarn-error.log
node_modules
.DS_STORE
.vscode
.python-version

# Foundry files
cache
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"lint:sol-tests": "solhint -c .solhint.tests.json 'test/**/*.sol'",
"prepare": "husky install",
"test": "forge test -vvv",
"test:fuzz": "echidna test/invariants/fuzz/Greeter.t.sol --contract GreeterInvariant --corpus-dir test/invariants/fuzz/echidna_coverage/ --test-mode assertion",
"test:fuzz": "echidna test/invariants/fuzz/Greeter.t.sol --contract InvariantGreeter --corpus-dir test/invariants/fuzz/echidna_coverage/ --test-mode assertion",
"test:integration": "forge test --match-contract Integration -vvv",
"test:symbolic": "halmos",
"test:unit": "forge test --match-contract Unit -vvv",
Expand Down
11 changes: 9 additions & 2 deletions src/contracts/Greeter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ import {IGreeter} from 'interfaces/IGreeter.sol';

contract Greeter is IGreeter {
/**
* @notice Empty string for revert checks
* @notice Empty string signature for revert checks
* @dev result of doing keccak256(bytes(''))
*/
bytes32 internal constant _EMPTY_STRING = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;

/**
* @notice Forbidden string signature for revert checks
* @dev result of doing keccak256(bytes('SECRET_STRING'))
*/
bytes32 internal constant _FORBIDDEN_STRING = 0x8c917c6c6ed13e2a7bc9a85e333804f00ef06bf49d17d1140551e128758a022c;

/// @inheritdoc IGreeter
address public immutable OWNER;

Expand Down Expand Up @@ -49,7 +55,8 @@ contract Greeter is IGreeter {

/// @inheritdoc IGreeter
function setGreeting(string memory _greeting) public onlyOwner {
if (keccak256(bytes(_greeting)) == _EMPTY_STRING) {
bytes32 _greetingHash = keccak256(bytes(_greeting));
if (_greetingHash == _EMPTY_STRING || _greetingHash == _FORBIDDEN_STRING) {
revert Greeter_InvalidGreeting();
}

Expand Down

0 comments on commit a4ba28e

Please sign in to comment.