mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-08-03 15:05:41 +00:00
b0e1212d48
* Using child storage, (srml-support only), test failing . * fix simple tests. * Enumerable by requiring owned struct (previous form only allow &'static). Broken tests are from genesis init. * implement for_child_keys_with_prefix * indent * clear_child_prefix fix. * clear_child_prefix fix 2. * fix for storage_impl, if/when allowing child and not child this could be reverted. * Fix lot of urlinked child genesis, still need to look upon actual genesis srml module code. Probably still a lot of broken code needing debugging. * switch well_known_key to their associated module child trie. Fix a genesis init (balance). Complete some testing. Comment some tests before using. * fixing test runtime child keys * latest commit fix broken genesis init * fix system balances child name. * Important fix: storage_root from test externalities need children (it is already the case for ext). * executive root with child calculation * Avoid empty trie on test ext. * Symetric removal of key for system. * commenting changes related tests. * Remove child module specifics. * fix issues. * fix some formatting * fix bench and bump runtime * Remove extend_storage_overlays, assimilate_storage do the same as is proper considering srml macro. * Fix warning for assimilate. * Removing kill as they do not impact any test cases. * Use tuple of storage map instead of two parameters. This changes the behavior of decl_storage genesis build closure (breaking api). * Do not use build storage before assimilate. * fix error * Update core/state-machine/src/backend.rs
145 lines
3.6 KiB
Rust
145 lines
3.6 KiB
Rust
// Copyright 2019
|
|
// by Centrality Investments Ltd.
|
|
// and Parity Technologies (UK) Ltd.
|
|
// This file is part of Substrate.
|
|
|
|
// Substrate is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Substrate is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//! Mocks for the module.
|
|
|
|
#![cfg(test)]
|
|
|
|
use sr_primitives::{
|
|
Perbill,
|
|
testing::Header,
|
|
traits::{BlakeTwo256, IdentityLookup},
|
|
};
|
|
use primitives::{Blake2Hasher, H256};
|
|
use support::{parameter_types, impl_outer_event, impl_outer_origin};
|
|
|
|
use super::*;
|
|
|
|
impl_outer_origin! {
|
|
pub enum Origin for Test {}
|
|
}
|
|
|
|
// For testing the module, we construct most of a mock runtime. This means
|
|
// first constructing a configuration type (`Test`) which `impl`s each of the
|
|
// configuration traits of modules we want to use.
|
|
#[derive(Clone, Eq, PartialEq)]
|
|
pub struct Test;
|
|
parameter_types! {
|
|
pub const BlockHashCount: u64 = 250;
|
|
pub const MaximumBlockWeight: u32 = 1024;
|
|
pub const MaximumBlockLength: u32 = 2 * 1024;
|
|
pub const AvailableBlockRatio: Perbill = Perbill::one();
|
|
}
|
|
impl system::Trait for Test {
|
|
type Origin = Origin;
|
|
type Index = u64;
|
|
type BlockNumber = u64;
|
|
type Call = ();
|
|
type Hash = H256;
|
|
type Hashing = BlakeTwo256;
|
|
type AccountId = u64;
|
|
type Lookup = IdentityLookup<u64>;
|
|
type Header = Header;
|
|
type Event = TestEvent;
|
|
type WeightMultiplierUpdate = ();
|
|
type MaximumBlockWeight = MaximumBlockWeight;
|
|
type MaximumBlockLength = MaximumBlockLength;
|
|
type AvailableBlockRatio = AvailableBlockRatio;
|
|
type BlockHashCount = BlockHashCount;
|
|
}
|
|
|
|
impl Trait for Test {
|
|
type Balance = u64;
|
|
type AssetId = u32;
|
|
type Event = TestEvent;
|
|
}
|
|
|
|
mod generic_asset {
|
|
pub use crate::Event;
|
|
}
|
|
|
|
impl_outer_event! {
|
|
pub enum TestEvent for Test {
|
|
generic_asset<T>,
|
|
}
|
|
}
|
|
|
|
pub type GenericAsset = Module<Test>;
|
|
|
|
pub type System = system::Module<Test>;
|
|
|
|
pub struct ExtBuilder {
|
|
asset_id: u32,
|
|
next_asset_id: u32,
|
|
accounts: Vec<u64>,
|
|
initial_balance: u64,
|
|
}
|
|
|
|
// Returns default values for genesis config
|
|
impl Default for ExtBuilder {
|
|
fn default() -> Self {
|
|
Self {
|
|
asset_id: 0,
|
|
next_asset_id: 1000,
|
|
accounts: vec![0],
|
|
initial_balance: 0,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl ExtBuilder {
|
|
// Sets free balance to genesis config
|
|
pub fn free_balance(mut self, free_balance: (u32, u64, u64)) -> Self {
|
|
self.asset_id = free_balance.0;
|
|
self.accounts = vec![free_balance.1];
|
|
self.initial_balance = free_balance.2;
|
|
self
|
|
}
|
|
|
|
pub fn next_asset_id(mut self, asset_id: u32) -> Self {
|
|
self.next_asset_id = asset_id;
|
|
self
|
|
}
|
|
|
|
// builds genesis config
|
|
pub fn build(self) -> runtime_io::TestExternalities<Blake2Hasher> {
|
|
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
|
|
|
GenesisConfig::<Test> {
|
|
assets: vec![self.asset_id],
|
|
endowed_accounts: self.accounts,
|
|
initial_balance: self.initial_balance,
|
|
next_asset_id: self.next_asset_id,
|
|
staking_asset_id: 16000,
|
|
spending_asset_id: 16001,
|
|
}
|
|
.assimilate_storage(&mut t).unwrap();
|
|
|
|
t.into()
|
|
}
|
|
}
|
|
|
|
// This function basically just builds a genesis storage key/value store according to
|
|
// our desired mockup.
|
|
pub fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
|
|
system::GenesisConfig::default()
|
|
.build_storage::<Test>()
|
|
.unwrap()
|
|
.into()
|
|
}
|