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

Conversation

Thoralf-M
Copy link
Member

@Thoralf-M Thoralf-M commented Jun 20, 2025

Fix feature flags so cargo test without any additional features doesn't fail to compile anymore

Tested by running following commands in crates/iota-sdk-types

cargo test
cargo test --features schemars
cargo test --features proptest

@thibault-martinez thibault-martinez changed the title fix: fix feature flags for tests fix: feature flags for tests Jun 20, 2025
@Thoralf-M Thoralf-M force-pushed the fix/feature-flags branch from 89ee32d to 517224a Compare June 20, 2025 10:18
@Thoralf-M Thoralf-M force-pushed the fix/feature-flags branch from 29e3ad0 to b584ded Compare July 30, 2025 12:40
@Thoralf-M Thoralf-M marked this pull request as ready for review July 30, 2025 13:15
@Thoralf-M Thoralf-M force-pushed the fix/feature-flags branch from 21bd720 to e60ec91 Compare July 31, 2025 08:35
Base automatically changed from feat/more-bindings to sdk-bindings August 7, 2025 09:30
@thibault-martinez
Copy link
Member

What exactly is this PR doing?

@Thoralf-M
Copy link
Member Author

What exactly is this PR doing?

Adjust the feature gates so cargo test works fine without all features enabled
Right now if you run cargo test in iota-sdk-types it fails:

cargo test
   Compiling iota-sdk-types v0.0.1 (/home/t/Desktop/iota-rust-sdk/crates/iota-sdk-types)
error[E0432]: unresolved import `test_strategy`
   --> crates/iota-sdk-types/src/address.rs:286:9
    |
286 |     use test_strategy::proptest;
    |         ^^^^^^^^^^^^^ use of unresolved module or unlinked crate `test_strategy`
    |
    = help: if you wanted to use a crate named `test_strategy`, use `cargo add test_strategy` to add it to your `Cargo.toml`

error[E0432]: unresolved import `test_strategy`
   --> crates/iota-sdk-types/src/digest.rs:352:9
    |
352 |     use test_strategy::proptest;
    |         ^^^^^^^^^^^^^ use of unresolved module or unlinked crate `test_strategy`
    |
    = help: if you wanted to use a crate named `test_strategy`, use `cargo add test_strategy` to add it to your `Cargo.toml`

error[E0432]: unresolved import `test_strategy`
   --> crates/iota-sdk-types/src/crypto/mod.rs:138:17
    |
138 |             use test_strategy::proptest;
    |                 ^^^^^^^^^^^^^ use of unresolved module or unlinked crate `test_strategy`
...
152 | impl_base64_helper!(Base64Array32, Base64Display32, Base64FromStr32, test32, 32);
    | -------------------------------------------------------------------------------- in this macro invocation
    |
    = help: if you wanted to use a crate named `test_strategy`, use `cargo add test_strategy` to add it to your `Cargo.toml`
    = note: this error originates in the macro `impl_base64_helper` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0432]: unresolved import `test_strategy`
   --> crates/iota-sdk-types/src/crypto/mod.rs:138:17
    |
138 |             use test_strategy::proptest;
    |                 ^^^^^^^^^^^^^ use of unresolved module or unlinked crate `test_strategy`
...
153 | impl_base64_helper!(Base64Array33, Base64Display33, Base64FromStr33, test33, 33);
    | -------------------------------------------------------------------------------- in this macro invocation
    |
    = help: if you wanted to use a crate named `test_strategy`, use `cargo add test_strategy` to add it to your `Cargo.toml`
    = note: this error originates in the macro `impl_base64_helper` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0432]: unresolved import `test_strategy`
   --> crates/iota-sdk-types/src/crypto/mod.rs:138:17
    |
138 |             use test_strategy::proptest;
    |                 ^^^^^^^^^^^^^ use of unresolved module or unlinked crate `test_strategy`
...
154 | impl_base64_helper!(Base64Array34, Base64Display34, Base64FromStr34, test34, 34);
    | -------------------------------------------------------------------------------- in this macro invocation
    |
    = help: if you wanted to use a crate named `test_strategy`, use `cargo add test_strategy` to add it to your `Cargo.toml`
    = note: this error originates in the macro `impl_base64_helper` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0432]: unresolved import `test_strategy`
   --> crates/iota-sdk-types/src/crypto/mod.rs:138:17
    |
138 |             use test_strategy::proptest;
    |                 ^^^^^^^^^^^^^ use of unresolved module or unlinked crate `test_strategy`
...
155 | impl_base64_helper!(Base64Array48, Base64Display48, Base64FromStr48, test48, 48);
    | -------------------------------------------------------------------------------- in this macro invocation
    |
    = help: if you wanted to use a crate named `test_strategy`, use `cargo add test_strategy` to add it to your `Cargo.toml`
    = note: this error originates in the macro `impl_base64_helper` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0432]: unresolved import `test_strategy`
   --> crates/iota-sdk-types/src/crypto/mod.rs:138:17
    |
