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

Unbalanced and Balanced fungible conformance tests, and fungible fixes #1296

Merged
merged 34 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e5c876d
balanced and unbalanced conformance tests
liamaharon Aug 30, 2023
41e5345
Merge branch 'master' into liam/fungible-conformance-tests-balanced-u…
liamaharon Aug 30, 2023
73d7e32
Update substrate/frame/support/src/traits/tokens/fungible/regular.rs
liamaharon Sep 27, 2023
9ad460b
Merge branch 'master' of github.com:paritytech/polkadot-sdk into liam…
liamaharon Oct 16, 2023
a0f12da
mirror decrease_balance fix in fungibles
liamaharon Oct 16, 2023
177b231
address pr comments
liamaharon Oct 16, 2023
dbc2972
use FundsUnavailable
liamaharon Oct 16, 2023
e8c5baf
update fungible test
liamaharon Oct 16, 2023
03c97a2
Merge branch 'master' into liam/fungible-conformance-tests-balanced-u…
liamaharon Oct 23, 2023
69772db
revert change to item_of
liamaharon Oct 23, 2023
6224e9a
Merge branch 'master' of github.com:paritytech/polkadot-sdk into liam…
liamaharon Oct 27, 2023
8da4b0a
address comments
liamaharon Nov 3, 2023
4cff38d
use bounded and fix fungibles
liamaharon Nov 7, 2023
05af723
fix
liamaharon Nov 7, 2023
c3126e1
Merge branch 'master' into liam/fungible-conformance-tests-balanced-u…
liamaharon Nov 7, 2023
5f8e1e2
fix typo
liamaharon Nov 7, 2023
548879c
Merge branch 'master' into liam/fungible-conformance-tests-balanced-u…
liamaharon Nov 9, 2023
4b331fe
Merge branch 'master' into liam/fungible-conformance-tests-balanced-u…
liamaharon Nov 20, 2023
65b2b80
Merge branch 'master' into liam/fungible-conformance-tests-balanced-u…
liamaharon Nov 23, 2023
c5a1d7b
Merge branch 'master' into liam/fungible-conformance-tests-balanced-u…
liamaharon Nov 24, 2023
3d14f3d
Merge branch 'master' into liam/fungible-conformance-tests-balanced-u…
liamaharon Nov 27, 2023
c50c714
better pair handling
liamaharon Nov 28, 2023
1f72253
fix variable name
liamaharon Nov 28, 2023
a5241ba
refactor tests
liamaharon Nov 28, 2023
973dd1d
Merge branch 'master' into liam/fungible-conformance-tests-balanced-u…
liamaharon Dec 1, 2023
c20d010
fix edge case
liamaharon Dec 1, 2023
fba9468
Merge branch 'master' into liam/fungible-conformance-tests-balanced-u…
liamaharon Dec 1, 2023
e8ac4cd
Merge branch 'master' into liam/fungible-conformance-tests-balanced-u…
liamaharon Dec 4, 2023
b6e8998
Merge branch 'master' into liam/fungible-conformance-tests-balanced-u…
liamaharon Jan 15, 2024
429bac5
remove comments
liamaharon Jan 15, 2024
3f8d2b9
prdoc
liamaharon Jan 15, 2024
270ab9e
add missing paran
liamaharon Jan 15, 2024
ca55ec1
fix types
liamaharon Jan 15, 2024
f395791
fix test
liamaharon Jan 15, 2024
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
5 changes: 4 additions & 1 deletion substrate/frame/balances/src/impl_fungible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ impl<T: Config<I>, I: 'static> fungible::Unbalanced<T::AccountId> for Pallet<T,
}

fn deactivate(amount: Self::Balance) {
InactiveIssuance::<T, I>::mutate(|b| b.saturating_accrue(amount));
InactiveIssuance::<T, I>::mutate(|b| {
// InactiveIssuance cannot be greater than TotalIssuance.
*b = b.saturating_add(amount).min(TotalIssuance::<T, I>::get());
muharem marked this conversation as resolved.
Show resolved Hide resolved
});
}

