From 976816c3dc1691ea310f3bb3ae1adf442e49b0f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jo=C3=A3o=20Pedro=20Serrat?= Date: Thu, 1 Jun 2023 09:29:35 -0300 Subject: [PATCH 1/3] add test locking removed when amount is zero --- frame/balances/src/tests/currency_tests.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/frame/balances/src/tests/currency_tests.rs b/frame/balances/src/tests/currency_tests.rs index e25b122c1fcf0..ab1a9c9368c6e 100644 --- a/frame/balances/src/tests/currency_tests.rs +++ b/frame/balances/src/tests/currency_tests.rs @@ -33,6 +33,18 @@ const ID_2: LockIdentifier = *b"2 "; pub const CALL: &::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!(>::transfer(&1, &2, 1, AllowDeath)); + }); +} + #[test] fn basic_locking_should_work() { ExtBuilder::default() From 16bd5e8bdf1c9e19373eee1e63d88495e11564d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jo=C3=A3o=20Pedro=20Serrat?= Date: Thu, 1 Jun 2023 12:05:33 -0300 Subject: [PATCH 2/3] add test set lock with withdraw reasons empty removes lock --- frame/balances/src/tests/currency_tests.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/frame/balances/src/tests/currency_tests.rs b/frame/balances/src/tests/currency_tests.rs index ab1a9c9368c6e..aed8fec61525b 100644 --- a/frame/balances/src/tests/currency_tests.rs +++ b/frame/balances/src/tests/currency_tests.rs @@ -34,7 +34,7 @@ pub const CALL: &::RuntimeCall = &RuntimeCall::Balances(crate::Call::transfer_allow_death { dest: 0, value: 0 }); #[test] -fn locking_should_be_removed_when_amount_is_zero() { +fn set_lock_with_amount_zero_removes_lock() { ExtBuilder::default() .existential_deposit(1) .monied(true) @@ -45,6 +45,18 @@ fn locking_should_be_removed_when_amount_is_zero() { }); } +#[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, 2, WithdrawReasons::empty()); + assert_ok!(>::transfer(&1, &2, 1, AllowDeath)); + }); +} + #[test] fn basic_locking_should_work() { ExtBuilder::default() From e910cb312ac9340f54a87b4eef06a5087de937f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jo=C3=A3o=20Pedro=20Serrat?= Date: Thu, 1 Jun 2023 13:41:08 -0300 Subject: [PATCH 3/3] fix test set lock with withdraw reasons --- frame/balances/src/tests/currency_tests.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frame/balances/src/tests/currency_tests.rs b/frame/balances/src/tests/currency_tests.rs index aed8fec61525b..0c6ab0dbbaad5 100644 --- a/frame/balances/src/tests/currency_tests.rs +++ b/frame/balances/src/tests/currency_tests.rs @@ -36,7 +36,7 @@ pub const CALL: &::RuntimeCall = #[test] fn set_lock_with_amount_zero_removes_lock() { ExtBuilder::default() - .existential_deposit(1) + .existential_deposit(1) .monied(true) .build_and_execute_with(|| { Balances::set_lock(ID_1, &1, u64::MAX, WithdrawReasons::all()); @@ -48,11 +48,11 @@ fn set_lock_with_amount_zero_removes_lock() { #[test] fn set_lock_with_withdraw_reasons_empty_removes_lock() { ExtBuilder::default() - .existential_deposit(1) + .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, 2, WithdrawReasons::empty()); + Balances::set_lock(ID_1, &1, u64::MAX, WithdrawReasons::empty()); assert_ok!(>::transfer(&1, &2, 1, AllowDeath)); }); }