Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Rename Burn to Slash in Assets #8878

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 4 additions & 5 deletions frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ pub mod pallet {
///
/// Bails with `BalanceZero` if the `who` is already dead.
///
/// - `id`: The identifier of the asset to have some amount burned.
/// - `id`: The identifier of the asset to have some amount slashed.
/// - `who`: The account to be debited from.
/// - `amount`: The maximum amount by which `who`'s balance should be reduced.
///
Expand All @@ -553,8 +553,8 @@ pub mod pallet {
///
/// Weight: `O(1)`
/// Modes: Post-existence of `who`; Pre & post Zombie-status of `who`.
#[pallet::weight(T::WeightInfo::burn())]
pub(super) fn burn(
#[pallet::weight(T::WeightInfo::slash())]
pub(super) fn slash(
origin: OriginFor<T>,
#[pallet::compact] id: T::AssetId,
who: <T::Lookup as StaticLookup>::Source,
Expand All @@ -564,8 +564,7 @@ pub mod pallet {
let who = T::Lookup::lookup(who)?;

let f = DebitFlags { keep_alive: false, best_effort: true };
let burned = Self::do_burn(id, &who, amount, Some(origin), f)?;
Self::deposit_event(Event::Burned(id, who, burned));
joepetrowski marked this conversation as resolved.
Show resolved Hide resolved
let _ = Self::do_burn(id, &who, amount, Some(origin), f)?;
Ok(())
}

Expand Down
14 changes: 7 additions & 7 deletions frame/assets/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ fn min_balance_should_work() {
assert_eq!(Assets::balance(0, 1), 100);
assert_eq!(Asset::<Test>::get(0).unwrap().accounts, 1);

assert_ok!(Assets::burn(Origin::signed(1), 0, 1, 91));
assert_ok!(Assets::slash(Origin::signed(1), 0, 1, 91));
assert!(Assets::balance(0, 1).is_zero());
assert_eq!(Asset::<Test>::get(0).unwrap().accounts, 0);
});
Expand All @@ -250,7 +250,7 @@ fn querying_total_supply_should_work() {
assert_eq!(Assets::balance(0, 1), 50);
assert_eq!(Assets::balance(0, 2), 19);
assert_eq!(Assets::balance(0, 3), 31);
assert_ok!(Assets::burn(Origin::signed(1), 0, 3, u64::max_value()));
assert_ok!(Assets::slash(Origin::signed(1), 0, 3, u64::max_value()));
assert_eq!(Assets::total_supply(0), 69);
});
}
Expand Down Expand Up @@ -316,7 +316,7 @@ fn origin_guards_should_work() {
assert_noop!(Assets::freeze(Origin::signed(2), 0, 1), Error::<Test>::NoPermission);
assert_noop!(Assets::thaw(Origin::signed(2), 0, 2), Error::<Test>::NoPermission);
assert_noop!(Assets::mint(Origin::signed(2), 0, 2, 100), Error::<Test>::NoPermission);
assert_noop!(Assets::burn(Origin::signed(2), 0, 1, 100), Error::<Test>::NoPermission);
assert_noop!(Assets::slash(Origin::signed(2), 0, 1, 100), Error::<Test>::NoPermission);
assert_noop!(Assets::force_transfer(Origin::signed(2), 0, 1, 2, 100), Error::<Test>::NoPermission);
let w = Asset::<Test>::get(0).unwrap().destroy_witness();
assert_noop!(Assets::destroy(Origin::signed(2), 0, w), Error::<Test>::NoPermission);
Expand Down Expand Up @@ -356,7 +356,7 @@ fn set_team_should_work() {
assert_ok!(Assets::freeze(Origin::signed(4), 0, 2));
assert_ok!(Assets::thaw(Origin::signed(3), 0, 2));
assert_ok!(Assets::force_transfer(Origin::signed(3), 0, 2, 3, 100));
assert_ok!(Assets::burn(Origin::signed(3), 0, 3, 100));
assert_ok!(Assets::slash(Origin::signed(3), 0, 3, 100));
});
}

Expand All @@ -383,7 +383,7 @@ fn transferring_amount_more_than_available_balance_should_not_work() {
assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, 50));
assert_eq!(Assets::balance(0, 1), 50);
assert_eq!(Assets::balance(0, 2), 50);
assert_ok!(Assets::burn(Origin::signed(1), 0, 1, u64::max_value()));
assert_ok!(Assets::slash(Origin::signed(1), 0, 1, u64::max_value()));
assert_eq!(Assets::balance(0, 1), 0);
assert_noop!(Assets::transfer(Origin::signed(1), 0, 1, 50), Error::<Test>::BalanceLow);
assert_noop!(Assets::transfer(Origin::signed(2), 0, 1, 51), Error::<Test>::BalanceLow);
Expand Down Expand Up @@ -417,7 +417,7 @@ fn burning_asset_balance_with_positive_balance_should_work() {
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
assert_eq!(Assets::balance(0, 1), 100);
assert_ok!(Assets::burn(Origin::signed(1), 0, 1, u64::max_value()));
assert_ok!(Assets::slash(Origin::signed(1), 0, 1, u64::max_value()));
assert_eq!(Assets::balance(0, 1), 0);
});
}
Expand All @@ -428,7 +428,7 @@ fn burning_asset_balance_with_zero_balance_does_nothing() {
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
assert_eq!(Assets::balance(0, 2), 0);
assert_ok!(Assets::burn(Origin::signed(1), 0, 2, u64::max_value()));
assert_ok!(Assets::slash(Origin::signed(1), 0, 2, u64::max_value()));
assert_eq!(Assets::balance(0, 2), 0);
assert_eq!(Assets::total_supply(0), 100);
});
Expand Down
6 changes: 3 additions & 3 deletions frame/assets/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub trait WeightInfo {
fn force_create() -> Weight;
fn destroy(c: u32, s: u32, a: u32, ) -> Weight;
fn mint() -> Weight;
fn burn() -> Weight;
fn slash() -> Weight;
fn transfer() -> Weight;
fn transfer_keep_alive() -> Weight;
fn force_transfer() -> Weight;
Expand Down Expand Up @@ -103,7 +103,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
fn burn() -> Weight {
fn slash() -> Weight {
(46_000_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
Expand Down Expand Up @@ -237,7 +237,7 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
}
fn burn() -> Weight {
fn slash() -> Weight {
(46_000_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
Expand Down