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

✅ New tests #372

Merged
merged 1 commit into from
Aug 23, 2024
Merged
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
2 changes: 1 addition & 1 deletion integration-tests/src/tests/ct_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ fn create_settled_project() -> (ProjectId, Vec<AccountId>) {
participants.sort();
participants.dedup();

inst.settle_project(project_id);
inst.settle_project(project_id, true);
(project_id, participants)
})
}
Expand Down
22 changes: 11 additions & 11 deletions pallets/funding/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2703,7 +2703,7 @@ mod benchmarks {
let settlement_block = inst.go_to_next_state(project_id).unwrap();
inst.jump_to_block(settlement_block);

inst.settle_project(project_id).unwrap();
inst.settle_project(project_id, true).unwrap();

let jwt = get_mock_jwt_with_cid(
issuer.clone(),
Expand Down Expand Up @@ -2753,7 +2753,7 @@ mod benchmarks {
let settlement_block = inst.go_to_next_state(project_id).unwrap();
inst.jump_to_block(settlement_block);

inst.settle_project(project_id).unwrap();
inst.settle_project(project_id, true).unwrap();

let jwt = get_mock_jwt_with_cid(
issuer.clone(),
Expand Down Expand Up @@ -2824,7 +2824,7 @@ mod benchmarks {
let settlement_block = inst.go_to_next_state(project_id).unwrap();
inst.jump_to_block(settlement_block);

inst.settle_project(project_id).unwrap();
inst.settle_project(project_id, true).unwrap();

let jwt = get_mock_jwt_with_cid(
issuer.clone(),
Expand Down Expand Up @@ -2870,7 +2870,7 @@ mod benchmarks {
let settlement_block = inst.go_to_next_state(project_id).unwrap();
inst.jump_to_block(settlement_block);

inst.settle_project(project_id).unwrap();
inst.settle_project(project_id, true).unwrap();

let jwt = get_mock_jwt_with_cid(
issuer.clone(),
Expand Down Expand Up @@ -2929,7 +2929,7 @@ mod benchmarks {
let settlement_block = inst.go_to_next_state(project_id).unwrap();
inst.jump_to_block(settlement_block);

inst.settle_project(project_id).unwrap();
inst.settle_project(project_id, true).unwrap();

let jwt = get_mock_jwt_with_cid(
issuer.clone(),
Expand Down Expand Up @@ -2992,7 +2992,7 @@ mod benchmarks {
let settlement_block = inst.go_to_next_state(project_id).unwrap();
inst.jump_to_block(settlement_block);

inst.settle_project(project_id).unwrap();
inst.settle_project(project_id, true).unwrap();

let jwt = get_mock_jwt_with_cid(
issuer.clone(),
Expand Down Expand Up @@ -3073,7 +3073,7 @@ mod benchmarks {
let settlement_block = inst.go_to_next_state(project_id).unwrap();
inst.jump_to_block(settlement_block);

inst.settle_project(project_id).unwrap();
inst.settle_project(project_id, true).unwrap();

let jwt = get_mock_jwt_with_cid(
issuer.clone(),
Expand Down Expand Up @@ -3195,7 +3195,7 @@ mod benchmarks {
let settlement_block = inst.go_to_next_state(project_id).unwrap();
inst.jump_to_block(settlement_block);

inst.settle_project(project_id).unwrap();
inst.settle_project(project_id, true).unwrap();

let jwt = get_mock_jwt_with_cid(
issuer.clone(),
Expand Down Expand Up @@ -3290,7 +3290,7 @@ mod benchmarks {
let settlement_block = inst.go_to_next_state(project_id).unwrap();
inst.jump_to_block(settlement_block);

inst.settle_project(project_id).unwrap();
inst.settle_project(project_id, true).unwrap();

let jwt = get_mock_jwt_with_cid(
issuer.clone(),
Expand Down Expand Up @@ -3366,7 +3366,7 @@ mod benchmarks {
let settlement_block = inst.go_to_next_state(project_id).unwrap();
inst.jump_to_block(settlement_block);

inst.settle_project(project_id).unwrap();
inst.settle_project(project_id, true).unwrap();

let jwt = get_mock_jwt_with_cid(
issuer.clone(),
Expand Down Expand Up @@ -3416,7 +3416,7 @@ mod benchmarks {
let settlement_block = inst.go_to_next_state(project_id).unwrap();
inst.jump_to_block(settlement_block);

inst.settle_project(project_id).unwrap();
inst.settle_project(project_id, true).unwrap();

let jwt = get_mock_jwt_with_cid(
issuer.clone(),
Expand Down
14 changes: 3 additions & 11 deletions pallets/funding/src/functions/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,20 +273,12 @@ impl<T: Config> Pallet<T> {
pub fn generate_liquidity_pools_and_long_term_holder_rewards(
project_id: ProjectId,
) -> Result<(BalanceOf<T>, BalanceOf<T>), DispatchError> {
let details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
let total_fee_allocation = Self::calculate_fee_allocation(project_id)?;

let percentage_of_target_funding =
Perquintill::from_rational(details.funding_amount_reached_usd, details.fundraising_target_usd);

let liquidity_pools_percentage = Perquintill::from_percent(50);
let liquidity_pools_reward_pot = liquidity_pools_percentage * total_fee_allocation;

let long_term_holder_percentage = if percentage_of_target_funding < Perquintill::from_percent(90) {
Perquintill::from_percent(50)
} else {
Perquintill::from_percent(20)
};
let long_term_holder_percentage = Perquintill::from_percent(20);
let long_term_holder_reward_pot = long_term_holder_percentage * total_fee_allocation;

Ok((liquidity_pools_reward_pot, long_term_holder_reward_pot))
Expand Down Expand Up @@ -398,15 +390,15 @@ impl<T: Config> Pallet<T> {
) -> DispatchResult {
/* Verify */
let now = <frame_system::Pallet<T>>::block_number();
ensure!(project_details.round_duration.ended(now) || skip_end_check, Error::<T>::TooEarlyForRound);
ensure!(project_details.status == current_round, Error::<T>::IncorrectRound);
ensure!(project_details.round_duration.ended(now) || skip_end_check, Error::<T>::TooEarlyForRound);

let round_end = if let Some(round_duration) = maybe_round_duration {
Some(now.saturating_add(round_duration).saturating_sub(One::one()))
} else {
None
};
project_details.round_duration.update(Some(now), round_end);
project_details.round_duration = BlockNumberPair::new(Some(now), round_end);
project_details.status = next_round.clone();

// * Update storage *
Expand Down
8 changes: 5 additions & 3 deletions pallets/funding/src/instantiator/chain_interactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ impl<
Ok(().into())
}

pub fn settle_project(&mut self, project_id: ProjectId) {
pub fn settle_project(&mut self, project_id: ProjectId, mark_as_settled: bool) {
self.execute(|| {
Evaluations::<T>::iter_prefix((project_id,))
.for_each(|(_, evaluation)| Pallet::<T>::do_settle_evaluation(evaluation, project_id).unwrap());
Expand All @@ -651,7 +651,9 @@ impl<
Contributions::<T>::iter_prefix((project_id,))
.for_each(|(_, contribution)| Pallet::<T>::do_settle_contribution(contribution, project_id).unwrap());

crate::Pallet::<T>::do_mark_project_as_settled(project_id).unwrap();
if mark_as_settled {
crate::Pallet::<T>::do_mark_project_as_settled(project_id).unwrap();
}
});
}

Expand Down Expand Up @@ -1053,7 +1055,7 @@ impl<

assert!(matches!(self.go_to_next_state(project_id), ProjectStatus::SettlementStarted(_)));

self.settle_project(project_id);
self.settle_project(project_id, true);
project_id
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/funding/src/tests/2_evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ mod round_flow {
assert_eq!(inst.go_to_next_state(project_id), ProjectStatus::FundingFailed);
assert_eq!(inst.go_to_next_state(project_id), ProjectStatus::SettlementStarted(FundingOutcome::Failure));

inst.settle_project(project_id);
inst.settle_project(project_id, true);
inst.do_free_plmc_assertions(expected_evaluator_balances);
}
}
Expand Down
Loading