Skip to content
Merged
Prev Previous commit
Next Next commit
Extract the dev utils and clean up the tests root mod
  • Loading branch information
MOZGIII committed Aug 19, 2022
commit a725897be63a8f89c1977868a6bbeaa534f29b5b
23 changes: 23 additions & 0 deletions crates/humanode-runtime/src/dev_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use crypto_utils::{authority_keys_from_seed, get_account_id_from_seed};
use sp_application_crypto::ByteArray;
use sp_runtime::app_crypto::sr25519;

use super::*;

/// The public key for the accounts.
pub type AccountPublic = <Signature as Verify>::Signer;

/// A helper function to return [`AccountId`] based on runtime data and provided seed.
pub fn account_id(seed: &str) -> AccountId {
get_account_id_from_seed::<sr25519::Public, AccountPublic, AccountId>(seed)
}

/// A helper function to return authorities keys based on runtime data and provided seed.
pub fn authority_keys(seed: &str) -> (AccountId, BabeId, GrandpaId, ImOnlineId) {
authority_keys_from_seed::<sr25519::Public, AccountPublic, AccountId>(seed)
}

/// A helper function to get a corresponding EVM truncated address for provided AccountId.
pub fn evm_truncated_address(account_id: AccountId) -> H160 {
H160::from_slice(&account_id.as_slice()[0..20])
}
2 changes: 2 additions & 0 deletions crates/humanode-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ mod frontier_precompiles;
mod vesting;
use frontier_precompiles::FrontierPrecompiles;

#[cfg(test)]
mod dev_utils;
mod display_moment;
pub mod eip712;
mod find_author;
Expand Down
3 changes: 3 additions & 0 deletions crates/humanode-runtime/src/tests/fixed_supply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
use std::str::FromStr;

use frame_support::{
assert_ok,
dispatch::DispatchInfo,
weights::{DispatchClass, Pays},
};
use pallet_evm::AddressMapping;
use sp_runtime::traits::SignedExtension;

use super::*;
use crate::dev_utils::*;
use crate::opaque::SessionKeys;

const INIT_BALANCE: u128 = 10u128.pow(18 + 6);

Expand Down
24 changes: 0 additions & 24 deletions crates/humanode-runtime/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
use crypto_utils::{authority_keys_from_seed, get_account_id_from_seed};
use frame_support::assert_ok;
use sp_application_crypto::ByteArray;
use sp_runtime::app_crypto::sr25519;

use super::*;
use crate::{opaque::SessionKeys, AccountId, Signature};

mod fixed_supply;

/// The public key for the accounts.
type AccountPublic = <Signature as Verify>::Signer;

/// A helper function to return [`AccountId`] based on runtime data and provided seed.
fn account_id(seed: &str) -> AccountId {
get_account_id_from_seed::<sr25519::Public, AccountPublic, AccountId>(seed)
}

/// A helper function to return authorities keys based on runtime data and provided seed.
fn authority_keys(seed: &str) -> (AccountId, BabeId, GrandpaId, ImOnlineId) {
authority_keys_from_seed::<sr25519::Public, AccountPublic, AccountId>(seed)
}

/// A helper function to get a corresponding EVM truncated address for provided AccountId.
fn evm_truncated_address(account_id: AccountId) -> H160 {
H160::from_slice(&account_id.as_slice()[0..20])
}