Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
f-gate committed Dec 8, 2023
1 parent 62b9929 commit 2f3e5cc
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 32 deletions.
5 changes: 4 additions & 1 deletion libs/common-types/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ impl ForeignOwnedAccount {
}
#[cfg(feature = "runtime-benchmarks")]
pub fn get_supported_currency_eoa_combo() -> (ForeignOwnedAccount, CurrencyId) {
(ForeignOwnedAccount::ETH(Default::default()), CurrencyId::ForeignAsset(ForeignAssetId::ETH))
(
ForeignOwnedAccount::ETH(Default::default()),
CurrencyId::ForeignAsset(ForeignAssetId::ETH),
)
}
}

Expand Down
7 changes: 5 additions & 2 deletions pallets/briefs/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ mod benchmarks {
let brief_id = gen_hash(1);
let milestones = get_max_milestones::<T>();


assert_ok!(Briefs::<T>::create_brief(
RawOrigin::Signed(caller).into(),
brief_owners,
Expand Down Expand Up @@ -147,7 +146,11 @@ mod benchmarks {
);
}

fn create_account_id<T: Config>(suri: &'static str, n: u32, currency_id: CurrencyId) -> T::AccountId {
fn create_account_id<T: Config>(
suri: &'static str,
n: u32,
currency_id: CurrencyId,
) -> T::AccountId {
let user = account(suri, n, SEED);
let initial_balance = 1_000_000_000_000_000u128;
assert_ok!(T::RMultiCurrency::deposit(
Expand Down
1 change: 0 additions & 1 deletion pallets/briefs/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ pub(crate) mod v1 {
};

v2::BriefsV2::<T>::insert(key, migrated);

}
})
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/grants/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::*;
use crate::test_utils::gen_grant_id;
use crate::Pallet as Grants;
use crate::{BoundedApprovers, BoundedPMilestones, Config};
use common_types::{CurrencyId, TreasuryOrigin, ForeignOwnedAccount};
use common_types::{CurrencyId, ForeignOwnedAccount, TreasuryOrigin};
use frame_benchmarking::v2::*;
use frame_support::{assert_ok, traits::Get};
use frame_system::pallet_prelude::BlockNumberFor;
Expand Down
6 changes: 3 additions & 3 deletions pallets/proposals/src/impls/pallet_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ impl<T: Config> Pallet<T> {
// Prevent hook from calling.
// TODO: only remove project key????
RoundsExpiring::<T>::remove(exp_block);
MilestoneVotes::<T>::mutate(project_key, |btree_votes|{
let _val = btree_votes.remove(&milestone_key);

MilestoneVotes::<T>::mutate(project_key, |btree_votes| {
let _val = btree_votes.remove(&milestone_key);
});

// Allow future votes to occur on this milestone
Expand Down
66 changes: 49 additions & 17 deletions pallets/proposals/src/tests/foreign_asset.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
use crate::{mock::*, *};
use frame_support::{assert_noop, assert_ok, error::BadOrigin};
use common_types::ForeignAssetId;
use frame_support::{assert_noop, assert_ok, error::BadOrigin};
use test_utils::*;

#[test]
fn set_foreign_asset_signer_check_permission_for_edit() {
build_test_externality().execute_with(|| {
assert_ok!(Proposals::set_foreign_asset_signer(RuntimeOrigin::root(), ALICE));
assert_eq!(ForeignCurrencySigner::<Test>::get().unwrap(), ALICE, "Alice should have been set as signer.");
assert_ok!(Proposals::set_foreign_asset_signer(RuntimeOrigin::root(), BOB));
assert_eq!(ForeignCurrencySigner::<Test>::get().unwrap(), BOB, "Bob should be set as signer.");
assert_noop!(Proposals::set_foreign_asset_signer(RuntimeOrigin::signed(BOB), ALICE), BadOrigin);
assert_ok!(Proposals::set_foreign_asset_signer(
RuntimeOrigin::root(),
ALICE
));
assert_eq!(
ForeignCurrencySigner::<Test>::get().unwrap(),
ALICE,
"Alice should have been set as signer."
);
assert_ok!(Proposals::set_foreign_asset_signer(
RuntimeOrigin::root(),
BOB
));
assert_eq!(
ForeignCurrencySigner::<Test>::get().unwrap(),
BOB,
"Bob should be set as signer."
);
assert_noop!(
Proposals::set_foreign_asset_signer(RuntimeOrigin::signed(BOB), ALICE),
BadOrigin
);
})
}

Expand All @@ -22,15 +39,14 @@ fn foreign_asset_signer_can_mint() {
let amount = 92839572;
let _ = Proposals::set_foreign_asset_signer(RuntimeOrigin::root(), ALICE);
let asset_signer = ForeignCurrencySigner::<Test>::get().unwrap();
assert_eq!(
Tokens::free_balance(currency_id, &BOB),
0
);
assert_ok!(Proposals::mint_offchain_assets(RuntimeOrigin::signed(asset_signer), beneficiary, currency_id, amount));
assert_eq!(
Tokens::free_balance(currency_id, &BOB),
assert_eq!(Tokens::free_balance(currency_id, &BOB), 0);
assert_ok!(Proposals::mint_offchain_assets(
RuntimeOrigin::signed(asset_signer),
beneficiary,
currency_id,
amount
);
));
assert_eq!(Tokens::free_balance(currency_id, &BOB), amount);
})
}

Expand All @@ -42,7 +58,23 @@ fn non_foreign_asset_signer_cannot_mint() {
let amount = 92839572;
let _ = Proposals::set_foreign_asset_signer(RuntimeOrigin::root(), ALICE);

assert_noop!(Proposals::mint_offchain_assets(RuntimeOrigin::signed(BOB), beneficiary, currency_id, amount), Error::<Test>::RequireForeignAssetSigner);
assert_noop!(Proposals::mint_offchain_assets(RuntimeOrigin::signed(CHARLIE), beneficiary, currency_id, amount), Error::<Test>::RequireForeignAssetSigner);
assert_noop!(
Proposals::mint_offchain_assets(
RuntimeOrigin::signed(BOB),
beneficiary,
currency_id,
amount
),
Error::<Test>::RequireForeignAssetSigner
);
assert_noop!(
Proposals::mint_offchain_assets(
RuntimeOrigin::signed(CHARLIE),
beneficiary,
currency_id,
amount
),
Error::<Test>::RequireForeignAssetSigner
);
})
}
}
2 changes: 1 addition & 1 deletion pallets/proposals/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod disputes;
pub mod foreign_asset;
pub mod immutable_votes;
pub mod pallet;
pub mod refunds;
pub mod foreign_asset;
19 changes: 13 additions & 6 deletions pallets/proposals/src/tests/pallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,15 +635,19 @@ fn vote_struct_removed_on_autofinalisation_success() {
milestone_key,
true
));
assert!(MilestoneVotes::<Test>::get(project_key).get(&milestone_key).is_some());

