-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fuzzer tests with multiple attributes
- Loading branch information
1 parent
3a18d4c
commit ca0e40c
Showing
3 changed files
with
106 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use snforge_std::fuzzable::generate_arg; | ||
|
||
#[test] | ||
fn use_generate_arg_outside_fuzzer() { | ||
let random: usize = generate_arg(100, 999); | ||
assert(99 < random && random < 1000, 'value outside correct range'); | ||
} | ||
|
||
|
||
#[test] | ||
fn generate_arg_incorrect_range() { | ||
generate_arg(101, 100); | ||
} |
35 changes: 35 additions & 0 deletions
35
crates/forge/tests/data/fuzzing/tests/multiple_attributes.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use fuzzing::adder; | ||
use fuzzing::fib; | ||
|
||
#[available_gas(100)] | ||
#[fuzzer(runs: 50, seed: 123)] | ||
#[test] | ||
fn with_available_gas(a: usize) { | ||
fib(0, 1, 1000); | ||
assert(a >= 0, 'unsigned must be >= 0'); | ||
} | ||
|
||
|
||
#[fuzzer] | ||
#[test] | ||
#[should_panic(expected: 'panic message')] | ||
fn with_should_panic(a: u64) { | ||
let b: i128 = a.into(); | ||
assert(b < 0, 'panic message'); | ||
} | ||
|
||
#[available_gas(5)] | ||
#[should_panic(expected: 'panic message')] | ||
#[test] | ||
#[fuzzer(runs: 300)] | ||
fn with_both(a: felt252, b: u128) { | ||
let sum = adder(a, b.into()); | ||
assert(sum + 1 == 0, 'panic message'); | ||
} | ||
|
||
#[test] | ||
#[fuzzer(seed: 5)] | ||
#[ignore] | ||
fn ignored(a: felt252) { | ||
assert(1 == 1, ''); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters