mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 10:31:03 +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,10 +21,10 @@
|
||||
|
||||
use super::*;
|
||||
|
||||
use sp_runtime::traits::Bounded;
|
||||
use frame_system::RawOrigin;
|
||||
use frame_benchmarking::{benchmarks, account, whitelisted_caller, impl_benchmark_test_suite};
|
||||
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};
|
||||
use frame_support::traits::OnInitialize;
|
||||
use frame_system::RawOrigin;
|
||||
use sp_runtime::traits::Bounded;
|
||||
|
||||
use crate::Module as Bounties;
|
||||
use pallet_treasury::Pallet as Treasury;
|
||||
@@ -33,7 +33,7 @@ const SEED: u32 = 0;
|
||||
|
||||
// Create bounties that are approved for use in `on_initialize`.
|
||||
fn create_approved_bounties<T: Config>(n: u32) -> Result<(), &'static str> {
|
||||
for i in 0 .. n {
|
||||
for i in 0..n {
|
||||
let (caller, _curator, _fee, value, reason) = setup_bounty::<T>(i, MAX_BYTES);
|
||||
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
|
||||
let bounty_id = BountyCount::get() - 1;
|
||||
@@ -44,13 +44,10 @@ fn create_approved_bounties<T: Config>(n: u32) -> Result<(), &'static str> {
|
||||
}
|
||||
|
||||
// Create the pre-requisite information needed to create a treasury `propose_bounty`.
|
||||
fn setup_bounty<T: Config>(u: u32, d: u32) -> (
|
||||
T::AccountId,
|
||||
T::AccountId,
|
||||
BalanceOf<T>,
|
||||
BalanceOf<T>,
|
||||
Vec<u8>,
|
||||
) {
|
||||
fn setup_bounty<T: Config>(
|
||||
u: u32,
|
||||
d: u32,
|
||||
) -> (T::AccountId, T::AccountId, BalanceOf<T>, BalanceOf<T>, Vec<u8>) {
|
||||
let caller = account("caller", u, SEED);
|
||||
let value: BalanceOf<T> = T::BountyValueMinimum::get().saturating_mul(100u32.into());
|
||||
let fee = value / 2u32.into();
|
||||
@@ -62,10 +59,8 @@ fn setup_bounty<T: Config>(u: u32, d: u32) -> (
|
||||
(caller, curator, fee, value, reason)
|
||||
}
|
||||
|
||||
fn create_bounty<T: Config>() -> Result<(
|
||||
<T::Lookup as StaticLookup>::Source,
|
||||
BountyIndex,
|
||||
), &'static str> {
|
||||
fn create_bounty<T: Config>(
|
||||
) -> Result<(<T::Lookup as StaticLookup>::Source, BountyIndex), &'static str> {
|
||||
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, MAX_BYTES);
|
||||
let curator_lookup = T::Lookup::unlookup(curator.clone());
|
||||
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
|
||||
@@ -216,8 +211,4 @@ benchmarks! {
|
||||
}
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(
|
||||
Bounties,
|
||||
crate::tests::new_test_ext(),
|
||||
crate::tests::Test,
|
||||
);
|
||||
impl_benchmark_test_suite!(Bounties, crate::tests::new_test_ext(), crate::tests::Test,);
|
||||
|
||||
@@ -74,28 +74,28 @@
|
||||
|
||||
#![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};
|
||||
use frame_support::{decl_error, decl_event, decl_module, decl_storage, ensure};
|
||||
|
||||
use frame_support::traits::{
|
||||
Currency, Get, Imbalance, OnUnbalanced, ExistenceRequirement::{AllowDeath},
|
||||
ReservableCurrency};
|
||||
Currency, ExistenceRequirement::AllowDeath, Get, Imbalance, OnUnbalanced, ReservableCurrency,
|
||||
};
|
||||
|
||||
use sp_runtime::{Permill, RuntimeDebug, DispatchResult, traits::{
|
||||
Zero, StaticLookup, AccountIdConversion, Saturating, BadOrigin
|
||||
}};
|
||||
use sp_runtime::{
|
||||
traits::{AccountIdConversion, BadOrigin, Saturating, StaticLookup, Zero},
|
||||
DispatchResult, Permill, RuntimeDebug,
|
||||
};
|
||||
|
||||
use frame_support::dispatch::DispatchResultWithPostInfo;
|
||||
use frame_support::traits::{EnsureOrigin};
|
||||
use frame_support::{dispatch::DispatchResultWithPostInfo, traits::EnsureOrigin};
|
||||
|
||||
use frame_support::weights::{Weight};
|
||||
use frame_support::weights::Weight;
|
||||
|
||||
use codec::{Encode, Decode};
|
||||
use codec::{Decode, Encode};
|
||||
use frame_system::{self as system, ensure_signed};
|
||||
pub use weights::WeightInfo;
|
||||
|
||||
@@ -104,7 +104,6 @@ type BalanceOf<T> = pallet_treasury::BalanceOf<T>;
|
||||
type PositiveImbalanceOf<T> = pallet_treasury::PositiveImbalanceOf<T>;
|
||||
|
||||
pub trait Config: frame_system::Config + pallet_treasury::Config {
|
||||
|
||||
/// The amount held on deposit for placing a bounty proposal.
|
||||
type BountyDepositBase: Get<BalanceOf<Self>>;
|
||||
|
||||
@@ -692,14 +691,17 @@ impl<T: Config> Module<T> {
|
||||
description: Vec<u8>,
|
||||
value: BalanceOf<T>,
|
||||
) -> DispatchResult {
|
||||
ensure!(description.len() <= T::MaximumReasonLength::get() as usize, Error::<T>::ReasonTooBig);
|
||||
ensure!(
|
||||
description.len() <= T::MaximumReasonLength::get() as usize,
|
||||
Error::<T>::ReasonTooBig
|
||||
);
|
||||
ensure!(value >= T::BountyValueMinimum::get(), Error::<T>::InvalidValue);
|
||||
|
||||
let index = Self::bounty_count();
|
||||
|
||||
// reserve deposit for new bounty
|
||||
let bond = T::BountyDepositBase::get()
|
||||
+ T::DataDepositPerByte::get() * (description.len() as u32).into();
|
||||
let bond = T::BountyDepositBase::get() +
|
||||
T::DataDepositPerByte::get() * (description.len() as u32).into();
|
||||
T::Currency::reserve(&proposer, bond)
|
||||
.map_err(|_| Error::<T>::InsufficientProposersBalance)?;
|
||||
|
||||
@@ -721,7 +723,6 @@ impl<T: Config> Module<T> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl<T: Config> pallet_treasury::SpendFunds<T> for Module<T> {
|
||||
@@ -729,7 +730,7 @@ impl<T: Config> pallet_treasury::SpendFunds<T> for Module<T> {
|
||||
budget_remaining: &mut BalanceOf<T>,
|
||||
imbalance: &mut PositiveImbalanceOf<T>,
|
||||
total_weight: &mut Weight,
|
||||
missed_any: &mut bool
|
||||
missed_any: &mut bool,
|
||||
) {
|
||||
let bounties_len = BountyApprovals::mutate(|v| {
|
||||
let bounties_approval_len = v.len() as u32;
|
||||
@@ -747,7 +748,10 @@ impl<T: Config> pallet_treasury::SpendFunds<T> for Module<T> {
|
||||
debug_assert!(err_amount.is_zero());
|
||||
|
||||
// fund the bounty account
|
||||
imbalance.subsume(T::Currency::deposit_creating(&Self::bounty_account_id(index), bounty.value));
|
||||
imbalance.subsume(T::Currency::deposit_creating(
|
||||
&Self::bounty_account_id(index),
|
||||
bounty.value,
|
||||
));
|
||||
|
||||
Self::deposit_event(RawEvent::BountyBecameActive(index));
|
||||
false
|
||||
|
||||
@@ -19,20 +19,20 @@
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use crate as pallet_bounties;
|
||||
use super::*;
|
||||
use crate as pallet_bounties;
|
||||
use std::cell::RefCell;
|
||||
|
||||
use frame_support::{
|
||||
assert_noop, assert_ok, parameter_types, weights::Weight, traits::OnInitialize,
|
||||
PalletId, pallet_prelude::GenesisBuild,
|
||||
assert_noop, assert_ok, pallet_prelude::GenesisBuild, parameter_types, traits::OnInitialize,
|
||||
weights::Weight, PalletId,
|
||||
};
|
||||
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
Perbill,
|
||||
testing::Header,
|
||||
traits::{BlakeTwo256, IdentityLookup, BadOrigin},
|
||||
traits::{BadOrigin, BlakeTwo256, IdentityLookup},
|
||||
Perbill,
|
||||
};
|
||||
|
||||
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
|
||||
@@ -121,7 +121,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 = Bounties;
|
||||
type MaxApprovals = MaxApprovals;
|
||||
@@ -146,23 +146,25 @@ impl Config for Test {
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
type TreasuryError = pallet_treasury::Error::<Test>;
|
||||
type TreasuryError = pallet_treasury::Error<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> {
|
||||
System::events().into_iter().map(|r| r.event)
|
||||
.filter_map(|e| {
|
||||
if let Event::Bounties(inner) = e { Some(inner) } else { None }
|
||||
})
|
||||
System::events()
|
||||
.into_iter()
|
||||
.map(|r| r.event)
|
||||
.filter_map(|e| if let Event::Bounties(inner) = e { Some(inner) } else { None })
|
||||
.last()
|
||||
.unwrap()
|
||||
}
|
||||
@@ -267,8 +269,10 @@ fn reject_already_rejected_spend_proposal_fails() {
|
||||
#[test]
|
||||
fn reject_non_existent_spend_proposal_fails() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(Treasury::reject_proposal(Origin::root(), 0),
|
||||
pallet_treasury::Error::<Test, _>::InvalidIndex);
|
||||
assert_noop!(
|
||||
Treasury::reject_proposal(Origin::root(), 0),
|
||||
pallet_treasury::Error::<Test, _>::InvalidIndex
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -353,9 +357,9 @@ fn treasury_account_doesnt_get_deleted() {
|
||||
#[test]
|
||||
fn inexistent_account_works() {
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
pallet_balances::GenesisConfig::<Test>{
|
||||
balances: vec![(0, 100), (1, 99), (2, 1)],
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
pallet_balances::GenesisConfig::<Test> { balances: vec![(0, 100), (1, 99), (2, 1)] }
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
// Treasury genesis config is not build thus treasury account does not exist
|
||||
let mut t: sp_io::TestExternalities = t.into();
|
||||
|
||||
@@ -398,14 +402,17 @@ fn propose_bounty_works() {
|
||||
assert_eq!(Balances::reserved_balance(0), deposit);
|
||||
assert_eq!(Balances::free_balance(0), 100 - deposit);
|
||||
|
||||
assert_eq!(Bounties::bounties(0).unwrap(), Bounty {
|
||||
proposer: 0,
|
||||
fee: 0,
|
||||
curator_deposit: 0,
|
||||
value: 10,
|
||||
bond: deposit,
|
||||
status: BountyStatus::Proposed,
|
||||
});
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
Bounty {
|
||||
proposer: 0,
|
||||
fee: 0,
|
||||
curator_deposit: 0,
|
||||
value: 10,
|
||||
bond: deposit,
|
||||
status: BountyStatus::Proposed,
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(Bounties::bounty_descriptions(0).unwrap(), b"1234567890".to_vec());
|
||||
|
||||
@@ -476,14 +483,17 @@ fn approve_bounty_works() {
|
||||
|
||||
let deposit: u64 = 80 + 5;
|
||||
|
||||
assert_eq!(Bounties::bounties(0).unwrap(), Bounty {
|
||||
proposer: 0,
|
||||
fee: 0,
|
||||
value: 50,
|
||||
curator_deposit: 0,
|
||||
bond: deposit,
|
||||
status: BountyStatus::Approved,
|
||||
});
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
Bounty {
|
||||
proposer: 0,
|
||||
fee: 0,
|
||||
value: 50,
|
||||
curator_deposit: 0,
|
||||
bond: deposit,
|
||||
status: BountyStatus::Approved,
|
||||
}
|
||||
);
|
||||
assert_eq!(Bounties::bounty_approvals(), vec![0]);
|
||||
|
||||
assert_noop!(Bounties::close_bounty(Origin::root(), 0), Error::<Test>::UnexpectedStatus);
|
||||
@@ -498,14 +508,17 @@ fn approve_bounty_works() {
|
||||
assert_eq!(Balances::reserved_balance(0), 0);
|
||||
assert_eq!(Balances::free_balance(0), 100);
|
||||
|
||||
assert_eq!(Bounties::bounties(0).unwrap(), Bounty {
|
||||
proposer: 0,
|
||||
fee: 0,
|
||||
curator_deposit: 0,
|
||||
value: 50,
|
||||
bond: deposit,
|
||||
status: BountyStatus::Funded,
|
||||
});
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
Bounty {
|
||||
proposer: 0,
|
||||
fee: 0,
|
||||
curator_deposit: 0,
|
||||
value: 50,
|
||||
bond: deposit,
|
||||
status: BountyStatus::Funded,
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(Treasury::pot(), 100 - 50 - 25); // burn 25
|
||||
assert_eq!(Balances::free_balance(Bounties::bounty_account_id(0)), 50);
|
||||
@@ -518,7 +531,10 @@ fn assign_curator_works() {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
|
||||
assert_noop!(Bounties::propose_curator(Origin::root(), 0, 4, 4), Error::<Test>::InvalidIndex);
|
||||
assert_noop!(
|
||||
Bounties::propose_curator(Origin::root(), 0, 4, 4),
|
||||
Error::<Test>::InvalidIndex
|
||||
);
|
||||
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
@@ -527,39 +543,46 @@ fn assign_curator_works() {
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_noop!(Bounties::propose_curator(Origin::root(), 0, 4, 50), Error::<Test>::InvalidFee);
|
||||
assert_noop!(
|
||||
Bounties::propose_curator(Origin::root(), 0, 4, 50),
|
||||
Error::<Test>::InvalidFee
|
||||
);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 4, 4));
|
||||
|
||||
assert_eq!(Bounties::bounties(0).unwrap(), Bounty {
|
||||
proposer: 0,
|
||||
fee: 4,
|
||||
curator_deposit: 0,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::CuratorProposed {
|
||||
curator: 4,
|
||||
},
|
||||
});
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
Bounty {
|
||||
proposer: 0,
|
||||
fee: 4,
|
||||
curator_deposit: 0,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::CuratorProposed { curator: 4 },
|
||||
}
|
||||
);
|
||||
|
||||
assert_noop!(Bounties::accept_curator(Origin::signed(1), 0), Error::<Test>::RequireCurator);
|
||||
assert_noop!(Bounties::accept_curator(Origin::signed(4), 0), pallet_balances::Error::<Test, _>::InsufficientBalance);
|
||||
assert_noop!(
|
||||
Bounties::accept_curator(Origin::signed(4), 0),
|
||||
pallet_balances::Error::<Test, _>::InsufficientBalance
|
||||
);
|
||||
|
||||
Balances::make_free_balance_be(&4, 10);
|
||||
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(4), 0));
|
||||
|
||||
assert_eq!(Bounties::bounties(0).unwrap(), Bounty {
|
||||
proposer: 0,
|
||||
fee: 4,
|
||||
curator_deposit: 2,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::Active {
|
||||
curator: 4,
|
||||
update_due: 22,
|
||||
},
|
||||
});
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
Bounty {
|
||||
proposer: 0,
|
||||
fee: 4,
|
||||
curator_deposit: 2,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::Active { curator: 4, update_due: 22 },
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(Balances::free_balance(&4), 8);
|
||||
assert_eq!(Balances::reserved_balance(&4), 2);
|
||||
@@ -584,14 +607,17 @@ fn unassign_curator_works() {
|
||||
|
||||
assert_ok!(Bounties::unassign_curator(Origin::signed(4), 0));
|
||||
|
||||
assert_eq!(Bounties::bounties(0).unwrap(), Bounty {
|
||||
proposer: 0,
|
||||
fee: 4,
|
||||
curator_deposit: 0,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::Funded,
|
||||
});
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
Bounty {
|
||||
proposer: 0,
|
||||
fee: 4,
|
||||
curator_deposit: 0,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::Funded,
|
||||
}
|
||||
);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 4, 4));
|
||||
|
||||
@@ -601,21 +627,23 @@ fn unassign_curator_works() {
|
||||
|
||||
assert_ok!(Bounties::unassign_curator(Origin::root(), 0));
|
||||
|
||||
assert_eq!(Bounties::bounties(0).unwrap(), Bounty {
|
||||
proposer: 0,
|
||||
fee: 4,
|
||||
curator_deposit: 0,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::Funded,
|
||||
});
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
Bounty {
|
||||
proposer: 0,
|
||||
fee: 4,
|
||||
curator_deposit: 0,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::Funded,
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(Balances::free_balance(&4), 8);
|
||||
assert_eq!(Balances::reserved_balance(&4), 0); // slashed 2
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn award_and_claim_bounty_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
@@ -634,22 +662,24 @@ fn award_and_claim_bounty_works() {
|
||||
|
||||
assert_eq!(Balances::free_balance(4), 8); // inital 10 - 2 deposit
|
||||
|
||||
assert_noop!(Bounties::award_bounty(Origin::signed(1), 0, 3), Error::<Test>::RequireCurator);
|
||||
assert_noop!(
|
||||
Bounties::award_bounty(Origin::signed(1), 0, 3),
|
||||
Error::<Test>::RequireCurator
|
||||
);
|
||||
|
||||
assert_ok!(Bounties::award_bounty(Origin::signed(4), 0, 3));
|
||||
|
||||
assert_eq!(Bounties::bounties(0).unwrap(), Bounty {
|
||||
proposer: 0,
|
||||
fee: 4,
|
||||
curator_deposit: 2,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::PendingPayout {
|
||||
curator: 4,
|
||||
beneficiary: 3,
|
||||
unlock_at: 5
|
||||
},
|
||||
});
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
Bounty {
|
||||
proposer: 0,
|
||||
fee: 4,
|
||||
curator_deposit: 2,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::PendingPayout { curator: 4, beneficiary: 3, unlock_at: 5 },
|
||||
}
|
||||
);
|
||||
|
||||
assert_noop!(Bounties::claim_bounty(Origin::signed(1), 0), Error::<Test>::Premature);
|
||||
|
||||
@@ -713,7 +743,6 @@ fn claim_handles_high_fee() {
|
||||
#[test]
|
||||
fn cancel_and_refund() {
|
||||
new_test_ext().execute_with(|| {
|
||||
|
||||
System::set_block_number(1);
|
||||
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
@@ -727,14 +756,17 @@ fn cancel_and_refund() {
|
||||
|
||||
assert_ok!(Balances::transfer(Origin::signed(0), Bounties::bounty_account_id(0), 10));
|
||||
|
||||
assert_eq!(Bounties::bounties(0).unwrap(), Bounty {
|
||||
proposer: 0,
|
||||
fee: 0,
|
||||
curator_deposit: 0,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::Funded,
|
||||
});
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
Bounty {
|
||||
proposer: 0,
|
||||
fee: 0,
|
||||
curator_deposit: 0,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::Funded,
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(Balances::free_balance(Bounties::bounty_account_id(0)), 60);
|
||||
|
||||
@@ -743,9 +775,7 @@ fn cancel_and_refund() {
|
||||
assert_ok!(Bounties::close_bounty(Origin::root(), 0));
|
||||
|
||||
assert_eq!(Treasury::pot(), 85); // - 25 + 10
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -816,18 +846,20 @@ fn expire_and_unassign() {
|
||||
|
||||
assert_ok!(Bounties::unassign_curator(Origin::signed(0), 0));
|
||||
|
||||
assert_eq!(Bounties::bounties(0).unwrap(), Bounty {
|
||||
proposer: 0,
|
||||
fee: 10,
|
||||
curator_deposit: 0,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::Funded,
|
||||
});
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
Bounty {
|
||||
proposer: 0,
|
||||
fee: 10,
|
||||
curator_deposit: 0,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::Funded,
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(Balances::free_balance(1), 93);
|
||||
assert_eq!(Balances::reserved_balance(1), 0); // slashed
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -841,7 +873,10 @@ fn extend_expiry() {
|
||||
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
|
||||
assert_noop!(Bounties::extend_bounty_expiry(Origin::signed(1), 0, Vec::new()), Error::<Test>::UnexpectedStatus);
|
||||
assert_noop!(
|
||||
Bounties::extend_bounty_expiry(Origin::signed(1), 0, Vec::new()),
|
||||
Error::<Test>::UnexpectedStatus
|
||||
);
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
@@ -855,28 +890,37 @@ fn extend_expiry() {
|
||||
System::set_block_number(10);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(10);
|
||||
|
||||
assert_noop!(Bounties::extend_bounty_expiry(Origin::signed(0), 0, Vec::new()), Error::<Test>::RequireCurator);
|
||||
assert_noop!(
|
||||
Bounties::extend_bounty_expiry(Origin::signed(0), 0, Vec::new()),
|
||||
Error::<Test>::RequireCurator
|
||||
);
|
||||
assert_ok!(Bounties::extend_bounty_expiry(Origin::signed(4), 0, Vec::new()));
|
||||
|
||||
assert_eq!(Bounties::bounties(0).unwrap(), Bounty {
|
||||
proposer: 0,
|
||||
fee: 10,
|
||||
curator_deposit: 5,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::Active { curator: 4, update_due: 30 },
|
||||
});
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
Bounty {
|
||||
proposer: 0,
|
||||
fee: 10,
|
||||
curator_deposit: 5,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::Active { curator: 4, update_due: 30 },
|
||||
}
|
||||
);
|
||||
|
||||
assert_ok!(Bounties::extend_bounty_expiry(Origin::signed(4), 0, Vec::new()));
|
||||
|
||||
assert_eq!(Bounties::bounties(0).unwrap(), Bounty {
|
||||
proposer: 0,
|
||||
fee: 10,
|
||||
curator_deposit: 5,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::Active { curator: 4, update_due: 30 }, // still the same
|
||||
});
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
Bounty {
|
||||
proposer: 0,
|
||||
fee: 10,
|
||||
curator_deposit: 5,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::Active { curator: 4, update_due: 30 }, // still the same
|
||||
}
|
||||
);
|
||||
|
||||
System::set_block_number(25);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(25);
|
||||
@@ -893,10 +937,12 @@ fn extend_expiry() {
|
||||
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