I am using the balances pallet while testing my runtime and custom pallet(s).
...
/pallets
/things
/src
lib.rs
mock.rs
tests.rs
/runtime
/src
lib.rs
mock.rs
tests.rs
...
// runtime/src/tests.rs
use crate::{
mock::*,
sp_api_hidden_includes_construct_runtime::hidden_include::traits::Currency,
};
use frame_support::{assert_noop, assert_ok};
#[test]
fn balance_pallet_works() {
new_test_ext().execute_with(|| {
let _ = Balances::deposit_creating(&1, 10);
assert_eq!(Balances::free_balance(1), 10);
});
}
...
This works. I was warned to add use crate::sp_api_hidden_includes_construct_runtime::hidden_include::traits::Currency
to implement (within scope) the trait requiring deposit_creating
.
However, the same pattern in pallets/jobs/src/tests.rs
is recommending that I import from its runtime implementation mock.
// pallets/things/src/tests.rs
use crate::{
mock::*,
};
use frame_support::{assert_err, assert_ok};
// use crate::*mock::*sp_api_hidden_includes_construct_runtime::hidden_include::traits::Currency;
#[test]
fn things_pallet_works() {
new_test_ext().execute_with(|| {
let _ = Balances::deposit_creating(&1, 100);
assert_eq!(Things::<Test>::count(), 0);
});
}
let _ = Balances::deposit_creating(&1, 100);
reports the error use crate::mock::sp_api_hidden_includes_construct_runtime::hidden_include::traits::Currency;
which, when I use
as suggested, errors with error[E0603]: module sp_api_hidden_includes_construct_runtime is private
.
I'm confused as to why the import recommendation is for the crate
in my runtime tests yet crate::mocks
for my pallet tests clearly due to a gap in my understanding of Rust's module system.