multi-gomoku 0.8.3

Multi Gomoku runtime module
#![cfg(test)]

use super::*;
use crate as multi_gomoku;
use frame_support::{
    impl_outer_event, impl_outer_origin, impl_outer_dispatch, 
    parameter_types, weights::Weight
};
use frame_system as system;
use sp_core::{sr25519, Pair, H256};
use pallet_balances;
use sp_runtime::testing::Header;
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
use sp_runtime::Perbill;

#[derive(Clone, Eq, PartialEq)]
pub struct TestRuntime;

pub(crate) type AccountId = sr25519::Public;
pub(crate) type BlockNumber = u64;
pub(crate) type Signature = sr25519::Signature;

impl_outer_event! {
    pub enum TestEvent for TestRuntime {
        system<T>,
        pallet_balances<T>,
        multi_gomoku<T>,
    }
}

impl_outer_dispatch! {
    pub enum Call for TestRuntime where origin: Origin {
        frame_system::System,
        pallet_balances::Balances,
        multi_gomoku::MultiGomoku,
    }
}

impl_outer_origin! {
    pub enum Origin for TestRuntime where system = frame_system  {}
}

parameter_types! {
    pub const BlockHashCount: u64 = 250;
    pub const MaximumBlockWeight: Weight = 1024;
    pub const MaximumBlockLength: u32 = 2 * 1024;
    pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
    pub const ExistentialDeposit: u64 = 1; // should be greater than zero
}

impl frame_system::Trait for TestRuntime {
    	/// The basic call filter to use in dispatchable.
	type BaseCallFilter = ();
    	/// The identifier used to distinguish between accounts.
	type AccountId = sr25519::Public;
    	/// The aggregated dispatch type that is available for extrinsics.
	type Call = Call;
    	/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
	type Lookup = IdentityLookup<AccountId>;
    	/// The index type for storing how many extrinsics an account has signed.
	type Index = u64;
    	/// The index type for blocks.
	type BlockNumber = u64;
   	/// The type for hashing blocks and tries.
	type Hash = H256;
    	/// The hashing algorithm used.
	type Hashing = BlakeTwo256;
    	/// The header type.
	type Header = Header;
    	/// The ubiquitous event type.
	type Event = TestEvent;
    	/// The ubiquitous origin type.
	type Origin = Origin;
    	/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
	type BlockHashCount = BlockHashCount;
	/// Maximum weight of each block.
	type MaximumBlockWeight = MaximumBlockWeight;
    	/// The weight of database operations that the runtime can invoke.
	type DbWeight = ();
    	/// The weight of the overhead invoked on the block import process, independent of the
	/// extrinsics included in that block.
	type BlockExecutionWeight = ();
    	/// The base weight of any extrinsic processed by the runtime, independent of the
	/// logic of that extrinsic. (Signature verification, nonce increment, fee, etc...)
	type ExtrinsicBaseWeight = ();
    	/// The maximum weight that a single extrinsic of `Normal` dispatch class can have,
	/// idependent of the logic of that extrinsics. (Roughly max block weight - average on
	/// initialize cost).
	type MaximumExtrinsicWeight = MaximumBlockWeight;
    	/// Maximum size of all encoded transactions (in bytes) that are allowed in one block.
	type MaximumBlockLength = MaximumBlockLength;
	/// Portion of the block weight that is available to all normal transactions.
	type AvailableBlockRatio = AvailableBlockRatio;
	/// Version of the runtime.
	type Version = ();
	/// Converts a module to the index of the module in `construct_runtime!`.
	///
	/// This type is being generated by `construct_runtime!`.
	type PalletInfo = ();
	/// What to do if a new account is created.
	type OnNewAccount = ();
	/// What to do if an account is fully reaped from the system.
	type OnKilledAccount = ();
	/// The data to be stored in an account.
	type AccountData = pallet_balances::AccountData<u64>;
	/// Weight information for the extrinsics of this pallet.
	type SystemWeightInfo = ();
}

impl pallet_balances::Trait for TestRuntime {
    type MaxLocks = ();
    type Balance = u64;
    type Event = TestEvent;
    type DustRemoval = ();
    type ExistentialDeposit = ExistentialDeposit;
    type AccountStore = frame_system::Module<TestRuntime>;
    type WeightInfo = ();
}

impl Trait for TestRuntime {
    type Event = TestEvent;
    type Public = sr25519::Public;
    type Signature = sr25519::Signature;
}

pub type MultiGomoku = Module<TestRuntime>;
pub type System = frame_system::Module<TestRuntime>;
type Balances = pallet_balances::Module<TestRuntime>;

pub struct ExtBuilder;
impl ExtBuilder {
    pub fn build() -> sp_io::TestExternalities {
        let t = system::GenesisConfig::default()
            .build_storage::<TestRuntime>().unwrap();
        let ext = sp_io::TestExternalities::new(t);
        ext
    }
}

pub(crate) fn account_pair(s: &str) -> sr25519::Pair {
    sr25519::Pair::from_string(&format!("//{}", s), None).expect("static values are valid: qed")
}

pub(crate) fn account_key(s: &str) -> sr25519::Public {
    sr25519::Pair::from_string(&format!("//{}", s), None)
        .expect("static values are valid; qed")
        .public()
}

pub(crate) fn get_sorted_peer(
    peer_1: sr25519::Pair,
    peer_2: sr25519::Pair,
) -> (Vec<AccountId>, Vec<sr25519::Pair>) {
    if peer_1.public() < peer_2.public() {
        return (
            vec![peer_1.clone().public(), peer_2.clone().public()],
            vec![peer_1, peer_2],
        );
    } else {
        return (
            vec![peer_2.clone().public(), peer_1.clone().public()],
            vec![peer_2, peer_1],
        );
    }
}