mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 02:37:58 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -21,8 +21,8 @@
|
||||
|
||||
use super::*;
|
||||
|
||||
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};
|
||||
use frame_system::RawOrigin;
|
||||
use frame_benchmarking::{benchmarks, account, whitelisted_caller, impl_benchmark_test_suite};
|
||||
use sp_runtime::traits::Saturating;
|
||||
|
||||
use crate::Module as TipsMod;
|
||||
@@ -32,9 +32,9 @@ const SEED: u32 = 0;
|
||||
// Create the pre-requisite information needed to create a `report_awesome`.
|
||||
fn setup_awesome<T: Config>(length: u32) -> (T::AccountId, Vec<u8>, T::AccountId) {
|
||||
let caller = whitelisted_caller();
|
||||
let value = T::TipReportDepositBase::get()
|
||||
+ T::DataDepositPerByte::get() * length.into()
|
||||
+ T::Currency::minimum_balance();
|
||||
let value = T::TipReportDepositBase::get() +
|
||||
T::DataDepositPerByte::get() * length.into() +
|
||||
T::Currency::minimum_balance();
|
||||
let _ = T::Currency::make_free_balance_be(&caller, value);
|
||||
let reason = vec![0; length as usize];
|
||||
let awesome_person = account("awesome", 0, SEED);
|
||||
@@ -42,12 +42,13 @@ fn setup_awesome<T: Config>(length: u32) -> (T::AccountId, Vec<u8>, T::AccountId
|
||||
}
|
||||
|
||||
// Create the pre-requisite information needed to call `tip_new`.
|
||||
fn setup_tip<T: Config>(r: u32, t: u32) ->
|
||||
Result<(T::AccountId, Vec<u8>, T::AccountId, BalanceOf<T>), &'static str>
|
||||
{
|
||||
fn setup_tip<T: Config>(
|
||||
r: u32,
|
||||
t: u32,
|
||||
) -> Result<(T::AccountId, Vec<u8>, T::AccountId, BalanceOf<T>), &'static str> {
|
||||
let tippers_count = T::Tippers::count();
|
||||
|
||||
for i in 0 .. t {
|
||||
for i in 0..t {
|
||||
let member = account("member", i, SEED);
|
||||
T::Tippers::add(&member);
|
||||
ensure!(T::Tippers::contains(&member), "failed to add tipper");
|
||||
@@ -63,10 +64,8 @@ fn setup_tip<T: Config>(r: u32, t: u32) ->
|
||||
|
||||
// Create `t` new tips for the tip proposal with `hash`.
|
||||
// This function automatically makes the tip able to close.
|
||||
fn create_tips<T: Config>(t: u32, hash: T::Hash, value: BalanceOf<T>) ->
|
||||
Result<(), &'static str>
|
||||
{
|
||||
for i in 0 .. t {
|
||||
fn create_tips<T: Config>(t: u32, hash: T::Hash, value: BalanceOf<T>) -> Result<(), &'static str> {
|
||||
for i in 0..t {
|
||||
let caller = account("member", i, SEED);
|
||||
ensure!(T::Tippers::contains(&caller), "caller is not a tipper");
|
||||
TipsMod::<T>::tip(RawOrigin::Signed(caller).into(), hash, value)?;
|
||||
@@ -193,8 +192,4 @@ benchmarks! {
|
||||
}: _(RawOrigin::Root, hash)
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(
|
||||
TipsMod,
|
||||
crate::tests::new_test_ext(),
|
||||
crate::tests::Test,
|
||||
);
|
||||
impl_benchmark_test_suite!(TipsMod, crate::tests::new_test_ext(), crate::tests::Test,);
|
||||
|
||||
@@ -54,23 +54,24 @@
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
mod tests;
|
||||
mod benchmarking;
|
||||
mod tests;
|
||||
pub mod weights;
|
||||
|
||||
use sp_std::prelude::*;
|
||||
use frame_support::{decl_module, decl_storage, decl_event, ensure, decl_error, Parameter};
|
||||
use frame_support::traits::{
|
||||
Currency, Get, ExistenceRequirement::{KeepAlive},
|
||||
ReservableCurrency
|
||||
use frame_support::{
|
||||
decl_error, decl_event, decl_module, decl_storage, ensure,
|
||||
traits::{Currency, ExistenceRequirement::KeepAlive, Get, ReservableCurrency},
|
||||
Parameter,
|
||||
};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
use sp_runtime::{ Percent, RuntimeDebug, traits::{
|
||||
Zero, AccountIdConversion, Hash, BadOrigin
|
||||
}};
|
||||
use frame_support::traits::{SortedMembers, ContainsLengthBound, OnUnbalanced, EnsureOrigin};
|
||||
use codec::{Encode, Decode};
|
||||
use codec::{Decode, Encode};
|
||||
use frame_support::traits::{ContainsLengthBound, EnsureOrigin, OnUnbalanced, SortedMembers};
|
||||
use frame_system::{self as system, ensure_signed};
|
||||
use sp_runtime::{
|
||||
traits::{AccountIdConversion, BadOrigin, Hash, Zero},
|
||||
Percent, RuntimeDebug,
|
||||
};
|
||||
pub use weights::WeightInfo;
|
||||
|
||||
pub type BalanceOf<T> = pallet_treasury::BalanceOf<T>;
|
||||
@@ -484,9 +485,9 @@ impl<T: Config> Module<T> {
|
||||
if m < a {
|
||||
continue
|
||||
} else {
|
||||
break true;
|
||||
break true
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -495,7 +496,10 @@ impl<T: Config> Module<T> {
|
||||
///
|
||||
/// Up to three balance operations.
|
||||
/// Plus `O(T)` (`T` is Tippers length).
|
||||
fn payout_tip(hash: T::Hash, tip: OpenTip<T::AccountId, BalanceOf<T>, T::BlockNumber, T::Hash>) {
|
||||
fn payout_tip(
|
||||
hash: T::Hash,
|
||||
tip: OpenTip<T::AccountId, BalanceOf<T>, T::BlockNumber, T::Hash>,
|
||||
) {
|
||||
let mut tips = tip.tips;
|
||||
Self::retain_active_tips(&mut tips);
|
||||
tips.sort_by_key(|i| i.1);
|
||||
@@ -549,22 +553,18 @@ impl<T: Config> Module<T> {
|
||||
tips: Vec<(AccountId, Balance)>,
|
||||
}
|
||||
|
||||
use frame_support::{Twox64Concat, migration::storage_key_iter};
|
||||
use frame_support::{migration::storage_key_iter, Twox64Concat};
|
||||
|
||||
for (hash, old_tip) in storage_key_iter::<
|
||||
T::Hash,
|
||||
OldOpenTip<T::AccountId, BalanceOf<T>, T::BlockNumber, T::Hash>,
|
||||
Twox64Concat,
|
||||
>(b"Treasury", b"Tips").drain()
|
||||
>(b"Treasury", b"Tips")
|
||||
.drain()
|
||||
{
|
||||
|
||||
let (finder, deposit, finders_fee) = match old_tip.finder {
|
||||
Some((finder, deposit)) => {
|
||||
(finder, deposit, true)
|
||||
},
|
||||
None => {
|
||||
(T::AccountId::default(), Zero::zero(), false)
|
||||
},
|
||||
Some((finder, deposit)) => (finder, deposit, true),
|
||||
None => (T::AccountId::default(), Zero::zero(), false),
|
||||
};
|
||||
let new_tip = OpenTip {
|
||||
reason: old_tip.reason,
|
||||
@@ -573,7 +573,7 @@ impl<T: Config> Module<T> {
|
||||
deposit,
|
||||
closes: old_tip.closes,
|
||||
tips: old_tip.tips,
|
||||
finders_fee
|
||||
finders_fee,
|
||||
};
|
||||
Tips::<T>::insert(hash, new_tip)
|
||||
}
|
||||
|
||||
@@ -19,21 +19,19 @@
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use crate as tips;
|
||||
use super::*;
|
||||
use std::cell::RefCell;
|
||||
use crate as tips;
|
||||
use frame_support::{
|
||||
assert_noop, assert_ok, parameter_types,
|
||||
weights::Weight, traits::SortedMembers,
|
||||
PalletId, pallet_prelude::GenesisBuild,
|
||||
assert_noop, assert_ok, pallet_prelude::GenesisBuild, parameter_types, traits::SortedMembers,
|
||||
weights::Weight, PalletId,
|
||||
};
|
||||
use sp_runtime::Permill;
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
Perbill,
|
||||
testing::Header,
|
||||
traits::{BlakeTwo256, IdentityLookup, BadOrigin},
|
||||
traits::{BadOrigin, BlakeTwo256, IdentityLookup},
|
||||
Perbill, Permill,
|
||||
};
|
||||
use std::cell::RefCell;
|
||||
|
||||
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
|
||||
type Block = frame_system::mocking::MockBlock<Test>;
|
||||
@@ -102,9 +100,7 @@ thread_local! {
|
||||
pub struct TenToFourteen;
|
||||
impl SortedMembers<u128> for TenToFourteen {
|
||||
fn sorted_members() -> Vec<u128> {
|
||||
TEN_TO_FOURTEEN.with(|v| {
|
||||
v.borrow().clone()
|
||||
})
|
||||
TEN_TO_FOURTEEN.with(|v| v.borrow().clone())
|
||||
}
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn add(new: &u128) {
|
||||
@@ -119,7 +115,9 @@ impl ContainsLengthBound for TenToFourteen {
|
||||
fn max_len() -> usize {
|
||||
TEN_TO_FOURTEEN.with(|v| v.borrow().len())
|
||||
}
|
||||
fn min_len() -> usize { 0 }
|
||||
fn min_len() -> usize {
|
||||
0
|
||||
}
|
||||
}
|
||||
parameter_types! {
|
||||
pub const ProposalBond: Permill = Permill::from_percent(5);
|
||||
@@ -142,7 +140,7 @@ impl pallet_treasury::Config for Test {
|
||||
type ProposalBondMinimum = ProposalBondMinimum;
|
||||
type SpendPeriod = SpendPeriod;
|
||||
type Burn = Burn;
|
||||
type BurnDestination = (); // Just gets burned.
|
||||
type BurnDestination = (); // Just gets burned.
|
||||
type WeightInfo = ();
|
||||
type SpendFunds = ();
|
||||
type MaxApprovals = MaxApprovals;
|
||||
@@ -165,19 +163,21 @@ impl Config for Test {
|
||||
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
pallet_balances::GenesisConfig::<Test>{
|
||||
pallet_balances::GenesisConfig::<Test> {
|
||||
// Total issuance will be 200 with treasury account initialized at ED.
|
||||
balances: vec![(0, 100), (1, 98), (2, 1)],
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
}
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
GenesisBuild::<Test>::assimilate_storage(&pallet_treasury::GenesisConfig, &mut t).unwrap();
|
||||
t.into()
|
||||
}
|
||||
|
||||
fn last_event() -> RawEvent<u64, u128, H256> {
|
||||
System::events().into_iter().map(|r| r.event)
|
||||
.filter_map(|e| {
|
||||
if let Event::TipsModTestInst(inner) = e { Some(inner) } else { None }
|
||||
})
|
||||
System::events()
|
||||
.into_iter()
|
||||
.map(|r| r.event)
|
||||
.filter_map(|e| if let Event::TipsModTestInst(inner) = e { Some(inner) } else { None })
|
||||
.last()
|
||||
.unwrap()
|
||||
}
|
||||
@@ -267,13 +267,19 @@ fn close_tip_works() {
|
||||
|
||||
assert_ok!(TipsModTestInst::tip(Origin::signed(11), h.clone(), 10));
|
||||
|
||||
assert_noop!(TipsModTestInst::close_tip(Origin::signed(0), h.into()), Error::<Test>::StillOpen);
|
||||
assert_noop!(
|
||||
TipsModTestInst::close_tip(Origin::signed(0), h.into()),
|
||||
Error::<Test>::StillOpen
|
||||
);
|
||||
|
||||
assert_ok!(TipsModTestInst::tip(Origin::signed(12), h.clone(), 10));
|
||||
|
||||
assert_eq!(last_event(), RawEvent::TipClosing(h));
|
||||
|
||||
assert_noop!(TipsModTestInst::close_tip(Origin::signed(0), h.into()), Error::<Test>::Premature);
|
||||
assert_noop!(
|
||||
TipsModTestInst::close_tip(Origin::signed(0), h.into()),
|
||||
Error::<Test>::Premature
|
||||
);
|
||||
|
||||
System::set_block_number(2);
|
||||
assert_noop!(TipsModTestInst::close_tip(Origin::none(), h.into()), BadOrigin);
|
||||
@@ -282,7 +288,10 @@ fn close_tip_works() {
|
||||
|
||||
assert_eq!(last_event(), RawEvent::TipClosed(h, 3, 10));
|
||||
|
||||
assert_noop!(TipsModTestInst::close_tip(Origin::signed(100), h.into()), Error::<Test>::UnknownTip);
|
||||
assert_noop!(
|
||||
TipsModTestInst::close_tip(Origin::signed(100), h.into()),
|
||||
Error::<Test>::UnknownTip
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -305,10 +314,7 @@ fn slash_tip_works() {
|
||||
assert_eq!(last_event(), RawEvent::NewTip(h));
|
||||
|
||||
// can't remove from any origin
|
||||
assert_noop!(
|
||||
TipsModTestInst::slash_tip(Origin::signed(0), h.clone()),
|
||||
BadOrigin,
|
||||
);
|
||||
assert_noop!(TipsModTestInst::slash_tip(Origin::signed(0), h.clone()), BadOrigin,);
|
||||
|
||||
// can remove from root.
|
||||
assert_ok!(TipsModTestInst::slash_tip(Origin::root(), h.clone()));
|
||||
@@ -330,10 +336,16 @@ fn retract_tip_works() {
|
||||
assert_ok!(TipsModTestInst::tip(Origin::signed(10), h.clone(), 10));
|
||||
assert_ok!(TipsModTestInst::tip(Origin::signed(11), h.clone(), 10));
|
||||
assert_ok!(TipsModTestInst::tip(Origin::signed(12), h.clone(), 10));
|
||||
assert_noop!(TipsModTestInst::retract_tip(Origin::signed(10), h.clone()), Error::<Test>::NotFinder);
|
||||
assert_noop!(
|
||||
TipsModTestInst::retract_tip(Origin::signed(10), h.clone()),
|
||||
Error::<Test>::NotFinder
|
||||
);
|
||||
assert_ok!(TipsModTestInst::retract_tip(Origin::signed(0), h.clone()));
|
||||
System::set_block_number(2);
|
||||
assert_noop!(TipsModTestInst::close_tip(Origin::signed(0), h.into()), Error::<Test>::UnknownTip);
|
||||
assert_noop!(
|
||||
TipsModTestInst::close_tip(Origin::signed(0), h.into()),
|
||||
Error::<Test>::UnknownTip
|
||||
);
|
||||
|
||||
// with tip new
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
@@ -341,10 +353,16 @@ fn retract_tip_works() {
|
||||
let h = tip_hash();
|
||||
assert_ok!(TipsModTestInst::tip(Origin::signed(11), h.clone(), 10));
|
||||
assert_ok!(TipsModTestInst::tip(Origin::signed(12), h.clone(), 10));
|
||||
assert_noop!(TipsModTestInst::retract_tip(Origin::signed(0), h.clone()), Error::<Test>::NotFinder);
|
||||
assert_noop!(
|
||||
TipsModTestInst::retract_tip(Origin::signed(0), h.clone()),
|
||||
Error::<Test>::NotFinder
|
||||
);
|
||||
assert_ok!(TipsModTestInst::retract_tip(Origin::signed(10), h.clone()));
|
||||
System::set_block_number(2);
|
||||
assert_noop!(TipsModTestInst::close_tip(Origin::signed(10), h.into()), Error::<Test>::UnknownTip);
|
||||
assert_noop!(
|
||||
TipsModTestInst::close_tip(Origin::signed(10), h.into()),
|
||||
Error::<Test>::UnknownTip
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -416,7 +434,7 @@ fn test_last_reward_migration() {
|
||||
who: 10,
|
||||
finder: Some((20, 30)),
|
||||
closes: Some(13),
|
||||
tips: vec![(40, 50), (60, 70)]
|
||||
tips: vec![(40, 50), (60, 70)],
|
||||
};
|
||||
|
||||
let reason2 = BlakeTwo256::hash(b"reason2");
|
||||
@@ -427,24 +445,17 @@ fn test_last_reward_migration() {
|
||||
who: 20,
|
||||
finder: None,
|
||||
closes: Some(13),
|
||||
tips: vec![(40, 50), (60, 70)]
|
||||
tips: vec![(40, 50), (60, 70)],
|
||||
};
|
||||
|
||||
let data = vec![
|
||||
(
|
||||
Tips::<Test>::hashed_key_for(hash1),
|
||||
old_tip_finder.encode().to_vec()
|
||||
),
|
||||
(
|
||||
Tips::<Test>::hashed_key_for(hash2),
|
||||
old_tip_no_finder.encode().to_vec()
|
||||
),
|
||||
(Tips::<Test>::hashed_key_for(hash1), old_tip_finder.encode().to_vec()),
|
||||
(Tips::<Test>::hashed_key_for(hash2), old_tip_no_finder.encode().to_vec()),
|
||||
];
|
||||
|
||||
s.top = data.into_iter().collect();
|
||||
|
||||
sp_io::TestExternalities::new(s).execute_with(|| {
|
||||
|
||||
TipsModTestInst::migrate_retract_tip_for_tip_new();
|
||||
|
||||
// Test w/ finder
|
||||
@@ -481,10 +492,12 @@ fn test_last_reward_migration() {
|
||||
fn genesis_funding_works() {
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
let initial_funding = 100;
|
||||
pallet_balances::GenesisConfig::<Test>{
|
||||
pallet_balances::GenesisConfig::<Test> {
|
||||
// Total issuance will be 200 with treasury account initialized with 100.
|
||||
balances: vec![(0, 100), (Treasury::account_id(), initial_funding)],
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
}
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
GenesisBuild::<Test>::assimilate_storage(&pallet_treasury::GenesisConfig, &mut t).unwrap();
|
||||
let mut t: sp_io::TestExternalities = t.into();
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
// --template=./.maintain/frame-weight-template.hbs
|
||||
|
||||
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
#![allow(unused_parens)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user