Skip to content

Commit

Permalink
Fix existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios authored and lrazovic committed Aug 16, 2024
1 parent 49e8d93 commit 10ed7d7
Show file tree
Hide file tree
Showing 32 changed files with 2,173 additions and 4,782 deletions.
12 changes: 6 additions & 6 deletions integration-tests/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ pub mod polimec {
#[allow(unused)]
pub fn set_prices() {
PolimecNet::execute_with(|| {
let dot = (AcceptedFundingAsset::DOT.to_assethub_id(), FixedU128::from_rational(69, 1));
let usdc = (AcceptedFundingAsset::USDC.to_assethub_id(), FixedU128::from_rational(1, 1));
let usdt = (AcceptedFundingAsset::USDT.to_assethub_id(), FixedU128::from_rational(1, 1));
let dot = (AcceptedFundingAsset::DOT.id(), FixedU128::from_rational(69, 1));
let usdc = (AcceptedFundingAsset::USDC.id(), FixedU128::from_rational(1, 1));
let usdt = (AcceptedFundingAsset::USDT.id(), FixedU128::from_rational(1, 1));
let plmc = (pallet_funding::PLMC_FOREIGN_ID, FixedU128::from_rational(840, 100));

let values: BoundedVec<(u32, FixedU128), <PolimecRuntime as orml_oracle::Config>::MaxFeedValues> =
Expand Down Expand Up @@ -424,9 +424,9 @@ pub mod polimec {
}

pub fn genesis() -> Storage {
let dot_asset_id = AcceptedFundingAsset::DOT.to_assethub_id();
let usdt_asset_id = AcceptedFundingAsset::USDT.to_assethub_id();
let usdc_asset_id = AcceptedFundingAsset::USDC.to_assethub_id();
let dot_asset_id = AcceptedFundingAsset::DOT.id();
let usdt_asset_id = AcceptedFundingAsset::USDT.id();
let usdc_asset_id = AcceptedFundingAsset::USDC.id();
let mut funded_accounts = vec![
(
PolimecNet::sovereign_account_id_of((Parent, xcm::prelude::Parachain(penpal::PARA_ID)).into()),
Expand Down
24 changes: 12 additions & 12 deletions integration-tests/src/tests/ct_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ fn create_settled_project() -> (ProjectId, Vec<AccountId>) {
default_community_contributions(),
default_remainder_contributions(),
);
inst.advance_time(<PolimecRuntime as pallet_funding::Config>::SuccessToSettlementTime::get()).unwrap();
assert_eq!(
inst.go_to_next_state(project_id),
pallet_funding::ProjectStatus::SettlementStarted(FundingOutcome::Success)
);
let mut participants: Vec<AccountId> =
pallet_funding::Evaluations::<PolimecRuntime>::iter_prefix_values((project_id,))
.map(|eval| eval.evaluator)
Expand All @@ -187,7 +190,7 @@ fn create_settled_project() -> (ProjectId, Vec<AccountId>) {
participants.sort();
participants.dedup();

inst.settle_project(project_id).unwrap();
inst.settle_project(project_id);
(project_id, participants)
})
}
Expand Down Expand Up @@ -229,7 +232,10 @@ fn create_project_with_unsettled_participation(participation_type: Participation
default_remainder_contributions(),
);

inst.advance_time(<PolimecRuntime as pallet_funding::Config>::SuccessToSettlementTime::get()).unwrap();
assert_eq!(
inst.go_to_next_state(project_id),
pallet_funding::ProjectStatus::SettlementStarted(FundingOutcome::Success)
);
let evaluations_to_settle =
pallet_funding::Evaluations::<PolimecRuntime>::iter_prefix_values((project_id,)).collect_vec();
let bids_to_settle = pallet_funding::Bids::<PolimecRuntime>::iter_prefix_values((project_id,)).collect_vec();
Expand All @@ -247,7 +253,7 @@ fn create_project_with_unsettled_participation(participation_type: Participation

let start = if participation_type == ParticipationType::Evaluation { 1 } else { 0 };
for evaluation in evaluations_to_settle[start..].iter() {
PolimecFunding::settle_successful_evaluation(
PolimecFunding::settle_evaluation(
RuntimeOrigin::signed(alice()),
project_id,
evaluation.evaluator.clone(),
Expand All @@ -258,18 +264,12 @@ fn create_project_with_unsettled_participation(participation_type: Participation

let start = if participation_type == ParticipationType::Bid { 1 } else { 0 };
for bid in bids_to_settle[start..].iter() {
PolimecFunding::settle_successful_bid(
RuntimeOrigin::signed(alice()),
project_id,
bid.bidder.clone(),
bid.id,
)
.unwrap()
PolimecFunding::settle_bid(RuntimeOrigin::signed(alice()), project_id, bid.bidder.clone(), bid.id).unwrap()
}

let start = if participation_type == ParticipationType::Contribution { 1 } else { 0 };
for contribution in contributions_to_settle[start..].iter() {
PolimecFunding::settle_successful_contribution(
PolimecFunding::settle_contribution(
RuntimeOrigin::signed(alice()),
project_id,
contribution.contributor.clone(),
Expand Down
32 changes: 12 additions & 20 deletions integration-tests/src/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,8 @@ fn remainder_round_completed() {
let total_stored =
contributions.into_iter().fold(0, |acc, contribution| acc + contribution.funding_asset_amount);

let usdt_decimals = <PolimecRuntime as pallet_funding::Config>::FundingCurrency::decimals(
AcceptedFundingAsset::USDT.to_assethub_id(),
);
let usdt_decimals =
<PolimecRuntime as pallet_funding::Config>::FundingCurrency::decimals(AcceptedFundingAsset::USDT.id());
let usdt_total_from_excel_f64 = 503_945.4_517_000_000f64;
let usdt_total_from_excel_fixed = FixedU128::from_float(usdt_total_from_excel_f64);
let usdt_total_from_excel = usdt_total_from_excel_fixed.saturating_mul_int(10u128.pow(usdt_decimals as u32));
Expand All @@ -392,7 +391,7 @@ fn funds_raised() {
let mut inst = IntegrationInstantiator::new(None);

PolimecNet::execute_with(|| {
let project_id = inst.create_finished_project(
let _project_id = inst.create_settled_project(
excel_project(),
ISSUER.into(),
None,
Expand All @@ -403,14 +402,13 @@ fn funds_raised() {
);

inst.execute(|| {
let project_specific_account: AccountId = PolimecFunding::fund_account_id(project_id);
let funding_destination_account: AccountId = excel_project().funding_destination_account;
let stored_usdt_funded =
PolimecForeignAssets::balance(AcceptedFundingAsset::USDT.to_assethub_id(), project_specific_account);
PolimecForeignAssets::balance(AcceptedFundingAsset::USDT.id(), funding_destination_account);
let excel_usdt_funded_f64 = 1_004_256.0_140_000_000f64;
let excet_usdt_funding_fixed = FixedU128::from_float(excel_usdt_funded_f64);
let usdt_decimals = <PolimecRuntime as pallet_funding::Config>::FundingCurrency::decimals(
AcceptedFundingAsset::USDT.to_assethub_id(),
);
let usdt_decimals =
<PolimecRuntime as pallet_funding::Config>::FundingCurrency::decimals(AcceptedFundingAsset::USDT.id());
let excel_usdt_funded = excet_usdt_funding_fixed.saturating_mul_int(10u128.pow(usdt_decimals as u32));
assert_close_enough!(stored_usdt_funded, excel_usdt_funded, Perquintill::from_float(0.99));
})
Expand All @@ -424,7 +422,7 @@ fn ct_minted() {
let mut inst = IntegrationInstantiator::new(None);

PolimecNet::execute_with(|| {
let project_id = inst.create_finished_project(
let project_id = inst.create_settled_project(
excel_project(),
ISSUER.into(),
None,
Expand All @@ -433,9 +431,6 @@ fn ct_minted() {
excel_contributions(),
excel_remainders(),
);
inst.advance_time(<PolimecRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

inst.settle_project(project_id).unwrap();

for (contributor, expected_amount_fixed, project_id) in excel_ct_amounts() {
let minted = inst
Expand All @@ -453,7 +448,7 @@ fn ct_migrated() {
let mut inst = IntegrationInstantiator::new(None);

let project_id = PolimecNet::execute_with(|| {
let project_id = inst.create_finished_project(
let project_id = inst.create_settled_project(
excel_project(),
ISSUER.into(),
None,
Expand All @@ -462,22 +457,19 @@ fn ct_migrated() {
excel_contributions(),
excel_remainders(),
);
inst.advance_time(<PolimecRuntime as Config>::SuccessToSettlementTime::get()).unwrap();

inst.settle_project(project_id).unwrap();

for (contributor, expected_amount_fixed, project_id) in excel_ct_amounts() {
let minted = inst
.execute(|| <PolimecRuntime as Config>::ContributionTokenCurrency::balance(project_id, &contributor));
let expected_amount = expected_amount_fixed.saturating_mul_int(CT_UNIT);
assert_close_enough!(minted, expected_amount, Perquintill::from_float(0.99));
assert_close_enough!(minted, expected_amount, Perquintill::from_float(0.999));
}

project_id
});

let project_details = PolimecNet::execute_with(|| inst.get_project_details(project_id));
assert!(matches!(project_details.evaluation_round_info.evaluators_outcome, EvaluatorsOutcome::Rewarded(_)));
assert!(matches!(project_details.evaluation_round_info.evaluators_outcome, Some(EvaluatorsOutcome::Rewarded(_))));
let ct_issued =
PolimecNet::execute_with(|| <PolimecRuntime as Config>::ContributionTokenCurrency::total_issuance(project_id));

Expand Down Expand Up @@ -540,7 +532,7 @@ fn ct_migrated() {
));
let key: [u8; 32] = account.clone().into();
println!("Migrated CTs for {}", names[&key]);
inst.advance_time(1u32).unwrap();
inst.advance_time(1u32);
});
}

Expand Down
6 changes: 3 additions & 3 deletions integration-tests/src/tests/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn members_can_feed_data() {

PolimecNet::execute_with(|| {
// pallet_funding genesis builder already inputs prices, so we need to advance one block to feed new values.
inst.advance_time(1u32).unwrap();
inst.advance_time(1u32);
let alice = PolimecNet::account_id_of(ALICE);
assert_ok!(Oracle::feed_values(RuntimeOrigin::signed(alice.clone()), values([4.84, 1.0, 1.0, 0.4])));

Expand Down Expand Up @@ -81,7 +81,7 @@ fn data_is_correctly_combined() {
let mut inst = IntegrationInstantiator::new(None);
PolimecNet::execute_with(|| {
// pallet_funding genesis builder already inputs prices, so we need to advance one block to feed new values.
inst.advance_time(1u32).unwrap();
inst.advance_time(1u32);

let alice = PolimecNet::account_id_of(ALICE);
assert_ok!(Oracle::feed_values(RuntimeOrigin::signed(alice.clone()), values([1.0, 1.5, 1.1, 0.11111])));
Expand Down Expand Up @@ -113,7 +113,7 @@ fn pallet_funding_works() {

PolimecNet::execute_with(|| {
// pallet_funding genesis builder already inputs prices, so we need to advance one block to feed new values.
inst.advance_time(1u32).unwrap();
inst.advance_time(1u32);

let alice = PolimecNet::account_id_of(ALICE);
assert_ok!(Oracle::feed_values(RuntimeOrigin::signed(alice.clone()), values([4.84, 1.0, 1.0, 0.4])));
Expand Down
12 changes: 6 additions & 6 deletions nodes/parachain/src/chain_spec/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ pub fn genesis_config(genesis_config_params: GenesisConfigParams) -> serde_json:
#[cfg(feature = "runtime-benchmarks")]
let staking_candidates: Vec<(AccountId, Balance)> = vec![];

let usdt_id = pallet_funding::types::AcceptedFundingAsset::USDT.to_assethub_id();
let usdc_id = pallet_funding::types::AcceptedFundingAsset::USDC.to_assethub_id();
let dot_id = pallet_funding::types::AcceptedFundingAsset::DOT.to_assethub_id();
let usdt_id = pallet_funding::types::AcceptedFundingAsset::USDT.id();
let usdc_id = pallet_funding::types::AcceptedFundingAsset::USDC.id();
let dot_id = pallet_funding::types::AcceptedFundingAsset::DOT.id();

serde_json::json!({
"balances": {
Expand All @@ -114,19 +114,19 @@ pub fn genesis_config(genesis_config_params: GenesisConfigParams) -> serde_json:
},
"foreignAssets": {
"assets": vec![(
pallet_funding::types::AcceptedFundingAsset::USDT.to_assethub_id(),
pallet_funding::types::AcceptedFundingAsset::USDT.id(),
&AccountIdConversion::<AccountId>::into_account_truncating(&<Runtime as pallet_funding::Config>::PalletId::get()),
true,
70000,
),
(
pallet_funding::types::AcceptedFundingAsset::USDC.to_assethub_id(),
pallet_funding::types::AcceptedFundingAsset::USDC.id(),
&AccountIdConversion::<AccountId>::into_account_truncating(&<Runtime as pallet_funding::Config>::PalletId::get()),
true,
70000,
),
(
pallet_funding::types::AcceptedFundingAsset::DOT.to_assethub_id(),
pallet_funding::types::AcceptedFundingAsset::DOT.id(),
&AccountIdConversion::<AccountId>::into_account_truncating(&<Runtime as pallet_funding::Config>::PalletId::get()),
true,
70000,
Expand Down
Loading

0 comments on commit 10ed7d7

Please sign in to comment.