mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 00:31:07 +00:00
Bounties (#5715)
* add some compact annotation * implement bounties for treasury * fix test build * remove some duplicated code * fix build * add tests * fix build * fix tests * rename * merge deposit byte fee * add comments * refactor storage * support sub bounty * emit BountyBecameActive when sub bounty is created * able to contribute bounty * allow curator to cancel bounty * remove bounty contribution * implement bounty expiry * Able to extend bounty * fix build and update tests * create sub bounty test * add more tests * add benchmarks for bounties * fix build * line width * fix benchmarking test * update trait * fix typo * Update lib.rs Missing documentation on Bounties added on this change. Please check the definitions of `propose_bounty` and `create_bounty`. * update docs * add MaximumSubBountyDepth * put BountyValueMinimum into storage * rework bount depth * split on_initialize benchmarks * remove components from constant functions * Update weight integration into treasury * Update reject proposal read/writes * fix weight calculation * Ignore weights with 0 factor * Remove 0 multipliers * add some docs * allow unused for generated code * line width * allow RejectOrigin to cancel a pending payout bounty * require BountyValueMinimum > ED * make BountyValueMinimum configurable by chain spec * remove sub-bounty features * update curator * accept curator * unassign and cancel * fix tests * new tests * Update lib.rs - Include on `Assign_curator`, `accept_curator` and `unassign_curator` on Bounties Protocol Section - Include curator fee and curator deposit definitions on Terminology - Update intro. * fix test * update extend_bounty_expiry * fix benchmarking * add new benchmarking code * add docs * fix tests * Update benchmarking.rs * Make BountyValueMinimum a trait config instead of stroage value * fix runtime build * Update weights * Update default_weights.rs * update weights * update * update comments * unreserve curator fee * update tests * update benchmarks * fix curator deposit handling * trigger CI * fix benchmarking * use append instead of mutate push * additional noop tests * improve fee hanlding. update event docs * RejectOrigin to unassign * update bounty cancel logic * use Zero::zero() over 0.into() * fix tests * fix benchmarks * proposed fixes to bounties * fix tests * fix benchmarks * update weightinfo * use closure * fix compile * update weights Co-authored-by: RRTTI <raul@ost.com> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -67,7 +67,7 @@ impl frame_system::Trait for Test {
|
||||
type Call = ();
|
||||
type Hash = H256;
|
||||
type Hashing = BlakeTwo256;
|
||||
type AccountId = u64;
|
||||
type AccountId = u128; // u64 is not enough to hold bytes used to generate bounty account
|
||||
type Lookup = IdentityLookup<Self::AccountId>;
|
||||
type Header = Header;
|
||||
type Event = Event;
|
||||
@@ -99,17 +99,17 @@ impl pallet_balances::Trait for Test {
|
||||
type WeightInfo = ();
|
||||
}
|
||||
thread_local! {
|
||||
static TEN_TO_FOURTEEN: RefCell<Vec<u64>> = RefCell::new(vec![10,11,12,13,14]);
|
||||
static TEN_TO_FOURTEEN: RefCell<Vec<u128>> = RefCell::new(vec![10,11,12,13,14]);
|
||||
}
|
||||
pub struct TenToFourteen;
|
||||
impl Contains<u64> for TenToFourteen {
|
||||
fn sorted_members() -> Vec<u64> {
|
||||
impl Contains<u128> for TenToFourteen {
|
||||
fn sorted_members() -> Vec<u128> {
|
||||
TEN_TO_FOURTEEN.with(|v| {
|
||||
v.borrow().clone()
|
||||
})
|
||||
}
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn add(new: &u64) {
|
||||
fn add(new: &u128) {
|
||||
TEN_TO_FOURTEEN.with(|v| {
|
||||
let mut members = v.borrow_mut();
|
||||
members.push(*new);
|
||||
@@ -131,25 +131,37 @@ parameter_types! {
|
||||
pub const TipCountdown: u64 = 1;
|
||||
pub const TipFindersFee: Percent = Percent::from_percent(20);
|
||||
pub const TipReportDepositBase: u64 = 1;
|
||||
pub const TipReportDepositPerByte: u64 = 1;
|
||||
pub const DataDepositPerByte: u64 = 1;
|
||||
pub const BountyDepositBase: u64 = 80;
|
||||
pub const BountyDepositPayoutDelay: u64 = 3;
|
||||
pub const TreasuryModuleId: ModuleId = ModuleId(*b"py/trsry");
|
||||
pub const BountyUpdatePeriod: u32 = 20;
|
||||
pub const MaximumReasonLength: u32 = 16384;
|
||||
pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);
|
||||
pub const BountyValueMinimum: u64 = 1;
|
||||
}
|
||||
impl Trait for Test {
|
||||
type ModuleId = TreasuryModuleId;
|
||||
type Currency = pallet_balances::Module<Test>;
|
||||
type ApproveOrigin = frame_system::EnsureRoot<u64>;
|
||||
type RejectOrigin = frame_system::EnsureRoot<u64>;
|
||||
type ApproveOrigin = frame_system::EnsureRoot<u128>;
|
||||
type RejectOrigin = frame_system::EnsureRoot<u128>;
|
||||
type Tippers = TenToFourteen;
|
||||
type TipCountdown = TipCountdown;
|
||||
type TipFindersFee = TipFindersFee;
|
||||
type TipReportDepositBase = TipReportDepositBase;
|
||||
type TipReportDepositPerByte = TipReportDepositPerByte;
|
||||
type DataDepositPerByte = DataDepositPerByte;
|
||||
type Event = Event;
|
||||
type ProposalRejection = ();
|
||||
type OnSlash = ();
|
||||
type ProposalBond = ProposalBond;
|
||||
type ProposalBondMinimum = ProposalBondMinimum;
|
||||
type SpendPeriod = SpendPeriod;
|
||||
type Burn = Burn;
|
||||
type BountyDepositBase = BountyDepositBase;
|
||||
type BountyDepositPayoutDelay = BountyDepositPayoutDelay;
|
||||
type BountyUpdatePeriod = BountyUpdatePeriod;
|
||||
type BountyCuratorDeposit = BountyCuratorDeposit;
|
||||
type BountyValueMinimum = BountyValueMinimum;
|
||||
type MaximumReasonLength = MaximumReasonLength;
|
||||
type BurnDestination = (); // Just gets burned.
|
||||
type WeightInfo = ();
|
||||
}
|
||||
@@ -167,6 +179,15 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
t.into()
|
||||
}
|
||||
|
||||
fn last_event() -> RawEvent<u64, u128, H256, DefaultInstance> {
|
||||
System::events().into_iter().map(|r| r.event)
|
||||
.filter_map(|e| {
|
||||
if let Event::treasury(inner) = e { Some(inner) } else { None }
|
||||
})
|
||||
.last()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn genesis_config_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
@@ -176,7 +197,7 @@ fn genesis_config_works() {
|
||||
}
|
||||
|
||||
fn tip_hash() -> H256 {
|
||||
BlakeTwo256::hash_of(&(BlakeTwo256::hash(b"awesome.dot"), 3u64))
|
||||
BlakeTwo256::hash_of(&(BlakeTwo256::hash(b"awesome.dot"), 3u128))
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -225,7 +246,7 @@ fn report_awesome_from_beneficiary_and_tip_works() {
|
||||
assert_ok!(Treasury::report_awesome(Origin::signed(0), b"awesome.dot".to_vec(), 0));
|
||||
assert_eq!(Balances::reserved_balance(0), 12);
|
||||
assert_eq!(Balances::free_balance(0), 88);
|
||||
let h = BlakeTwo256::hash_of(&(BlakeTwo256::hash(b"awesome.dot"), 0u64));
|
||||
let h = BlakeTwo256::hash_of(&(BlakeTwo256::hash(b"awesome.dot"), 0u128));
|
||||
assert_ok!(Treasury::tip(Origin::signed(10), h.clone(), 10));
|
||||
assert_ok!(Treasury::tip(Origin::signed(11), h.clone(), 10));
|
||||
assert_ok!(Treasury::tip(Origin::signed(12), h.clone(), 10));
|
||||
@@ -248,15 +269,7 @@ fn close_tip_works() {
|
||||
|
||||
let h = tip_hash();
|
||||
|
||||
assert_eq!(
|
||||
System::events().into_iter().map(|r| r.event)
|
||||
.filter_map(|e| {
|
||||
if let Event::treasury(inner) = e { Some(inner) } else { None }
|
||||
})
|
||||
.last()
|
||||
.unwrap(),
|
||||
RawEvent::NewTip(h),
|
||||
);
|
||||
assert_eq!(last_event(), RawEvent::NewTip(h));
|
||||
|
||||
assert_ok!(Treasury::tip(Origin::signed(11), h.clone(), 10));
|
||||
|
||||
@@ -264,15 +277,7 @@ fn close_tip_works() {
|
||||
|
||||
assert_ok!(Treasury::tip(Origin::signed(12), h.clone(), 10));
|
||||
|
||||
assert_eq!(
|
||||
System::events().into_iter().map(|r| r.event)
|
||||
.filter_map(|e| {
|
||||
if let Event::treasury(inner) = e { Some(inner) } else { None }
|
||||
})
|
||||
.last()
|
||||
.unwrap(),
|
||||
RawEvent::TipClosing(h),
|
||||
);
|
||||
assert_eq!(last_event(), RawEvent::TipClosing(h));
|
||||
|
||||
assert_noop!(Treasury::close_tip(Origin::signed(0), h.into()), Error::<Test, _>::Premature);
|
||||
|
||||
@@ -281,15 +286,7 @@ fn close_tip_works() {
|
||||
assert_ok!(Treasury::close_tip(Origin::signed(0), h.into()));
|
||||
assert_eq!(Balances::free_balance(3), 10);
|
||||
|
||||
assert_eq!(
|
||||
System::events().into_iter().map(|r| r.event)
|
||||
.filter_map(|e| {
|
||||
if let Event::treasury(inner) = e { Some(inner) } else { None }
|
||||
})
|
||||
.last()
|
||||
.unwrap(),
|
||||
RawEvent::TipClosed(h, 3, 10),
|
||||
);
|
||||
assert_eq!(last_event(), RawEvent::TipClosed(h, 3, 10));
|
||||
|
||||
assert_noop!(Treasury::close_tip(Origin::signed(100), h.into()), Error::<Test, _>::UnknownTip);
|
||||
});
|
||||
@@ -441,30 +438,21 @@ fn reject_already_rejected_spend_proposal_fails() {
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::reject_proposal(Origin::root(), 0));
|
||||
assert_noop!(
|
||||
Treasury::reject_proposal(Origin::root(), 0),
|
||||
Error::<Test, _>::InvalidProposalIndex,
|
||||
);
|
||||
assert_noop!(Treasury::reject_proposal(Origin::root(), 0), Error::<Test, _>::InvalidIndex);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reject_non_existent_spend_proposal_fails() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
Treasury::reject_proposal(Origin::root(), 0),
|
||||
Error::<Test, _>::InvalidProposalIndex,
|
||||
);
|
||||
assert_noop!(Treasury::reject_proposal(Origin::root(), 0), Error::<Test, _>::InvalidIndex);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn accept_non_existent_spend_proposal_fails() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
Treasury::approve_proposal(Origin::root(), 0),
|
||||
Error::<Test, _>::InvalidProposalIndex,
|
||||
);
|
||||
assert_noop!(Treasury::approve_proposal(Origin::root(), 0), Error::<Test, _>::InvalidIndex);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -475,10 +463,7 @@ fn accept_already_rejected_spend_proposal_fails() {
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::reject_proposal(Origin::root(), 0));
|
||||
assert_noop!(
|
||||
Treasury::approve_proposal(Origin::root(), 0),
|
||||
Error::<Test, _>::InvalidProposalIndex,
|
||||
);
|
||||
assert_noop!(Treasury::approve_proposal(Origin::root(), 0), Error::<Test, _>::InvalidIndex);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -574,6 +559,502 @@ fn inexistent_account_works() {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn propose_bounty_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(1);
|
||||
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
assert_eq!(Treasury::pot(), 100);
|
||||
|
||||
assert_ok!(Treasury::propose_bounty(Origin::signed(0), 10, b"1234567890".to_vec()));
|
||||
|
||||
assert_eq!(last_event(), RawEvent::BountyProposed(0));
|
||||
|
||||
let deposit: u64 = 85 + 5;
|
||||
assert_eq!(Balances::reserved_balance(0), deposit);
|
||||
assert_eq!(Balances::free_balance(0), 100 - deposit);
|
||||
|
||||
assert_eq!(Treasury::bounties(0).unwrap(), Bounty {
|
||||
proposer: 0,
|
||||
fee: 0,
|
||||
curator_deposit: 0,
|
||||
value: 10,
|
||||
bond: deposit,
|
||||
status: BountyStatus::Proposed,
|
||||
});
|
||||
|
||||
assert_eq!(Treasury::bounty_descriptions(0).unwrap(), b"1234567890".to_vec());
|
||||
|
||||
assert_eq!(Treasury::bounty_count(), 1);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn propose_bounty_validation_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(1);
|
||||
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
assert_eq!(Treasury::pot(), 100);
|
||||
|
||||
assert_noop!(
|
||||
Treasury::propose_bounty(Origin::signed(1), 0, [0; 17_000].to_vec()),
|
||||
Error::<Test, _>::ReasonTooBig
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
Treasury::propose_bounty(Origin::signed(1), 10, b"12345678901234567890".to_vec()),
|
||||
Error::<Test, _>::InsufficientProposersBalance
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
Treasury::propose_bounty(Origin::signed(1), 0, b"12345678901234567890".to_vec()),
|
||||
Error::<Test, _>::InvalidValue
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn close_bounty_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
assert_noop!(Treasury::close_bounty(Origin::root(), 0), Error::<Test, _>::InvalidIndex);
|
||||
|
||||
assert_ok!(Treasury::propose_bounty(Origin::signed(0), 10, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Treasury::close_bounty(Origin::root(), 0));
|
||||
|
||||
let deposit: u64 = 80 + 5;
|
||||
|
||||
assert_eq!(last_event(), RawEvent::BountyRejected(0, deposit));
|
||||
|
||||
assert_eq!(Balances::reserved_balance(0), 0);
|
||||
assert_eq!(Balances::free_balance(0), 100 - deposit);
|
||||
|
||||
assert_eq!(Treasury::bounties(0), None);
|
||||
assert!(!Bounties::<Test>::contains_key(0));
|
||||
assert_eq!(Treasury::bounty_descriptions(0), None);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn approve_bounty_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
assert_noop!(Treasury::approve_bounty(Origin::root(), 0), Error::<Test, _>::InvalidIndex);
|
||||
|
||||
assert_ok!(Treasury::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Treasury::approve_bounty(Origin::root(), 0));
|
||||
|
||||
let deposit: u64 = 80 + 5;
|
||||
|
||||
assert_eq!(Treasury::bounties(0).unwrap(), Bounty {
|
||||
proposer: 0,
|
||||
fee: 0,
|
||||
value: 50,
|
||||
curator_deposit: 0,
|
||||
bond: deposit,
|
||||
status: BountyStatus::Approved,
|
||||
});
|
||||
assert_eq!(Treasury::bounty_approvals(), vec![0]);
|
||||
|
||||
assert_noop!(Treasury::close_bounty(Origin::root(), 0), Error::<Test, _>::UnexpectedStatus);
|
||||
|
||||
// deposit not returned yet
|
||||
assert_eq!(Balances::reserved_balance(0), deposit);
|
||||
assert_eq!(Balances::free_balance(0), 100 - deposit);
|
||||
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
// return deposit
|
||||
assert_eq!(Balances::reserved_balance(0), 0);
|
||||
assert_eq!(Balances::free_balance(0), 100);
|
||||
|
||||
assert_eq!(Treasury::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(Treasury::bounty_account_id(0)), 50);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn assign_curator_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
|
||||
assert_noop!(Treasury::propose_curator(Origin::root(), 0, 4, 4), Error::<Test, _>::InvalidIndex);
|
||||
|
||||
assert_ok!(Treasury::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Treasury::approve_bounty(Origin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_noop!(Treasury::propose_curator(Origin::root(), 0, 4, 50), Error::<Test, _>::InvalidFee);
|
||||
|
||||
assert_ok!(Treasury::propose_curator(Origin::root(), 0, 4, 4));
|
||||
|
||||
assert_eq!(Treasury::bounties(0).unwrap(), Bounty {
|
||||
proposer: 0,
|
||||
fee: 4,
|
||||
curator_deposit: 0,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::CuratorProposed {
|
||||
curator: 4,
|
||||
},
|
||||
});
|
||||
|
||||
assert_noop!(Treasury::accept_curator(Origin::signed(1), 0), Error::<Test, _>::RequireCurator);
|
||||
assert_noop!(Treasury::accept_curator(Origin::signed(4), 0), pallet_balances::Error::<Test, _>::InsufficientBalance);
|
||||
|
||||
Balances::make_free_balance_be(&4, 10);
|
||||
|
||||
assert_ok!(Treasury::accept_curator(Origin::signed(4), 0));
|
||||
|
||||
assert_eq!(Treasury::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);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unassign_curator_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
assert_ok!(Treasury::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Treasury::approve_bounty(Origin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Treasury::propose_curator(Origin::root(), 0, 4, 4));
|
||||
|
||||
assert_noop!(Treasury::unassign_curator(Origin::signed(1), 0), BadOrigin);
|
||||
|
||||
assert_ok!(Treasury::unassign_curator(Origin::signed(4), 0));
|
||||
|
||||
assert_eq!(Treasury::bounties(0).unwrap(), Bounty {
|
||||
proposer: 0,
|
||||
fee: 4,
|
||||
curator_deposit: 0,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::Funded,
|
||||
});
|
||||
|
||||
assert_ok!(Treasury::propose_curator(Origin::root(), 0, 4, 4));
|
||||
|
||||
Balances::make_free_balance_be(&4, 10);
|
||||
|
||||
assert_ok!(Treasury::accept_curator(Origin::signed(4), 0));
|
||||
|
||||
assert_ok!(Treasury::unassign_curator(Origin::root(), 0));
|
||||
|
||||
assert_eq!(Treasury::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(|| {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
Balances::make_free_balance_be(&4, 10);
|
||||
assert_ok!(Treasury::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Treasury::approve_bounty(Origin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Treasury::propose_curator(Origin::root(), 0, 4, 4));
|
||||
assert_ok!(Treasury::accept_curator(Origin::signed(4), 0));
|
||||
|
||||
assert_eq!(Balances::free_balance(4), 8); // inital 10 - 2 deposit
|
||||
|
||||
assert_noop!(Treasury::award_bounty(Origin::signed(1), 0, 3), Error::<Test, _>::RequireCurator);
|
||||
|
||||
assert_ok!(Treasury::award_bounty(Origin::signed(4), 0, 3));
|
||||
|
||||
assert_eq!(Treasury::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!(Treasury::claim_bounty(Origin::signed(1), 0), Error::<Test, _>::Premature);
|
||||
|
||||
System::set_block_number(5);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(5);
|
||||
|
||||
assert_ok!(Balances::transfer(Origin::signed(0), Treasury::bounty_account_id(0), 10));
|
||||
|
||||
assert_ok!(Treasury::claim_bounty(Origin::signed(1), 0));
|
||||
|
||||
assert_eq!(last_event(), RawEvent::BountyClaimed(0, 56, 3));
|
||||
|
||||
assert_eq!(Balances::free_balance(4), 14); // initial 10 + fee 4
|
||||
assert_eq!(Balances::free_balance(3), 56);
|
||||
assert_eq!(Balances::free_balance(Treasury::bounty_account_id(0)), 0);
|
||||
|
||||
assert_eq!(Treasury::bounties(0), None);
|
||||
assert_eq!(Treasury::bounty_descriptions(0), None);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn claim_handles_high_fee() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
Balances::make_free_balance_be(&4, 30);
|
||||
assert_ok!(Treasury::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Treasury::approve_bounty(Origin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Treasury::propose_curator(Origin::root(), 0, 4, 49));
|
||||
assert_ok!(Treasury::accept_curator(Origin::signed(4), 0));
|
||||
|
||||
assert_ok!(Treasury::award_bounty(Origin::signed(4), 0, 3));
|
||||
|
||||
System::set_block_number(5);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(5);
|
||||
|
||||
// make fee > balance
|
||||
let _ = Balances::slash(&Treasury::bounty_account_id(0), 10);
|
||||
|
||||
assert_ok!(Treasury::claim_bounty(Origin::signed(1), 0));
|
||||
|
||||
assert_eq!(last_event(), RawEvent::BountyClaimed(0, 0, 3));
|
||||
|
||||
assert_eq!(Balances::free_balance(4), 70); // 30 + 50 - 10
|
||||
assert_eq!(Balances::free_balance(3), 0);
|
||||
assert_eq!(Balances::free_balance(Treasury::bounty_account_id(0)), 0);
|
||||
|
||||
assert_eq!(Treasury::bounties(0), None);
|
||||
assert_eq!(Treasury::bounty_descriptions(0), None);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cancel_and_refund() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
assert_ok!(Treasury::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Treasury::approve_bounty(Origin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Balances::transfer(Origin::signed(0), Treasury::bounty_account_id(0), 10));
|
||||
|
||||
assert_eq!(Treasury::bounties(0).unwrap(), Bounty {
|
||||
proposer: 0,
|
||||
fee: 0,
|
||||
curator_deposit: 0,
|
||||
value: 50,
|
||||
bond: 85,
|
||||
status: BountyStatus::Funded,
|
||||
});
|
||||
|
||||
assert_eq!(Balances::free_balance(Treasury::bounty_account_id(0)), 60);
|
||||
|
||||
assert_noop!(Treasury::close_bounty(Origin::signed(0), 0), BadOrigin);
|
||||
|
||||
assert_ok!(Treasury::close_bounty(Origin::root(), 0));
|
||||
|
||||
assert_eq!(Treasury::pot(), 85); // - 25 + 10
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn award_and_cancel() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
assert_ok!(Treasury::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Treasury::approve_bounty(Origin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Treasury::propose_curator(Origin::root(), 0, 0, 10));
|
||||
assert_ok!(Treasury::accept_curator(Origin::signed(0), 0));
|
||||
|
||||
assert_eq!(Balances::free_balance(0), 95);
|
||||
assert_eq!(Balances::reserved_balance(0), 5);
|
||||
|
||||
assert_ok!(Treasury::award_bounty(Origin::signed(0), 0, 3));
|
||||
|
||||
// Cannot close bounty directly when payout is happening...
|
||||
assert_noop!(Treasury::close_bounty(Origin::root(), 0), Error::<Test, _>::PendingPayout);
|
||||
|
||||
// Instead unassign the curator to slash them and then close.
|
||||
assert_ok!(Treasury::unassign_curator(Origin::root(), 0));
|
||||
assert_ok!(Treasury::close_bounty(Origin::root(), 0));
|
||||
|
||||
assert_eq!(last_event(), RawEvent::BountyCanceled(0));
|
||||
|
||||
assert_eq!(Balances::free_balance(Treasury::bounty_account_id(0)), 0);
|
||||
// Slashed.
|
||||
assert_eq!(Balances::free_balance(0), 95);
|
||||
assert_eq!(Balances::reserved_balance(0), 0);
|
||||
|
||||
assert_eq!(Treasury::bounties(0), None);
|
||||
assert_eq!(Treasury::bounty_descriptions(0), None);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expire_and_unassign() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
assert_ok!(Treasury::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Treasury::approve_bounty(Origin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Treasury::propose_curator(Origin::root(), 0, 1, 10));
|
||||
assert_ok!(Treasury::accept_curator(Origin::signed(1), 0));
|
||||
|
||||
assert_eq!(Balances::free_balance(1), 93);
|
||||
assert_eq!(Balances::reserved_balance(1), 5);
|
||||
|
||||
System::set_block_number(22);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(22);
|
||||
|
||||
assert_noop!(Treasury::unassign_curator(Origin::signed(0), 0), Error::<Test, _>::Premature);
|
||||
|
||||
System::set_block_number(23);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(23);
|
||||
|
||||
assert_ok!(Treasury::unassign_curator(Origin::signed(0), 0));
|
||||
|
||||
assert_eq!(Treasury::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
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extend_expiry() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
Balances::make_free_balance_be(&4, 10);
|
||||
assert_ok!(Treasury::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Treasury::approve_bounty(Origin::root(), 0));
|
||||
|
||||
assert_noop!(Treasury::extend_bounty_expiry(Origin::signed(1), 0, Vec::new()), Error::<Test, _>::UnexpectedStatus);
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Treasury::propose_curator(Origin::root(), 0, 4, 10));
|
||||
assert_ok!(Treasury::accept_curator(Origin::signed(4), 0));
|
||||
|
||||
assert_eq!(Balances::free_balance(4), 5);
|
||||
assert_eq!(Balances::reserved_balance(4), 5);
|
||||
|
||||
System::set_block_number(10);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(10);
|
||||
|
||||
assert_noop!(Treasury::extend_bounty_expiry(Origin::signed(0), 0, Vec::new()), Error::<Test, _>::RequireCurator);
|
||||
assert_ok!(Treasury::extend_bounty_expiry(Origin::signed(4), 0, Vec::new()));
|
||||
|
||||
assert_eq!(Treasury::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!(Treasury::extend_bounty_expiry(Origin::signed(4), 0, Vec::new()));
|
||||
|
||||
assert_eq!(Treasury::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);
|
||||
|
||||
assert_noop!(Treasury::unassign_curator(Origin::signed(0), 0), Error::<Test, _>::Premature);
|
||||
assert_ok!(Treasury::unassign_curator(Origin::signed(4), 0));
|
||||
|
||||
assert_eq!(Balances::free_balance(4), 10); // not slashed
|
||||
assert_eq!(Balances::reserved_balance(4), 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_last_reward_migration() {
|
||||
use sp_storage::Storage;
|
||||
@@ -604,7 +1085,7 @@ fn test_last_reward_migration() {
|
||||
let reason1 = BlakeTwo256::hash(b"reason1");
|
||||
let hash1 = BlakeTwo256::hash_of(&(reason1, 10u64));
|
||||
|
||||
let old_tip_finder = OldOpenTip::<u64, u64, u64, H256> {
|
||||
let old_tip_finder = OldOpenTip::<u128, u64, u64, H256> {
|
||||
reason: reason1,
|
||||
who: 10,
|
||||
finder: Some((20, 30)),
|
||||
@@ -615,7 +1096,7 @@ fn test_last_reward_migration() {
|
||||
let reason2 = BlakeTwo256::hash(b"reason2");
|
||||
let hash2 = BlakeTwo256::hash_of(&(reason2, 20u64));
|
||||
|
||||
let old_tip_no_finder = OldOpenTip::<u64, u64, u64, H256> {
|
||||
let old_tip_no_finder = OldOpenTip::<u128, u64, u64, H256> {
|
||||
reason: reason2,
|
||||
who: 20,
|
||||
finder: None,
|
||||
|
||||
Reference in New Issue
Block a user