Browse Source

runtime: membership: Add tests.

- add tests for the is_member_staking_account_works() method.
Shamil Gadelshin 4 years ago
parent
commit
fc117020e5
1 changed files with 35 additions and 0 deletions
  1. 35 0
      runtime-modules/membership/src/tests/mod.rs

+ 35 - 0
runtime-modules/membership/src/tests/mod.rs

@@ -7,6 +7,7 @@ use crate::{Error, Event};
 use fixtures::*;
 use mock::*;
 
+use common::StakingAccountValidator;
 use frame_support::traits::{LockIdentifier, LockableCurrency, WithdrawReasons};
 use frame_support::{assert_ok, StorageMap, StorageValue};
 use frame_system::RawOrigin;
@@ -911,3 +912,37 @@ fn confirm_staking_account_candidate_fails_with_missing_staking_account_id() {
             .call_and_assert(Err(Error::<Test>::StakingAccountDoesntExist.into()));
     });
 }
+
+#[test]
+fn is_member_staking_account_works() {
+    let initial_members = [(ALICE_MEMBER_ID, ALICE_ACCOUNT_ID)];
+
+    build_test_externalities_with_initial_members(initial_members.to_vec()).execute_with(|| {
+        // Before adding candidate should be false.
+        assert_eq!(
+            Membership::is_member_staking_account(&ALICE_MEMBER_ID, &BOB_ACCOUNT_ID),
+            false
+        );
+        AddStakingAccountFixture::default().call_and_assert(Ok(()));
+
+        // After adding but before confirmation of the candidate should be false.
+        assert_eq!(
+            Membership::is_member_staking_account(&ALICE_MEMBER_ID, &BOB_ACCOUNT_ID),
+            false
+        );
+        ConfirmStakingAccountFixture::default().call_and_assert(Ok(()));
+
+        // After confirmation of the candidate should be true.
+        assert_eq!(
+            Membership::is_member_staking_account(&ALICE_MEMBER_ID, &BOB_ACCOUNT_ID),
+            true
+        );
+
+        // After removing of the staking account should be false.
+        RemoveStakingAccountFixture::default().call_and_assert(Ok(()));
+        assert_eq!(
+            Membership::is_member_staking_account(&ALICE_MEMBER_ID, &BOB_ACCOUNT_ID),
+            false
+        );
+    });
+}