Skip to content

Commit

Permalink
Merge branch 'staging' of github.com:ImbueNetwork/imbue into foreign-…
Browse files Browse the repository at this point in the history
…minting
  • Loading branch information
f-gate committed Dec 5, 2023
2 parents 86a2dd9 + 4295352 commit 30822af
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 30 deletions.
27 changes: 14 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build-on-self-hosted-runner
name: test-features
on:
workflow_dispatch:
push:
Expand All @@ -9,13 +9,22 @@ on:
pull_request:
branches:
- main
- staging
paths-ignore:
- "**.md"
env:
CARGO_TERM_COLOR: always
GCP_ZONE: europe-west3-a

jobs:
check_branch:
runs-on: ubuntu-latest
steps:
- name: Check branch
if: github.base_ref == 'main' && github.head_ref != 'staging'
run: |
echo "ERROR: You can only merge to main from staging."
exit 1
create-runner:
runs-on: ubuntu-latest
outputs:
Expand All @@ -31,13 +40,12 @@ jobs:
image_family: ubuntu-2004-lts
machine_type: e2-highcpu-32
disk_size: 100
machine_zone: ${{ env.GCP_ZONE }}
ephemeral: true

test-features:
needs: create-runner
runs-on: ${{ needs.create-runner.outputs.label }}
steps:
needs: create-runner
runs-on: ${{ needs.create-runner.outputs.label }}
steps:
- uses: actions/checkout@v4

- name: Set HOME
Expand All @@ -50,16 +58,9 @@ jobs:
toolchain: nightly-2023-05-22
target: wasm32-unknown-unknown
override: true
components: rustfmt, clippy

- name: Install Dependencies
run: sudo apt install protobuf-compiler clang build-essential -y

- name: 🫠 rustfmt 🫠
uses: actions-rs/cargo@v1
with:
command: fmt
args: --check

- name: Run tests with benchmarks
run: cargo test --features runtime-benchmarks
37 changes: 37 additions & 0 deletions .github/workflows/fmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: cargo-fmt
on:
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- "**.md"
pull_request:
branches:
- main
paths-ignore:
- "**.md"

jobs:
cargo-fmt:
runs-on: ${{ needs.create-runner.outputs.label }}
steps:
- uses: actions/checkout@v4

- name: Set HOME
run: echo "HOME=/home/ubuntu" >> ${GITHUB_ENV}

- name: Install minimal nightly Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2023-05-22
target: wasm32-unknown-unknown
override: true
components: rustfmt, clippy

- name: 🫠 rustfmt 🫠
uses: actions-rs/cargo@v1
with:
command: fmt
args: --check
10 changes: 7 additions & 3 deletions pallets/briefs/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ mod benchmarks {
brief_id,
CurrencyId::Native,
milestones,
false,
);
assert_last_event::<T>(Event::<T>::BriefSubmitted(caller, brief_id).into());
}
Expand All @@ -63,7 +64,8 @@ mod benchmarks {
initial_contribution,
brief_id,
CurrencyId::Native,
milestones
milestones,
false,
));
let brief_owner: T::AccountId = brief_owners[0].clone();
// (brief_owner, brief_id, contribution)
Expand Down Expand Up @@ -93,7 +95,8 @@ mod benchmarks {
initial_contribution,
brief_id,
CurrencyId::Native,
milestones
milestones,
false,
));
// (origin, brief_id)
#[extrinsic_call]
Expand All @@ -118,7 +121,8 @@ mod benchmarks {
initial_contribution,
brief_id,
CurrencyId::Native,
milestones
milestones,
false,
));
// (origin, brief_id)
#[extrinsic_call]
Expand Down
1 change: 1 addition & 0 deletions pallets/briefs/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fn create_proposal_from_brief() {
brief_id,
CurrencyId::Native,
get_milestones(10),
false,
);

