Skip to content

Commit

Permalink
Merge branch 'main' into release/0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
lrazovic authored Dec 20, 2024
2 parents cb5fff5 + 38af93a commit da15133
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pallets/funding/src/functions/2_evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ impl<T: Config> Pallet<T> {
ensure!(usd_amount >= T::MinUsdPerEvaluation::get(), Error::<T>::TooLow);
ensure!(project_details.issuer_did != did, Error::<T>::ParticipationToOwnProject);
ensure!(project_details.status == ProjectStatus::EvaluationRound, Error::<T>::IncorrectRound);
ensure!(
project_details.round_duration.started(now) && !project_details.round_duration.ended(now),
Error::<T>::IncorrectRound
);
ensure!(total_evaluations_count < T::MaxEvaluationsPerProject::get(), Error::<T>::TooManyProjectParticipations);
ensure!(user_evaluations_count < T::MaxEvaluationsPerUser::get(), Error::<T>::TooManyUserParticipations);

Expand Down
4 changes: 4 additions & 0 deletions pallets/funding/src/functions/3_auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ impl<T: Config> Pallet<T> {
ensure!(ct_amount > Zero::zero(), Error::<T>::TooLow);
ensure!(did != project_details.issuer_did, Error::<T>::ParticipationToOwnProject);
ensure!(matches!(project_details.status, ProjectStatus::AuctionRound), Error::<T>::IncorrectRound);
ensure!(
project_details.round_duration.started(now) && !project_details.round_duration.ended(now),
Error::<T>::IncorrectRound
);
ensure!(
project_metadata.participation_currencies.contains(&funding_asset),
Error::<T>::FundingAssetNotAccepted
Expand Down
6 changes: 4 additions & 2 deletions pallets/funding/src/functions/4_contribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ impl<T: Config> Pallet<T> {

let now = <frame_system::Pallet<T>>::block_number();
let remainder_started = now >= remainder_start;
let round_end = project_details.round_duration.end().ok_or(Error::<T>::ImpossibleState)?;
ensure!(!did_has_winning_bid || remainder_started, Error::<T>::UserHasWinningBid);
ensure!(now < round_end, Error::<T>::TooLateForRound);
ensure!(
project_details.round_duration.started(now) && !project_details.round_duration.ended(now),
Error::<T>::IncorrectRound
);

let buyable_tokens = token_amount.min(project_details.remaining_contribution_tokens);
if buyable_tokens.is_zero() {
Expand Down
1 change: 1 addition & 0 deletions pallets/funding/src/runtime_api.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[allow(clippy::wildcard_imports)]
use crate::*;

use crate::traits::BondingRequirementCalculation;
use alloc::collections::BTreeMap;
use frame_support::traits::fungibles::{Inspect, InspectEnumerable};
Expand Down
28 changes: 28 additions & 0 deletions pallets/funding/src/tests/2_evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -982,5 +982,33 @@ mod evaluate_extrinsic {
);
});
}

#[test]
fn evaluated_after_end_block_before_transitioning_project() {
let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext())));
let issuer = ISSUER_1;
let project_metadata = default_project_metadata(issuer);
let project_id = inst.create_evaluating_project(project_metadata.clone(), issuer, None);
let project_details = inst.get_project_details(project_id);
let end_block = project_details.round_duration.end().unwrap();
inst.jump_to_block(end_block + 1);
assert_eq!(inst.get_project_details(project_id).status, ProjectStatus::EvaluationRound);
inst.execute(|| {
assert_noop!(
PolimecFunding::evaluate(
RuntimeOrigin::signed(EVALUATOR_1),
get_mock_jwt_with_cid(
EVALUATOR_1,
InvestorType::Retail,
generate_did_from_account(EVALUATOR_1),
project_metadata.clone().policy_ipfs_cid.unwrap()
),
project_id,
500 * USD_UNIT,
),
Error::<TestRuntime>::IncorrectRound
);
});
}
}
}
29 changes: 29 additions & 0 deletions pallets/funding/src/tests/3_auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,35 @@ mod bid_extrinsic {
);
});
}

#[test]
fn bid_after_end_block_before_transitioning_project() {
let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext())));
let project_metadata = default_project_metadata(ISSUER_1);
let project_id =
inst.create_auctioning_project(project_metadata.clone(), ISSUER_1, None, default_evaluations());
let end_block = inst.get_project_details(project_id).round_duration.end.unwrap();
inst.jump_to_block(end_block + 1);
assert_eq!(inst.get_project_details(project_id).status, ProjectStatus::AuctionRound);
inst.execute(|| {
assert_noop!(
PolimecFunding::bid(
RuntimeOrigin::signed(BIDDER_1),
get_mock_jwt_with_cid(
BIDDER_1,
InvestorType::Professional,
generate_did_from_account(BIDDER_1),
project_metadata.clone().policy_ipfs_cid.unwrap()
),
project_id,
5000 * CT_UNIT,
ParticipationMode::Classic(1u8),
AcceptedFundingAsset::USDT
),
Error::<TestRuntime>::IncorrectRound
);
});
}
}
}

Expand Down
35 changes: 35 additions & 0 deletions pallets/funding/src/tests/4_contribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2184,5 +2184,40 @@ mod contribute_extrinsic {
);
});
}

#[test]
fn contributed_after_end_block_before_transitioning_project() {
let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext())));
let project_metadata = default_project_metadata(ISSUER_1);
let project_id = inst.create_community_contributing_project(
project_metadata.clone(),
ISSUER_1,
None,
default_evaluations(),
vec![],
);
let end_block = inst.get_project_details(project_id).round_duration.end.unwrap();
inst.jump_to_block(end_block + 1);
assert!(matches!(inst.get_project_details(project_id).status, ProjectStatus::CommunityRound(..)));

inst.execute(|| {
assert_noop!(
PolimecFunding::contribute(
RuntimeOrigin::signed(BUYER_1),
get_mock_jwt_with_cid(
BUYER_1,
InvestorType::Professional,
generate_did_from_account(BUYER_1),
project_metadata.clone().policy_ipfs_cid.unwrap()
),
project_id,
5000 * CT_UNIT,
ParticipationMode::Classic(1u8),
AcceptedFundingAsset::USDT
),
Error::<TestRuntime>::IncorrectRound
);
});
}
}
}

0 comments on commit da15133

Please sign in to comment.