Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI testing possible improvements #283

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ env:
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 @@ -40,8 +31,8 @@ jobs:
image_project: ubuntu-os-cloud
image_family: ubuntu-2004-lts
machine_type: e2-highcpu-32
disk_size: 100
machine_zone: ${{ env.GCP_ZONE }}
disk_size: 100
ephemeral: true

test-features:
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/check_branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

name: check-branch
on:
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- "**.md"
pull_request:
branches:
- main
- staging
paths-ignore:
- "**.md"

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
6 changes: 2 additions & 4 deletions .github/workflows/fmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ on:
pull_request:
branches:
- main
- staging
paths-ignore:
- "**.md"

jobs:
cargo-fmt:
runs-on: ${{ needs.create-runner.outputs.label }}
runs-on: ubuntu-latest
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:
Expand Down
70 changes: 70 additions & 0 deletions .github/workflows/try_runtime.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: try-runtime
on:
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- "**.md"
pull_request:
branches:
- main
- staging
paths-ignore:
- "**.md"
env:
CARGO_TERM_COLOR: always
GCP_ZONE: europe-west3-b

jobs:
create-runner:
runs-on: ubuntu-latest
outputs:
label: ${{ steps.create-runner.outputs.label }}
steps:
- id: create-runner
uses: related-sciences/[email protected]
with:
token: ${{ secrets.GH_SA_TOKEN }}
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
image_project: ubuntu-os-cloud
image_family: ubuntu-2004
machine_type: e2-highcpu-32
machine_zone: ${{ env.GCP_ZONE }}
disk_size: 100
ephemeral: true

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

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

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: default
toolchain: stable
target: wasm32-unknown-unknown
override: true

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

- name: Install try-runtime
run: cargo install --git https://github.com/paritytech/try-runtime-cli --locked

- name: Build binary with try-runtime
run: cargo build --features try-runtime

- name: run imbue kusama try-runtime
run: try-runtime --runtime ./target/debug/wbuild/imbue-kusama-runtime/imbue_kusama_runtime.wasm on-runtime-upgrade live --uri ws://34.123.139.91:9942

- name: run imbue rococo try-runtime
run: try-runtime --runtime ./target/debug/wbuild/imbue-kusama-runtime/imbue_kusama_runtime.wasm on-runtime-upgrade live --uri ws://35.202.116.137:9942


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
Loading