Skip to content

Conversation

benhaq
Copy link

@benhaq benhaq commented Jun 10, 2025

A. Vesting pallet

1. Unit test


tests-vesting

2. Additional test case

Add additional test case for force_remove_vesting_schedule

#[test]
fn force_remove_vesting_schedule_works() {
	ExtBuilder::build().execute_with(|| {
		System::set_block_number(1);
		// Create two vesting schedules
		let schedule1 = VestingSchedule {
			start: 2u64,
			period: 10u64,
			period_count: 3u32,
			per_period: 100u64,
		}; // total=300
		let schedule2 = VestingSchedule {
			start: 5u64,
			period: 5u64,
			period_count: 4u32,
			per_period: 50u64,
		}; // total=200

		// Create vesting schedules for BOB
		assert_ok!(Vesting::vested_transfer(RuntimeOrigin::signed(ALICE), BOB, schedule1));
		assert_ok!(Vesting::vested_transfer(RuntimeOrigin::signed(ALICE), BOB, schedule2.clone()));

		// Verify initial state
		let total_transferred = 300 + 200;
		assert_eq!(PalletBalances::free_balance(&BOB), total_transferred);
		let initial_schedules = VestingSchedules::<Runtime>::get(&BOB);
		assert_eq!(initial_schedules.len(), 2);

		// Try to remove schedule with non-root origin (should fail)
		assert_noop!(
			Vesting::force_remove_vesting_schedule(RuntimeOrigin::signed(ALICE), BOB, 0),
			DispatchError::BadOrigin
		);

		// Try to remove schedule with invalid index (should fail)
		assert_noop!(
			Vesting::force_remove_vesting_schedule(RuntimeOrigin::root(), BOB, 2),
			Error::<Runtime>::InvalidVestingIndex
		);

		// Remove first schedule (index 0)
		assert_ok!(Vesting::force_remove_vesting_schedule(RuntimeOrigin::root(), BOB, 0));

		// Verify state after removal
		let remaining_schedules = VestingSchedules::<Runtime>::get(&BOB);
		assert_eq!(remaining_schedules.len(), 1);
		assert_eq!(remaining_schedules[0], schedule2);

		// Verify lock amount is updated
		let locks = PalletBalances::locks(&BOB);
		assert_eq!(locks[0].amount, 200); // Only schedule2 remains (200 total)

		// Remove second schedule (index 0 since we removed the first one)
		assert_ok!(Vesting::force_remove_vesting_schedule(RuntimeOrigin::root(), BOB, 0));

		// Verify all schedules are removed
		let final_schedules = VestingSchedules::<Runtime>::get(&BOB);
		assert_eq!(final_schedules.len(), 0);

		// Verify lock is removed
		let final_locks = PalletBalances::locks(&BOB);
		assert_eq!(final_locks.len(), 0);
	});
}

3. Simulation videos

Successful Vested Transfer And Claiming Vested Tokens

This simulation shows:

  • a standard vested_transfer works correctly, locks the funds, and creates a vesting schedule. It corresponds to vested_transfer_works in tests.rs.

  • a recipient can claim tokens that have vested over time. It corresponds to claim_works in tests.rs.

Video:

Vesting_.Create.vesting.schedule.and.claim.vesting.mp4

Invalid Vesting Schedule Parameters

This simulation ensures that a vested_transfer will fail if the schedule has a period or period count of zero. It corresponds to vested_transfer_fails_if_zero_period_or_count in tests.rs.

Video:

Vesting_.Error.when.provide.invalid.parameters.while.creating.vesting.schedules.mp4

Updating Vesting Schedules (Sudo)

This simulation shows that a privileged account (Root origin) can update the vesting schedules for any account. It corresponds to update_vesting_schedules_works in tests.rs.

Video:

Vesting_.Update.vesting.schedules.mp4

Force remove vesting schedules

This simulation shows the logic when force remove vesting schedules. It corresponds to force_remove_vesting_schedule_works in tests.rs.

Video:

Vesting_.Force.remove.vesting.schedules.mp4

Claiming with Multiple Schedules

This simulation shows the claim logic when an account has multiple, overlapping vesting schedules. It corresponds to multiple_vesting_schedule_claim_works in tests.rs.

Video:

Vesting_.Claim.multiple.vesting.schedules.mp4

@benhaq benhaq closed this Jun 12, 2025
@benhaq
Copy link
Author

benhaq commented Jun 15, 2025

A. Native pools pallet

1. Unit test

test-native

2. Simulation

2.1 Deposit and multiple deposit works

It corresponds to deposit_works / multiple_deposits_should_sum in tests.rs.

Track.4_.Deposit.pool.works.mp4

2.2 Deposit should fail with zero amount

It corresponds to deposit_fails_with_zero_amount in tests.rs.

deposit.with.zero.mp4

2.3 Deposit to pool fail with insufficient balance

It corresponds to deposit_fails_with_insufficient_balance in tests.rs.

insufficent-balance.mp4

2.4 Deposit rewards works

It corresponds to deposit_rewards_works in tests.rs.

deposit-rewards.mp4

2.5 Deposit rewards without any deposit should fail

It corresponds to deposit_rewards_without_any_deposits_fails in tests.rs.

deposit-rewards-with-no-deposit.mp4

2.6 Deposit rewards with zero amount should fail

It corresponds to deposit_rewards_fails_with_zero_amount in tests.rs.

deposit-rewards-zero.mp4

2.7 Withdraw all works

It corresponds to withdraw_all_works in tests.rs.

Simulation with None parameter

withdraw-all-with-none.mp4

Simulation with Some parameter equals to total balance

withdraw-full-with-some.mp4

2.8 Partial withdraw works

withdraw-partial.mp4

2.9 Withdraw with zero amount fail

It corresponds to withdraw_zero_amount_fails in tests.rs.

withdraw-some-0.mp4

2.10 Withdraw fail with insufficient deposit

It corresponds to withdraw_fails_with_insufficient_deposit in tests.rs.

withdraw-insufficient-amount.mp4

2.11 Withdraw fail with no deposit

It corresponds to withdraw_fails_with_no_deposit in tests.rs.

withdraw-no-deposit.mp4

2.12 Partial withdraw should retrieve pending rewards

It corresponds to partial_withdraw_with_rewards_works in tests.rs.

partial-withdraw-with-rewards.mp4

2.13 Partial withdraw then claim rewards works

It corresponds to partial_withdraw_then_claim_rewards_works in tests.rs.

partial-withdraw-then-claim-rewards.mp4

2.14 Claim rewards works

It corresponds to claim_rewards_works in tests.rs.

claim-rewards.mp4

2.15 Deposit once, claim rewards twice should fail

It corresponds to claim_rewards_twice_fails_with_zero_amount in tests.rs.

claim.2.reward.zero.amount.mp4

2.16 Late pool joiner receive proportional rewards

It corresponds to late_joiner_receives_proportional_rewards in tests.rs.

late-joiner-receives-proportional-rewards.mp4

2.17 Reward distribution with multiple users works

It corresponds to reward_distribution_multiple_users in tests.rs.

reward_distribution_multiple_users.mp4

3. Enhancement

Add pending_rewards getter to better debug in chain state.

/// Pending rewards for each user
	#[pallet::storage]
	#[pallet::getter(fn pending_rewards)]
	pub type PendingRewards<T: Config> = StorageMap<
		_,
		Blake2_128Concat,
		T::AccountId,
		BalanceOf<T>,
		ValueQuery,
	>;

@benhaq benhaq reopened this Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant