Skip to content

fix: feature flags for tests #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: sdk-bindings
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion crates/iota-crypto/src/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,12 @@ mod keypair {
}
}

#[cfg(test)]
#[cfg(all(
test,
feature = "ed25519",
feature = "secp256k1",
feature = "secp256r1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could have put the specific features on the specific tests, otherwise tests are only run together

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this initially, but it ends up in a big mess and at the end also doesn't really test much anymore, because all the tests contain parts of the other types

))]
mod test {
use test_strategy::proptest;

Expand Down
2 changes: 1 addition & 1 deletion crates/iota-sdk-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ serde = [
schemars = ["serde", "dep:schemars", "dep:serde_json"]
rand = ["dep:rand_core"]
hash = ["dep:blake2"]
proptest = ["dep:proptest", "dep:test-strategy", "serde"]
proptest = ["dep:proptest", "dep:test-strategy", "serde", "schemars"]

[dependencies]
base64ct = { version = "1.6.0", features = ["alloc"] }
Expand Down
2 changes: 2 additions & 0 deletions crates/iota-sdk-types/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ impl schemars::JsonSchema for Address {

#[cfg(test)]
mod test {
#[cfg(feature = "proptest")]
use test_strategy::proptest;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test as test;
Expand All @@ -309,6 +310,7 @@ mod test {
}

#[proptest]
#[cfg(feature = "proptest")]
fn roundtrip_display_fromstr(address: Address) {
let s = address.to_string();
let a = s.parse::<Address>().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-sdk-types/src/crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ macro_rules! impl_base64_helper {
}
}

#[cfg(test)]
#[cfg(all(feature = "proptest", test))]
mod $test_module {
use test_strategy::proptest;

Expand Down
2 changes: 1 addition & 1 deletion crates/iota-sdk-types/src/crypto/passkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ impl proptest::arbitrary::Arbitrary for PasskeyAuthenticator {
}
}

#[cfg(test)]
#[cfg(all(feature = "serde", test))]
mod tests {
use crate::UserSignature;

Expand Down
2 changes: 2 additions & 0 deletions crates/iota-sdk-types/src/crypto/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,13 +684,15 @@ mod serialization {
#[cfg(test)]
mod test {
use base64ct::{Base64, Encoding};
#[cfg(feature = "proptest")]
use test_strategy::proptest;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test as test;

use super::*;

#[proptest]
#[cfg(feature = "proptest")]
fn roundtrip_signature_scheme(scheme: SignatureScheme) {
assert_eq!(Ok(scheme), SignatureScheme::from_byte(scheme.to_u8()));
}
Expand Down
3 changes: 1 addition & 2 deletions crates/iota-sdk-types/src/crypto/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,13 @@ pub struct ValidatorSignature {
pub signature: Bls12381Signature,
}

#[cfg(test)]
#[cfg(all(feature = "serde", test))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this actually failing? Seems a bit annoying if we ever add more tests, we may forget to remove the serde feature

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not failing, but without the serde feature there are warnings for unused imports

mod test {
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test as test;

use super::*;

#[cfg(feature = "serde")]
#[test]
fn aggregated_signature_fixture() {
use base64ct::{Base64, Encoding};
Expand Down
6 changes: 6 additions & 0 deletions crates/iota-sdk-types/src/crypto/zklogin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,14 @@ impl std::str::FromStr for Bn254FieldElement {

#[cfg(test)]
mod test {
#[cfg(feature = "proptest")]
use std::str::FromStr;

#[cfg(feature = "proptest")]
use num_bigint::BigUint;
#[cfg(feature = "proptest")]
use proptest::prelude::*;
#[cfg(feature = "proptest")]
use test_strategy::proptest;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test as test;
Expand All @@ -381,6 +385,7 @@ mod test {
assert_eq!(seed.unpadded(), [1; 31].as_slice());
}

#[cfg(feature = "proptest")]
#[proptest]
fn dont_crash_on_large_inputs(
#[strategy(proptest::collection::vec(any::<u8>(), 33..1024))] bytes: Vec<u8>,
Expand All @@ -392,6 +397,7 @@ mod test {
let _ = Bn254FieldElement::from_str(&radix10);
}

#[cfg(feature = "proptest")]
#[proptest]
fn valid_address_seeds(
#[strategy(proptest::collection::vec(any::<u8>(), 1..=32))] bytes: Vec<u8>,
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-sdk-types/src/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl_digest!(EffectsAuxiliaryDataDigest);
// serialized
pub type SigningDigest = [u8; Digest::LENGTH];

#[cfg(test)]
#[cfg(all(feature = "proptest", test))]
mod test {
use test_strategy::proptest;

Expand Down
3 changes: 1 addition & 2 deletions crates/iota-sdk-types/src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,14 @@ impl std::fmt::Display for GasCostSummary {
}
}

#[cfg(test)]
#[cfg(all(feature = "serde", test))]
mod test {
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test as test;

use super::*;

#[test]
#[cfg(feature = "serde")]
fn formats() {
let actual = GasCostSummary {
computation_cost: 42,
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-sdk-types/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ impl crate::ObjectId {
}
}

#[cfg(test)]
#[cfg(all(test, feature = "proptest"))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not asking you to change but I guess I would have preferred putting them on individual tests, even if redundant.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why though if all the tests inside need it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, you also need the features for the individual imports then if you don't want the warnings for unused imports

mod test {
use test_strategy::proptest;

Expand Down
2 changes: 1 addition & 1 deletion crates/iota-sdk-types/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ pub struct ChangeEpochV2 {
/// write out the modules below. Modules are provided with the version they
/// will be upgraded to, their modules in serialized form (which include
/// their package ID), and a list of their transitive dependencies.
#[cfg_attr(test, any(proptest::collection::size_range(0..=2).lift()))]
#[cfg_attr(all(test, feature = "proptest"), any(proptest::collection::size_range(0..=2).lift()))]
pub system_packages: Vec<SystemPackage>,
}

Expand Down
6 changes: 6 additions & 0 deletions crates/iota-sdk-types/src/u256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@ const ASSERT_ENDIANNESS: () = {

#[cfg(test)]
mod test {
#[cfg(feature = "proptest")]
use std::str::FromStr;

#[cfg(feature = "proptest")]
use num_bigint::BigUint;
#[cfg(feature = "proptest")]
use proptest::prelude::*;
#[cfg(feature = "proptest")]
use test_strategy::proptest;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test as test;
Expand Down Expand Up @@ -108,6 +112,7 @@ mod test {
assert_eq!(one_platform, U256::from_be(U256::from_digits(one_be)));
}

#[cfg(feature = "proptest")]
#[proptest]
fn dont_crash_on_large_inputs(
#[strategy(proptest::collection::vec(any::<u8>(), 33..1024))] bytes: Vec<u8>,
Expand All @@ -119,6 +124,7 @@ mod test {
let _ = U256::from_str_radix(&radix10, 10);
}

#[cfg(feature = "proptest")]
#[proptest]
fn valid_u256_strings(
#[strategy(proptest::collection::vec(any::<u8>(), 1..=32))] bytes: Vec<u8>,
Expand Down