From d52003ad027c04b3d3e61f67fb53ac0c3aa7d8b7 Mon Sep 17 00:00:00 2001
From: librelois <c@elo.tf>
Date: Wed, 24 Aug 2022 21:37:43 +0200
Subject: [PATCH] =?UTF-8?q?tests(sanity):rule=20"If=20idty=20have=20old=5F?=
 =?UTF-8?q?owner=5Fkey,=20old=20account=20should=E2=80=A6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

"If idty have old_owner_key, old account should exist and be sufficient"
---
 live-tests/tests/sanity_gdev.rs | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/live-tests/tests/sanity_gdev.rs b/live-tests/tests/sanity_gdev.rs
index b3a20d25e..1c61ef0ea 100644
--- a/live-tests/tests/sanity_gdev.rs
+++ b/live-tests/tests/sanity_gdev.rs
@@ -221,7 +221,7 @@ mod verifier {
             identities: &HashMap<IdtyIndex, IdtyValue>,
         ) {
             for (idty_index, idty_value) in identities {
-                // Rule 1: each identity should have an account
+                // Eeach identity should have an account
                 let maybe_account = accounts.get(&idty_value.owner_key);
                 self.assert(
                     maybe_account.is_some(),
@@ -229,7 +229,7 @@ mod verifier {
                 );
 
                 if let Some(account) = maybe_account {
-                    // Rule 2: each identity account should be sufficient
+                    // Each identity account should be sufficient
                     self.assert(
                         account.sufficients > 0,
                         format!(
@@ -239,9 +239,26 @@ mod verifier {
                     );
                 }
 
+                if let Some((ref old_owner_key, _last_change)) = idty_value.old_owner_key {
+                    // If the identity have an old_owner_key, the old account should still exist
+                    let old_account = accounts.get(old_owner_key);
+                    self.assert(
+                        old_account.is_some(),
+                        format!("Identity {} old account not exist anymore.", idty_index),
+                    );
+                    if let Some(account) = old_account {
+                        // If the identity have an old_owner_key, the old account should still
+                        // sufficients
+                        self.assert(
+                            account.sufficients > 0,
+                            format!("Identity {} old account not sufficient", idty_index),
+                        );
+                    }
+                }
+
                 match idty_value.status {
                     IdtyStatus::Validated => {
-                        // Rule 3: If the identity is validated, removable_on shoud be zero
+                        // If the identity is validated, removable_on shoud be zero
                         self.assert(
                             idty_value.removable_on == 0,
                             format!(
@@ -260,7 +277,7 @@ mod verifier {
                         );
                     }
                     _ => {
-                        // Rule 4: If the identity is not validated, next_creatable_identity_on shoud be zero
+                        // If the identity is not validated, next_creatable_identity_on shoud be zero
                         self.assert(
 							idty_value.next_creatable_identity_on == 0,
 							format!("Identity {} is corrupted: next_creatable_identity_on > 0 on non-validated idty",
-- 
GitLab