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 22, 2024
1 parent 6bab3a7 commit 4cfc55a
Showing 1 changed file with 157 additions and 54 deletions.
211 changes: 157 additions & 54 deletions pallets/funding/src/tests/6_funding_end.rs
Original file line number Diff line number Diff line change
@@ -1,65 +1,168 @@
use super::*;

#[test]
fn automatic_fail_less_eq_33_percent() {
for funding_percent in (1..=33).step_by(5) {
let _ = create_project_with_funding_percentage(funding_percent, None);
}
#[cfg(test)]
mod round_flow {
use super::*;
#[cfg(test)]
mod success {}
}

#[test]
fn automatic_success_bigger_eq_90_percent() {
for funding_percent in (90..=100).step_by(2) {
let _ = create_project_with_funding_percentage(funding_percent, None);
}
}
#[cfg(test)]
mod decide_project_outcome {
use super::*;
#[cfg(test)]
mod success {
use super::*;

#[test]
fn manual_acceptance_percentage_between_34_89() {
for funding_percent in (34..=89).step_by(5) {
let _ = create_project_with_funding_percentage(funding_percent, Some(FundingOutcomeDecision::AcceptFunding));
}
}
#[test]
fn manual_acceptance_percentage_between_34_89() {
for funding_percent in (34..=89).step_by(5) {
let _ = create_project_with_funding_percentage(
funding_percent,
Some(FundingOutcomeDecision::AcceptFunding),
);
}
}

#[test]
fn manual_rejection_percentage_between_34_89() {
for funding_percent in (34..=89).step_by(5) {
let _ = create_project_with_funding_percentage(
funding_percent,
Some(FundingOutcomeDecision::RejectFunding),
);
}
}

#[test]
fn automatic_fail_less_eq_33_percent() {
for funding_percent in (1..=33).step_by(5) {
let _ = create_project_with_funding_percentage(funding_percent, None);
}
}

#[test]
fn manual_rejection_percentage_between_34_89() {
for funding_percent in (34..=89).step_by(5) {
let _ = create_project_with_funding_percentage(funding_percent, Some(FundingOutcomeDecision::RejectFunding));
#[test]
fn automatic_acceptance_on_manual_decision_after_time_delta() {
let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext())));
let project_metadata = default_project_metadata(ISSUER_1);
let min_price = project_metadata.minimum_price;
let twenty_percent_funding_usd = Perquintill::from_percent(55) *
(project_metadata.minimum_price.checked_mul_int(project_metadata.total_allocation_size).unwrap());
let evaluations = default_evaluations();
let bids = inst.generate_bids_from_total_usd(
Percent::from_percent(50u8) * twenty_percent_funding_usd,
min_price,
default_weights(),
default_bidders(),
default_multipliers(),
);
let contributions = inst.generate_contributions_from_total_usd(
Percent::from_percent(50u8) * twenty_percent_funding_usd,
min_price,
default_weights(),
default_community_contributors(),
default_multipliers(),
);
let project_id =
inst.create_finished_project(project_metadata, ISSUER_1, evaluations, bids, contributions, vec![]);
assert_eq!(inst.get_project_details(project_id).status, ProjectStatus::AwaitingProjectDecision);

let project_id = project_id;
inst.advance_time(1u64 + <TestRuntime as Config>::ManualAcceptanceDuration::get()).unwrap();
assert_eq!(inst.get_project_details(project_id).status, ProjectStatus::FundingSuccessful);
dbg!(inst.get_project_details(project_id));
inst.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

inst.test_ct_created_for(project_id);

inst.settle_project(project_id).unwrap();
}

#[test]
fn automatic_success_bigger_eq_90_percent() {
for funding_percent in (90..=100).step_by(2) {
let _ = create_project_with_funding_percentage(funding_percent, None);
}
}
}
}

