Skip to content

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

}

#[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

}

#[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

Copy link
Contributor

@Alex6323 Alex6323 left a comment

Choose a reason for hiding this comment

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

How about cleanly separating regular tests and proptests by having each of them separated by module, so we have a regular test module and a proptest module? Then you can disable/enable the proptests with a single cfg attribute instead of repeating it for many imports in the combined module.

howjmay pushed a commit to howjmay/iota-rust-sdk that referenced this pull request Oct 7, 2025
@Thoralf-M Thoralf-M marked this pull request as draft October 16, 2025 14:15
@Thoralf-M Thoralf-M changed the base branch from sdk-bindings to develop November 5, 2025 13:53
@Thoralf-M Thoralf-M changed the title fix: feature flags for tests fix(iota-sdk-types): feature flags for tests Nov 5, 2025
@Thoralf-M Thoralf-M marked this pull request as ready for review November 5, 2025 13:56
@Thoralf-M Thoralf-M requested a review from a team as a code owner November 5, 2025 13:56
@Thoralf-M
Copy link
Member Author

How about cleanly separating regular tests and proptests by having each of them separated by module, so we have a regular test module and a proptest module? Then you can disable/enable the proptests with a single cfg attribute instead of repeating it for many imports in the combined module.

Changed it

@thibault-martinez
Copy link
Member

Right now if you run cargo test in iota-sdk-types it fails:

It still fails

@Thoralf-M
Copy link
Member Author

Right now if you run cargo test in iota-sdk-types it fails:

It still fails

Not for me, what do you do?

iota-rust-sdk/crates/iota-sdk-types   fix/feature-flags ±  cargo test
   Compiling iota-sdk-types v0.0.1-alpha.1 (/home/t/iota-rust-sdk/crates/iota-sdk-types)
    Finished `test` profile [unoptimized + debuginfo] target(s) in 1.56s
     Running unittests src/lib.rs (/home/t/iota-rust-sdk/target/debug/deps/iota_sdk_types-d036a0a8675ca48e)

running 11 tests
test address::tests::hex_parsing ... ok
test crypto::zklogin::tests::unpadded_slice ... ok
test iota_names::name::tests::invalid_inputs ... ok
test iota_names::name::tests::outputs ... ok
test iota_names::name::tests::name_service_outputs ... ok
test iota_names::name::tests::parent_extraction ... ok
test iota_names::registry::tests::expirations ... ok
test u256::tests::endianness ... ok
test type_tag::parse::tests::test_type_tag ... ok
test type_tag::parse::tests::test_parse_valid_struct_type ... ok
test type_tag::parse::tests::test_parse_struct_tag_with_type_names ... ok

test result: ok. 11 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.23s

   Doc-tests iota_sdk_types

running 3 tests
test crates/iota-sdk-types/src/address.rs - address::Address (line 13) ... ok
test crates/iota-sdk-types/src/iota_names/name.rs - iota_names::name::Name::num_labels (line 129) ... ok
test crates/iota-sdk-types/src/iota_names/name.rs - iota_names::name::Name::parent (line 89) ... ok

test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.14s

@thibault-martinez
Copy link
Member

thibault-martinez commented Nov 7, 2025

I tested in the crypto crate sorry

thibault@Thibaults-MacBook-Pro-2 ~/i/i/c/iota-sdk-crypto (fix/feature-flags) [101]> cargo test
   Compiling iota-sdk-crypto v0.0.1-alpha.0 (/Users/thibault/iota/iota-rust-sdk/crates/iota-sdk-crypto)
error[E0432]: unresolved imports `crate::ed25519`, `crate::secp256k1`, `crate::secp256r1`
   --> crates/iota-sdk-crypto/src/lib.rs:362:9
    |
362 |         ed25519::Ed25519PrivateKey, secp256k1::Secp256k1PrivateKey, secp256r1::Secp256r1PrivateKey,
    |         ^^^^^^^                     ^^^^^^^^^                       ^^^^^^^^^ could not find `secp256r1` in the crate root
    |         |                           |
    |         |                           could not find `secp256k1` in the crate root
    |         could not find `ed25519` in the crate root
    |
note: found an item that was configured out
   --> crates/iota-sdk-crypto/src/lib.rs:44:9
    |
 42 | #[cfg(feature = "ed25519")]
    |       ------------------- the item is gated behind the `ed25519` feature
 43 | #[cfg_attr(doc_cfg, doc(cfg(feature = "ed25519")))]
 44 | pub mod ed25519;
    |         ^^^^^^^
note: found an item that was configured out
   --> crates/iota-sdk-crypto/src/lib.rs:48:9
    |
 46 | #[cfg(feature = "secp256k1")]
    |       --------------------- the item is gated behind the `secp256k1` feature
 47 | #[cfg_attr(doc_cfg, doc(cfg(feature = "secp256k1")))]
 48 | pub mod secp256k1;
    |         ^^^^^^^^^
note: found an item that was configured out
   --> crates/iota-sdk-crypto/src/lib.rs:52:9
    |
 50 | #[cfg(feature = "secp256r1")]
    |       --------------------- the item is gated behind the `secp256r1` feature
 51 | #[cfg_attr(doc_cfg, doc(cfg(feature = "secp256r1")))]
 52 | pub mod secp256r1;
    |         ^^^^^^^^^

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

For more information about this error, try `rustc --explain E0432`.
warning: `iota-sdk-crypto` (lib test) generated 1 warning
error: could not compile `iota-sdk-crypto` (lib test) due to 1 previous error; 1 warning emitted
thibault@Thibaults-MacBook-Pro-2 ~/i/i/c/iota-sdk-crypto (fix/feature-flags) [101]>

@Thoralf-M Thoralf-M changed the title fix(iota-sdk-types): feature flags for tests fix(crates): feature flags for tests Nov 7, 2025
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.

5 participants