Repository: paritytech/substrate
File: frame/balances/src/tests/currency_tests.rs (Rust)

Code before:
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Tests regarding the functionality of the `Currency` trait set implementations.

use super::*;
use crate::NegativeImbalance;
use frame_support::traits::{
	BalanceStatus::{Free, Reserved},
	Currency,
	ExistenceRequirement::{self, AllowDeath},
	Hooks, LockIdentifier, LockableCurrency, NamedReservableCurrency, ReservableCurrency,
	WithdrawReasons,
};

const ID_1: LockIdentifier = *b"1       ";
const ID_2: LockIdentifier = *b"2       ";

pub const CALL: &<Test as frame_system::Config>::RuntimeCall =
	&RuntimeCall::Balances(crate::Call::transfer_allow_death { dest: 0, value: 0 });

#[test]
fn locking_should_be_removed_when_amount_is_zero() {
	ExtBuilder::default()
	    .existential_deposit(1)
		.monied(true)
		.build_and_execute_with(|| {
			Balances::set_lock(ID_1, &1, u64::MAX, WithdrawReasons::all());
			Balances::set_lock(ID_1, &1, 0, WithdrawReasons::all());
			assert_ok!(<Balances as Currency<_>>::transfer(&1, &2, 1, AllowDeath));
		});
}

#[test]
fn basic_locking_should_work() {
	ExtBuilder::default()
		.existential_deposit(1)
		.monied(true)
		.build_and_execute_with(|| {
			assert_eq!(Balances::free_balance(1), 10);
			Balances::set_lock(ID_1, &1, 9, WithdrawReasons::all());
			assert_noop!(
				<Balances as Currency<_>>::transfer(&1, &2, 5, AllowDeath),
				TokenError::Frozen
			);
		});
}


Review comment (suggestion):
```suggestion
fn set_lock_with_amount_zero_removes_lock() {
```

Code after:
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Tests regarding the functionality of the `Currency` trait set implementations.

use super::*;
use crate::NegativeImbalance;
use frame_support::traits::{
	BalanceStatus::{Free, Reserved},
	Currency,
	ExistenceRequirement::{self, AllowDeath},
	Hooks, LockIdentifier, LockableCurrency, NamedReservableCurrency, ReservableCurrency,
	WithdrawReasons,
};

const ID_1: LockIdentifier = *b"1       ";
const ID_2: LockIdentifier = *b"2       ";

pub const CALL: &<Test as frame_system::Config>::RuntimeCall =
	&RuntimeCall::Balances(crate::Call::transfer_allow_death { dest: 0, value: 0 });

#[test]
fn set_lock_with_amount_zero_removes_lock() {
	ExtBuilder::default()
		.existential_deposit(1)
		.monied(true)
		.build_and_execute_with(|| {
			Balances::set_lock(ID_1, &1, u64::MAX, WithdrawReasons::all());
			Balances::set_lock(ID_1, &1, 0, WithdrawReasons::all());
			assert_ok!(<Balances as Currency<_>>::transfer(&1, &2, 1, AllowDeath));
		});
}

#[test]
fn set_lock_with_withdraw_reasons_empty_removes_lock() {
	ExtBuilder::default()
		.existential_deposit(1)
		.monied(true)
		.build_and_execute_with(|| {
			Balances::set_lock(ID_1, &1, u64::MAX, WithdrawReasons::all());
			Balances::set_lock(ID_1, &1, u64::MAX, WithdrawReasons::empty());
			assert_ok!(<Balances as Currency<_>>::transfer(&1, &2, 1, AllowDeath));
		});
}

#[test]
fn basic_locking_should_work() {
	ExtBuilder::default()