mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-23 21:21:06 +00:00
002d9260f9
**Update:** Pushed additional changes based on the review comments. **This pull request fixes various spelling mistakes in this repository.** Most of the changes are contained in the first **3** commits: - `Fix spelling mistakes in comments and docs` - `Fix spelling mistakes in test names` - `Fix spelling mistakes in error messages, panic messages, logs and tracing` Other source code spelling mistakes are separated into individual commits for easier reviewing: - `Fix the spelling of 'authority'` - `Fix the spelling of 'REASONABLE_HEADERS_IN_JUSTIFICATION_ANCESTRY'` - `Fix the spelling of 'prev_enqueud_messages'` - `Fix the spelling of 'endpoint'` - `Fix the spelling of 'children'` - `Fix the spelling of 'PenpalSiblingSovereignAccount'` - `Fix the spelling of 'PenpalSudoAccount'` - `Fix the spelling of 'insufficient'` - `Fix the spelling of 'PalletXcmExtrinsicsBenchmark'` - `Fix the spelling of 'subtracted'` - `Fix the spelling of 'CandidatePendingAvailability'` - `Fix the spelling of 'exclusive'` - `Fix the spelling of 'until'` - `Fix the spelling of 'discriminator'` - `Fix the spelling of 'nonexistent'` - `Fix the spelling of 'subsystem'` - `Fix the spelling of 'indices'` - `Fix the spelling of 'committed'` - `Fix the spelling of 'topology'` - `Fix the spelling of 'response'` - `Fix the spelling of 'beneficiary'` - `Fix the spelling of 'formatted'` - `Fix the spelling of 'UNKNOWN_PROOF_REQUEST'` - `Fix the spelling of 'succeeded'` - `Fix the spelling of 'reopened'` - `Fix the spelling of 'proposer'` - `Fix the spelling of 'InstantiationNonce'` - `Fix the spelling of 'depositor'` - `Fix the spelling of 'expiration'` - `Fix the spelling of 'phantom'` - `Fix the spelling of 'AggregatedKeyValue'` - `Fix the spelling of 'randomness'` - `Fix the spelling of 'defendant'` - `Fix the spelling of 'AquaticMammal'` - `Fix the spelling of 'transactions'` - `Fix the spelling of 'PassingTracingSubscriber'` - `Fix the spelling of 'TxSignaturePayload'` - `Fix the spelling of 'versioning'` - `Fix the spelling of 'descendant'` - `Fix the spelling of 'overridden'` - `Fix the spelling of 'network'` Let me know if this structure is adequate. **Note:** The usage of the words `Merkle`, `Merkelize`, `Merklization`, `Merkelization`, `Merkleization`, is somewhat inconsistent but I left it as it is. ~~**Note:** In some places the term `Receival` is used to refer to message reception, IMO `Reception` is the correct word here, but I left it as it is.~~ ~~**Note:** In some places the term `Overlayed` is used instead of the more acceptable version `Overlaid` but I also left it as it is.~~ ~~**Note:** In some places the term `Applyable` is used instead of the correct version `Applicable` but I also left it as it is.~~ **Note:** Some usage of British vs American english e.g. `judgement` vs `judgment`, `initialise` vs `initialize`, `optimise` vs `optimize` etc. are both present in different places, but I suppose that's understandable given the number of contributors. ~~**Note:** There is a spelling mistake in `.github/CODEOWNERS` but it triggers errors in CI when I make changes to it, so I left it as it is.~~
281 lines
8.0 KiB
Rust
281 lines
8.0 KiB
Rust
// This file is part of Substrate.
|
|
|
|
// Copyright (C) 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.
|
|
|
|
//! The crate's tests.
|
|
|
|
use frame_support::{
|
|
assert_noop, assert_ok, derive_impl, hypothetically,
|
|
pallet_prelude::Weight,
|
|
parameter_types,
|
|
traits::{ConstU64, EitherOf, MapSuccess, PollStatus, Polling},
|
|
};
|
|
use pallet_ranked_collective::{EnsureRanked, Geometric, TallyOf, Votes};
|
|
use sp_core::{ConstU16, Get};
|
|
use sp_runtime::{
|
|
traits::{Convert, ReduceBy, ReplaceWithDefault},
|
|
BuildStorage, DispatchError,
|
|
};
|
|
|
|
use crate as pallet_salary;
|
|
use crate::*;
|
|
|
|
type Rank = u16;
|
|
type Block = frame_system::mocking::MockBlock<Test>;
|
|
|
|
frame_support::construct_runtime!(
|
|
pub enum Test
|
|
{
|
|
System: frame_system,
|
|
Salary: pallet_salary,
|
|
Club: pallet_ranked_collective,
|
|
}
|
|
);
|
|
|
|
parameter_types! {
|
|
pub BlockWeights: frame_system::limits::BlockWeights =
|
|
frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1_000_000, 0));
|
|
}
|
|
|
|
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
|
|
impl frame_system::Config for Test {
|
|
type Block = Block;
|
|
}
|
|
|
|
pub struct TestPolls;
|
|
impl Polling<TallyOf<Test>> for TestPolls {
|
|
type Index = u8;
|
|
type Votes = Votes;
|
|
type Moment = u64;
|
|
type Class = Rank;
|
|
|
|
fn classes() -> Vec<Self::Class> {
|
|
unimplemented!()
|
|
}
|
|
fn as_ongoing(_index: u8) -> Option<(TallyOf<Test>, Self::Class)> {
|
|
unimplemented!()
|
|
}
|
|
fn access_poll<R>(
|
|
_index: Self::Index,
|
|
_f: impl FnOnce(PollStatus<&mut TallyOf<Test>, Self::Moment, Self::Class>) -> R,
|
|
) -> R {
|
|
unimplemented!()
|
|
}
|
|
fn try_access_poll<R>(
|
|
_index: Self::Index,
|
|
_f: impl FnOnce(
|
|
PollStatus<&mut TallyOf<Test>, Self::Moment, Self::Class>,
|
|
) -> Result<R, DispatchError>,
|
|
) -> Result<R, DispatchError> {
|
|
unimplemented!()
|
|
}
|
|
|
|
#[cfg(feature = "runtime-benchmarks")]
|
|
fn create_ongoing(_class: Self::Class) -> Result<Self::Index, ()> {
|
|
unimplemented!()
|
|
}
|
|
|
|
#[cfg(feature = "runtime-benchmarks")]
|
|
fn end_ongoing(_index: Self::Index, _approved: bool) -> Result<(), ()> {
|
|
unimplemented!()
|
|
}
|
|
}
|
|
|
|
pub struct MinRankOfClass<Delta>(PhantomData<Delta>);
|
|
impl<Delta: Get<Rank>> Convert<u16, Rank> for MinRankOfClass<Delta> {
|
|
fn convert(a: u16) -> Rank {
|
|
a.saturating_sub(Delta::get())
|
|
}
|
|
}
|
|
|
|
pub struct TestPay;
|
|
impl Pay for TestPay {
|
|
type Beneficiary = u64;
|
|
type Balance = u64;
|
|
type Id = u64;
|
|
type AssetKind = ();
|
|
type Error = ();
|
|
|
|
fn pay(
|
|
_: &Self::Beneficiary,
|
|
_: Self::AssetKind,
|
|
_: Self::Balance,
|
|
) -> Result<Self::Id, Self::Error> {
|
|
unreachable!()
|
|
}
|
|
fn check_payment(_: Self::Id) -> PaymentStatus {
|
|
unreachable!()
|
|
}
|
|
#[cfg(feature = "runtime-benchmarks")]
|
|
fn ensure_successful(_: &Self::Beneficiary, _: Self::AssetKind, _: Self::Balance) {}
|
|
#[cfg(feature = "runtime-benchmarks")]
|
|
fn ensure_concluded(_: Self::Id) {
|
|
unreachable!()
|
|
}
|
|
}
|
|
|
|
parameter_types! {
|
|
pub static Budget: u64 = 10;
|
|
}
|
|
|
|
impl Config for Test {
|
|
type WeightInfo = ();
|
|
type RuntimeEvent = RuntimeEvent;
|
|
type Paymaster = TestPay;
|
|
type Members = Club;
|
|
type Salary = FixedSalary;
|
|
type RegistrationPeriod = ConstU64<2>;
|
|
type PayoutPeriod = ConstU64<2>;
|
|
type Budget = Budget;
|
|
}
|
|
|
|
pub struct FixedSalary;
|
|
impl GetSalary<u16, u64, u64> for FixedSalary {
|
|
fn get_salary(_rank: u16, _who: &u64) -> u64 {
|
|
123
|
|
}
|
|
}
|
|
|
|
parameter_types! {
|
|
pub static MinRankOfClassDelta: Rank = 0;
|
|
}
|
|
|
|
impl pallet_ranked_collective::Config for Test {
|
|
type WeightInfo = ();
|
|
type RuntimeEvent = RuntimeEvent;
|
|
type PromoteOrigin = EitherOf<
|
|
// Root can promote arbitrarily.
|
|
frame_system::EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
|
|
// Members can promote up to the rank of 2 below them.
|
|
MapSuccess<EnsureRanked<Test, (), 2>, ReduceBy<ConstU16<2>>>,
|
|
>;
|
|
type AddOrigin = MapSuccess<Self::PromoteOrigin, ReplaceWithDefault<()>>;
|
|
type DemoteOrigin = EitherOf<
|
|
// Root can demote arbitrarily.
|
|
frame_system::EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
|
|
// Members can demote up to the rank of 3 below them.
|
|
MapSuccess<EnsureRanked<Test, (), 3>, ReduceBy<ConstU16<3>>>,
|
|
>;
|
|
type RemoveOrigin = Self::DemoteOrigin;
|
|
type ExchangeOrigin = EitherOf<
|
|
// Root can exchange arbitrarily.
|
|
frame_system::EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
|
|
// Members can exchange up to the rank of 2 below them.
|
|
MapSuccess<EnsureRanked<Test, (), 2>, ReduceBy<ConstU16<2>>>,
|
|
>;
|
|
type Polls = TestPolls;
|
|
type MinRankOfClass = MinRankOfClass<MinRankOfClassDelta>;
|
|
type MemberSwappedHandler = Salary;
|
|
type VoteWeight = Geometric;
|
|
#[cfg(feature = "runtime-benchmarks")]
|
|
type BenchmarkSetup = Salary;
|
|
}
|
|
|
|
pub fn new_test_ext() -> sp_io::TestExternalities {
|
|
let t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
|
let mut ext = sp_io::TestExternalities::new(t);
|
|
ext.execute_with(|| System::set_block_number(1));
|
|
ext
|
|
}
|
|
|
|
fn assert_last_event(generic_event: <Test as Config>::RuntimeEvent) {
|
|
let events = frame_system::Pallet::<Test>::events();
|
|
let system_event: <Test as frame_system::Config>::RuntimeEvent = generic_event.into();
|
|
let frame_system::EventRecord { event, .. } = events.last().expect("Event expected");
|
|
assert_eq!(event, &system_event.into());
|
|
}
|
|
|
|
fn promote_n_times(acc: u64, r: u16) {
|
|
for _ in 0..r {
|
|
assert_ok!(Club::promote_member(RuntimeOrigin::root(), acc));
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn swap_simple_works() {
|
|
new_test_ext().execute_with(|| {
|
|
for i in 0u16..9 {
|
|
let acc = i as u64;
|
|
|
|
assert_ok!(Club::add_member(RuntimeOrigin::root(), acc));
|
|
promote_n_times(acc, i);
|
|
let _ = Salary::init(RuntimeOrigin::signed(acc));
|
|
assert_ok!(Salary::induct(RuntimeOrigin::signed(acc)));
|
|
|
|
// Swapping normally works:
|
|
assert_ok!(Club::exchange_member(RuntimeOrigin::root(), acc, acc + 10));
|
|
assert_last_event(Event::Swapped { who: acc, new_who: acc + 10 }.into());
|
|
}
|
|
});
|
|
}
|
|
|
|
#[test]
|
|
fn swap_exhaustive_works() {
|
|
new_test_ext().execute_with(|| {
|
|
let root_add = hypothetically!({
|
|
assert_ok!(Club::add_member(RuntimeOrigin::root(), 1));
|
|
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 1));
|
|
assert_ok!(Salary::init(RuntimeOrigin::signed(1)));
|
|
assert_ok!(Salary::induct(RuntimeOrigin::signed(1)));
|
|
|
|
// The events mess up the storage root:
|
|
System::reset_events();
|
|
sp_io::storage::root(sp_runtime::StateVersion::V1)
|
|
});
|
|
|
|
let root_swap = hypothetically!({
|
|
assert_ok!(Club::add_member(RuntimeOrigin::root(), 0));
|
|
assert_ok!(Club::promote_member(RuntimeOrigin::root(), 0));
|
|
assert_ok!(Salary::init(RuntimeOrigin::signed(0)));
|
|
assert_ok!(Salary::induct(RuntimeOrigin::signed(0)));
|
|
|
|
assert_ok!(Club::exchange_member(RuntimeOrigin::root(), 0, 1));
|
|
|
|
// The events mess up the storage root:
|
|
System::reset_events();
|
|
sp_io::storage::root(sp_runtime::StateVersion::V1)
|
|
});
|
|
|
|
assert_eq!(root_add, root_swap);
|
|
// Ensure that we don't compare trivial stuff like `()` from a type error above.
|
|
assert_eq!(root_add.len(), 32);
|
|
});
|
|
}
|
|
|
|
#[test]
|
|
fn swap_bad_noops() {
|
|
new_test_ext().execute_with(|| {
|
|
assert_ok!(Club::add_member(RuntimeOrigin::root(), 0));
|
|
promote_n_times(0, 0);
|
|
assert_ok!(Salary::init(RuntimeOrigin::signed(0)));
|
|
assert_ok!(Salary::induct(RuntimeOrigin::signed(0)));
|
|
assert_ok!(Club::add_member(RuntimeOrigin::root(), 1));
|
|
promote_n_times(1, 1);
|
|
assert_ok!(Salary::induct(RuntimeOrigin::signed(1)));
|
|
|
|
// Swapping for another member is a noop:
|
|
assert_noop!(
|
|
Club::exchange_member(RuntimeOrigin::root(), 0, 1),
|
|
pallet_ranked_collective::Error::<Test>::AlreadyMember
|
|
);
|
|
// Swapping for the same member is a noop:
|
|
assert_noop!(
|
|
Club::exchange_member(RuntimeOrigin::root(), 0, 0),
|
|
pallet_ranked_collective::Error::<Test>::SameMember
|
|
);
|
|
});
|
|
}
|