Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 78ce061

Browse files
ferrell-codeKiChjanggui1117
authored
Bounties Pallet to FrameV2 (#9566)
* migrate bounties pallet * events in tests * test import event * Update frame/bounties/src/lib.rs Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> * cargo fmt * line width * benchmarks compile * add migrations * fmt * comments * mod migrations * fix Cargo.toml * never remember cargo fmt * fix migration * migrations and test * change checks in migration * remove unused values * Update frame/bounties/src/migrations/v4.rs * cargo fmt * fix benchmarking * trigger ci Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
1 parent ce3c31f commit 78ce061

File tree

7 files changed

+566
-239
lines changed

7 files changed

+566
-239
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frame/bounties/Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,27 @@ sp-runtime = { version = "4.0.0-dev", default-features = false, path = "../../pr
2222
frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" }
2323
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }
2424
pallet-treasury = { version = "4.0.0-dev", default-features = false, path = "../treasury" }
25-
25+
sp-io = { version = "4.0.0-dev", path = "../../primitives/io", default-features = false }
26+
sp-core = { version = "4.0.0-dev", path = "../../primitives/core", default-features = false }
2627
frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../benchmarking", optional = true }
28+
log = { version = "0.4.14", default-features = false }
2729

2830
[dev-dependencies]
29-
sp-io = { version = "4.0.0-dev", path = "../../primitives/io" }
30-
sp-core = { version = "4.0.0-dev", path = "../../primitives/core" }
3131
pallet-balances = { version = "4.0.0-dev", path = "../balances" }
3232

3333
[features]
3434
default = ["std"]
3535
std = [
3636
"codec/std",
37+
"sp-core/std",
38+
"sp-io/std",
3739
"scale-info/std",
3840
"sp-std/std",
3941
"sp-runtime/std",
4042
"frame-support/std",
4143
"frame-system/std",
4244
"pallet-treasury/std",
45+
"log/std",
4346
]
4447
runtime-benchmarks = [
4548
"frame-benchmarking",

frame/bounties/src/benchmarking.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222
use super::*;
2323

2424
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};
25-
use frame_support::traits::OnInitialize;
2625
use frame_system::RawOrigin;
2726
use sp_runtime::traits::Bounded;
2827

29-
use crate::Module as Bounties;
28+
use crate::Pallet as Bounties;
3029
use pallet_treasury::Pallet as Treasury;
3130

3231
const SEED: u32 = 0;
@@ -36,10 +35,10 @@ fn create_approved_bounties<T: Config>(n: u32) -> Result<(), &'static str> {
3635
for i in 0..n {
3736
let (caller, _curator, _fee, value, reason) = setup_bounty::<T>(i, MAX_BYTES);
3837
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
39-
let bounty_id = BountyCount::get() - 1;
38+
let bounty_id = BountyCount::<T>::get() - 1;
4039
Bounties::<T>::approve_bounty(RawOrigin::Root.into(), bounty_id)?;
4140
}
42-
ensure!(BountyApprovals::get().len() == n as usize, "Not all bounty approved");
41+
ensure!(BountyApprovals::<T>::get().len() == n as usize, "Not all bounty approved");
4342
Ok(())
4443
}
4544

@@ -64,7 +63,7 @@ fn create_bounty<T: Config>(
6463
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, MAX_BYTES);
6564
let curator_lookup = T::Lookup::unlookup(curator.clone());
6665
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
67-
let bounty_id = BountyCount::get() - 1;
66+
let bounty_id = BountyCount::<T>::get() - 1;
6867
Bounties::<T>::approve_bounty(RawOrigin::Root.into(), bounty_id)?;
6968
Treasury::<T>::on_initialize(T::BlockNumber::zero());
7069
Bounties::<T>::propose_curator(RawOrigin::Root.into(), bounty_id, curator_lookup.clone(), fee)?;
@@ -94,15 +93,15 @@ benchmarks! {
9493
approve_bounty {
9594
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, MAX_BYTES);
9695
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
97-
let bounty_id = BountyCount::get() - 1;
96+
let bounty_id = BountyCount::<T>::get() - 1;
9897
}: _(RawOrigin::Root, bounty_id)
9998

10099
propose_curator {
101100
setup_pot_account::<T>();
102101
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, MAX_BYTES);
103102
let curator_lookup = T::Lookup::unlookup(curator.clone());
104103
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
105-
let bounty_id = BountyCount::get() - 1;
104+
let bounty_id = BountyCount::<T>::get() - 1;
106105
Bounties::<T>::approve_bounty(RawOrigin::Root.into(), bounty_id)?;
107106
Bounties::<T>::on_initialize(T::BlockNumber::zero());
108107
}: _(RawOrigin::Root, bounty_id, curator_lookup, fee)
@@ -112,7 +111,7 @@ benchmarks! {
112111
setup_pot_account::<T>();
113112
let (curator_lookup, bounty_id) = create_bounty::<T>()?;
114113
Bounties::<T>::on_initialize(T::BlockNumber::zero());
115-
let bounty_id = BountyCount::get() - 1;
114+
let bounty_id = BountyCount::<T>::get() - 1;
116115
frame_system::Pallet::<T>::set_block_number(T::BountyUpdatePeriod::get() + 1u32.into());
117116
let caller = whitelisted_caller();
118117
}: _(RawOrigin::Signed(caller), bounty_id)
@@ -122,7 +121,7 @@ benchmarks! {
122121
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, MAX_BYTES);
123122
let curator_lookup = T::Lookup::unlookup(curator.clone());
124123
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
125-
let bounty_id = BountyCount::get() - 1;
124+
let bounty_id = BountyCount::<T>::get() - 1;
126125
Bounties::<T>::approve_bounty(RawOrigin::Root.into(), bounty_id)?;
127126
Bounties::<T>::on_initialize(T::BlockNumber::zero());
128127
Bounties::<T>::propose_curator(RawOrigin::Root.into(), bounty_id, curator_lookup, fee)?;
@@ -133,7 +132,7 @@ benchmarks! {
133132
let (curator_lookup, bounty_id) = create_bounty::<T>()?;
134133
Bounties::<T>::on_initialize(T::BlockNumber::zero());
135134

136-
let bounty_id = BountyCount::get() - 1;
135+
let bounty_id = BountyCount::<T>::get() - 1;
137136
let curator = T::Lookup::lookup(curator_lookup).map_err(<&str>::from)?;
138137

139138
let beneficiary = T::Lookup::unlookup(account("beneficiary", 0, SEED));
@@ -144,10 +143,9 @@ benchmarks! {
144143
let (curator_lookup, bounty_id) = create_bounty::<T>()?;
145144
Bounties::<T>::on_initialize(T::BlockNumber::zero());
146145

147-
let bounty_id = BountyCount::get() - 1;
146+
let bounty_id = BountyCount::<T>::get() - 1;
148147
let curator = T::Lookup::lookup(curator_lookup).map_err(<&str>::from)?;
149148

150-
151149
let beneficiary_account: T::AccountId = account("beneficiary", 0, SEED);
152150
let beneficiary = T::Lookup::unlookup(beneficiary_account.clone());
153151
Bounties::<T>::award_bounty(RawOrigin::Signed(curator.clone()).into(), bounty_id, beneficiary)?;
@@ -164,29 +162,29 @@ benchmarks! {
164162
setup_pot_account::<T>();
165163
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, 0);
166164
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
167-
let bounty_id = BountyCount::get() - 1;
165+
let bounty_id = BountyCount::<T>::get() - 1;
168166
}: close_bounty(RawOrigin::Root, bounty_id)
169167

170168
close_bounty_active {
171169
setup_pot_account::<T>();
172170
let (curator_lookup, bounty_id) = create_bounty::<T>()?;
173171
Bounties::<T>::on_initialize(T::BlockNumber::zero());
174-
let bounty_id = BountyCount::get() - 1;
172+
let bounty_id = BountyCount::<T>::get() - 1;
175173
}: close_bounty(RawOrigin::Root, bounty_id)
176174
verify {
177-
assert_last_event::<T>(RawEvent::BountyCanceled(bounty_id).into())
175+
assert_last_event::<T>(Event::BountyCanceled(bounty_id).into())
178176
}
179177

180178
extend_bounty_expiry {
181179
setup_pot_account::<T>();
182180
let (curator_lookup, bounty_id) = create_bounty::<T>()?;
183181
Bounties::<T>::on_initialize(T::BlockNumber::zero());
184182

185-
let bounty_id = BountyCount::get() - 1;
183+
let bounty_id = BountyCount::<T>::get() - 1;
186184
let curator = T::Lookup::lookup(curator_lookup).map_err(<&str>::from)?;
187185
}: _(RawOrigin::Signed(curator), bounty_id, Vec::new())
188186
verify {
189-
assert_last_event::<T>(RawEvent::BountyExtended(bounty_id).into())
187+
assert_last_event::<T>(Event::BountyExtended(bounty_id).into())
190188
}
191189

192190
spend_funds {
@@ -209,7 +207,7 @@ benchmarks! {
209207
verify {
210208
ensure!(budget_remaining < BalanceOf::<T>::max_value(), "Budget not used");
211209
ensure!(missed_any == false, "Missed some");
212-
assert_last_event::<T>(RawEvent::BountyBecameActive(b - 1).into())
210+
assert_last_event::<T>(Event::BountyBecameActive(b - 1).into())
213211
}
214212
}
215213

0 commit comments

Comments
 (0)