assert!(MilestoneVotes::<Test>::get(project_key)
.get(&milestone_key)
.is_some());

assert_ok!(Proposals::vote_on_milestone(
RuntimeOrigin::signed(CHARLIE),
project_key,
milestone_key,
true
));
assert!(MilestoneVotes::<Test>::get(project_key).get(&milestone_key).is_none());
assert!(MilestoneVotes::<Test>::get(project_key)
.get(&milestone_key)
.is_none());
});
}

Expand All @@ -667,19 +671,22 @@ fn vote_struct_removed_on_autofinalisation_failure() {
milestone_key,
false
));
assert!(MilestoneVotes::<Test>::get(project_key).get(&milestone_key).is_some());
assert!(MilestoneVotes::<Test>::get(project_key)
.get(&milestone_key)
.is_some());
assert_ok!(Proposals::vote_on_milestone(
RuntimeOrigin::signed(CHARLIE),
project_key,
milestone_key,
false
));

assert!(MilestoneVotes::<Test>::get(project_key).get(&milestone_key).is_none());
assert!(MilestoneVotes::<Test>::get(project_key)
.get(&milestone_key)
.is_none());
});
}


#[test]
fn withdraw_not_initiator() {
build_test_externality().execute_with(|| {
Expand Down

0 comments on commit 2f3e5cc

Please sign in to comment.