From 5576a757c6e6fc0bc97fbe2f8accef5d4c1e74ed Mon Sep 17 00:00:00 2001 From: Thoralf-M Date: Wed, 5 Nov 2025 15:52:40 +0200 Subject: [PATCH 1/3] fix(iota-sdk-types): fix feature flags for tests --- crates/iota-sdk-types/Cargo.toml | 2 +- crates/iota-sdk-types/src/address.rs | 22 +++--- crates/iota-sdk-types/src/crypto/mod.rs | 2 +- crates/iota-sdk-types/src/crypto/passkey.rs | 1 + crates/iota-sdk-types/src/crypto/signature.rs | 2 + crates/iota-sdk-types/src/crypto/zklogin.rs | 62 +++++++++-------- crates/iota-sdk-types/src/digest.rs | 2 +- crates/iota-sdk-types/src/gas.rs | 3 +- crates/iota-sdk-types/src/hash.rs | 2 +- crates/iota-sdk-types/src/move_package.rs | 3 +- crates/iota-sdk-types/src/transaction/mod.rs | 4 +- crates/iota-sdk-types/src/u256.rs | 68 ++++++++++--------- crates/iota-sdk-types/src/validator.rs | 3 +- 13 files changed, 98 insertions(+), 78 deletions(-) diff --git a/crates/iota-sdk-types/Cargo.toml b/crates/iota-sdk-types/Cargo.toml index a7a5f0366..6da17636e 100644 --- a/crates/iota-sdk-types/Cargo.toml +++ b/crates/iota-sdk-types/Cargo.toml @@ -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 = { workspace = true, features = ["alloc"] } diff --git a/crates/iota-sdk-types/src/address.rs b/crates/iota-sdk-types/src/address.rs index 1878b0b52..60f172759 100644 --- a/crates/iota-sdk-types/src/address.rs +++ b/crates/iota-sdk-types/src/address.rs @@ -284,7 +284,20 @@ impl schemars::JsonSchema for Address { #[cfg(test)] mod tests { - use test_strategy::proptest; + #[cfg(feature = "proptest")] + mod proptests { + use test_strategy::proptest; + + use super::*; + + #[proptest] + fn roundtrip_display_fromstr(address: Address) { + let s = address.to_string(); + let a = s.parse::
().unwrap(); + assert_eq!(address, a); + } + } + #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::wasm_bindgen_test as test; @@ -308,11 +321,4 @@ mod tests { let a: Address = serde_json::from_str("\"0x2\"").unwrap(); println!("{a}"); } - - #[proptest] - fn roundtrip_display_fromstr(address: Address) { - let s = address.to_string(); - let a = s.parse::
().unwrap(); - assert_eq!(address, a); - } } diff --git a/crates/iota-sdk-types/src/crypto/mod.rs b/crates/iota-sdk-types/src/crypto/mod.rs index 091131a46..c5f583129 100644 --- a/crates/iota-sdk-types/src/crypto/mod.rs +++ b/crates/iota-sdk-types/src/crypto/mod.rs @@ -129,7 +129,7 @@ macro_rules! impl_base64_helper { } } - #[cfg(test)] + #[cfg(all(test, feature = "proptest"))] mod $test_module { use test_strategy::proptest; diff --git a/crates/iota-sdk-types/src/crypto/passkey.rs b/crates/iota-sdk-types/src/crypto/passkey.rs index d0d9a084e..c2de91880 100644 --- a/crates/iota-sdk-types/src/crypto/passkey.rs +++ b/crates/iota-sdk-types/src/crypto/passkey.rs @@ -407,6 +407,7 @@ impl proptest::arbitrary::Arbitrary for PasskeyAuthenticator { } } +#[cfg(feature = "serde")] #[cfg(test)] mod tests { use crate::UserSignature; diff --git a/crates/iota-sdk-types/src/crypto/signature.rs b/crates/iota-sdk-types/src/crypto/signature.rs index 75d267162..7c16cb575 100644 --- a/crates/iota-sdk-types/src/crypto/signature.rs +++ b/crates/iota-sdk-types/src/crypto/signature.rs @@ -822,6 +822,7 @@ mod serialization { #[cfg(test)] mod tests { use base64ct::{Base64, Encoding}; + #[cfg(feature = "proptest")] use test_strategy::proptest; #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::wasm_bindgen_test as test; @@ -829,6 +830,7 @@ mod serialization { use super::*; #[proptest] + #[cfg(feature = "proptest")] fn roundtrip_signature_scheme(scheme: SignatureScheme) { assert_eq!(Ok(scheme), SignatureScheme::from_byte(scheme.to_u8())); } diff --git a/crates/iota-sdk-types/src/crypto/zklogin.rs b/crates/iota-sdk-types/src/crypto/zklogin.rs index ac1fa8090..0d8e97343 100644 --- a/crates/iota-sdk-types/src/crypto/zklogin.rs +++ b/crates/iota-sdk-types/src/crypto/zklogin.rs @@ -652,11 +652,41 @@ impl std::str::FromStr for Bn254FieldElement { #[cfg(test)] mod tests { - use std::str::FromStr; + #[cfg(feature = "proptest")] + mod proptests { + use std::str::FromStr; + + use num_bigint::BigUint; + use proptest::prelude::*; + use test_strategy::proptest; + + use super::*; + + #[proptest] + fn dont_crash_on_large_inputs( + #[strategy(proptest::collection::vec(any::(), 33..1024))] bytes: Vec, + ) { + let big_int = BigUint::from_bytes_be(&bytes); + let radix10 = big_int.to_str_radix(10); + + // doesn't crash + let _ = Bn254FieldElement::from_str(&radix10); + } + + #[proptest] + fn valid_address_seeds( + #[strategy(proptest::collection::vec(any::(), 1..=32))] bytes: Vec, + ) { + let big_int = BigUint::from_bytes_be(&bytes); + let radix10 = big_int.to_str_radix(10); + + let seed = Bn254FieldElement::from_str(&radix10).unwrap(); + assert_eq!(radix10, seed.to_string()); + // Ensure unpadded doesn't crash + seed.unpadded(); + } + } - use num_bigint::BigUint; - use proptest::prelude::*; - use test_strategy::proptest; #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::wasm_bindgen_test as test; @@ -672,30 +702,6 @@ mod tests { seed.0[0] = 0; assert_eq!(seed.unpadded(), [1; 31].as_slice()); } - - #[proptest] - fn dont_crash_on_large_inputs( - #[strategy(proptest::collection::vec(any::(), 33..1024))] bytes: Vec, - ) { - let big_int = BigUint::from_bytes_be(&bytes); - let radix10 = big_int.to_str_radix(10); - - // doesn't crash - let _ = Bn254FieldElement::from_str(&radix10); - } - - #[proptest] - fn valid_address_seeds( - #[strategy(proptest::collection::vec(any::(), 1..=32))] bytes: Vec, - ) { - let big_int = BigUint::from_bytes_be(&bytes); - let radix10 = big_int.to_str_radix(10); - - let seed = Bn254FieldElement::from_str(&radix10).unwrap(); - assert_eq!(radix10, seed.to_string()); - // Ensure unpadded doesn't crash - seed.unpadded(); - } } #[cfg(feature = "serde")] diff --git a/crates/iota-sdk-types/src/digest.rs b/crates/iota-sdk-types/src/digest.rs index ff6fceec4..f55909cc7 100644 --- a/crates/iota-sdk-types/src/digest.rs +++ b/crates/iota-sdk-types/src/digest.rs @@ -215,7 +215,7 @@ impl std::error::Error for DigestParseError {} // serialized pub type SigningDigest = [u8; Digest::LENGTH]; -#[cfg(test)] +#[cfg(all(test, feature = "proptest"))] mod tests { use test_strategy::proptest; diff --git a/crates/iota-sdk-types/src/gas.rs b/crates/iota-sdk-types/src/gas.rs index ae6fb45e7..687ec37dd 100644 --- a/crates/iota-sdk-types/src/gas.rs +++ b/crates/iota-sdk-types/src/gas.rs @@ -123,7 +123,7 @@ impl std::fmt::Display for GasCostSummary { } } -#[cfg(test)] +#[cfg(all(test, feature = "serde"))] mod tests { #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::wasm_bindgen_test as test; @@ -131,7 +131,6 @@ mod tests { use super::*; #[test] - #[cfg(feature = "serde")] fn formats() { let actual = GasCostSummary { computation_cost: 42, diff --git a/crates/iota-sdk-types/src/hash.rs b/crates/iota-sdk-types/src/hash.rs index 54a66ed51..037541c3a 100644 --- a/crates/iota-sdk-types/src/hash.rs +++ b/crates/iota-sdk-types/src/hash.rs @@ -522,7 +522,7 @@ impl crate::ObjectId { } } -#[cfg(test)] +#[cfg(all(test, feature = "proptest"))] mod tests { use test_strategy::proptest; diff --git a/crates/iota-sdk-types/src/move_package.rs b/crates/iota-sdk-types/src/move_package.rs index 70cfe77bf..a608dcf66 100644 --- a/crates/iota-sdk-types/src/move_package.rs +++ b/crates/iota-sdk-types/src/move_package.rs @@ -149,7 +149,7 @@ mod serialization { } } -#[cfg(test)] +#[cfg(all(test, feature = "serde"))] mod tests { use super::*; @@ -162,6 +162,7 @@ mod tests { assert_eq!(new_json, PACKAGE); } + #[cfg(feature = "hash")] #[test] fn test_digest() { let json_package: MovePackageData = serde_json::from_str(PACKAGE).unwrap(); diff --git a/crates/iota-sdk-types/src/transaction/mod.rs b/crates/iota-sdk-types/src/transaction/mod.rs index c1bfcab51..52eed5f8b 100644 --- a/crates/iota-sdk-types/src/transaction/mod.rs +++ b/crates/iota-sdk-types/src/transaction/mod.rs @@ -739,7 +739,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(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))] pub system_packages: Vec, } @@ -789,7 +789,7 @@ pub struct ChangeEpochV3 { /// 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, /// Vector of active validator indices eligible to take part in committee /// selection because they support the new, target protocol version. diff --git a/crates/iota-sdk-types/src/u256.rs b/crates/iota-sdk-types/src/u256.rs index 7ce80c21d..94b446391 100644 --- a/crates/iota-sdk-types/src/u256.rs +++ b/crates/iota-sdk-types/src/u256.rs @@ -69,11 +69,44 @@ const ASSERT_ENDIANNESS: () = { #[cfg(test)] mod tests { - use std::str::FromStr; + #[cfg(feature = "proptest")] + mod proptests { + use std::str::FromStr; + + use num_bigint::BigUint; + use proptest::prelude::*; + use test_strategy::proptest; + + use super::*; + + #[proptest] + fn dont_crash_on_large_inputs( + #[strategy(proptest::collection::vec(any::(), 33..1024))] bytes: Vec, + ) { + let big_int = BigUint::from_bytes_be(&bytes); + let radix10 = big_int.to_str_radix(10); + + // doesn't crash + let _ = U256::from_str_radix(&radix10, 10); + } + + #[proptest] + fn valid_u256_strings( + #[strategy(proptest::collection::vec(any::(), 1..=32))] bytes: Vec, + ) { + let big_int = BigUint::from_bytes_be(&bytes); + let radix10 = big_int.to_str_radix(10); + + let u256 = U256::from_str_radix(&radix10, 10).unwrap(); + + assert_eq!(radix10, u256.to_str_radix(10)); + + let from_str = U256::from_str(&radix10).unwrap(); + assert_eq!(from_str, u256); + assert_eq!(radix10, from_str.to_string()); + } + } - use num_bigint::BigUint; - use proptest::prelude::*; - use test_strategy::proptest; #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::wasm_bindgen_test as test; @@ -107,31 +140,4 @@ mod tests { // From big endian assert_eq!(one_platform, U256::from_be(U256::from_digits(one_be))); } - - #[proptest] - fn dont_crash_on_large_inputs( - #[strategy(proptest::collection::vec(any::(), 33..1024))] bytes: Vec, - ) { - let big_int = BigUint::from_bytes_be(&bytes); - let radix10 = big_int.to_str_radix(10); - - // doesn't crash - let _ = U256::from_str_radix(&radix10, 10); - } - - #[proptest] - fn valid_u256_strings( - #[strategy(proptest::collection::vec(any::(), 1..=32))] bytes: Vec, - ) { - let big_int = BigUint::from_bytes_be(&bytes); - let radix10 = big_int.to_str_radix(10); - - let u256 = U256::from_str_radix(&radix10, 10).unwrap(); - - assert_eq!(radix10, u256.to_str_radix(10)); - - let from_str = U256::from_str(&radix10).unwrap(); - assert_eq!(from_str, u256); - assert_eq!(radix10, from_str.to_string()); - } } diff --git a/crates/iota-sdk-types/src/validator.rs b/crates/iota-sdk-types/src/validator.rs index 375ba91db..d18f7e4fb 100644 --- a/crates/iota-sdk-types/src/validator.rs +++ b/crates/iota-sdk-types/src/validator.rs @@ -161,14 +161,13 @@ pub struct ValidatorSignature { pub signature: Bls12381Signature, } -#[cfg(test)] +#[cfg(all(test, feature = "serde"))] mod tests { #[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}; From a9d595946d6a5595eedbcfdb2778a413aa0d3e81 Mon Sep 17 00:00:00 2001 From: Thoralf-M Date: Thu, 6 Nov 2025 11:27:24 +0200 Subject: [PATCH 2/3] fix imports --- crates/iota-sdk-types/src/address.rs | 4 ++-- crates/iota-sdk-types/src/crypto/zklogin.rs | 2 +- crates/iota-sdk-types/src/u256.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/iota-sdk-types/src/address.rs b/crates/iota-sdk-types/src/address.rs index 60f172759..1f884652d 100644 --- a/crates/iota-sdk-types/src/address.rs +++ b/crates/iota-sdk-types/src/address.rs @@ -288,7 +288,7 @@ mod tests { mod proptests { use test_strategy::proptest; - use super::*; + use super::super::Address; #[proptest] fn roundtrip_display_fromstr(address: Address) { @@ -301,7 +301,7 @@ mod tests { #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::wasm_bindgen_test as test; - use super::*; + use super::Address; #[test] fn hex_parsing() { diff --git a/crates/iota-sdk-types/src/crypto/zklogin.rs b/crates/iota-sdk-types/src/crypto/zklogin.rs index 0d8e97343..360a7d793 100644 --- a/crates/iota-sdk-types/src/crypto/zklogin.rs +++ b/crates/iota-sdk-types/src/crypto/zklogin.rs @@ -660,7 +660,7 @@ mod tests { use proptest::prelude::*; use test_strategy::proptest; - use super::*; + use super::super::Bn254FieldElement; #[proptest] fn dont_crash_on_large_inputs( diff --git a/crates/iota-sdk-types/src/u256.rs b/crates/iota-sdk-types/src/u256.rs index 94b446391..f60dec350 100644 --- a/crates/iota-sdk-types/src/u256.rs +++ b/crates/iota-sdk-types/src/u256.rs @@ -77,7 +77,7 @@ mod tests { use proptest::prelude::*; use test_strategy::proptest; - use super::*; + use super::super::U256; #[proptest] fn dont_crash_on_large_inputs( From a3514c5b53ef878b6a880de0ca6970e71a8cd702 Mon Sep 17 00:00:00 2001 From: Thoralf-M Date: Fri, 7 Nov 2025 10:30:44 +0200 Subject: [PATCH 3/3] fix iota-sdk-crypto test feature flags --- crates/iota-sdk-crypto/src/lib.rs | 12 ++++++++---- crates/iota-sdk-crypto/src/simple.rs | 8 +++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/iota-sdk-crypto/src/lib.rs b/crates/iota-sdk-crypto/src/lib.rs index e86052efc..5c387ec8a 100644 --- a/crates/iota-sdk-crypto/src/lib.rs +++ b/crates/iota-sdk-crypto/src/lib.rs @@ -355,14 +355,20 @@ pub trait FromMnemonic { Self: Sized; } -#[cfg(test)] +#[cfg(all( + test, + feature = "mnemonic", + feature = "ed25519", + feature = "secp256k1", + feature = "secp256r1", + feature = "bech32" +))] mod tests { use super::*; use crate::{ ed25519::Ed25519PrivateKey, secp256k1::Secp256k1PrivateKey, secp256r1::Secp256r1PrivateKey, }; - #[cfg(feature = "mnemonic")] #[test] fn test_mnemonics_ed25519() { const TEST_CASES: [[&str; 3]; 3] = [ @@ -390,7 +396,6 @@ mod tests { } } - #[cfg(feature = "mnemonic")] #[test] fn test_mnemonics_secp256k1() { const TEST_CASES: [[&str; 3]; 3] = [ @@ -418,7 +423,6 @@ mod tests { } } - #[cfg(feature = "mnemonic")] #[test] fn test_mnemonics_secp256r1() { const TEST_CASES: [[&str; 3]; 3] = [ diff --git a/crates/iota-sdk-crypto/src/simple.rs b/crates/iota-sdk-crypto/src/simple.rs index e862c42eb..fe2dde13d 100644 --- a/crates/iota-sdk-crypto/src/simple.rs +++ b/crates/iota-sdk-crypto/src/simple.rs @@ -557,7 +557,13 @@ mod keypair { } } -#[cfg(test)] +#[cfg(all( + test, + feature = "pem", + feature = "ed25519", + feature = "secp256k1", + feature = "secp256r1" +))] mod tests { use test_strategy::proptest;