From 8a88c7584dbf3705eb5fbb4323b76611fe4a4fea Mon Sep 17 00:00:00 2001
From: bgallois <benjamin@gallois.cc>
Date: Fri, 26 Jan 2024 19:37:14 +0100
Subject: [PATCH] fix oracle

---
 distance-oracle/src/api.rs                    | 26 +++++++++++--------
 .../identity_creation.feature                 |  6 ++---
 2 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/distance-oracle/src/api.rs b/distance-oracle/src/api.rs
index 9332fb07a..647f0900d 100644
--- a/distance-oracle/src/api.rs
+++ b/distance-oracle/src/api.rs
@@ -114,11 +114,11 @@ pub struct MemberIter(
 
 impl MemberIter {
     pub async fn next(&mut self) -> Result<Option<IdtyIndex>, subxt::error::Error> {
-        self.0
-            .next()
-            .await
-            .unwrap()
-            .map(|(storage_key, _membership_data)| Some(idty_id_from_storage_key(&storage_key)))
+        if let Some(i) = self.0.next().await {
+            i.map(|(storage_key, _membership_data)| Some(idty_id_from_storage_key(&storage_key)))
+        } else {
+            Ok(None)
+        }
     }
 }
 
@@ -139,14 +139,18 @@ impl CertIter {
     pub async fn next(
         &mut self,
     ) -> Result<Option<(IdtyIndex, Vec<(IdtyIndex, u32)>)>, subxt::error::Error> {
-        self.0
-            .next()
-            .await
-            .unwrap()
-            .map(|(storage_key, issuers)| Some((idty_id_from_storage_key(&storage_key), issuers)))
+        if let Some(i) = self.0.next().await {
+            i.map(|(storage_key, issuers)| Some((idty_id_from_storage_key(&storage_key), issuers)))
+        } else {
+            Ok(None)
+        }
     }
 }
 
 fn idty_id_from_storage_key(storage_key: &[u8]) -> IdtyIndex {
-    u32::from_le_bytes(storage_key[40..44].try_into().unwrap())
+    u32::from_le_bytes(
+        storage_key.as_ref()[40..44]
+            .try_into()
+            .expect("Cannot convert StorageKey to IdtyIndex"),
+    )
 }
diff --git a/end2end-tests/cucumber-features/identity_creation.feature b/end2end-tests/cucumber-features/identity_creation.feature
index 3bdeeead3..7de97f182 100644
--- a/end2end-tests/cucumber-features/identity_creation.feature
+++ b/end2end-tests/cucumber-features/identity_creation.feature
@@ -27,6 +27,6 @@ Feature: Identity creation
     Then dave should have distance result in 2 sessions
     When 30 blocks later
     Then dave should have distance result in 1 session
-    #When alice runs distance oracle
-    #When 30 blocks later
-    #Then dave identity should be member TODO fix distance oracle
+    When alice runs distance oracle
+    When 30 blocks later
+    Then dave identity should be member
-- 
GitLab