Browse Source

staking handler - lock comparator and related test fix

ondratra 4 years ago
parent
commit
32f7374cd9

+ 1 - 1
runtime-modules/council/src/mock.rs

@@ -305,7 +305,7 @@ impl LockComparator<<Runtime as balances::Trait>::Balance> for Runtime {
         _new_lock: &LockIdentifier,
         _existing_locks: &[LockIdentifier],
     ) -> bool {
-        true
+        false
     }
 }
 

+ 1 - 1
runtime-modules/proposals/codex/src/tests/mock.rs

@@ -459,7 +459,7 @@ impl LockComparator<<Test as balances::Trait>::Balance> for Test {
         _new_lock: &LockIdentifier,
         _existing_locks: &[LockIdentifier],
     ) -> bool {
-        true
+        false
     }
 }
 

+ 1 - 1
runtime-modules/proposals/engine/src/tests/mock/mod.rs

@@ -230,7 +230,7 @@ impl LockComparator<<Test as balances::Trait>::Balance> for Test {
         _new_lock: &LockIdentifier,
         _existing_locks: &[LockIdentifier],
     ) -> bool {
-        true
+        false
     }
 }
 

+ 1 - 1
runtime-modules/service-discovery/src/mock.rs

@@ -229,7 +229,7 @@ impl LockComparator<<Test as balances::Trait>::Balance> for Test {
         _new_lock: &LockIdentifier,
         _existing_locks: &[LockIdentifier],
     ) -> bool {
-        true
+        false
     }
 }
 

+ 1 - 1
runtime-modules/staking-handler/src/lib.rs

@@ -170,7 +170,7 @@ impl<
         let lock_ids: Vec<LockIdentifier> =
             locks.iter().map(|balance_lock| balance_lock.id).collect();
 
-        T::are_locks_conflicting(&LockId::get(), lock_ids.as_slice())
+        !T::are_locks_conflicting(&LockId::get(), lock_ids.as_slice())
     }
 
     fn is_enough_balance_for_stake(

+ 1 - 1
runtime-modules/staking-handler/src/mock.rs

@@ -82,7 +82,7 @@ impl LockComparator<<Test as pallet_balances::Trait>::Balance> for Test {
         existing_locks
             .iter()
             .find(|lock| *lock == new_lock)
-            .is_none()
+            .is_some()
     }
 }
 

+ 1 - 1
runtime-modules/storage/src/tests/mock.rs

@@ -297,7 +297,7 @@ impl LockComparator<<Test as balances::Trait>::Balance> for Test {
         _new_lock: &LockIdentifier,
         _existing_locks: &[LockIdentifier],
     ) -> bool {
-        true
+        false
     }
 }
 

+ 1 - 1
runtime-modules/working-group/src/tests/mock.rs

@@ -109,7 +109,7 @@ impl LockComparator<<Test as balances::Trait>::Balance> for Test {
         _new_lock: &LockIdentifier,
         _existing_locks: &[LockIdentifier],
     ) -> bool {
-        true
+        false
     }
 }
 

+ 3 - 7
runtime/src/lib.rs

@@ -589,13 +589,9 @@ impl forum::Trait for Runtime {
 
 impl LockComparator<<Runtime as pallet_balances::Trait>::Balance> for Runtime {
     fn are_locks_conflicting(new_lock: &LockIdentifier, existing_locks: &[LockIdentifier]) -> bool {
-        for lock in existing_locks {
-            if !ALLOWED_LOCK_COMBINATIONS.contains(&(*new_lock, *lock)) {
-                return false;
-            }
-        }
-
-        true
+        existing_locks
+            .iter()
+            .any(|lock| !ALLOWED_LOCK_COMBINATIONS.contains(&(*new_lock, *lock)))
     }
 }