138 |             use test_strategy::proptest;
    |                 ^^^^^^^^^^^^^ use of unresolved module or unlinked crate `test_strategy`
...
156 | impl_base64_helper!(Base64Array64, Base64Display64, Base64FromStr64, test64, 64);
    | -------------------------------------------------------------------------------- in this macro invocation
    |
    = help: if you wanted to use a crate named `test_strategy`, use `cargo add test_strategy` to add it to your `Cargo.toml`
    = note: this error originates in the macro `impl_base64_helper` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of unresolved module or unlinked crate `proptest`
   --> crates/iota-sdk-types/src/crypto/zklogin.rs:366:9
    |
366 |     use proptest::prelude::*;
    |         ^^^^^^^^ use of unresolved module or unlinked crate `proptest`
    |
    = help: if you wanted to use a crate named `proptest`, use `cargo add proptest` to add it to your `Cargo.toml`

error[E0432]: unresolved import `test_strategy`
   --> crates/iota-sdk-types/src/crypto/mod.rs:138:17
    |
138 |             use test_strategy::proptest;
    |                 ^^^^^^^^^^^^^ use of unresolved module or unlinked crate `test_strategy`
...
157 | impl_base64_helper!(Base64Array96, Base64Display96, Base64FromStr96, test96, 96);
    | -------------------------------------------------------------------------------- in this macro invocation
    |
    = help: if you wanted to use a crate named `test_strategy`, use `cargo add test_strategy` to add it to your `Cargo.toml`
    = note: this error originates in the macro `impl_base64_helper` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of unresolved module or unlinked crate `proptest`
  --> crates/iota-sdk-types/src/u256.rs:75:9
   |
75 |     use proptest::prelude::*;
   |         ^^^^^^^^ use of unresolved module or unlinked crate `proptest`
   |
   = help: if you wanted to use a crate named `proptest`, use `cargo add proptest` to add it to your `Cargo.toml`

error[E0432]: unresolved import `test_strategy`
   --> crates/iota-sdk-types/src/crypto/zklogin.rs:367:9
    |
367 |     use test_strategy::proptest;
    |         ^^^^^^^^^^^^^ use of unresolved module or unlinked crate `test_strategy`
    |
    = help: if you wanted to use a crate named `test_strategy`, use `cargo add test_strategy` to add it to your `Cargo.toml`

error[E0432]: unresolved import `test_strategy`
  --> crates/iota-sdk-types/src/u256.rs:76:9
   |
76 |     use test_strategy::proptest;
   |         ^^^^^^^^^^^^^ use of unresolved module or unlinked crate `test_strategy`
   |
   = help: if you wanted to use a crate named `test_strategy`, use `cargo add test_strategy` to add it to your `Cargo.toml`

error: cannot find attribute `any` in this scope
   --> crates/iota-sdk-types/src/transaction/mod.rs:700:22
    |
700 |     #[cfg_attr(test, any(proptest::collection::size_range(0..=2).lift()))]
    |                      ^^^

error: cannot find attribute `strategy` in this scope
   --> crates/iota-sdk-types/src/u256.rs:124:11
    |
124 |         #[strategy(proptest::collection::vec(any::<u8>(), 1..=32))] bytes: Vec<u8>,
    |           ^^^^^^^^

error: cannot find attribute `strategy` in this scope
   --> crates/iota-sdk-types/src/u256.rs:113:11
    |
113 |         #[strategy(proptest::collection::vec(any::<u8>(), 33..1024))] bytes: Vec<u8>,
    |           ^^^^^^^^

error: cannot find attribute `strategy` in this scope
   --> crates/iota-sdk-types/src/crypto/zklogin.rs:397:11
    |
397 |         #[strategy(proptest::collection::vec(any::<u8>(), 1..=32))] bytes: Vec<u8>,
    |           ^^^^^^^^

error: cannot find attribute `strategy` in this scope
   --> crates/iota-sdk-types/src/crypto/zklogin.rs:386:11
    |
386 |         #[strategy(proptest::collection::vec(any::<u8>(), 33..1024))] bytes: Vec<u8>,
    |           ^^^^^^^^

warning: unused import: `super::*`
   --> crates/iota-sdk-types/src/crypto/validator.rs:169:9
    |
169 |     use super::*;
    |         ^^^^^^^^
    |
    = note: `#[warn(unused_imports)]` on by default

warning: unused import: `super::*`
   --> crates/iota-sdk-types/src/gas.rs:135:9
    |
135 |     use super::*;
    |         ^^^^^^^^

error[E0599]: no variant or associated item named `from_base64` found for enum `UserSignature` in the current scope
   --> crates/iota-sdk-types/src/crypto/passkey.rs:415:34
    |
415 |         let sig = UserSignature::from_base64(b64).unwrap();
    |                                  ^^^^^^^^^^^ variant or associated item not found in `UserSignature`
    |
   ::: crates/iota-sdk-types/src/crypto/signature.rs:195:1
    |
195 | pub enum UserSignature {
    | ---------------------- variant or associated item `from_base64` not found for this enum

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

@@ -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

@@ -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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants