Skip to content

Commit 1b8c2fe

Browse files
authored
Merge branch 'staging' into ci-improvements
2 parents cde24e7 + 4295352 commit 1b8c2fe

File tree

9 files changed

+101
-11
lines changed

9 files changed

+101
-11
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ on:
1414
- "**.md"
1515
env:
1616
CARGO_TERM_COLOR: always
17-
GCP_ZONE: europe-west3-b
1817

1918
jobs:
2019
create-runner:
@@ -32,7 +31,6 @@ jobs:
3231
image_family: ubuntu-2004-lts
3332
machine_type: e2-highcpu-32
3433
disk_size: 100
35-
machine_zone: ${{ env.GCP_ZONE }}
3634
ephemeral: true
3735

3836
test-features:

pallets/briefs/src/benchmarking.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ mod benchmarks {
4141
brief_id,
4242
CurrencyId::Native,
4343
milestones,
44+
false,
4445
);
4546
assert_last_event::<T>(Event::<T>::BriefSubmitted(caller, brief_id).into());
4647
}
@@ -63,7 +64,8 @@ mod benchmarks {
6364
initial_contribution,
6465
brief_id,
6566
CurrencyId::Native,
66-
milestones
67+
milestones,
68+
false,
6769
));
6870
let brief_owner: T::AccountId = brief_owners[0].clone();
6971
// (brief_owner, brief_id, contribution)
@@ -93,7 +95,8 @@ mod benchmarks {
9395
initial_contribution,
9496
brief_id,
9597
CurrencyId::Native,
96-
milestones
98+
milestones,
99+
false,
97100
));
98101
// (origin, brief_id)
99102
#[extrinsic_call]
@@ -118,7 +121,8 @@ mod benchmarks {
118121
initial_contribution,
119122
brief_id,
120123
CurrencyId::Native,
121-
milestones
124+
milestones,
125+
false,
122126
));
123127
// (origin, brief_id)
124128
#[extrinsic_call]

pallets/briefs/src/integration_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fn create_proposal_from_brief() {
2222
brief_id,
2323
CurrencyId::Native,
2424
get_milestones(10),
25+
false,
2526
);
2627

