Skip to content

Commit

Permalink
Comprehensive funding end tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed May 29, 2024
1 parent 3812826 commit b022520
Show file tree
Hide file tree
Showing 7 changed files with 367 additions and 83 deletions.
1 change: 1 addition & 0 deletions integration-tests/src/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ fn ct_minted() {
excel_contributions(),
excel_remainders(),
);
dbg!(inst.get_project_details(project_id).funding_amount_reached_usd);
inst.advance_time(<PolitestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

inst.settle_project(project_id).unwrap();
Expand Down
26 changes: 26 additions & 0 deletions pallets/funding/src/functions/5_funding_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,30 @@ impl<T: Config> Pallet<T> {
pays_fee: Pays::Yes,
})
}

pub fn finalize_funding(
project_id: ProjectId,
mut project_details: ProjectDetailsOf<T>,
outcome: ProjectOutcome,
settlement_delta: BlockNumberFor<T>,
) -> Result<u32, DispatchError> {
let now = <frame_system::Pallet<T>>::block_number();

project_details.status = match outcome {
ProjectOutcome::FundingSuccessful | ProjectOutcome::FundingAccepted => ProjectStatus::FundingSuccessful,
_ => ProjectStatus::FundingFailed,
};
ProjectsDetails::<T>::insert(project_id, project_details);

let insertion_iterations =
match Self::add_to_update_store(now + settlement_delta, (&project_id, UpdateType::StartSettlement)) {
Ok(iterations) => iterations,
Err(_iterations) => return Err(Error::<T>::TooManyInsertionAttempts.into()),
};
Self::deposit_event(Event::ProjectPhaseTransition {
project_id,
phase: ProjectPhases::FundingFinalization(outcome),
});
Ok(insertion_iterations)
}
}
28 changes: 2 additions & 26 deletions pallets/funding/src/functions/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ impl<T: Config> Pallet<T> {
}

/// Computes the total fee from all defined fee brackets.
fn compute_total_fee_from_brackets(funding_reached: BalanceOf<T>) -> BalanceOf<T> {
pub fn compute_total_fee_from_brackets(funding_reached: BalanceOf<T>) -> BalanceOf<T> {
let mut remaining_for_fee = funding_reached;

T::FeeBrackets::get()
Expand All @@ -413,7 +413,7 @@ impl<T: Config> Pallet<T> {
}

/// Calculate the fee for a particular bracket.
fn compute_fee_for_bracket(
pub fn compute_fee_for_bracket(
remaining_for_fee: &mut BalanceOf<T>,
fee: Percent,
limit: BalanceOf<T>,
Expand Down Expand Up @@ -533,31 +533,7 @@ impl<T: Config> Pallet<T> {
Ok((liquidity_pools_reward_pot, long_term_holder_reward_pot))
}

pub fn finalize_funding(
project_id: ProjectId,
mut project_details: ProjectDetailsOf<T>,
outcome: ProjectOutcome,
settlement_delta: BlockNumberFor<T>,
) -> Result<u32, DispatchError> {
let now = <frame_system::Pallet<T>>::block_number();

project_details.status = match outcome {
ProjectOutcome::FundingSuccessful | ProjectOutcome::FundingAccepted => ProjectStatus::FundingSuccessful,
_ => ProjectStatus::FundingFailed,
};
ProjectsDetails::<T>::insert(project_id, project_details);

let insertion_iterations =
match Self::add_to_update_store(now + settlement_delta, (&project_id, UpdateType::StartSettlement)) {
Ok(iterations) => iterations,
Err(_iterations) => return Err(Error::<T>::TooManyInsertionAttempts.into()),
};
Self::deposit_event(Event::ProjectPhaseTransition {
project_id,
phase: ProjectPhases::FundingFinalization(outcome),
});
Ok(insertion_iterations)
}

pub fn migrations_per_xcm_message_allowed() -> u32 {
const MAX_WEIGHT: Weight = Weight::from_parts(20_000_000_000, 1_000_000);
Expand Down
2 changes: 1 addition & 1 deletion pallets/funding/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ parameter_types! {
pub const FundingPalletId: PalletId = PalletId(*b"py/cfund");
pub FeeBrackets: Vec<(Percent, Balance)> = vec![
(Percent::from_percent(10), 1_000_000 * USD_UNIT),
(Percent::from_percent(8), 5_000_000 * USD_UNIT),
(Percent::from_percent(8), 4_000_000 * USD_UNIT),
(Percent::from_percent(6), u128::MAX), // Making it max signifies the last bracket
];
pub EarlyEvaluationThreshold: Percent = Percent::from_percent(10);
Expand Down
Loading

0 comments on commit b022520

Please sign in to comment.