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;
diff --git a/crates/iota-sdk-types/Cargo.toml b/crates/iota-sdk-types/Cargo.toml
index 0c9409aef..686ddde1a 100644
--- a/crates/iota-sdk-types/Cargo.toml
+++ b/crates/iota-sdk-types/Cargo.toml
@@ -35,7 +35,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 c5d5a638a..e52ff36c9 100644
--- a/crates/iota-sdk-types/src/address.rs
+++ b/crates/iota-sdk-types/src/address.rs
@@ -281,11 +281,24 @@ impl schemars::JsonSchema for Address {
#[cfg(test)]
mod tests {
- use test_strategy::proptest;
+ #[cfg(feature = "proptest")]
+ mod proptests {
+ use test_strategy::proptest;
+
+ use super::super::Address;
+
+ #[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;
- use super::*;
+ use super::Address;
#[test]
fn hex_parsing() {
@@ -305,11 +318,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 a194a63f8..da84d67c9 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 f8ad9bce3..e41474583 100644
--- a/crates/iota-sdk-types/src/crypto/zklogin.rs
+++ b/crates/iota-sdk-types/src/crypto/zklogin.rs
@@ -640,11 +640,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::super::Bn254FieldElement;
+
+ #[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;
@@ -660,30 +690,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 77d0015d1..c025d39a5 100644
--- a/crates/iota-sdk-types/src/digest.rs
+++ b/crates/iota-sdk-types/src/digest.rs
@@ -212,7 +212,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 92743f777..016df5f05 100644
--- a/crates/iota-sdk-types/src/gas.rs
+++ b/crates/iota-sdk-types/src/gas.rs
@@ -120,7 +120,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;
@@ -128,7 +128,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 2dd227021..76b2a24a7 100644
--- a/crates/iota-sdk-types/src/transaction/mod.rs
+++ b/crates/iota-sdk-types/src/transaction/mod.rs
@@ -688,7 +688,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,
}
@@ -735,7 +735,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..f60dec350 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::super::U256;
+
+ #[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 dd7cd24b0..54009c0c4 100644
--- a/crates/iota-sdk-types/src/validator.rs
+++ b/crates/iota-sdk-types/src/validator.rs
@@ -149,14 +149,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};