It is important to have the mock.rs
inside the runtime folder. Then you can just import all runtime parameters with use crate::*;
inside the mock.rs
.
Just found out that I can just use Runtime
instead of Test
as a generic to all instances of the test and mock. In addition to that, you need to create Accounts as actual accounts and not just numbers.
use sp_core::{sr25519, Pair, Public, H256};
use sp_runtime::traits::{IdentifyAccount, Verify};
type AccountPublic = <Signature as Verify>::Signer;
/// Helper function to generate a crypto pair from seed
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{seed}"), None)
.expect("static values are valid; qed")
.public()
}
/// Helper function to generate an account ID from seed
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
{
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
}
pub fn alice() -> AccountId {
get_account_id_from_seed::<sr25519::Public>("Alice")
}
pub fn bob() -> AccountId {
get_account_id_from_seed::<sr25519::Public>("Bob")
}
pub fn charlie() -> AccountId {
get_account_id_from_seed::<sr25519::Public>("Charlie")
}
pub fn dave() -> AccountId {
get_account_id_from_seed::<sr25519::Public>("Dave")
}
pub fn eva() -> AccountId {
get_account_id_from_seed::<sr25519::Public>("Eva")
}
pub fn fred() -> AccountId {
get_account_id_from_seed::<sr25519::Public>("Fred")
}
You can leave the ExtBuilder
as it is. It just builds the execution environment with the actual runtime as a charm!