Skip to content

Commit

Permalink
test-freeze-contribution-interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed May 27, 2024
1 parent 93443f9 commit 9ba16be
Show file tree
Hide file tree
Showing 4 changed files with 535 additions and 80 deletions.
43 changes: 22 additions & 21 deletions pallets/funding/src/tests/2_evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,10 @@ mod evaluate_extrinsic {
#[cfg(test)]
mod success {
use super::*;
use frame_support::traits::{fungible::Mutate, tokens::Preservation};
use frame_support::traits::fungible::InspectFreeze;
use frame_support::traits::{
fungible::{InspectFreeze, Mutate},
tokens::Preservation,
};
use pallet_balances::AccountData;
use sp_runtime::DispatchError::Token;

Expand Down Expand Up @@ -644,11 +646,7 @@ mod evaluate_extrinsic {

inst.execute(|| {
assert_noop!(
Balances::transfer_allow_death(
RuntimeOrigin::signed(EVALUATOR_4),
ISSUER_1,
frozen_amount,
),
Balances::transfer_allow_death(RuntimeOrigin::signed(EVALUATOR_4), ISSUER_1, frozen_amount,),
TokenError::Frozen
);
});
Expand Down Expand Up @@ -682,11 +680,10 @@ mod evaluate_extrinsic {
assert_eq!(inst.get_project_details(project_id).status, ProjectStatus::FundingFailed);

let free_balance = inst.get_free_plmc_balance_for(EVALUATOR_4);
let evaluation_held_balance = inst.get_reserved_plmc_balance_for(EVALUATOR_4, HoldReason::Evaluation(project_id).into());
let frozen_balance = inst.execute(|| {
mock::Balances::balance_frozen(&(), &EVALUATOR_4)
});
let account_data = inst.execute(|| {System::account(&EVALUATOR_4)}).data;
let evaluation_held_balance =
inst.get_reserved_plmc_balance_for(EVALUATOR_4, HoldReason::Evaluation(project_id).into());
let frozen_balance = inst.execute(|| mock::Balances::balance_frozen(&(), &EVALUATOR_4));
let account_data = inst.execute(|| System::account(&EVALUATOR_4)).data;

assert_eq!(free_balance, inst.get_ed());
assert_eq!(evaluation_held_balance, frozen_amount);
Expand All @@ -706,19 +703,20 @@ mod evaluate_extrinsic {
RuntimeOrigin::signed(EVALUATOR_4),
project_id,
EVALUATOR_4,
0
).unwrap();
0,
)
.unwrap();
});

let post_slash_treasury_balance = inst.get_free_plmc_balance_for(treasury_account);
let free_balance = inst.get_free_plmc_balance_for(EVALUATOR_4);
let evaluation_held_balance = inst.get_reserved_plmc_balance_for(EVALUATOR_4, HoldReason::Evaluation(project_id).into());
let frozen_balance = inst.execute(|| {
mock::Balances::balance_frozen(&(), &EVALUATOR_4)
});
let account_data = inst.execute(|| {System::account(&EVALUATOR_4)}).data;
let evaluation_held_balance =
inst.get_reserved_plmc_balance_for(EVALUATOR_4, HoldReason::Evaluation(project_id).into());
let frozen_balance = inst.execute(|| mock::Balances::balance_frozen(&(), &EVALUATOR_4));
let account_data = inst.execute(|| System::account(&EVALUATOR_4)).data;

let post_slash_evaluation_plmc = frozen_amount - (<TestRuntime as Config>::EvaluatorSlash::get() * frozen_amount);
let post_slash_evaluation_plmc =
frozen_amount - (<TestRuntime as Config>::EvaluatorSlash::get() * frozen_amount);
assert_eq!(free_balance, inst.get_ed() + post_slash_evaluation_plmc);
assert_eq!(evaluation_held_balance, Zero::zero());
assert_eq!(frozen_balance, frozen_amount);
Expand All @@ -731,7 +729,10 @@ mod evaluate_extrinsic {
assert_eq!(account_data, expected_account_data);

assert!(account_data.frozen > account_data.free);
assert_eq!(post_slash_treasury_balance, pre_slash_treasury_balance + <TestRuntime as Config>::EvaluatorSlash::get() * frozen_amount);
assert_eq!(
post_slash_treasury_balance,
pre_slash_treasury_balance + <TestRuntime as Config>::EvaluatorSlash::get() * frozen_amount
);
}
}

