Assets pallet: Don't allow set_min_balance when sufficient (#13510)

* Assets pallet: Don't allow set_min_balance when sufficient

* fix

* fix benchmark

* ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_assets

* Update frame/assets/src/lib.rs

* fix

* ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_assets

---------

Co-authored-by: command-bot <>
Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
Sergej Sakac
2023-03-03 21:39:45 +01:00
committed by GitHub
parent e4bf9f2125
commit 1d6423b41d
4 changed files with 169 additions and 189 deletions
+37 -7
View File
@@ -1101,23 +1101,53 @@ fn set_min_balance_should_work() {
Balances::make_free_balance_be(&1, 10);
assert_ok!(Assets::create(RuntimeOrigin::signed(1), id, 1, 30));
assert_ok!(Assets::mint(RuntimeOrigin::signed(1), id, 1, 50));
// won't execute because there is an asset holder.
assert_ok!(Assets::mint(RuntimeOrigin::signed(1), id, 1, 100));
// Won't execute because there is an asset holder.
assert_noop!(
Assets::set_min_balance(RuntimeOrigin::signed(1), id, 50),
Error::<Test>::NoPermission
);
// will execute because the new value of min_balance is less than the
// old value. 10 < 30
assert_ok!(Assets::mint(RuntimeOrigin::signed(1), id, 1, 10));
// Force asset status to make this a sufficient asset.
assert_ok!(Assets::force_asset_status(
RuntimeOrigin::root(),
id,
1,
1,
1,
1,
30,
true,
false
));
assert_ok!(Assets::burn(RuntimeOrigin::signed(1), id, 1, 50));
// Won't execute because there is an account holding the asset and the asset is marked as
// sufficient.
assert_noop!(
Assets::set_min_balance(RuntimeOrigin::signed(2), id, 50),
Assets::set_min_balance(RuntimeOrigin::signed(1), id, 10),
Error::<Test>::NoPermission
);
// Make the asset not sufficient.
assert_ok!(Assets::force_asset_status(
RuntimeOrigin::root(),
id,
1,
1,
1,
1,
60,
false,
false
));
// Will execute because the new value of min_balance is less than the
// old value. 10 < 30
assert_ok!(Assets::set_min_balance(RuntimeOrigin::signed(1), id, 10));
assert_eq!(Asset::<Test>::get(id).unwrap().min_balance, 10);
assert_ok!(Assets::burn(RuntimeOrigin::signed(1), id, 1, 100));
assert_ok!(Assets::set_min_balance(RuntimeOrigin::signed(1), id, 50));
assert_eq!(Asset::<Test>::get(id).unwrap().min_balance, 50);
});