diff --git a/.gitlab/pipeline/test.yml b/.gitlab/pipeline/test.yml index 7d7007acd8a8..f67474efcd5a 100644 --- a/.gitlab/pipeline/test.yml +++ b/.gitlab/pipeline/test.yml @@ -157,6 +157,23 @@ test-linux-stable-slow: # --features=runtime-benchmarks,runtime-metrics,try-runtime -- # --skip upgrade_version_checks_should_work +cargo-check-core-crypto-features: + stage: test + extends: + - .docker-env + - .common-refs + - .run-immediately + - .pipeline-stopper-artifacts + variables: + RUST_TOOLCHAIN: stable + # Enable debug assertions since we are running optimized builds for testing + # but still want to have debug assertions. + RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings" + script: + - time cargo check --release -p sp-core --no-default-features --features="full_crypto" + - time cargo check --release -p sp-core --no-default-features --features="full_crypto,serde" + - time cargo check --release -p sp-core --no-default-features --features="serde,sp-runtime-interface/disable_target_static_assertions" + test-doc: stage: test extends: diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs index ccb61c12f321..7060f681bc44 100644 --- a/substrate/primitives/core/src/crypto.rs +++ b/substrate/primitives/core/src/crypto.rs @@ -1223,14 +1223,30 @@ impl_from_entropy_base!(u8, u16, u32, u64, u128, i8, i16, i32, i64, i128); #[cfg(test)] mod tests { use super::*; - use crate::DeriveJunction; + #[cfg(feature = "full_crypto")] + use crate::crypto::DeriveJunction; + #[cfg(feature = "full_crypto")] + use sp_std::prelude::ToOwned; + #[cfg(not(feature = "std"))] + use sp_std::vec; #[derive(Clone, Eq, PartialEq, Debug)] enum TestPair { Generated, + #[cfg(feature = "std")] GeneratedWithPhrase, - GeneratedFromPhrase { phrase: String, password: Option }, - Standard { phrase: String, password: Option, path: Vec }, + #[cfg(feature = "std")] + GeneratedFromPhrase { + phrase: String, + password: Option, + }, + #[cfg(feature = "std")] + Standard { + phrase: String, + password: Option, + path: Vec, + }, + #[cfg(feature = "full_crypto")] Seed(Vec), } impl Default for TestPair { @@ -1238,6 +1254,7 @@ mod tests { TestPair::Generated } } + #[cfg(feature = "full_crypto")] impl CryptoType for TestPair { type Pair = Self; } @@ -1262,6 +1279,7 @@ mod tests { } } impl CryptoType for TestPublic { + #[cfg(feature = "full_crypto")] type Pair = TestPair; } impl Derive for TestPublic {} @@ -1282,19 +1300,23 @@ mod tests { } } impl Public for TestPublic {} + #[cfg(feature = "full_crypto")] impl Pair for TestPair { type Public = TestPublic; type Seed = [u8; 8]; type Signature = [u8; 0]; + #[cfg(feature = "std")] fn generate() -> (Self, ::Seed) { (TestPair::Generated, [0u8; 8]) } + #[cfg(feature = "std")] fn generate_with_phrase(_password: Option<&str>) -> (Self, String, ::Seed) { (TestPair::GeneratedWithPhrase, "".into(), [0u8; 8]) } + #[cfg(feature = "std")] fn from_phrase( phrase: &str, password: Option<&str>, @@ -1308,6 +1330,7 @@ mod tests { )) } + #[cfg(feature = "full_crypto")] fn derive>( &self, path_iter: Iter, @@ -1315,11 +1338,13 @@ mod tests { ) -> Result<(Self, Option<[u8; 8]>), DeriveError> { Ok(( match self.clone() { + #[cfg(feature = "std")] TestPair::Standard { phrase, password, path } => TestPair::Standard { phrase, password, path: path.into_iter().chain(path_iter).collect(), }, + #[cfg(feature = "std")] TestPair::GeneratedFromPhrase { phrase, password } => TestPair::Standard { phrase, password, path: path_iter.collect() }, x => @@ -1355,6 +1380,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn interpret_std_seed_should_work() { assert_eq!( TestPair::from_string("0x0123456789abcdef", None), @@ -1363,6 +1389,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn password_override_should_work() { assert_eq!( TestPair::from_string("hello world///password", None), @@ -1375,6 +1402,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn interpret_std_secret_string_should_work() { assert_eq!( TestPair::from_string("hello world", None), @@ -1475,8 +1503,9 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn accountid_32_from_str_works() { - use std::str::FromStr; + use sp_std::str::FromStr; assert!(AccountId32::from_str("5G9VdMwXvzza9pS8qE8ZHJk3CheHW9uucBn9ngW4C1gmmzpv").is_ok()); assert!(AccountId32::from_str( "5c55177d67b064bb5d189a3e1ddad9bc6646e02e64d6e308f5acbb1533ac430d" diff --git a/substrate/primitives/core/src/defer.rs b/substrate/primitives/core/src/defer.rs index efa9ee5cebb7..21befb9d2117 100644 --- a/substrate/primitives/core/src/defer.rs +++ b/substrate/primitives/core/src/defer.rs @@ -48,7 +48,7 @@ impl Drop for DeferGuard { /// ```rust /// use sp_core::defer; /// -/// let message = std::cell::RefCell::new("".to_string()); +/// let message = sp_std::cell::RefCell::new("".to_string()); /// { /// defer!( /// message.borrow_mut().push_str("world!"); @@ -82,7 +82,7 @@ mod test { #[test] /// `defer` executes the code in reverse order of being called. fn defer_guard_order_works() { - let called = std::cell::RefCell::new(1); + let called = sp_std::cell::RefCell::new(1); defer!( assert_eq!(*called.borrow(), 3); @@ -101,7 +101,7 @@ mod test { #[allow(unused_braces)] #[allow(clippy::unnecessary_operation)] fn defer_guard_syntax_works() { - let called = std::cell::RefCell::new(0); + let called = sp_std::cell::RefCell::new(0); { defer!(*called.borrow_mut() += 1); defer!(*called.borrow_mut() += 1;); // With ; @@ -113,6 +113,7 @@ mod test { #[test] /// `defer` executes the code even in case of a panic. + #[cfg(feature = "std")] fn defer_guard_panic_unwind_works() { use std::panic::{catch_unwind, AssertUnwindSafe}; let mut called = false; @@ -128,9 +129,10 @@ mod test { #[test] /// `defer` executes the code even in case another `defer` panics. + #[cfg(feature = "std")] fn defer_guard_defer_panics_unwind_works() { use std::panic::{catch_unwind, AssertUnwindSafe}; - let counter = std::cell::RefCell::new(0); + let counter = sp_std::cell::RefCell::new(0); let should_panic = catch_unwind(AssertUnwindSafe(|| { defer!(*counter.borrow_mut() += 1); diff --git a/substrate/primitives/core/src/ecdsa.rs b/substrate/primitives/core/src/ecdsa.rs index 603fa515a30e..a8426d540260 100644 --- a/substrate/primitives/core/src/ecdsa.rs +++ b/substrate/primitives/core/src/ecdsa.rs @@ -535,13 +535,20 @@ impl CryptoType for Pair { #[cfg(test)] mod test { use super::*; - use crate::crypto::{ - set_default_ss58_version, PublicError, Ss58AddressFormat, Ss58AddressFormatRegistry, - DEV_PHRASE, - }; + + #[cfg(feature = "std")] + use crate::crypto::set_default_ss58_version; + #[cfg(feature = "std")] + use crate::crypto::DEV_PHRASE; + #[cfg(all(feature = "serde", feature = "full_crypto"))] + use crate::crypto::{PublicError, Ss58AddressFormat, Ss58AddressFormatRegistry}; + #[cfg(feature = "serde")] use serde_json; + #[cfg(feature = "full_crypto")] + use sp_std::vec; #[test] + #[cfg(feature = "std")] fn default_phrase_should_be_used() { assert_eq!( Pair::from_string("//Alice///password", None).unwrap().public(), @@ -552,6 +559,7 @@ mod test { } #[test] + #[cfg(feature = "full_crypto")] fn seed_and_derive_should_work() { let seed = array_bytes::hex2array_unchecked( "9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60", @@ -569,6 +577,7 @@ mod test { } #[test] + #[cfg(feature = "std")] fn test_vector_should_work() { let pair = Pair::from_seed(&array_bytes::hex2array_unchecked( "9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60", @@ -588,6 +597,7 @@ mod test { } #[test] + #[cfg(feature = "std")] fn test_vector_by_string_should_work() { let pair = Pair::from_string( "0x9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60", @@ -609,6 +619,7 @@ mod test { } #[test] + #[cfg(feature = "std")] fn generated_pair_should_work() { let (pair, _) = Pair::generate(); let public = pair.public(); @@ -619,6 +630,7 @@ mod test { } #[test] + #[cfg(feature = "std")] fn seeded_pair_should_work() { let pair = Pair::from_seed(b"12345678901234567890123456789012"); let public = pair.public(); @@ -630,12 +642,12 @@ mod test { ); let message = array_bytes::hex2bytes_unchecked("2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee00000000000000000200d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a4500000000000000"); let signature = pair.sign(&message[..]); - println!("Correct signature: {:?}", signature); assert!(Pair::verify(&signature, &message[..], &public)); assert!(!Pair::verify(&signature, "Other message", &public)); } #[test] + #[cfg(feature = "std")] fn generate_with_phrase_recovery_possible() { let (pair1, phrase, _) = Pair::generate_with_phrase(None); let (pair2, _) = Pair::from_phrase(&phrase, None).unwrap(); @@ -644,6 +656,7 @@ mod test { } #[test] + #[cfg(feature = "std")] fn generate_with_password_phrase_recovery_possible() { let (pair1, phrase, _) = Pair::generate_with_phrase(Some("password")); let (pair2, _) = Pair::from_phrase(&phrase, Some("password")).unwrap(); @@ -652,6 +665,7 @@ mod test { } #[test] + #[cfg(feature = "std")] fn password_does_something() { let (pair1, phrase, _) = Pair::generate_with_phrase(Some("password")); let (pair2, _) = Pair::from_phrase(&phrase, None).unwrap(); @@ -660,16 +674,17 @@ mod test { } #[test] + #[cfg(all(feature = "full_crypto", feature = "serde"))] fn ss58check_roundtrip_works() { let pair = Pair::from_seed(b"12345678901234567890123456789012"); let public = pair.public(); let s = public.to_ss58check(); - println!("Correct: {}", s); let cmp = Public::from_ss58check(&s).unwrap(); assert_eq!(cmp, public); } #[test] + #[cfg(all(feature = "full_crypto", feature = "serde"))] fn ss58check_format_check_works() { let pair = Pair::from_seed(b"12345678901234567890123456789012"); let public = pair.public(); @@ -679,6 +694,7 @@ mod test { } #[test] + #[cfg(all(feature = "full_crypto", feature = "serde"))] fn ss58check_full_roundtrip_works() { let pair = Pair::from_seed(b"12345678901234567890123456789012"); let public = pair.public(); @@ -696,6 +712,7 @@ mod test { } #[test] + #[cfg(feature = "std")] fn ss58check_custom_format_works() { // We need to run this test in its own process to not interfere with other tests running in // parallel and also relying on the ss58 version. @@ -730,6 +747,7 @@ mod test { } #[test] + #[cfg(all(feature = "full_crypto", feature = "serde"))] fn signature_serialization_works() { let pair = Pair::from_seed(b"12345678901234567890123456789012"); let message = b"Something important"; @@ -742,6 +760,7 @@ mod test { } #[test] + #[cfg(feature = "serde")] fn signature_serialization_doesnt_panic() { fn deserialize_signature(text: &str) -> Result { serde_json::from_str(text) @@ -753,6 +772,7 @@ mod test { } #[test] + #[cfg(feature = "std")] fn sign_prehashed_works() { let (pair, _, _) = Pair::generate_with_phrase(Some("password")); @@ -777,6 +797,7 @@ mod test { } #[test] + #[cfg(feature = "std")] fn verify_prehashed_works() { let (pair, _, _) = Pair::generate_with_phrase(Some("password")); @@ -791,6 +812,7 @@ mod test { } #[test] + #[cfg(feature = "std")] fn recover_prehashed_works() { let (pair, _, _) = Pair::generate_with_phrase(Some("password")); diff --git a/substrate/primitives/core/src/ed25519.rs b/substrate/primitives/core/src/ed25519.rs index 151a7229315e..9bf4b1f9deca 100644 --- a/substrate/primitives/core/src/ed25519.rs +++ b/substrate/primitives/core/src/ed25519.rs @@ -471,10 +471,17 @@ impl CryptoType for Pair { #[cfg(test)] mod test { use super::*; + #[cfg(feature = "full_crypto")] + use crate::crypto::DeriveJunction; + #[cfg(feature = "std")] use crate::crypto::DEV_PHRASE; + #[cfg(feature = "serde")] use serde_json; + #[cfg(feature = "full_crypto")] + use sp_std::vec; #[test] + #[cfg(feature = "std")] fn default_phrase_should_be_used() { assert_eq!( Pair::from_string("//Alice///password", None).unwrap().public(), @@ -485,6 +492,7 @@ mod test { } #[test] + #[cfg(feature = "full_crypto")] fn seed_and_derive_should_work() { let seed = array_bytes::hex2array_unchecked( "9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60", @@ -502,6 +510,7 @@ mod test { } #[test] + #[cfg(feature = "full_crypto")] fn test_vector_should_work() { let pair = Pair::from_seed(&array_bytes::hex2array_unchecked( "9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60", @@ -521,6 +530,7 @@ mod test { } #[test] + #[cfg(feature = "std")] fn test_vector_by_string_should_work() { let pair = Pair::from_string( "0x9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60", @@ -542,6 +552,7 @@ mod test { } #[test] + #[cfg(feature = "std")] fn generated_pair_should_work() { let (pair, _) = Pair::generate(); let public = pair.public(); @@ -552,6 +563,7 @@ mod test { } #[test] + #[cfg(feature = "full_crypto")] fn seeded_pair_should_work() { let pair = Pair::from_seed(b"12345678901234567890123456789012"); let public = pair.public(); @@ -563,12 +575,12 @@ mod test { ); let message = array_bytes::hex2bytes_unchecked("2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee00000000000000000200d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a4500000000000000"); let signature = pair.sign(&message[..]); - println!("Correct signature: {:?}", signature); assert!(Pair::verify(&signature, &message[..], &public)); assert!(!Pair::verify(&signature, "Other message", &public)); } #[test] + #[cfg(feature = "std")] fn generate_with_phrase_recovery_possible() { let (pair1, phrase, _) = Pair::generate_with_phrase(None); let (pair2, _) = Pair::from_phrase(&phrase, None).unwrap(); @@ -577,6 +589,7 @@ mod test { } #[test] + #[cfg(feature = "std")] fn generate_with_password_phrase_recovery_possible() { let (pair1, phrase, _) = Pair::generate_with_phrase(Some("password")); let (pair2, _) = Pair::from_phrase(&phrase, Some("password")).unwrap(); @@ -585,6 +598,7 @@ mod test { } #[test] + #[cfg(feature = "std")] fn password_does_something() { let (pair1, phrase, _) = Pair::generate_with_phrase(Some("password")); let (pair2, _) = Pair::from_phrase(&phrase, None).unwrap(); @@ -593,16 +607,17 @@ mod test { } #[test] + #[cfg(all(feature = "full_crypto", feature = "serde"))] fn ss58check_roundtrip_works() { let pair = Pair::from_seed(b"12345678901234567890123456789012"); let public = pair.public(); let s = public.to_ss58check(); - println!("Correct: {}", s); let cmp = Public::from_ss58check(&s).unwrap(); assert_eq!(cmp, public); } #[test] + #[cfg(all(feature = "full_crypto", feature = "serde"))] fn signature_serialization_works() { let pair = Pair::from_seed(b"12345678901234567890123456789012"); let message = b"Something important"; @@ -615,6 +630,7 @@ mod test { } #[test] + #[cfg(feature = "serde")] fn signature_serialization_doesnt_panic() { fn deserialize_signature(text: &str) -> Result { serde_json::from_str(text) diff --git a/substrate/primitives/core/src/hash.rs b/substrate/primitives/core/src/hash.rs index ece9b1af794a..b328456033d5 100644 --- a/substrate/primitives/core/src/hash.rs +++ b/substrate/primitives/core/src/hash.rs @@ -30,9 +30,13 @@ pub fn convert_hash, H2: AsRef<[u8]>>(src: &H2) -> H1 } #[cfg(test)] +#[cfg(feature = "bytesorder")] mod tests { use super::*; + #[cfg(not(feature = "std"))] + use sp_std::{alloc::format, vec}; + #[test] fn test_h160() { let tests = vec![ diff --git a/substrate/primitives/core/src/sr25519.rs b/substrate/primitives/core/src/sr25519.rs index ffa52ef97d1f..277fffc8ba12 100644 --- a/substrate/primitives/core/src/sr25519.rs +++ b/substrate/primitives/core/src/sr25519.rs @@ -832,11 +832,20 @@ pub mod vrf { #[cfg(test)] mod tests { - use super::{vrf::*, *}; - use crate::crypto::{Ss58Codec, VrfPublic, VrfSecret, DEV_ADDRESS, DEV_PHRASE}; + #[cfg(feature = "std")] + use super::vrf::*; + use super::*; + #[cfg(feature = "serde")] + // use crate::crypto::Ss58Codec; + #[cfg(feature = "std")] + use crate::crypto::{VrfPublic, VrfSecret}; + #[cfg(feature = "std")] + use crate::crypto::{DEV_ADDRESS, DEV_PHRASE}; + #[cfg(feature = "serde")] use serde_json; #[test] + #[cfg(feature = "std")] fn derive_soft_known_pair_should_work() { let pair = Pair::from_string(&format!("{}/Alice", DEV_PHRASE), None).unwrap(); // known address of DEV_PHRASE with 1.1 @@ -847,6 +856,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn derive_hard_known_pair_should_work() { let pair = Pair::from_string(&format!("{}//Alice", DEV_PHRASE), None).unwrap(); // known address of DEV_PHRASE with 1.1 @@ -857,6 +867,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn verify_known_old_message_should_work() { let public = Public::from_raw(array_bytes::hex2array_unchecked( "b4bfa1f7a5166695eb75299fd1c4c03ea212871c342f2c5dfea0902b2c246918", @@ -871,6 +882,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn default_phrase_should_be_used() { assert_eq!( Pair::from_string("//Alice///password", None).unwrap().public(), @@ -887,6 +899,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn default_address_should_be_used() { assert_eq!( Public::from_string(&format!("{}/Alice", DEV_ADDRESS)), @@ -895,6 +908,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn default_phrase_should_correspond_to_default_address() { assert_eq!( Pair::from_string(&format!("{}/Alice", DEV_PHRASE), None).unwrap().public(), @@ -907,6 +921,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] //randomness fn derive_soft_should_work() { let pair = Pair::from_seed(&array_bytes::hex2array_unchecked( "9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60", @@ -919,6 +934,7 @@ mod tests { } #[test] + #[cfg(feature = "full_crypto")] fn derive_hard_should_work() { let pair = Pair::from_seed(&array_bytes::hex2array_unchecked( "9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60", @@ -931,6 +947,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] //randomness fn derive_soft_public_should_work() { let pair = Pair::from_seed(&array_bytes::hex2array_unchecked( "9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60", @@ -942,6 +959,7 @@ mod tests { } #[test] + #[cfg(all(feature = "full_crypto", feature = "serde"))] fn derive_hard_public_should_fail() { let pair = Pair::from_seed(&array_bytes::hex2array_unchecked( "9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60", @@ -951,6 +969,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn sr_test_vector_should_work() { let pair = Pair::from_seed(&array_bytes::hex2array_unchecked( "9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60", @@ -968,6 +987,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn generated_pair_should_work() { let (pair, _) = Pair::generate(); let public = pair.public(); @@ -977,6 +997,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn messed_signature_should_not_work() { let (pair, _) = Pair::generate(); let public = pair.public(); @@ -989,6 +1010,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn messed_message_should_not_work() { let (pair, _) = Pair::generate(); let public = pair.public(); @@ -998,6 +1020,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn seeded_pair_should_work() { let pair = Pair::from_seed(b"12345678901234567890123456789012"); let public = pair.public(); @@ -1013,16 +1036,17 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn ss58check_roundtrip_works() { let (pair, _) = Pair::generate(); let public = pair.public(); let s = public.to_ss58check(); - println!("Correct: {}", s); let cmp = Public::from_ss58check(&s).unwrap(); assert_eq!(cmp, public); } #[test] + #[cfg(feature = "std")] fn verify_from_old_wasm_works() { // The values in this test case are compared to the output of `node-test.js` in // schnorrkel-js. @@ -1040,6 +1064,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] //randomness fn signature_serialization_works() { let pair = Pair::from_seed(b"12345678901234567890123456789012"); let message = b"Something important"; @@ -1052,6 +1077,7 @@ mod tests { } #[test] + #[cfg(feature = "serde")] fn signature_serialization_doesnt_panic() { fn deserialize_signature(text: &str) -> Result { serde_json::from_str(text) @@ -1063,6 +1089,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn vrf_sign_verify() { let pair = Pair::from_seed(b"12345678901234567890123456789012"); let public = pair.public(); @@ -1075,6 +1102,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn vrf_sign_verify_with_extra() { let pair = Pair::from_seed(b"12345678901234567890123456789012"); let public = pair.public(); @@ -1090,6 +1118,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn vrf_make_bytes_matches() { let pair = Pair::from_seed(b"12345678901234567890123456789012"); let public = pair.public(); @@ -1113,6 +1142,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn vrf_backend_compat() { let pair = Pair::from_seed(b"12345678901234567890123456789012"); let public = pair.public(); diff --git a/substrate/primitives/core/src/uint.rs b/substrate/primitives/core/src/uint.rs index b251671dbeea..80438ee01600 100644 --- a/substrate/primitives/core/src/uint.rs +++ b/substrate/primitives/core/src/uint.rs @@ -23,10 +23,15 @@ pub use primitive_types::{U256, U512}; mod tests { use super::*; use codec::{Decode, Encode}; + #[cfg(all(not(feature = "std"), feature = "serde"))] + use sp_std::alloc::format; + #[cfg(any(not(feature = "std"), feature = "serde"))] + use sp_std::vec; macro_rules! test { ($name: ident, $test_name: ident) => { #[test] + #[cfg(feature = "serde")] fn $test_name() { let tests = vec![ ($name::from(0), "0x0"), @@ -78,6 +83,7 @@ mod tests { } #[test] + #[cfg(feature = "serde")] fn test_large_values() { assert_eq!( serde_json::to_string_pretty(&!U256::zero()).expect("Json pretty print failed"),