Skip to content

Commit

Permalink
feat: make "arbitrary" feature enable proptest features (#1355)
Browse files Browse the repository at this point in the history
* Add proptest feature

* Update changelog

* Revert star import change

* Unify "proptest" feature with "arbitrary" and doc

* Update updated changelog

---------

Co-authored-by: Pedro Fontana <fontana.pedro93@gmail.com>
  • Loading branch information
MegaRedHand and pefontana authored Aug 4, 2023
1 parent 2191b5f commit e763cef
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#### Upcoming Changes

* feat: make *arbitrary* feature also enable a `proptest::arbitrary::Arbitrary` implementation for `Felt252` [#1355](https://github.com/lambdaclass/cairo-vm/pull/1355)

* fix: correctly display invalid signature error message [#1361](https://github.com/lambdaclass/cairo-vm/pull/1361)

#### [0.8.5] - 2023-7-31
Expand Down
3 changes: 2 additions & 1 deletion felt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ default = ["std"]
std = []
alloc = []
lambdaworks-felt = ["dep:lambdaworks-math"]
arbitrary = ["dep:arbitrary", "num-bigint/arbitrary"]
arbitrary = ["dep:arbitrary", "num-bigint/arbitrary", "dep:proptest"]

[dependencies]
num-integer = { version = "0.1.45", default-features = false }
Expand All @@ -25,6 +25,7 @@ lazy_static = { version = "1.4.0", default-features = false, features = [
serde = { version = "1.0", features = ["derive"], default-features = false }
lambdaworks-math = { version = "0.1.2", default-features = false, optional = true }
arbitrary = { version = "1.3.0", features = ["derive"], optional = true }
proptest = { version = "1.2.0", optional = true }

[dev-dependencies]
proptest = "1.2.0"
Expand Down
12 changes: 8 additions & 4 deletions felt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
#[cfg(all(not(feature = "std"), feature = "alloc"))]
pub extern crate alloc;

#[cfg(all(test, not(feature = "lambdaworks-felt")))]
mod arbitrary_bigint_felt;
#[cfg(all(test, feature = "lambdaworks-felt"))]
mod arbitrary_lambdaworks;
#[cfg(not(feature = "lambdaworks-felt"))]
mod bigint_felt;
#[cfg(not(feature = "lambdaworks-felt"))]
Expand Down Expand Up @@ -36,3 +32,11 @@ impl fmt::Display for ParseFeltError {
write!(f, "{ParseFeltError:?}")
}
}

#[cfg(any(feature = "arbitrary", test))]
#[cfg_attr(feature = "lambdaworks-felt", path = "arbitrary_lambdaworks.rs")]
#[cfg_attr(not(feature = "lambdaworks-felt"), path = "arbitrary_bigint_felt.rs")]
/// [`proptest::arbitrary::Arbitrary`] implementation for [`Felt252`], and [`Strategy`] generating functions.
///
/// Not to be confused with [`arbitrary::Arbitrary`], which is also enabled by the _arbitrary_ feature.
pub mod arbitrary;
2 changes: 1 addition & 1 deletion felt/src/lib_bigint_felt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ assert_felt_impl!(Felt252);
#[cfg(test)]
mod test {
use super::*;
use crate::{arbitrary_bigint_felt::nonzero_felt252, PRIME_STR};
use crate::{arbitrary::nonzero_felt252, PRIME_STR};
use core::cmp;
use rstest::rstest;

Expand Down
2 changes: 1 addition & 1 deletion felt/src/lib_lambdaworks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ mod test {
use core::cmp;

use super::*;
use crate::{arbitrary_lambdaworks::nonzero_felt252, PRIME_STR};
use crate::{arbitrary::nonzero_felt252, PRIME_STR};
use num_integer::Integer;
use rstest::rstest;

Expand Down

0 comments on commit e763cef

Please sign in to comment.