Skip to content
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
4 changes: 2 additions & 2 deletions pallets/capacity/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl pallet_balances::Config for Test {
type Balance = u64;
type RuntimeEvent = RuntimeEvent;
type DustRemoval = ();
type ExistentialDeposit = ConstU64<1>;
type ExistentialDeposit = ConstU64<10>;
type AccountStore = System;
type WeightInfo = ();
type FreezeIdentifier = RuntimeFreezeReason;
Expand Down Expand Up @@ -228,7 +228,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
pallet_balances::GenesisConfig::<Test> {
balances: vec![
(50, 5),
(50, 15),
(100, 100),
(200, 200),
(300, 300),
Expand Down
2 changes: 1 addition & 1 deletion pallets/capacity/src/tests/stake_and_deposit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ fn stake_when_staking_amount_is_less_than_min_token_balance_it_errors() {
register_provider(target, String::from("Foo"));
let account = 50;
// An amount that leaves less than the minimum token balance
let amount = 4;
let amount = 11;

assert_noop!(
Capacity::stake(RuntimeOrigin::signed(account), target, amount),
Expand Down
17 changes: 13 additions & 4 deletions pallets/time-release/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extern crate alloc;
use alloc::vec;

pub const DOLLARS: u32 = 10u32.saturating_pow(8u32);
pub const EXISTENTIAL_DEPOSIT: u32 = 10; // Matches the value in mock.rs

pub use crate::types::ReleaseSchedule;
pub type Schedule<T> = ReleaseSchedule<BlockNumberFor<T>, BalanceOf<T>>;
Expand Down Expand Up @@ -51,11 +52,15 @@ mod benchmarks {

let to: T::AccountId = account("to", 1, SEED);
let to_lookup = lookup_of_account::<T>(to.clone());
set_balance::<T>(&to, EXISTENTIAL_DEPOSIT.into());

#[extrinsic_call]
_(RawOrigin::Signed(from), to_lookup, schedule.clone());

assert_eq!(T::Currency::total_balance(&to), schedule.total_amount().unwrap());
assert_eq!(
T::Currency::total_balance(&to),
schedule.total_amount().unwrap() + EXISTENTIAL_DEPOSIT.into()
);
Ok(())
}

Expand Down Expand Up @@ -136,6 +141,7 @@ mod benchmarks {

let to: T::AccountId = whitelisted_caller();
let to_lookup = lookup_of_account::<T>(to.clone());
set_balance::<T>(&to, EXISTENTIAL_DEPOSIT.into());

for _ in 0..i {
schedule.start = i.into();
Expand All @@ -152,7 +158,7 @@ mod benchmarks {

assert_eq!(
T::Currency::balance(&to),
schedule.total_amount().unwrap() * BalanceOf::<T>::from(i),
schedule.total_amount().unwrap() * BalanceOf::<T>::from(i) + EXISTENTIAL_DEPOSIT.into(),
);
Ok(())
}
Expand All @@ -169,7 +175,10 @@ mod benchmarks {
};

let to: T::AccountId = account("to", 0, SEED);
set_balance::<T>(&to, schedule.total_amount().unwrap() * BalanceOf::<T>::from(i));
set_balance::<T>(
&to,
schedule.total_amount().unwrap() * BalanceOf::<T>::from(i) + EXISTENTIAL_DEPOSIT.into(),
);
let to_lookup = lookup_of_account::<T>(to.clone());

let mut schedules = vec![];
Expand All @@ -183,7 +192,7 @@ mod benchmarks {

assert_eq!(
T::Currency::balance(&to),
schedule.total_amount().unwrap() * BalanceOf::<T>::from(i)
schedule.total_amount().unwrap() * BalanceOf::<T>::from(i) + EXISTENTIAL_DEPOSIT.into()
);
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/time-release/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl pallet_balances::Config for Test {
type Balance = Balance;
type DustRemoval = ();
type RuntimeEvent = RuntimeEvent;
type ExistentialDeposit = ConstU64<1>;
type ExistentialDeposit = ConstU64<10>;
type AccountStore = frame_system::Pallet<Test>;
type MaxLocks = ();
type MaxReserves = ();
Expand Down
50 changes: 37 additions & 13 deletions pallets/time-release/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,51 @@ fn time_release_from_chain_spec_works() {
assert_eq!(
ReleaseSchedules::<Test>::get(CHARLIE),
vec![
ReleaseSchedule { start: 2u32, period: 3u32, period_count: 1u32, per_period: 5u64 },
ReleaseSchedule { start: 2u32, period: 3u32, period_count: 1u32, per_period: 5u64 }, // unlocks 5 at block 5
ReleaseSchedule {
start: 2u32 + 3u32,
period: 3u32,
period_count: 3u32,
per_period: 5u64,
// unlocks 5, 8, 11, 14
start: 2u32 + 3u32, // starts at 5
period: 3u32, // every 3 blocks ....
period_count: 3u32, // repeats 3 times
per_period: 5u64, // ... we add 5 tokens
}
]
);

MockBlockNumberProvider::set(13);
MockBlockNumberProvider::set(2);
// before anything is released
// 10 = 10(free) - 10(ExistentialDeposit) + 10(cancelled ED because frozen > 10)
// balance = 20(frozen) + 0(free)
assert_ok!(TimeRelease::claim(RuntimeOrigin::signed(CHARLIE)));
assert_eq!(PalletBalances::can_withdraw(&CHARLIE, 10), WithdrawConsequence::Success);
assert_eq!(PalletBalances::can_withdraw(&CHARLIE, 11), WithdrawConsequence::Frozen);

MockBlockNumberProvider::set(5);
// 5 tokens will be released after 5 blocks
// 15 = 15(free) - 10(ExistentialDeposit) + 10(cancelled ED because frozen > 10)
// balance = 15(frozen) + 0(free)
assert_ok!(TimeRelease::claim(RuntimeOrigin::signed(CHARLIE)));
assert_eq!(PalletBalances::can_withdraw(&CHARLIE, 15), WithdrawConsequence::Success);
assert_eq!(PalletBalances::can_withdraw(&CHARLIE, 16), WithdrawConsequence::Frozen);

MockBlockNumberProvider::set(8);
// 10 tokens will be released after 8 blocks
// 20 = 20(free) - 10(ExistentialDeposit) + 10(cancelled ED because frozen > 10)
// balance = 10(frozen) + 0(free)
// This is the max this account can withdraw while leaving an ED
assert_ok!(TimeRelease::claim(RuntimeOrigin::signed(CHARLIE)));
assert_eq!(PalletBalances::can_withdraw(&CHARLIE, 20), WithdrawConsequence::Success);
assert_eq!(PalletBalances::can_withdraw(&CHARLIE, 21), WithdrawConsequence::Frozen);

// 15 tokens will be released after 13 blocks
// 25 = 10(free) + 15(released)
MockBlockNumberProvider::set(11);
// 15 tokens will be released after 11 blocks
// balance = 5(frozen) + 0(free)
// ED no longer covered by the frozen balance becuase frozen = 5 < ED = 10
assert_ok!(TimeRelease::claim(RuntimeOrigin::signed(CHARLIE)));
assert_eq!(PalletBalances::can_withdraw(&CHARLIE, 25), WithdrawConsequence::Success);
assert_eq!(PalletBalances::can_withdraw(&CHARLIE, 26), WithdrawConsequence::Frozen);
assert_eq!(PalletBalances::can_withdraw(&CHARLIE, 20), WithdrawConsequence::Success);
assert_eq!(PalletBalances::can_withdraw(&CHARLIE, 21), WithdrawConsequence::Frozen);

MockBlockNumberProvider::set(14);

// The final 5 tokens are released after 14 = (5[start] + 3[period] x 3[period count]) blocks
assert_ok!(TimeRelease::claim(RuntimeOrigin::signed(CHARLIE)));

Expand All @@ -57,7 +82,6 @@ fn time_release_from_chain_spec_works() {
PalletBalances::can_withdraw(&CHARLIE, 30),
WithdrawConsequence::ReducedToZero(0)
);
assert_eq!(PalletBalances::can_withdraw(&CHARLIE, 29), WithdrawConsequence::Success);
});
}

Expand Down Expand Up @@ -327,7 +351,7 @@ fn update_release_schedules_works() {
#[test]
fn update_release_schedules_fails_if_unexpected_existing_freezes() {
ExtBuilder::build().execute_with(|| {
assert_ok!(PalletBalances::transfer_allow_death(RuntimeOrigin::signed(ALICE), BOB, 1));
assert_ok!(PalletBalances::transfer_allow_death(RuntimeOrigin::signed(ALICE), BOB, 11));
let _ = <Test as Config>::Currency::set_freeze(
&FreezeReason::TimeReleaseVesting.into(),
&BOB,
Expand Down