#[test]
fn automatic_acceptance_on_manual_decision_after_time_delta() {
let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext())));
let project_metadata = default_project_metadata(ISSUER_1);
let min_price = project_metadata.minimum_price;
let twenty_percent_funding_usd = Perquintill::from_percent(55) *
(project_metadata.minimum_price.checked_mul_int(project_metadata.total_allocation_size).unwrap());
let evaluations = default_evaluations();
let bids = inst.generate_bids_from_total_usd(
Percent::from_percent(50u8) * twenty_percent_funding_usd,
min_price,
default_weights(),
default_bidders(),
default_multipliers(),
);
let contributions = inst.generate_contributions_from_total_usd(
Percent::from_percent(50u8) * twenty_percent_funding_usd,
min_price,
default_weights(),
default_community_contributors(),
default_multipliers(),
);
let project_id = inst.create_finished_project(project_metadata, ISSUER_1, evaluations, bids, contributions, vec![]);
assert_eq!(inst.get_project_details(project_id).status, ProjectStatus::AwaitingProjectDecision);
#[cfg(test)]
mod failure {
use super::*;

#[test]
fn called_by_non_issuer() {
let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext())));
let project_metadata = default_project_metadata(ISSUER_1);
let funding_percentage = 40u64;
let min_price = project_metadata.minimum_price;
let percentage_funded_usd = Perquintill::from_percent(funding_percentage) *
(project_metadata.minimum_price.checked_mul_int(project_metadata.total_allocation_size).unwrap());
let evaluations = default_evaluations();
let bids = inst.generate_bids_from_total_usd(
Percent::from_percent(50u8) * percentage_funded_usd,
min_price,
default_weights(),
default_bidders(),
default_multipliers(),
);
let contributions = inst.generate_contributions_from_total_usd(
Percent::from_percent(50u8) * percentage_funded_usd,
min_price,
default_weights(),
default_community_contributors(),
default_multipliers(),
);
let project_id =
inst.create_finished_project(project_metadata.clone(), ISSUER_1, evaluations, bids, contributions, vec![]);

let project_id = project_id;
inst.advance_time(1u64 + <TestRuntime as Config>::ManualAcceptanceDuration::get()).unwrap();
assert_eq!(inst.get_project_details(project_id).status, ProjectStatus::FundingSuccessful);
dbg!(inst.get_project_details(project_id));
inst.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();
inst.execute(|| {
// Accepting doesn't work
assert_noop!(
PolimecFunding::decide_project_outcome(
RuntimeOrigin::signed(BUYER_1),
get_mock_jwt_with_cid(
BUYER_1,
InvestorType::Institutional,
generate_did_from_account(BUYER_1),
project_metadata.clone().policy_ipfs_cid.unwrap(),
),
project_id,
FundingOutcomeDecision::AcceptFunding
),
Error::<TestRuntime>::NotIssuer
);
// Rejecting doesn't work
assert_noop!(
PolimecFunding::decide_project_outcome(
RuntimeOrigin::signed(BUYER_1),
get_mock_jwt_with_cid(
BUYER_1,
InvestorType::Institutional,
generate_did_from_account(BUYER_1),
project_metadata.clone().policy_ipfs_cid.unwrap(),
),
project_id,
FundingOutcomeDecision::AcceptFunding
),
Error::<TestRuntime>::NotIssuer
);

inst.test_ct_created_for(project_id);
// But Issuer can accept or reject
assert_ok!(PolimecFunding::decide_project_outcome(
RuntimeOrigin::signed(ISSUER_1),
get_mock_jwt_with_cid(
ISSUER_1,
InvestorType::Institutional,
generate_did_from_account(ISSUER_1),
project_metadata.clone().policy_ipfs_cid.unwrap(),
),
project_id,
FundingOutcomeDecision::AcceptFunding
));
})
}

inst.settle_project(project_id).unwrap();
#[test]
fn called_on_incorrect_project_status() {}
}
}

0 comments on commit 4cfc55a

Please sign in to comment.