We often use some basic substrate crates such as sp-core
, and sp-io
while doing pallet tests. In general, those dependencies are put under [dev-dependencies]
. But I have an issue with whether we should add default-features = false
or not. Seems both work.
For example:
# pallet crate level
[dependencies]
frame-system = = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
# no sp-io here
[dev-dependencies]
# With`default-features = false`
sp-io = = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
or
# Without default-features = false
sp-io = = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
In the pallet tests (both ways can compile):
// mock.rs
use sp_io::TestExternalities;
Check from the substrate repo:
/// Type alias for Externalities implementation used in tests.
#[cfg(feature = "std")] // this line
pub type TestExternalities = sp_state_machine::TestExternalities<sp_core::Blake2Hasher>;
As the code snippet shows, the TestExternalities
is only available understd
feature.So why the first way, With default-features = false
can be compiled?