Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ Comprehensive settlement tests #304

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 37 additions & 10 deletions pallets/funding/src/instantiator/chain_interactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ impl<
})
}

pub fn get_free_plmc_balance_for(&mut self, user: AccountIdOf<T>) -> BalanceOf<T> {
self.execute(|| <T as Config>::NativeCurrency::balance(&user))
}

pub fn get_reserved_plmc_balances_for(
&mut self,
user_keys: Vec<AccountIdOf<T>>,
Expand All @@ -57,6 +61,14 @@ impl<
})
}

pub fn get_reserved_plmc_balance_for(
&mut self,
user: AccountIdOf<T>,
lock_type: <T as Config>::RuntimeHoldReason,
) -> BalanceOf<T> {
self.execute(|| <T as Config>::NativeCurrency::balance_on_hold(&lock_type, &user))
}

pub fn get_free_foreign_asset_balances_for(
&mut self,
asset_id: AssetIdOf<T>,
Expand All @@ -73,6 +85,10 @@ impl<
})
}

pub fn get_free_foreign_asset_balance_for(&mut self, asset_id: AssetIdOf<T>, user: AccountIdOf<T>) -> BalanceOf<T> {
self.execute(|| <T as Config>::FundingCurrency::balance(asset_id, &user))
}

pub fn get_ct_asset_balances_for(
&mut self,
project_id: ProjectId,
Expand All @@ -88,6 +104,10 @@ impl<
})
}

pub fn get_ct_asset_balance_for(&mut self, project_id: ProjectId, user: AccountIdOf<T>) -> BalanceOf<T> {
self.execute(|| <T as Config>::ContributionTokenCurrency::balance(project_id, &user))
}

pub fn get_all_free_plmc_balances(&mut self) -> Vec<UserToPLMCBalance<T>> {
let user_keys = self.execute(|| frame_system::Account::<T>::iter_keys().collect());
self.get_free_plmc_balances_for(user_keys)
Expand Down Expand Up @@ -876,7 +896,7 @@ impl<
}
}

fn assert_migration(
pub(crate) fn assert_migration(
&mut self,
project_id: ProjectId,
account: AccountIdOf<T>,
Expand All @@ -885,25 +905,32 @@ impl<
participation_type: ParticipationType,
should_exist: bool,
) {
let correct = match (should_exist, self.execute(|| UserMigrations::<T>::get(project_id, account.clone()))) {
match (should_exist, self.execute(|| UserMigrations::<T>::get(project_id, account.clone()))) {
// User has migrations, so we need to check if any matches our criteria
(_, Some((_, migrations))) => {
let maybe_migration = migrations.into_iter().find(|migration| {
let user = T::AccountId32Conversion::convert(account.clone());
matches!(migration.origin, MigrationOrigin { user: m_user, id: m_id, participation_type: m_participation_type } if m_user == user && m_id == id && m_participation_type == participation_type)
});
let user = T::AccountId32Conversion::convert(account.clone());
matches!(migration.origin, MigrationOrigin { user: m_user, id: m_id, participation_type: m_participation_type } if m_user == user && m_id == id && m_participation_type == participation_type)
});
match maybe_migration {
// Migration exists so we check if the amount is correct and if it should exist
Some(migration) => migration.info.contribution_token_amount == amount.into() && should_exist,
Some(migration) => {
assert!(should_exist);
assert_close_enough!(
migration.info.contribution_token_amount,
amount.into(),
Perquintill::from_percent(99u64)
);
},

// Migration doesn't exist so we check if it should not exist
None => !should_exist,
None => assert!(should_exist),
}
},
// User does not have any migrations, so the migration should not exist
(false, None) => true,
(true, None) => false,
(false, None) => (),
(true, None) => panic!("No migration should have been found"),
};
assert!(correct);
}

pub fn create_remainder_contributing_project(
Expand Down
2 changes: 0 additions & 2 deletions pallets/funding/src/tests/6_funding_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ mod round_flow {
let fee_2 = FEE_2 * 4_000_000 * USD_UNIT;
let fee_3 = FEE_3 * 4_500_000 * USD_UNIT;

let x = PolimecFunding::calculate_fees(USD_REACHED);
dbg!(x);
let total_fee = Perquintill::from_rational(fee_1 + fee_2 + fee_3, USD_REACHED);

let total_ct_fee =
Expand Down
Loading