Skip to content

Commit

Permalink
chore: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
lrazovic committed Jul 21, 2023
1 parent 326977a commit 78506e6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
12 changes: 6 additions & 6 deletions polimec-skeleton/pallets/linear-release/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl<T: Config> Pallet<T> {
// Validate user inputs.
ensure!(schedule.locked() >= T::MinVestedTransfer::get(), Error::<T>::AmountLow);
if !schedule.is_valid() {
return Err(Error::<T>::InvalidScheduleParams.into());
return Err(Error::<T>::InvalidScheduleParams.into())
};

// Check we can add to this account prior to any storage writes.
Expand Down Expand Up @@ -274,13 +274,13 @@ impl<T: Config> ReleaseSchedule<AccountIdOf<T>, ReasonOf<T>> for Pallet<T> {
reason: ReasonOf<T>,
) -> DispatchResult {
if locked.is_zero() {
return Ok(());
return Ok(())
}

let vesting_schedule = VestingInfo::new(locked, per_block, starting_block);
// Check for `per_block` or `locked` of 0.
if !vesting_schedule.is_valid() {
return Err(Error::<T>::InvalidScheduleParams.into());
return Err(Error::<T>::InvalidScheduleParams.into())
};

let mut schedules = Self::vesting(who, reason).unwrap_or_default();
Expand All @@ -307,7 +307,7 @@ impl<T: Config> ReleaseSchedule<AccountIdOf<T>, ReasonOf<T>> for Pallet<T> {
) -> DispatchResult {
// Check for `per_block` or `locked` of 0.
if !VestingInfo::new(locked, per_block, starting_block).is_valid() {
return Err(Error::<T>::InvalidScheduleParams.into());
return Err(Error::<T>::InvalidScheduleParams.into())
}

ensure!(
Expand All @@ -326,13 +326,13 @@ impl<T: Config> ReleaseSchedule<AccountIdOf<T>, ReasonOf<T>> for Pallet<T> {
reason: ReasonOf<T>,
) -> DispatchResult {
if locked.is_zero() {
return Ok(());
return Ok(())
}

let vesting_schedule = VestingInfo::new(locked, per_block, starting_block);
// Check for `per_block` or `locked` of 0.
if !vesting_schedule.is_valid() {
return Err(Error::<T>::InvalidScheduleParams.into());
return Err(Error::<T>::InvalidScheduleParams.into())
};

let mut schedules = Self::vesting(who, reason).unwrap_or_default();
Expand Down
2 changes: 1 addition & 1 deletion polimec-skeleton/pallets/linear-release/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ pub mod pallet {
) -> DispatchResult {
let who = ensure_signed(origin)?;
if schedule1_index == schedule2_index {
return Ok(());
return Ok(())
};
let schedule1_index = schedule1_index as usize;
let schedule2_index = schedule2_index as usize;
Expand Down
13 changes: 6 additions & 7 deletions polimec-skeleton/pallets/linear-release/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ impl Config for Test {
type Balance = u64;
type BlockNumberToBalance = Identity;
type Currency = Balances;
type Reason = LockType<u32>; // TODO: Use the type from Balances.
// TODO: Use the type from Balances.
type MinVestedTransfer = MinVestedTransfer;
type Reason = LockType<u32>;
type RuntimeEvent = RuntimeEvent;
type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons;
type WeightInfo = ();

const MAX_VESTING_SCHEDULES: u32 = 3;
}

Expand All @@ -116,7 +118,6 @@ impl ExtBuilder {
self
}


pub fn build(self) -> sp_io::TestExternalities {
EXISTENTIAL_DEPOSIT.with(|v| *v.borrow_mut() = self.existential_deposit);
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
Expand All @@ -140,15 +141,13 @@ impl ExtBuilder {
vec![
(1, 0, 10, 5 * self.existential_deposit, LockType::Participation(0)),
(2, 10, 20, self.existential_deposit, LockType::Participation(0)),
(12, 10, 20, 5 * self.existential_deposit, LockType::Participation(0)),
(12, 10, 20, 5 * self.existential_deposit, LockType::Participation(0)),
]
};

pallet_vesting::GenesisConfig::<Test> { vesting }
.assimilate_storage(&mut t)
.unwrap();
pallet_vesting::GenesisConfig::<Test> { vesting }.assimilate_storage(&mut t).unwrap();
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext
}
}
}
8 changes: 5 additions & 3 deletions polimec-skeleton/pallets/linear-release/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,13 +1298,15 @@ fn merge_schedules_different_reason() {
assert_eq!(Balances::balance(&2), ED);
assert_eq!(Vesting::vesting(&2, LockType::Participation(0)).unwrap(), vec![sched0]);


// Add a schedule that is identical to the one that already exists.
assert_ok!(Vesting::vested_transfer(Some(14).into(), 2, sched0, LockType::Participation(1)));
assert_ok!(Vesting::vested_transfer(Some(14).into(), 2, sched0, LockType::Participation(1)));
assert_eq!(Vesting::vesting(&2, LockType::Participation(1)).unwrap(), vec![sched0, sched0]);
assert_eq!(Balances::balance(&2), ED);
assert_noop!(Vesting::merge_schedules(Some(2).into(), 0, 1, LockType::Participation(0)), Error::<Test>::ScheduleIndexOutOfBounds);
assert_noop!(
Vesting::merge_schedules(Some(2).into(), 0, 1, LockType::Participation(0)),
Error::<Test>::ScheduleIndexOutOfBounds
);
assert_ok!(Vesting::merge_schedules(Some(2).into(), 0, 1, LockType::Participation(1)));

// Since we merged identical schedules, the new schedule finishes at the same
Expand All @@ -1318,4 +1320,4 @@ fn merge_schedules_different_reason() {

assert_eq!(Balances::balance(&2), ED);
});
}
}
10 changes: 6 additions & 4 deletions polimec-skeleton/pallets/linear-release/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ pub trait ReleaseSchedule<AccountId, Reason> {
type Currency: fungible::InspectHold<AccountId>
+ fungible::MutateHold<AccountId>
+ fungible::BalancedHold<AccountId>;


/// Get the amount that is currently being vested and cannot be transferred out of this account.
/// Returns `None` if the account has no vesting schedule.
fn vesting_balance(who: &AccountId, reason: Reason) -> Option<<Self::Currency as fungible::Inspect<AccountId>>::Balance>;
fn vesting_balance(
who: &AccountId,
reason: Reason,
) -> Option<<Self::Currency as fungible::Inspect<AccountId>>::Balance>;

/// Adds a release schedule to a given account.
///
Expand Down Expand Up @@ -61,7 +63,7 @@ pub trait ReleaseSchedule<AccountId, Reason> {
locked: <Self::Currency as fungible::Inspect<AccountId>>::Balance,
per_block: <Self::Currency as fungible::Inspect<AccountId>>::Balance,
starting_block: Self::Moment,
reason: Reason
reason: Reason,
) -> DispatchResult;

/// Checks if `add_release_schedule` would work against `who`.
Expand All @@ -70,7 +72,7 @@ pub trait ReleaseSchedule<AccountId, Reason> {
locked: <Self::Currency as fungible::Inspect<AccountId>>::Balance,
per_block: <Self::Currency as fungible::Inspect<AccountId>>::Balance,
starting_block: Self::Moment,
reason: Reason
reason: Reason,
) -> DispatchResult;

/// Remove a release schedule for a given account.
Expand Down

0 comments on commit 78506e6

Please sign in to comment.