Skip to content

Commit

Permalink
fix(238): add time to settlement period to automatic acceptance
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed Aug 10, 2023
1 parent e8b66a0 commit a54e3f8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pallets/funding/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ impl<T: Config> Pallet<T> {
project_id,
project_details,
SuccessReason::ReachedTarget,
1u32.into(),
T::SuccessToSettlementTime::get()
)
}
}
Expand Down
48 changes: 32 additions & 16 deletions pallets/funding/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1880,6 +1880,8 @@ mod evaluation_round_success {

community_funding_project.buy_for_retail_users(contributions).unwrap();
let finished_project = community_funding_project.finish_funding();
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

test_env.advance_time(10).unwrap();
let project_id = finished_project.project_id;
let actual_reward_balances = test_env.in_ext(|| {
Expand Down Expand Up @@ -1924,6 +1926,8 @@ mod evaluation_round_success {
let prev_free_plmc = test_env.get_free_plmc_balances_for(evaluators.clone());

remainder_funding_project.end_funding();
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

test_env.advance_time(10).unwrap();
let post_unbond_amounts: UserToPLMCBalance =
prev_reserved_plmc.iter().map(|(evaluator, _amount)| (*evaluator, Zero::zero())).collect();
Expand Down Expand Up @@ -2473,7 +2477,7 @@ mod auction_round_success {
let details = finished_project.get_project_details();
assert_eq!(details.status, ProjectStatus::FundingSuccessful);
assert_eq!(details.cleanup, Cleaner::NotReady);

test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();
test_env.advance_time(10u64).unwrap();
let details = finished_project.get_project_details();
assert_eq!(details.cleanup, Cleaner::Success(CleanerState::Finished(PhantomData)));
Expand Down Expand Up @@ -2535,7 +2539,7 @@ mod auction_round_success {
);
})
}
test_env.advance_time(1u64).unwrap();
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();
let details = finished_project.get_project_details();
assert_eq!(details.cleanup, Cleaner::Success(CleanerState::Initialized(PhantomData)));

Expand Down Expand Up @@ -2593,7 +2597,7 @@ mod auction_round_success {
let stored_bids =
test_env.in_ext(|| Bids::<TestRuntime>::iter_prefix_values((project_id,)).collect::<Vec<_>>());

test_env.advance_time(1u64).unwrap();
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();
let details = finished_project.get_project_details();
assert_eq!(details.cleanup, Cleaner::Success(CleanerState::Initialized(PhantomData)));

Expand Down Expand Up @@ -2644,7 +2648,8 @@ mod auction_round_success {
assert_eq!(details.status, ProjectStatus::FundingSuccessful);
assert_eq!(details.cleanup, Cleaner::NotReady);

test_env.advance_time(10u64).unwrap();
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();
test_env.advance_time(10u64.into()).unwrap();
let details = finished_project.get_project_details();
assert_eq!(details.cleanup, Cleaner::Success(CleanerState::Finished(PhantomData)));

Expand Down Expand Up @@ -2707,7 +2712,7 @@ mod auction_round_success {
community_contributions,
remainder_contributions,
);

test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();
test_env.advance_time(10u64).unwrap();
let details = finished_project.get_project_details();
assert_eq!(details.cleanup, Cleaner::Success(CleanerState::Finished(PhantomData)));
Expand Down Expand Up @@ -2750,8 +2755,7 @@ mod auction_round_success {
let details = finished_project.get_project_details();
assert_eq!(details.status, ProjectStatus::FundingSuccessful);
assert_eq!(details.cleanup, Cleaner::NotReady);

test_env.advance_time(1u64).unwrap();
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();
let details = finished_project.get_project_details();
assert_eq!(details.cleanup, Cleaner::Success(CleanerState::Initialized(PhantomData)));

Expand Down Expand Up @@ -2800,6 +2804,7 @@ mod auction_round_success {
community_contributions,
remainder_contributions,
);
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

test_env.advance_time(10u64).unwrap();
let details = finished_project.get_project_details();
Expand Down Expand Up @@ -2850,7 +2855,7 @@ mod auction_round_success {
community_contributions,
remainder_contributions,
);

test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();
test_env.advance_time(15u64).unwrap();
let details = finished_project.get_project_details();
assert_eq!(details.cleanup, Cleaner::Success(CleanerState::Finished(PhantomData)));
Expand Down Expand Up @@ -3749,7 +3754,7 @@ mod community_round_success {
let details = finished_project.get_project_details();
assert_eq!(details.status, ProjectStatus::FundingSuccessful);
assert_eq!(details.cleanup, Cleaner::NotReady);

test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();
test_env.advance_time(10u64).unwrap();
let details = finished_project.get_project_details();
assert_eq!(details.cleanup, Cleaner::Success(CleanerState::Finished(PhantomData)));
Expand Down Expand Up @@ -3811,7 +3816,8 @@ mod community_round_success {
);
})
}
test_env.advance_time(1u64).unwrap();
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

let details = finished_project.get_project_details();
assert_eq!(details.cleanup, Cleaner::Success(CleanerState::Initialized(PhantomData)));

Expand Down Expand Up @@ -3868,8 +3874,8 @@ mod community_round_success {
assert_eq!(details.cleanup, Cleaner::NotReady);
let stored_contributions =
test_env.in_ext(|| Contributions::<TestRuntime>::iter_prefix_values((project_id,)).collect::<Vec<_>>());
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

test_env.advance_time(1u64).unwrap();
let details = finished_project.get_project_details();
assert_eq!(details.cleanup, Cleaner::Success(CleanerState::Initialized(PhantomData)));

Expand Down Expand Up @@ -3919,6 +3925,7 @@ mod community_round_success {
let details = finished_project.get_project_details();
assert_eq!(details.status, ProjectStatus::FundingSuccessful);
assert_eq!(details.cleanup, Cleaner::NotReady);
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

test_env.advance_time(10u64).unwrap();
let details = finished_project.get_project_details();
Expand Down Expand Up @@ -3978,7 +3985,7 @@ mod community_round_success {

let price = finished_project.get_project_details().weighted_average_price.unwrap();
let contribution_locked_plmc = calculate_contributed_plmc_spent(community_contributions, price);

test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();
test_env.advance_time(10u64).unwrap();
let details = finished_project.get_project_details();
assert_eq!(details.cleanup, Cleaner::Success(CleanerState::Finished(PhantomData)));
Expand Down Expand Up @@ -4018,8 +4025,8 @@ mod community_round_success {
let details = finished_project.get_project_details();
assert_eq!(details.status, ProjectStatus::FundingSuccessful);
assert_eq!(details.cleanup, Cleaner::NotReady);
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

test_env.advance_time(1u64).unwrap();
let details = finished_project.get_project_details();
assert_eq!(details.cleanup, Cleaner::Success(CleanerState::Initialized(PhantomData)));

Expand Down Expand Up @@ -4075,6 +4082,7 @@ mod community_round_success {
community_contributions,
remainder_contributions,
);
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

test_env.advance_time(10u64).unwrap();
let details = finished_project.get_project_details();
Expand Down Expand Up @@ -4128,6 +4136,7 @@ mod community_round_success {
community_contributions,
remainder_contributions,
);
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

test_env.advance_time(15u64).unwrap();
let details = finished_project.get_project_details();
Expand Down Expand Up @@ -4435,6 +4444,7 @@ mod remainder_round_success {
let details = finished_project.get_project_details();
assert_eq!(details.status, ProjectStatus::FundingSuccessful);
assert_eq!(details.cleanup, Cleaner::NotReady);
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

test_env.advance_time(10u64).unwrap();
let details = finished_project.get_project_details();
Expand Down Expand Up @@ -4517,7 +4527,8 @@ mod remainder_round_success {
);
})
}
test_env.advance_time(1u64).unwrap();
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

let details = finished_project.get_project_details();
assert_eq!(details.cleanup, Cleaner::Success(CleanerState::Initialized(PhantomData)));

Expand Down Expand Up @@ -4614,7 +4625,8 @@ mod remainder_round_success {
);
})
}
test_env.advance_time(1u64).unwrap();
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

let details = finished_project.get_project_details();
assert_eq!(details.cleanup, Cleaner::Success(CleanerState::Initialized(PhantomData)));

Expand Down Expand Up @@ -4708,6 +4720,7 @@ mod remainder_round_success {
Contributions::<TestRuntime>::iter_prefix_values((project_id, BIDDER_1)).next().unwrap();
vec![evaluator_contribution.clone(), buyer_contribution.clone(), bidder_contribution.clone()]
});
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

test_env.advance_time(10u64).unwrap();
let details = finished_project.get_project_details();
Expand Down Expand Up @@ -4772,6 +4785,7 @@ mod remainder_round_success {
let remainder_locked_plmc = calculate_contributed_plmc_spent(remainder_contributions, price);
let all_plmc_locks =
merge_add_mappings_by_user(vec![auction_locked_plmc, community_locked_plmc, remainder_locked_plmc]);
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

test_env.advance_time(10u64).unwrap();
let details = finished_project.get_project_details();
Expand Down Expand Up @@ -4812,8 +4826,8 @@ mod remainder_round_success {
let details = finished_project.get_project_details();
assert_eq!(details.status, ProjectStatus::FundingSuccessful);
assert_eq!(details.cleanup, Cleaner::NotReady);
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

test_env.advance_time(1u64).unwrap();
let details = finished_project.get_project_details();
assert_eq!(details.cleanup, Cleaner::Success(CleanerState::Initialized(PhantomData)));

Expand Down Expand Up @@ -4882,6 +4896,7 @@ mod remainder_round_success {
community_contributions,
remainder_contributions,
);
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

test_env.advance_time(10u64).unwrap();
let details = finished_project.get_project_details();
Expand Down Expand Up @@ -4944,6 +4959,7 @@ mod remainder_round_success {
community_contributions,
remainder_contributions,
);
test_env.advance_time(<TestRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

test_env.advance_time(15u64).unwrap();
let details = finished_project.get_project_details();
Expand Down

0 comments on commit a54e3f8

Please sign in to comment.