Skip to content

Commit 4f30f9e

Browse files
committed
fix(iota-sdk-types): fix feature flags for tests
1 parent 367ee3b commit 4f30f9e

File tree

13 files changed

+99
-79
lines changed

13 files changed

+99
-79
lines changed

crates/iota-sdk-types/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ serde = [
3636
schemars = ["serde", "dep:schemars", "dep:serde_json"]
3737
rand = ["dep:rand_core"]
3838
hash = ["dep:blake2"]
39-
proptest = ["dep:proptest", "dep:test-strategy", "serde"]
39+
proptest = ["dep:proptest", "dep:test-strategy", "serde", "schemars"]
4040

4141
[dependencies]
4242
base64ct = { workspace = true, features = ["alloc"] }

crates/iota-sdk-types/src/address.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,20 @@ impl schemars::JsonSchema for Address {
284284

285285
#[cfg(test)]
286286
mod tests {
287-
use test_strategy::proptest;
287+
#[cfg(feature = "proptest")]
288+
mod proptests {
289+
use test_strategy::proptest;
290+
291+
use super::*;
292+
293+
#[proptest]
294+
fn roundtrip_display_fromstr(address: Address) {
295+
let s = address.to_string();
296+
let a = s.parse::<Address>().unwrap();
297+
assert_eq!(address, a);
298+
}
299+
}
300+
288301
#[cfg(target_arch = "wasm32")]
289302
use wasm_bindgen_test::wasm_bindgen_test as test;
290303

@@ -308,11 +321,4 @@ mod tests {
308321
let a: Address = serde_json::from_str("\"0x2\"").unwrap();
309322
println!("{a}");
310323
}
311-
312-
#[proptest]
313-
fn roundtrip_display_fromstr(address: Address) {
314-
let s = address.to_string();
315-
let a = s.parse::<Address>().unwrap();
316-
assert_eq!(address, a);
317-
}
318324
}

crates/iota-sdk-types/src/crypto/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ macro_rules! impl_base64_helper {
129129
}
130130
}
131131

132-
#[cfg(test)]
132+
#[cfg(all(test, feature = "proptest"))]
133133
mod $test_module {
134134
use test_strategy::proptest;
135135

crates/iota-sdk-types/src/crypto/passkey.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ impl proptest::arbitrary::Arbitrary for PasskeyAuthenticator {
407407
}
408408
}
409409

410+
#[cfg(feature = "serde")]
410411
#[cfg(test)]
411412
mod tests {
412413
use crate::UserSignature;

crates/iota-sdk-types/src/crypto/signature.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,13 +822,15 @@ mod serialization {
822822
#[cfg(test)]
823823
mod tests {
824824
use base64ct::{Base64, Encoding};
825+
#[cfg(feature = "proptest")]
825826
use test_strategy::proptest;
826827
#[cfg(target_arch = "wasm32")]
827828
use wasm_bindgen_test::wasm_bindgen_test as test;
828829

829830
use super::*;
830831

831832
#[proptest]
833+
#[cfg(feature = "proptest")]
832834
fn roundtrip_signature_scheme(scheme: SignatureScheme) {
833835
assert_eq!(Ok(scheme), SignatureScheme::from_byte(scheme.to_u8()));
834836
}

crates/iota-sdk-types/src/crypto/zklogin.rs

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -652,11 +652,41 @@ impl std::str::FromStr for Bn254FieldElement {
652652

653653
#[cfg(test)]
654654
mod tests {
655-
use std::str::FromStr;
655+
#[cfg(feature = "proptest")]
656+
mod proptests {
657+
use std::str::FromStr;
658+
659+
use num_bigint::BigUint;
660+
use proptest::prelude::*;
661+
use test_strategy::proptest;
662+
663+
use super::*;
664+
665+
#[proptest]
666+
fn dont_crash_on_large_inputs(
667+
#[strategy(proptest::collection::vec(any::<u8>(), 33..1024))] bytes: Vec<u8>,
668+
) {
669+
let big_int = BigUint::from_bytes_be(&bytes);
670+
let radix10 = big_int.to_str_radix(10);
671+
672+
// doesn't crash
673+
let _ = Bn254FieldElement::from_str(&radix10);
674+
}
675+
676+
#[proptest]
677+
fn valid_address_seeds(
678+
#[strategy(proptest::collection::vec(any::<u8>(), 1..=32))] bytes: Vec<u8>,
679+
) {
680+
let big_int = BigUint::from_bytes_be(&bytes);
681+
let radix10 = big_int.to_str_radix(10);
682+
683+
let seed = Bn254FieldElement::from_str(&radix10).unwrap();
684+
assert_eq!(radix10, seed.to_string());
685+
// Ensure unpadded doesn't crash
686+
seed.unpadded();
687+
}
688+
}
656689

657-
use num_bigint::BigUint;
658-
use proptest::prelude::*;
659-
use test_strategy::proptest;
660690
#[cfg(target_arch = "wasm32")]
661691
use wasm_bindgen_test::wasm_bindgen_test as test;
662692

@@ -672,30 +702,6 @@ mod tests {
672702
seed.0[0] = 0;
673703
assert_eq!(seed.unpadded(), [1; 31].as_slice());
674704
}
675-
676-
#[proptest]
677-
fn dont_crash_on_large_inputs(
678-
#[strategy(proptest::collection::vec(any::<u8>(), 33..1024))] bytes: Vec<u8>,
679-
) {
680-
let big_int = BigUint::from_bytes_be(&bytes);
681-
let radix10 = big_int.to_str_radix(10);
682-
683-
// doesn't crash
684-
let _ = Bn254FieldElement::from_str(&radix10);
685-
}
686-
687-
#[proptest]
688-
fn valid_address_seeds(
689-
#[strategy(proptest::collection::vec(any::<u8>(), 1..=32))] bytes: Vec<u8>,
690-
) {
691-
let big_int = BigUint::from_bytes_be(&bytes);
692-
let radix10 = big_int.to_str_radix(10);
693-
694-
let seed = Bn254FieldElement::from_str(&radix10).unwrap();
695-
assert_eq!(radix10, seed.to_string());
696-
// Ensure unpadded doesn't crash
697-
seed.unpadded();
698-
}
699705
}
700706

701707
#[cfg(feature = "serde")]

crates/iota-sdk-types/src/digest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl std::error::Error for DigestParseError {}
215215
// serialized
216216
pub type SigningDigest = [u8; Digest::LENGTH];
217217

218-
#[cfg(test)]
218+
#[cfg(all(test, feature = "proptest"))]
219219
mod tests {
220220
use test_strategy::proptest;
221221

crates/iota-sdk-types/src/gas.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,14 @@ impl std::fmt::Display for GasCostSummary {
123123
}
124124
}
125125

126-
#[cfg(test)]
126+
#[cfg(all(test, feature = "serde"))]
127127
mod tests {
128128
#[cfg(target_arch = "wasm32")]
129129
use wasm_bindgen_test::wasm_bindgen_test as test;
130130

131131
use super::*;
132132

133133
#[test]
134-
#[cfg(feature = "serde")]
135134
fn formats() {
136135
let actual = GasCostSummary {
137136
computation_cost: 42,

crates/iota-sdk-types/src/hash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ impl crate::ObjectId {
522522
}
523523
}
524524

525-
#[cfg(test)]
525+
#[cfg(all(test, feature = "proptest"))]
526526
mod tests {
527527
use test_strategy::proptest;
528528

crates/iota-sdk-types/src/move_package.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ mod serialization {
149149
}
150150
}
151151

152-
#[cfg(test)]
152+
#[cfg(all(test, feature = "serde"))]
153153
mod tests {
154154
use super::*;
155155

@@ -161,7 +161,8 @@ mod tests {
161161
let new_json = serde_json::to_string(&package).unwrap();
162162
assert_eq!(new_json, PACKAGE);
163163
}
164-
164+
165+
#[cfg(feature = "hash")]
165166
#[test]
166167
fn test_digest() {
167168
let json_package: MovePackageData = serde_json::from_str(PACKAGE).unwrap();

0 commit comments

Comments
 (0)