Expand Down
88 changes: 30 additions & 58 deletions pallets/funding/src/tests/3_auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,7 @@ mod bid_extrinsic {
#[cfg(test)]
mod success {
use super::*;
use frame_support::dispatch::DispatchResultWithPostInfo;
use frame_support::traits::fungible::InspectFreeze;
use frame_support::{dispatch::DispatchResultWithPostInfo, traits::fungible::InspectFreeze};
use pallet_balances::AccountData;

#[test]
Expand Down Expand Up @@ -1274,11 +1273,7 @@ mod bid_extrinsic {

inst.execute(|| {
assert_noop!(
Balances::transfer_allow_death(
RuntimeOrigin::signed(BIDDER_4),
ISSUER_1,
frozen_amount,
),
Balances::transfer_allow_death(RuntimeOrigin::signed(BIDDER_4), ISSUER_1, frozen_amount,),
TokenError::Frozen
);
});
Expand Down Expand Up @@ -1306,11 +1301,10 @@ mod bid_extrinsic {
assert_eq!(inst.get_project_details(project_id).status, ProjectStatus::FundingFailed);

let free_balance = inst.get_free_plmc_balance_for(BIDDER_4);
let bid_held_balance = inst.get_reserved_plmc_balance_for(BIDDER_4, HoldReason::Participation(project_id).into());
let frozen_balance = inst.execute(|| {
mock::Balances::balance_frozen(&(), &BIDDER_4)
});
let account_data = inst.execute(|| {System::account(&BIDDER_4)}).data;
let bid_held_balance =
inst.get_reserved_plmc_balance_for(BIDDER_4, HoldReason::Participation(project_id).into());
let frozen_balance = inst.execute(|| mock::Balances::balance_frozen(&(), &BIDDER_4));
let account_data = inst.execute(|| System::account(&BIDDER_4)).data;

assert_eq!(free_balance, inst.get_ed());
assert_eq!(bid_held_balance, frozen_amount);
Expand All @@ -1324,20 +1318,14 @@ mod bid_extrinsic {
assert_eq!(account_data, expected_account_data);

inst.execute(|| {
PolimecFunding::settle_failed_bid(
RuntimeOrigin::signed(BIDDER_4),
project_id,
BIDDER_4,
0
).unwrap();
PolimecFunding::settle_failed_bid(RuntimeOrigin::signed(BIDDER_4), project_id, BIDDER_4, 0).unwrap();
});

let free_balance = inst.get_free_plmc_balance_for(BIDDER_4);
let bid_held_balance = inst.get_reserved_plmc_balance_for(BIDDER_4, HoldReason::Evaluation(project_id).into());
let frozen_balance = inst.execute(|| {
mock::Balances::balance_frozen(&(), &BIDDER_4)
});
let account_data = inst.execute(|| {System::account(&BIDDER_4)}).data;
let bid_held_balance =
inst.get_reserved_plmc_balance_for(BIDDER_4, HoldReason::Evaluation(project_id).into());
let frozen_balance = inst.execute(|| mock::Balances::balance_frozen(&(), &BIDDER_4));
let account_data = inst.execute(|| System::account(&BIDDER_4)).data;

assert_eq!(free_balance, inst.get_ed() + frozen_amount);
assert_eq!(bid_held_balance, Zero::zero());
Expand Down Expand Up @@ -1384,11 +1372,7 @@ mod bid_extrinsic {

inst.execute(|| {
assert_noop!(
Balances::transfer_allow_death(
RuntimeOrigin::signed(BIDDER_4),
ISSUER_1,
frozen_amount,
),
Balances::transfer_allow_death(RuntimeOrigin::signed(BIDDER_4), ISSUER_1, frozen_amount,),
TokenError::Frozen
);
});
Expand Down Expand Up @@ -1419,18 +1403,12 @@ mod bid_extrinsic {
default_community_contributors(),
default_multipliers(),
);
let plmc_required = inst.calculate_contributed_plmc_spent(
contributions.clone(),
wap
);
let plmc_required = inst.calculate_contributed_plmc_spent(contributions.clone(), wap);
let plmc_existential_deposits = plmc_required.accounts().existential_deposits();
inst.mint_plmc_to(plmc_required.clone());
inst.mint_plmc_to(plmc_existential_deposits.clone());

let usdt_required = inst.calculate_contributed_funding_asset_spent(
contributions.clone(),
wap
);
let usdt_required = inst.calculate_contributed_funding_asset_spent(contributions.clone(), wap);
inst.mint_foreign_asset_to(usdt_required.clone());

inst.contribute_for_users(project_id, contributions).unwrap();
Expand All @@ -1443,11 +1421,10 @@ mod bid_extrinsic {
inst.jump_to_block(settlement_block);

let free_balance = inst.get_free_plmc_balance_for(BIDDER_4);
let bid_held_balance = inst.get_reserved_plmc_balance_for(BIDDER_4, HoldReason::Participation(project_id).into());
let frozen_balance = inst.execute(|| {
mock::Balances::balance_frozen(&(), &BIDDER_4)
});
let account_data = inst.execute(|| {System::account(&BIDDER_4)}).data;
let bid_held_balance =
inst.get_reserved_plmc_balance_for(BIDDER_4, HoldReason::Participation(project_id).into());
let frozen_balance = inst.execute(|| mock::Balances::balance_frozen(&(), &BIDDER_4));
let account_data = inst.execute(|| System::account(&BIDDER_4)).data;

assert_eq!(free_balance, inst.get_ed());
assert_eq!(bid_held_balance, frozen_amount);
Expand All @@ -1461,20 +1438,15 @@ mod bid_extrinsic {
assert_eq!(account_data, expected_account_data);

inst.execute(|| {
PolimecFunding::settle_successful_bid(
RuntimeOrigin::signed(BIDDER_4),
project_id,
BIDDER_4,
0
).unwrap();
PolimecFunding::settle_successful_bid(RuntimeOrigin::signed(BIDDER_4), project_id, BIDDER_4, 0)
.unwrap();
});

let free_balance = inst.get_free_plmc_balance_for(BIDDER_4);
let bid_held_balance = inst.get_reserved_plmc_balance_for(BIDDER_4, HoldReason::Participation(project_id).into());
let frozen_balance = inst.execute(|| {
mock::Balances::balance_frozen(&(), &BIDDER_4)
});
let account_data = inst.execute(|| {System::account(&BIDDER_4)}).data;
let bid_held_balance =
inst.get_reserved_plmc_balance_for(BIDDER_4, HoldReason::Participation(project_id).into());
let frozen_balance = inst.execute(|| mock::Balances::balance_frozen(&(), &BIDDER_4));
let account_data = inst.execute(|| System::account(&BIDDER_4)).data;

assert_eq!(free_balance, inst.get_ed());
assert_eq!(bid_held_balance, frozen_amount);
Expand All @@ -1487,7 +1459,8 @@ mod bid_extrinsic {
};
assert_eq!(account_data, expected_account_data);

let vest_duration = MultiplierOf::<TestRuntime>::new(5u8).unwrap().calculate_vesting_duration::<TestRuntime>();
let vest_duration =
MultiplierOf::<TestRuntime>::new(5u8).unwrap().calculate_vesting_duration::<TestRuntime>();
let now = inst.current_block();
inst.jump_to_block(now + vest_duration + 1u64);
inst.execute(|| {
Expand All @@ -1498,11 +1471,10 @@ mod bid_extrinsic {
});

let free_balance = inst.get_free_plmc_balance_for(BIDDER_4);
let bid_held_balance = inst.get_reserved_plmc_balance_for(BIDDER_4, HoldReason::Participation(project_id).into());
let frozen_balance = inst.execute(|| {
mock::Balances::balance_frozen(&(), &BIDDER_4)
});
let account_data = inst.execute(|| {System::account(&BIDDER_4)}).data;
let bid_held_balance =
inst.get_reserved_plmc_balance_for(BIDDER_4, HoldReason::Participation(project_id).into());
let frozen_balance = inst.execute(|| mock::Balances::balance_frozen(&(), &BIDDER_4));
let account_data = inst.execute(|| System::account(&BIDDER_4)).data;

assert_eq!(free_balance, inst.get_ed() + frozen_amount);
assert_eq!(bid_held_balance, Zero::zero());
Expand Down
Loading

0 comments on commit 9ba16be

Please sign in to comment.