Skip to content

Commit 9cc7972

Browse files
committed
test(ContractTest): add fuzzing example
1 parent 8579809 commit 9cc7972

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8;
3+
4+
import {IERC20} from "openzeppelin/contracts/token/ERC20/IERC20.sol";
5+
6+
contract FuzzTest {
7+
/// @custom:ape-fuzzer-max-examples 200
8+
function test_with_fuzzing(uint256 a) external {
9+
require(a != 29678634502528050652056023465820843, "Found a rare bug!");
10+
}
11+
12+
/// @custom:ape-fuzz-deadline 1000
13+
function test_token_approvals(IERC20 token, uint256 amount) external {
14+
require(token.approve(msg.sender, amount));
15+
require(token.allowance(address(this), msg.sender) == amount);
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from ethereum.ercs import IERC20
2+
3+
@external
4+
def test_with_fuzzing(a: uint256):
5+
"""@custom:ape-fuzzer-max-examples 200"""
6+
assert a != 29678634502528050652056023465820843, "Found a rare bug!"
7+
8+
9+
@external
10+
def test_token_approvals(token: IERC20, amount: uint256):
11+
"""@custom:ape-fuzz-deadline 1000"""
12+
assert extcall token.approve(msg.sender, amount)
13+
assert staticcall token.allowance(self, msg.sender) == amount

0 commit comments

Comments
 (0)