2728
assert_ok!(BriefsMod::commence_work(

pallets/briefs/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub mod pallet {
3131
use frame_system::pallet_prelude::*;
3232
use orml_traits::{MultiCurrency, MultiReservableCurrency};
3333
use pallet_deposits::traits::DepositHandler;
34+
use pallet_fellowship::traits::EnsureRole;
3435
use pallet_fellowship::traits::SelectJury;
3536
use pallet_proposals::traits::IntoProposal;
3637
use pallet_proposals::{Contribution, FundingPath, ProposedMilestone};
@@ -82,9 +83,12 @@ pub mod pallet {
8283
type MaxMilestonesPerBrief: Get<u32>;
8384
/// Storage deposits.
8485
type BriefStorageItem: Get<StorageItemOf<Self>>;
86+
/// Handler for deposits.
8587
type DepositHandler: DepositHandler<BalanceOf<Self>, AccountIdOf<Self>>;
8688
/// The type that selects a list of jury members.
8789
type JurySelector: SelectJury<AccountIdOf<Self>>;
90+
/// Type for ensuring an account is of a given fellowship role.
91+
type EnsureRole: pallet_fellowship::traits::EnsureRole<AccountIdOf<Self>>;
8892
/// The weight info for the extrinsics.
8993
type WeightInfo: WeightInfoT;
9094
}
@@ -170,9 +174,14 @@ pub mod pallet {
170174
brief_id: BriefHash,
171175
currency_id: CurrencyId,
172176
milestones: BoundedProposedMilestones<T>,
177+
require_fellowship: bool,
173178
) -> DispatchResult {
174179
let who = ensure_signed(origin)?;
175180

181+
if require_fellowship {
182+
T::EnsureRole::ensure_role(&applicant, pallet_fellowship::Role::Freelancer, None)?;
183+
}
184+
176185
ensure!(
177186
Briefs::<T>::get(brief_id).is_none(),
178187
Error::<T>::BriefAlreadyExists

pallets/briefs/src/mock.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use sp_runtime::{
1818
};
1919

2020
use pallet_deposits::traits::DepositHandler;
21+
use pallet_fellowship::traits::FellowshipHandle;
22+
use pallet_fellowship::Role;
2123
use sp_std::{
2224
convert::{TryFrom, TryInto},
2325
str,
@@ -57,6 +59,7 @@ frame_support::construct_runtime!(
5759
BriefsMod: pallet_briefs::{Pallet, Call, Storage, Event<T>},
5860
Proposals: pallet_proposals::{Pallet, Call, Storage, Event<T>},
5961
Identity: pallet_identity::{Pallet, Call, Storage, Event<T>},
62+
Fellowship: pallet_fellowship::{Pallet, Call, Storage, Event<T>},
6063
}
6164
);
6265

@@ -209,6 +212,7 @@ impl pallet_briefs::Config for Test {
209212
type DepositHandler = MockDepositHandler;
210213
type WeightInfo = pallet_briefs::WeightInfo<Self>;
211214
type JurySelector = MockJurySelector;
215+
type EnsureRole = pallet_fellowship::impls::EnsureFellowshipRole<Self>;
212216
}
213217

214218
parameter_types! {
@@ -273,13 +277,36 @@ impl pallet_identity::Config for Test {
273277
type WeightInfo = ();
274278
}
275279

280+
parameter_types! {
281+
pub MaxCandidatesPerShortlist: u32 = 100;
282+
pub ShortlistPeriod: BlockNumber = 100;
283+
pub MembershipDeposit: Balance = 50_000_000;
284+
pub SlashAccount: AccountId = 1;
285+
pub DepositCurrencyId: CurrencyId = CurrencyId::Native;
286+
}
287+
288+
impl pallet_fellowship::Config for Test {
289+
type RuntimeEvent = RuntimeEvent;
290+
type MultiCurrency = Tokens;
291+
type ForceAuthority = EnsureRoot<AccountId>;
292+
type MaxCandidatesPerShortlist = MaxCandidatesPerShortlist;
293+
type ShortlistPeriod = ShortlistPeriod;
294+
type MembershipDeposit = MembershipDeposit;
295+
type DepositCurrencyId = DepositCurrencyId;
296+
type SlashAccount = SlashAccount;
297+
type Permissions = pallet_fellowship::impls::VetterAndFreelancerAllPermissions;
298+
type WeightInfo = pallet_fellowship::weights::WeightInfo<Test>;
299+
}
300+
276301
parameter_types! {
277302
pub const UnitWeightCost: u64 = 10;
278303
pub const MaxInstructions: u32 = 100;
279304
}
305+
280306
pub static ALICE: AccountId = 125;
281307
pub static BOB: AccountId = 126;
282308
pub static CHARLIE: AccountId = 127;
309+
pub static FREELANCER: AccountId = 1270;
283310
pub static TREASURY: AccountId = 200;
284311

285312
pub(crate) fn build_test_externality() -> sp_io::TestExternalities {
@@ -292,7 +319,7 @@ pub(crate) fn build_test_externality() -> sp_io::TestExternalities {
292319
.unwrap();
293320
orml_tokens::GenesisConfig::<Test> {
294321
balances: {
295-
vec![ALICE, BOB, CHARLIE]
322+
vec![ALICE, BOB, CHARLIE, FREELANCER]
296323
.into_iter()
297324
.map(|id| (id, CurrencyId::Native, 1000000))
298325
.collect::<Vec<_>>()
@@ -303,6 +330,7 @@ pub(crate) fn build_test_externality() -> sp_io::TestExternalities {
303330

304331
let mut ext = sp_io::TestExternalities::new(t);
305332
ext.execute_with(|| {
333+
pallet_fellowship::Roles::<Test>::insert(&FREELANCER, (Role::Freelancer, 10));
306334
System::set_block_number(1);
307335
});
308336
ext

pallets/briefs/src/tests.rs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,53 @@ use crate::*;
66
use common_types::CurrencyId;
77
use frame_support::{assert_noop, assert_ok, pallet_prelude::*};
88
use orml_traits::{MultiCurrency, MultiReservableCurrency};
9+
use pallet_fellowship::traits::EnsureRole;
910
use pallet_proposals::{BoundedProposedMilestones, Projects, ProposedMilestone};
1011
use sp_arithmetic::per_things::Percent;
12+
use sp_runtime::DispatchError::BadOrigin;
1113

1214
use std::convert::TryInto;
1315

1416
#[test]
1517
fn create_brief_not_approved_applicant() {
1618
build_test_externality().execute_with(|| {
17-
// TODO:
18-
// Only accounts in the fellowship can apply for work
19+
assert_noop!(
20+
BriefsMod::create_brief(
21+
RuntimeOrigin::signed(BOB),
22+
get_brief_owners(u32::MAX),
23+
ALICE,
24+
100000,
25+
10000,
26+
gen_hash(1),
27+
CurrencyId::Native,
28+
get_milestones(10),
29+
true,
30+
),
31+
BadOrigin
32+
);
33+
});
34+
}
35+
36+
#[test]
37+
fn create_brief_approved_applicant() {
38+
build_test_externality().execute_with(|| {
39+
assert_ok!(<Test as Config>::EnsureRole::ensure_role(
40+
&FREELANCER,
41+
pallet_fellowship::Role::Freelancer,
42+
None
43+
));
44+
45+
assert_ok!(BriefsMod::create_brief(
46+
RuntimeOrigin::signed(BOB),
47+
get_brief_owners(10),
48+
FREELANCER,
49+
100000,
50+
10000,
51+
gen_hash(1),
52+
CurrencyId::Native,
53+
get_milestones(10),
54+
true,
55+
));
1956
});
2057
}
2158

@@ -32,6 +69,7 @@ fn create_brief_brief_owner_overflow() {
3269
gen_hash(1),
3370
CurrencyId::Native,
3471
get_milestones(10),
72+
false,
3573
),
3674
Error::<Test>::TooManyBriefOwners
3775
);
@@ -50,6 +88,7 @@ fn create_brief_with_no_contribution_ok() {
5088
gen_hash(1),
5189
CurrencyId::Native,
5290
get_milestones(10),
91+
false,
5392
));
5493
});
5594
}
@@ -70,6 +109,7 @@ fn create_brief_no_contribution_and_contribute() {
70109
brief_id,
71110
CurrencyId::Native,
72111
get_milestones(10),
112+
false,
73113
));
74114

75115
(0..5).for_each(|_| {
@@ -111,6 +151,7 @@ fn contribute_to_brief_not_brief_owner() {
111151
brief_id,
112152
CurrencyId::Native,
113153
get_milestones(10),
154+
false,
114155
));
115156

116157
assert_noop!(
@@ -139,6 +180,7 @@ fn contribute_to_brief_more_than_total_ok() {
139180
brief_id,
140181
CurrencyId::Native,
141182
get_milestones(10),
183+
false,
142184
));
143185
assert_ok!(BriefsMod::contribute_to_brief(
144186
RuntimeOrigin::signed(BOB),
@@ -163,6 +205,7 @@ fn create_brief_already_exists() {
163205
brief_id,
164206
CurrencyId::Native,
165207
get_milestones(10),
208+
false,
166209
));
167210

168211
assert_noop!(
@@ -175,6 +218,7 @@ fn create_brief_already_exists() {
175218
brief_id,
176219
CurrencyId::Native,
177220
get_milestones(10),
221+
false,
178222
),
179223
Error::<Test>::BriefAlreadyExists
180224
);
@@ -196,6 +240,7 @@ fn only_applicant_can_start_work() {
196240
brief_id,
197241
CurrencyId::Native,
198242
get_milestones(10),
243+
false,
199244
));
200245

201246
assert_noop!(
@@ -225,6 +270,7 @@ fn initial_contribution_and_extra_contribution_aggregates() {
225270
brief_id,
226271
CurrencyId::Native,
227272
get_milestones(10),
273+
false,
228274
));
229275

230276
assert_ok!(BriefsMod::contribute_to_brief(
@@ -261,6 +307,7 @@ fn reserved_funds_are_transferred_to_project_kitty() {
261307
brief_id,
262308
CurrencyId::Native,
263309
get_milestones(10),
310+
false,
264311
);
265312

266313
assert_ok!(BriefsMod::commence_work(
@@ -293,6 +340,7 @@ fn cancel_brief_works() {
293340
brief_id,
294341
CurrencyId::Native,
295342
get_milestones(10),
343+
false,
296344
));
297345

298346
assert_ok!(BriefsMod::contribute_to_brief(
@@ -359,6 +407,7 @@ fn cancel_brief_not_brief_owner() {
359407
brief_id,
360408
CurrencyId::Native,
361409
get_milestones(10),
410+
false,
362411
));
363412

364413
assert_noop!(

pallets/fellowship/src/impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use sp_std::{vec, vec::Vec};
88
/// Ensure that a account is of a given role.
99
/// Used in other pallets like an ensure origin.
1010
pub struct EnsureFellowshipRole<T>(T);
11-
impl<T: Config> EnsureRole<AccountIdOf<T>, Role> for EnsureFellowshipRole<T> {
11+
impl<T: Config> EnsureRole<AccountIdOf<T>> for EnsureFellowshipRole<T> {
1212
type Success = ();
1313

1414
fn ensure_role(

pallets/fellowship/src/traits.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::Rank;
1+
use crate::{Rank, Role};
22
use codec::{FullCodec, FullEncode};
33
use frame_support::{pallet_prelude::*, weights::Weight};
44
use sp_runtime::DispatchError;
@@ -19,7 +19,7 @@ pub trait FellowshipHandle<AccountId> {
1919
fn revoke_fellowship(who: &AccountId, slash_deposit: bool) -> Result<(), DispatchError>;
2020
}
2121

22-
pub trait EnsureRole<AccountId, Role> {
22+
pub trait EnsureRole<AccountId> {
2323
type Success;
2424
fn ensure_role(
2525
acc: &AccountId,

runtime/imbue-kusama/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,7 @@ impl pallet_briefs::Config for Runtime {
868868
type BriefStorageItem = BriefStorageItem;
869869
type DepositHandler = Deposits;
870870
type JurySelector = PointerBasedJurySelector<Runtime>;
871+
type EnsureRole = pallet_fellowship::impls::EnsureFellowshipRole<Runtime>;
871872
}
872873

873874
parameter_types! {

0 commit comments

Comments
 (0)