From 35a9f5ca0c33f2e0a094d9ae1918de9c499e6f08 Mon Sep 17 00:00:00 2001
From: Hugo Trentesaux <hugo@trentesaux.fr>
Date: Mon, 5 Sep 2022 17:38:32 +0200
Subject: [PATCH] wip

---
 .../identity_creation.feature                 |  6 +-
 end2end-tests/cucumber-genesis/default.json   |  8 +--
 end2end-tests/tests/common/identity.rs        | 19 +++++++
 end2end-tests/tests/cucumber_tests.rs         | 57 +++++++++++++++----
 node/src/chain_spec.rs                        |  2 +-
 5 files changed, 74 insertions(+), 18 deletions(-)

diff --git a/end2end-tests/cucumber-features/identity_creation.feature b/end2end-tests/cucumber-features/identity_creation.feature
index 376b6dec6..c706e95e2 100644
--- a/end2end-tests/cucumber-features/identity_creation.feature
+++ b/end2end-tests/cucumber-features/identity_creation.feature
@@ -1,7 +1,9 @@
 Feature: Identity creation
 
   Scenario: alice invites a new member to join the web of trust
+    When alice sends 6 ÄžD to ferdie
+    When 22 block later
     When alice creates identity for ferdie
-    When alice creates identity for ferdie
-    When 2 block later
     Then ferdie identity should be created
+    When ferdie confirms his identity with pseudo "Ferdie"
+    Then ferdie identity should be confirmed 
diff --git a/end2end-tests/cucumber-genesis/default.json b/end2end-tests/cucumber-genesis/default.json
index 9b59a9153..a141b1b7d 100644
--- a/end2end-tests/cucumber-genesis/default.json
+++ b/end2end-tests/cucumber-genesis/default.json
@@ -2,12 +2,12 @@
   "first_ud": 1000,
   "first_ud_reeval": 100,
   "genesis_parameters": {
-    "genesis_certs_expire_on": 100000,
+    "genesis_certs_expire_on": 1000,
     "genesis_certs_min_received": 2,
-    "genesis_memberships_expire_on": 100000,
-    "genesis_smith_certs_expire_on": 100000,
+    "genesis_memberships_expire_on": 1000,
+    "genesis_smith_certs_expire_on": 1000,
     "genesis_smith_certs_min_received": 2,
-    "genesis_smith_memberships_expire_on": 100000
+    "genesis_smith_memberships_expire_on": 1000
   },
   "identities": {
     "Alice": {
diff --git a/end2end-tests/tests/common/identity.rs b/end2end-tests/tests/common/identity.rs
index 85d0fbcf7..ea90b0068 100644
--- a/end2end-tests/tests/common/identity.rs
+++ b/end2end-tests/tests/common/identity.rs
@@ -43,3 +43,22 @@ pub async fn create_identity(
 
     Ok(())
 }
+
+pub async fn confirm_identity(client: &Client, from: AccountKeyring, pseudo: String) -> Result<()> {
+    let from = PairSigner::new(from.pair());
+
+    let _events = create_block_with_extrinsic(
+        client,
+        client
+            .tx()
+            .create_signed(
+                &gdev::tx().identity().confirm_identity(pseudo),
+                &from,
+                BaseExtrinsicParamsBuilder::new(),
+            )
+            .await?,
+    )
+    .await?;
+
+    Ok(())
+}
diff --git a/end2end-tests/tests/cucumber_tests.rs b/end2end-tests/tests/cucumber_tests.rs
index b821c95cf..559c3ffee 100644
--- a/end2end-tests/tests/cucumber_tests.rs
+++ b/end2end-tests/tests/cucumber_tests.rs
@@ -306,6 +306,13 @@ async fn creates_identity(world: &mut DuniterWorld, from: String, to: String) ->
     common::identity::create_identity(world.client(), from, to).await
 }
 
+#[when(regex = r#"([a-zA-Z]+) confirms (?:his|her) identity with pseudo "([a-zA-Z]+)""#)]
+async fn confirm_identity(world: &mut DuniterWorld, from: String, pseudo: String) -> Result<()> {
+    let from = AccountKeyring::from_str(&from).expect("unknown from");
+
+    common::identity::confirm_identity(world.client(), from, pseudo).await
+}
+
 // ===== then ====
 
 #[then(regex = r"([a-zA-Z]+) should have (\d+) (ÄžD|cÄžD)")]
@@ -421,33 +428,61 @@ async fn should_be_certified_by(
     }
 }
 
+// TODO refactor getting identity value from name
+
 #[then(regex = r"([a-zA-Z]+) identity should be created")]
 async fn identity_should_be_created(world: &mut DuniterWorld, receiver: String) -> Result<()> {
-    // Parse inputs
-    let receiver_account = AccountKeyring::from_str(&receiver)
-        .expect("unknown to")
+    let account = AccountKeyring::from_str(&receiver)
+        .expect("unknown account")
         .to_account_id();
 
-    let receiver_index = world
-        .read(
-            &gdev::storage()
-                .identity()
-                .identity_index_of(&receiver_account),
-        )
+    let identity_index = world
+        .read(&gdev::storage().identity().identity_index_of(&account))
         .await?
         .ok_or_else(|| anyhow::anyhow!("identity {} has no associated index", receiver))
         .unwrap();
 
     let _identity_value = world
-        .read(&gdev::storage().identity().identities(&receiver_index))
+        .read(&gdev::storage().identity().identities(&identity_index))
+        .await?
+        .ok_or_else(|| {
+            anyhow::anyhow!(
+                "indentity index {} does not have associated value",
+                identity_index
+            )
+        })?;
+
+    // TODO check that
+    // _identity_value.status == IdtyStatus::Created
+
+    Ok(())
+}
+
+#[then(regex = r"([a-zA-Z]+) identity should be confirmed")]
+async fn identity_should_be_confirmed(world: &mut DuniterWorld, name: String) -> Result<()> {
+    let account = AccountKeyring::from_str(&name)
+        .expect("unknown account")
+        .to_account_id();
+
+    let identity_index = world
+        .read(&gdev::storage().identity().identity_index_of(&account))
+        .await?
+        .ok_or_else(|| anyhow::anyhow!("identity {} has no associated index", name))
+        .unwrap();
+
+    let _identity_value = world
+        .read(&gdev::storage().identity().identities(&identity_index))
         .await?
         .ok_or_else(|| {
             anyhow::anyhow!(
                 "indentity index {} does not have associated value",
-                receiver_index
+                identity_index
             )
         })?;
 
+    // TODO check that
+    // _identity_value.status == IdtyStatus::ConfirmedByOwner
+
     Ok(())
 }
 
diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs
index 57d8aa0c0..dbeae1a49 100644
--- a/node/src/chain_spec.rs
+++ b/node/src/chain_spec.rs
@@ -39,7 +39,7 @@ pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Pu
         .public()
 }
 
-/*/// Generate an account ID from pain.
+/*/// Generate an account ID from pair.
 pub fn get_account_id_from_pair<TPublic: Public>(pair: TPublic::Pair) -> AccountId
 where
     AccountPublic: From<<TPublic::Pair as Pair>::Public>,
-- 
GitLab