mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 02:17:58 +00:00
39a776cd00
* Basic weights builder. * Fixing WiP * Make the tests work. * Fix weights in node/runtime. * WiP. * Update pallets with new weights parameters. * Validate returns a Result now. * Count mandatory weight separately. * DRY * BREAKING: Updating state root, because of the left-over weight-tracking stuff * Update tests affected by Mandatory tracking. * Fixing tests. * Fix defaults for simple_max * Update frame/system/src/weights.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Rework the API a bit. * Fix compilation & tests. * Apply suggestions from code review Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Add extra docs & rename few things. * Fix whitespace in ASCII art. * Update frame/system/src/limits.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Fix max_extrinsic calculations. * Fix conflicts. * Fix compilation. * Fix new code. * re-remove generic asset * Fix usage. * Update state root. * Update proxy. * Fix tests. * Move weights validity to integrity_test * Remove redundant BlockWeights. * Add all/non_mandatory comment * Add test. * Remove fn block_weights * Make the macro prettier. * Fix some docs. * Make max_total behave more predictabily. * Add BlockWeights to metadata. * fix balances test * Fix utility test. Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Benjamin Kampmann <ben@gnunicorn.org> Co-authored-by: thiolliere <gui.thiolliere@gmail.com>
146 lines
3.8 KiB
Rust
146 lines
3.8 KiB
Rust
// This file is part of Substrate.
|
|
|
|
// Copyright (C) 2020 Parity Technologies (UK) Ltd.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
use crate::*;
|
|
|
|
use codec::{Encode, Decode};
|
|
use frame_support::{impl_outer_origin, parameter_types};
|
|
use sp_core::H256;
|
|
use sp_runtime::{
|
|
Perbill,
|
|
testing::{Header},
|
|
traits::{BlakeTwo256, IdentityLookup},
|
|
};
|
|
|
|
impl_outer_origin! {
|
|
pub enum Origin for Test where system = frame_system {}
|
|
}
|
|
|
|
#[derive(Clone, Eq, PartialEq, Encode, Decode)]
|
|
pub struct Test;
|
|
parameter_types! {
|
|
pub const BlockHashCount: u64 = 250;
|
|
pub const AvailableBlockRatio: Perbill = Perbill::one();
|
|
}
|
|
|
|
impl frame_system::Config for Test {
|
|
type BaseCallFilter = ();
|
|
type Origin = Origin;
|
|
type Call = ();
|
|
type PalletInfo = ();
|
|
type Index = u64;
|
|
type BlockNumber = u64;
|
|
type Hash = H256;
|
|
type Hashing = BlakeTwo256;
|
|
type AccountId = sp_core::sr25519::Public;
|
|
type Lookup = IdentityLookup<Self::AccountId>;
|
|
type Header = Header;
|
|
type Event = ();
|
|
type BlockHashCount = BlockHashCount;
|
|
type DbWeight = ();
|
|
type BlockWeights = ();
|
|
type BlockLength = ();
|
|
type Version = ();
|
|
type AccountData = ();
|
|
type OnNewAccount = ();
|
|
type OnKilledAccount = ();
|
|
type SystemWeightInfo = ();
|
|
}
|
|
|
|
parameter_types! {
|
|
pub const GracePeriod: u64 = 5;
|
|
pub const UnsignedInterval: u64 = 128;
|
|
pub const UnsignedPriority: u64 = 1 << 20;
|
|
}
|
|
|
|
impl Config for Test {
|
|
type Event = ();
|
|
type Call = Call<Test>;
|
|
}
|
|
|
|
type Example = Module<Test>;
|
|
|
|
#[test]
|
|
fn it_can_enlist() {
|
|
use sp_core::Pair;
|
|
|
|
sp_io::TestExternalities::default().execute_with(|| {
|
|
let (pair1, _) = sp_core::sr25519::Pair::generate();
|
|
let (pair2, _) = sp_core::sr25519::Pair::generate();
|
|
|
|
let event_name = b"test";
|
|
|
|
Example::run_event(Origin::signed(Default::default()), event_name.to_vec())
|
|
.expect("Failed to enlist");
|
|
|
|
let participants = vec![
|
|
EnlistedParticipant {
|
|
account: pair1.public().to_vec(),
|
|
signature: AsRef::<[u8]>::as_ref(&pair1.sign(event_name)).to_vec(),
|
|
},
|
|
EnlistedParticipant {
|
|
account: pair2.public().to_vec(),
|
|
signature: AsRef::<[u8]>::as_ref(&pair2.sign(event_name)).to_vec(),
|
|
},
|
|
];
|
|
|
|
Example::enlist_participants(Origin::signed(Default::default()), participants)
|
|
.expect("Failed to enlist");
|
|
|
|
assert_eq!(Example::participants().len(), 2);
|
|
});
|
|
|
|
}
|
|
|
|
#[test]
|
|
fn one_wrong_will_not_enlist_anyone() {
|
|
use sp_core::Pair;
|
|
|
|
sp_io::TestExternalities::default().execute_with(|| {
|
|
let (pair1, _) = sp_core::sr25519::Pair::generate();
|
|
let (pair2, _) = sp_core::sr25519::Pair::generate();
|
|
let (pair3, _) = sp_core::sr25519::Pair::generate();
|
|
|
|
let event_name = b"test";
|
|
|
|
Example::run_event(Origin::signed(Default::default()), event_name.to_vec())
|
|
.expect("Failed to enlist");
|
|
|
|
let participants = vec![
|
|
EnlistedParticipant {
|
|
account: pair1.public().to_vec(),
|
|
signature: AsRef::<[u8]>::as_ref(&pair1.sign(event_name)).to_vec(),
|
|
},
|
|
EnlistedParticipant {
|
|
account: pair2.public().to_vec(),
|
|
signature: AsRef::<[u8]>::as_ref(&pair2.sign(event_name)).to_vec(),
|
|
},
|
|
// signing wrong event
|
|
EnlistedParticipant {
|
|
account: pair3.public().to_vec(),
|
|
signature: AsRef::<[u8]>::as_ref(&pair3.sign(&[])).to_vec(),
|
|
},
|
|
];
|
|
|
|
Example::enlist_participants(Origin::signed(Default::default()), participants)
|
|
.expect("Failed to enlist");
|
|
|
|
assert_eq!(Example::participants().len(), 0);
|
|
});
|
|
|
|
}
|