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 28, 2024
1 parent 6b94e27 commit ff0172f
Show file tree
Hide file tree
Showing 3 changed files with 513 additions and 59 deletions.
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 ff0172f

Please sign in to comment.