assert_ok!(BriefsMod::commence_work(
Expand Down
9 changes: 9 additions & 0 deletions pallets/briefs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub mod pallet {
use frame_system::pallet_prelude::*;
use orml_traits::{MultiCurrency, MultiReservableCurrency};
use pallet_deposits::traits::DepositHandler;
use pallet_fellowship::traits::EnsureRole;
use pallet_fellowship::traits::SelectJury;
use pallet_proposals::traits::IntoProposal;
use pallet_proposals::{Contribution, FundingPath, ProposedMilestone};
Expand Down Expand Up @@ -82,9 +83,12 @@ pub mod pallet {
type MaxMilestonesPerBrief: Get<u32>;
/// Storage deposits.
type BriefStorageItem: Get<StorageItemOf<Self>>;
/// Handler for deposits.
type DepositHandler: DepositHandler<BalanceOf<Self>, AccountIdOf<Self>>;
/// The type that selects a list of jury members.
type JurySelector: SelectJury<AccountIdOf<Self>>;
/// Type for ensuring an account is of a given fellowship role.
type EnsureRole: pallet_fellowship::traits::EnsureRole<AccountIdOf<Self>>;
/// The weight info for the extrinsics.
type WeightInfo: WeightInfoT;
}
Expand Down Expand Up @@ -170,9 +174,14 @@ pub mod pallet {
brief_id: BriefHash,
currency_id: CurrencyId,
milestones: BoundedProposedMilestones<T>,
require_fellowship: bool,
) -> DispatchResult {
let who = ensure_signed(origin)?;

if require_fellowship {
T::EnsureRole::ensure_role(&applicant, pallet_fellowship::Role::Freelancer, None)?;
}

ensure!(
Briefs::<T>::get(brief_id).is_none(),
Error::<T>::BriefAlreadyExists
Expand Down
30 changes: 29 additions & 1 deletion pallets/briefs/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use sp_runtime::{
};

use pallet_deposits::traits::DepositHandler;
use pallet_fellowship::traits::FellowshipHandle;
use pallet_fellowship::Role;
use sp_std::{
convert::{TryFrom, TryInto},
str,
Expand Down Expand Up @@ -57,6 +59,7 @@ frame_support::construct_runtime!(
BriefsMod: pallet_briefs::{Pallet, Call, Storage, Event<T>},
Proposals: pallet_proposals::{Pallet, Call, Storage, Event<T>},
Identity: pallet_identity::{Pallet, Call, Storage, Event<T>},
Fellowship: pallet_fellowship::{Pallet, Call, Storage, Event<T>},
}
);

Expand Down Expand Up @@ -209,6 +212,7 @@ impl pallet_briefs::Config for Test {
type DepositHandler = MockDepositHandler;
type WeightInfo = pallet_briefs::WeightInfo<Self>;
type JurySelector = MockJurySelector;
type EnsureRole = pallet_fellowship::impls::EnsureFellowshipRole<Self>;
}

parameter_types! {
Expand Down Expand Up @@ -273,13 +277,36 @@ impl pallet_identity::Config for Test {
type WeightInfo = ();
}

parameter_types! {
pub MaxCandidatesPerShortlist: u32 = 100;
pub ShortlistPeriod: BlockNumber = 100;
pub MembershipDeposit: Balance = 50_000_000;
pub SlashAccount: AccountId = 1;
pub DepositCurrencyId: CurrencyId = CurrencyId::Native;
}

impl pallet_fellowship::Config for Test {
type RuntimeEvent = RuntimeEvent;
type MultiCurrency = Tokens;
type ForceAuthority = EnsureRoot<AccountId>;
type MaxCandidatesPerShortlist = MaxCandidatesPerShortlist;
type ShortlistPeriod = ShortlistPeriod;
type MembershipDeposit = MembershipDeposit;
type DepositCurrencyId = DepositCurrencyId;
type SlashAccount = SlashAccount;
type Permissions = pallet_fellowship::impls::VetterAndFreelancerAllPermissions;
type WeightInfo = pallet_fellowship::weights::WeightInfo<Test>;
}

parameter_types! {
pub const UnitWeightCost: u64 = 10;
pub const MaxInstructions: u32 = 100;
}

pub static ALICE: AccountId = 125;
pub static BOB: AccountId = 126;
pub static CHARLIE: AccountId = 127;
pub static FREELANCER: AccountId = 1270;
pub static TREASURY: AccountId = 200;

pub(crate) fn build_test_externality() -> sp_io::TestExternalities {
Expand All @@ -292,7 +319,7 @@ pub(crate) fn build_test_externality() -> sp_io::TestExternalities {
.unwrap();
orml_tokens::GenesisConfig::<Test> {
balances: {
vec![ALICE, BOB, CHARLIE]
vec![ALICE, BOB, CHARLIE, FREELANCER]
.into_iter()
.map(|id| (id, CurrencyId::Native, 1000000))
.collect::<Vec<_>>()
Expand All @@ -303,6 +330,7 @@ pub(crate) fn build_test_externality() -> sp_io::TestExternalities {

let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| {
pallet_fellowship::Roles::<Test>::insert(&FREELANCER, (Role::Freelancer, 10));
System::set_block_number(1);
});
ext
Expand Down
Loading

0 comments on commit 30822af

Please sign in to comment.