fn reactivate(amount: Self::Balance) {
Expand Down
81 changes: 67 additions & 14 deletions substrate/frame/balances/src/tests/fungible_conformance_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,30 @@ use super::*;
use frame_support::traits::fungible::{conformance_tests, Inspect, Mutate};
use paste::paste;

macro_rules! run_tests {
($path:path, $ext_deposit:expr, $($name:ident),*) => {
macro_rules! generate_tests {
// Handle a conformance test that requires special testing with and without a dust trap.
(dust_trap_variation, $base_path:path, $scope:expr, $trait:ident, $ext_deposit:expr, $($test_name:ident),*) => {
$(
paste! {
#[test]
fn [< $name _existential_deposit_ $ext_deposit _dust_trap_on >]() {
fn [<$trait _ $scope _ $test_name _existential_deposit_ $ext_deposit _dust_trap_on >]() {
// Some random trap account.
let trap_account = <Test as frame_system::Config>::AccountId::from(65174286u64);
let builder = ExtBuilder::default().existential_deposit($ext_deposit).dust_trap(trap_account);
builder.build_and_execute_with(|| {
Balances::set_balance(&trap_account, Balances::minimum_balance());
$path::$name::<
$base_path::$scope::$trait::$test_name::<
Balances,
<Test as frame_system::Config>::AccountId,
>(Some(trap_account));
});
}

#[test]
fn [< $name _existential_deposit_ $ext_deposit _dust_trap_off >]() {
fn [< $trait _ $scope _ $test_name _existential_deposit_ $ext_deposit _dust_trap_off >]() {
let builder = ExtBuilder::default().existential_deposit($ext_deposit);
builder.build_and_execute_with(|| {
$path::$name::<
$base_path::$scope::$trait::$test_name::<
Balances,
<Test as frame_system::Config>::AccountId,
>(None);
Expand All @@ -49,9 +51,37 @@ macro_rules! run_tests {
}
)*
};
($path:path, $ext_deposit:expr) => {
run_tests!(
$path,
// Regular conformance test
($base_path:path, $scope:expr, $trait:ident, $ext_deposit:expr, $($test_name:ident),*) => {
$(
paste! {
#[test]
fn [< $trait _ $scope _ $test_name _existential_deposit_ $ext_deposit>]() {
let builder = ExtBuilder::default().existential_deposit($ext_deposit);
builder.build_and_execute_with(|| {
$base_path::$scope::$trait::$test_name::<
Balances,
<Test as frame_system::Config>::AccountId,
>();
});
}
}
)*
};
($base_path:path, $ext_deposit:expr) => {
// regular::mutate
generate_tests!(
dust_trap_variation,
$base_path,
regular,
mutate,
$ext_deposit,
transfer_expendable_dust
);
generate_tests!(
$base_path,
regular,
mutate,
$ext_deposit,
mint_into_success,
mint_into_overflow,
Expand All @@ -66,7 +96,6 @@ macro_rules! run_tests {
shelve_insufficient_funds,
transfer_success,
transfer_expendable_all,
transfer_expendable_dust,
transfer_protect_preserve,
set_balance_mint_success,
set_balance_burn_success,
Expand All @@ -79,10 +108,34 @@ macro_rules! run_tests {
reducible_balance_expendable,
reducible_balance_protect_preserve
);
// regular::unbalanced
generate_tests!(
$base_path,
regular,
unbalanced,
$ext_deposit,
write_balance,
decrease_balance_expendable,
decrease_balance_preserve,
increase_balance,
set_total_issuance,
deactivate_and_reactivate
);
// regular::balanced
generate_tests!(
$base_path,
regular,
balanced,
$ext_deposit,
issue_and_resolve_credit,
rescind_and_settle_debt,
deposit,
withdraw,
pair
);
};
}

run_tests!(conformance_tests::inspect_mutate, 1);
run_tests!(conformance_tests::inspect_mutate, 2);
run_tests!(conformance_tests::inspect_mutate, 5);
run_tests!(conformance_tests::inspect_mutate, 1000);
generate_tests!(conformance_tests, 1);
generate_tests!(conformance_tests, 5);
generate_tests!(conformance_tests, 1000);
2 changes: 1 addition & 1 deletion substrate/frame/balances/src/tests/fungible_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn unbalanced_trait_decrease_balance_works_2() {
assert_eq!(Balances::total_balance_on_hold(&1337), 60);
assert_noop!(
Balances::decrease_balance(&1337, 40, Exact, Expendable, Polite),
Error::<Test>::InsufficientBalance
TokenError::FundsUnavailable
);
assert_eq!(Balances::decrease_balance(&1337, 39, Exact, Expendable, Polite), Ok(39));
assert_eq!(<Balances as fungible::Inspect<_>>::balance(&1337), 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
// limitations under the License.

pub mod inspect_mutate;
pub mod regular;
Loading