mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 15:11:02 +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:
@@ -19,27 +19,17 @@
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use sp_runtime::{
|
||||
traits::IdentityLookup,
|
||||
testing::Header,
|
||||
};
|
||||
use crate::{self as pallet_balances, Config, Pallet};
|
||||
use frame_support::{parameter_types, traits::StorageMapShim, weights::IdentityFee};
|
||||
use pallet_transaction_payment::CurrencyAdapter;
|
||||
use sp_core::H256;
|
||||
use sp_io;
|
||||
use frame_support::parameter_types;
|
||||
use frame_support::traits::StorageMapShim;
|
||||
use frame_support::weights::{IdentityFee};
|
||||
use crate::{
|
||||
self as pallet_balances,
|
||||
Pallet, Config,
|
||||
};
|
||||
use pallet_transaction_payment::CurrencyAdapter;
|
||||
use sp_runtime::{testing::Header, traits::IdentityLookup};
|
||||
|
||||
use crate::*;
|
||||
use frame_support::{
|
||||
assert_ok,
|
||||
traits::{
|
||||
Currency, ReservableCurrency,
|
||||
}
|
||||
traits::{Currency, ReservableCurrency},
|
||||
};
|
||||
use frame_system::RawOrigin;
|
||||
|
||||
@@ -113,12 +103,8 @@ impl Config for Test {
|
||||
type DustRemoval = OnDustRemoval;
|
||||
type Event = Event;
|
||||
type ExistentialDeposit = ExistentialDeposit;
|
||||
type AccountStore = StorageMapShim<
|
||||
super::Account<Test>,
|
||||
system::Provider<Test>,
|
||||
u64,
|
||||
super::AccountData<u64>,
|
||||
>;
|
||||
type AccountStore =
|
||||
StorageMapShim<super::Account<Test>, system::Provider<Test>, u64, super::AccountData<u64>>;
|
||||
type MaxLocks = MaxLocks;
|
||||
type MaxReserves = MaxReserves;
|
||||
type ReserveIdentifier = [u8; 8];
|
||||
@@ -130,13 +116,10 @@ pub struct ExtBuilder {
|
||||
}
|
||||
impl Default for ExtBuilder {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
existential_deposit: 1,
|
||||
}
|
||||
Self { existential_deposit: 1 }
|
||||
}
|
||||
}
|
||||
impl ExtBuilder {
|
||||
|
||||
pub fn existential_deposit(mut self, existential_deposit: u64) -> Self {
|
||||
self.existential_deposit = existential_deposit;
|
||||
self
|
||||
@@ -149,9 +132,9 @@ impl ExtBuilder {
|
||||
pub fn build(self) -> sp_io::TestExternalities {
|
||||
self.set_associated_consts();
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
pallet_balances::GenesisConfig::<Test> {
|
||||
balances: vec![],
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
pallet_balances::GenesisConfig::<Test> { balances: vec![] }
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
let mut ext = sp_io::TestExternalities::new(t);
|
||||
ext.execute_with(|| System::set_block_number(1));
|
||||
ext
|
||||
@@ -160,112 +143,103 @@ impl ExtBuilder {
|
||||
|
||||
#[test]
|
||||
fn transfer_dust_removal_tst1_should_work() {
|
||||
ExtBuilder::default()
|
||||
.existential_deposit(100)
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
// Verification of reentrancy in dust removal
|
||||
assert_ok!(Balances::set_balance(RawOrigin::Root.into(), 1, 1000, 0));
|
||||
assert_ok!(Balances::set_balance(RawOrigin::Root.into(), 2, 500, 0));
|
||||
ExtBuilder::default().existential_deposit(100).build().execute_with(|| {
|
||||
// Verification of reentrancy in dust removal
|
||||
assert_ok!(Balances::set_balance(RawOrigin::Root.into(), 1, 1000, 0));
|
||||
assert_ok!(Balances::set_balance(RawOrigin::Root.into(), 2, 500, 0));
|
||||
|
||||
// In this transaction, account 2 free balance
|
||||
// drops below existential balance
|
||||
// and dust balance is removed from account 2
|
||||
assert_ok!(Balances::transfer(RawOrigin::Signed(2).into(), 3, 450));
|
||||
// In this transaction, account 2 free balance
|
||||
// drops below existential balance
|
||||
// and dust balance is removed from account 2
|
||||
assert_ok!(Balances::transfer(RawOrigin::Signed(2).into(), 3, 450));
|
||||
|
||||
// As expected dust balance is removed.
|
||||
assert_eq!(Balances::free_balance(&2), 0);
|
||||
// As expected dust balance is removed.
|
||||
assert_eq!(Balances::free_balance(&2), 0);
|
||||
|
||||
// As expected beneficiary account 3
|
||||
// received the transfered fund.
|
||||
assert_eq!(Balances::free_balance(&3), 450);
|
||||
// As expected beneficiary account 3
|
||||
// received the transfered fund.
|
||||
assert_eq!(Balances::free_balance(&3), 450);
|
||||
|
||||
// Dust balance is deposited to account 1
|
||||
// during the process of dust removal.
|
||||
assert_eq!(Balances::free_balance(&1), 1050);
|
||||
// Dust balance is deposited to account 1
|
||||
// during the process of dust removal.
|
||||
assert_eq!(Balances::free_balance(&1), 1050);
|
||||
|
||||
// Verify the events
|
||||
// Number of events expected is 8
|
||||
assert_eq!(System::events().len(), 11);
|
||||
// Verify the events
|
||||
// Number of events expected is 8
|
||||
assert_eq!(System::events().len(), 11);
|
||||
|
||||
System::assert_has_event(Event::Balances(crate::Event::Transfer(2, 3, 450)));
|
||||
System::assert_has_event(Event::Balances(crate::Event::DustLost(2, 50)));
|
||||
}
|
||||
);
|
||||
System::assert_has_event(Event::Balances(crate::Event::Transfer(2, 3, 450)));
|
||||
System::assert_has_event(Event::Balances(crate::Event::DustLost(2, 50)));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transfer_dust_removal_tst2_should_work() {
|
||||
ExtBuilder::default()
|
||||
.existential_deposit(100)
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
// Verification of reentrancy in dust removal
|
||||
assert_ok!(Balances::set_balance(RawOrigin::Root.into(), 1, 1000, 0));
|
||||
assert_ok!(Balances::set_balance(RawOrigin::Root.into(), 2, 500, 0));
|
||||
ExtBuilder::default().existential_deposit(100).build().execute_with(|| {
|
||||
// Verification of reentrancy in dust removal
|
||||
assert_ok!(Balances::set_balance(RawOrigin::Root.into(), 1, 1000, 0));
|
||||
assert_ok!(Balances::set_balance(RawOrigin::Root.into(), 2, 500, 0));
|
||||
|
||||
// In this transaction, account 2 free balance
|
||||
// drops below existential balance
|
||||
// and dust balance is removed from account 2
|
||||
assert_ok!(Balances::transfer(RawOrigin::Signed(2).into(), 1, 450));
|
||||
// In this transaction, account 2 free balance
|
||||
// drops below existential balance
|
||||
// and dust balance is removed from account 2
|
||||
assert_ok!(Balances::transfer(RawOrigin::Signed(2).into(), 1, 450));
|
||||
|
||||
// As expected dust balance is removed.
|
||||
assert_eq!(Balances::free_balance(&2), 0);
|
||||
// As expected dust balance is removed.
|
||||
assert_eq!(Balances::free_balance(&2), 0);
|
||||
|
||||
// Dust balance is deposited to account 1
|
||||
// during the process of dust removal.
|
||||
assert_eq!(Balances::free_balance(&1), 1500);
|
||||
// Dust balance is deposited to account 1
|
||||
// during the process of dust removal.
|
||||
assert_eq!(Balances::free_balance(&1), 1500);
|
||||
|
||||
// Verify the events
|
||||
// Number of events expected is 8
|
||||
assert_eq!(System::events().len(), 9);
|
||||
// Verify the events
|
||||
// Number of events expected is 8
|
||||
assert_eq!(System::events().len(), 9);
|
||||
|
||||
System::assert_has_event(Event::Balances(crate::Event::Transfer(2, 1, 450)));
|
||||
System::assert_has_event(Event::Balances(crate::Event::DustLost(2, 50)));
|
||||
}
|
||||
);
|
||||
System::assert_has_event(Event::Balances(crate::Event::Transfer(2, 1, 450)));
|
||||
System::assert_has_event(Event::Balances(crate::Event::DustLost(2, 50)));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repatriating_reserved_balance_dust_removal_should_work() {
|
||||
ExtBuilder::default()
|
||||
.existential_deposit(100)
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
// Verification of reentrancy in dust removal
|
||||
assert_ok!(Balances::set_balance(RawOrigin::Root.into(), 1, 1000, 0));
|
||||
assert_ok!(Balances::set_balance(RawOrigin::Root.into(), 2, 500, 0));
|
||||
ExtBuilder::default().existential_deposit(100).build().execute_with(|| {
|
||||
// Verification of reentrancy in dust removal
|
||||
assert_ok!(Balances::set_balance(RawOrigin::Root.into(), 1, 1000, 0));
|
||||
assert_ok!(Balances::set_balance(RawOrigin::Root.into(), 2, 500, 0));
|
||||
|
||||
// Reserve a value on account 2,
|
||||
// Such that free balance is lower than
|
||||
// Exestintial deposit.
|
||||
assert_ok!(Balances::reserve(&2, 450));
|
||||
// Reserve a value on account 2,
|
||||
// Such that free balance is lower than
|
||||
// Exestintial deposit.
|
||||
assert_ok!(Balances::reserve(&2, 450));
|
||||
|
||||
// Transfer of reserved fund from slashed account 2 to
|
||||
// beneficiary account 1
|
||||
assert_ok!(Balances::repatriate_reserved(&2, &1, 450, Status::Free), 0);
|
||||
// Transfer of reserved fund from slashed account 2 to
|
||||
// beneficiary account 1
|
||||
assert_ok!(Balances::repatriate_reserved(&2, &1, 450, Status::Free), 0);
|
||||
|
||||
// Since free balance of account 2 is lower than
|
||||
// existential deposit, dust amount is
|
||||
// removed from the account 2
|
||||
assert_eq!(Balances::reserved_balance(2), 0);
|
||||
assert_eq!(Balances::free_balance(2), 0);
|
||||
// Since free balance of account 2 is lower than
|
||||
// existential deposit, dust amount is
|
||||
// removed from the account 2
|
||||
assert_eq!(Balances::reserved_balance(2), 0);
|
||||
assert_eq!(Balances::free_balance(2), 0);
|
||||
|
||||
// account 1 is credited with reserved amount
|
||||
// together with dust balance during dust
|
||||
// removal.
|
||||
assert_eq!(Balances::reserved_balance(1), 0);
|
||||
assert_eq!(Balances::free_balance(1), 1500);
|
||||
// account 1 is credited with reserved amount
|
||||
// together with dust balance during dust
|
||||
// removal.
|
||||
assert_eq!(Balances::reserved_balance(1), 0);
|
||||
assert_eq!(Balances::free_balance(1), 1500);
|
||||
|
||||
// Verify the events
|
||||
// Number of events expected is 10
|
||||
assert_eq!(System::events().len(), 10);
|
||||
// Verify the events
|
||||
// Number of events expected is 10
|
||||
assert_eq!(System::events().len(), 10);
|
||||
|
||||
System::assert_has_event(Event::Balances(
|
||||
crate::Event::ReserveRepatriated(2, 1, 450, Status::Free),
|
||||
));
|
||||
System::assert_has_event(Event::Balances(crate::Event::ReserveRepatriated(
|
||||
2,
|
||||
1,
|
||||
450,
|
||||
Status::Free,
|
||||
)));
|
||||
|
||||
System::assert_last_event(Event::Balances(crate::Event::DustLost(2, 50)));
|
||||
}
|
||||
);
|
||||
System::assert_last_event(Event::Balances(crate::Event::DustLost(2, 50)));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user