From 897dabbb7916dfa006f9f511ca0516c96ba942d4 Mon Sep 17 00:00:00 2001
From: cgeek <cem.moreau@gmail.com>
Date: Sun, 25 Jun 2023 21:26:38 +0200
Subject: [PATCH] wip: fix: NoAuthor

---
 pallets/distance/src/mock.rs  | 17 ++++++++++++++---
 pallets/distance/src/tests.rs | 13 +++++++++++++
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/pallets/distance/src/mock.rs b/pallets/distance/src/mock.rs
index a20f27fd1..363f410e5 100644
--- a/pallets/distance/src/mock.rs
+++ b/pallets/distance/src/mock.rs
@@ -15,7 +15,8 @@
 // along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
 
 use crate::{self as pallet_distance};
-use frame_support::traits::GenesisBuild;
+use codec::Decode;
+use frame_support::traits::{FindAuthor, GenesisBuild};
 use frame_support::{
     parameter_types, sp_io,
     traits::{Everything, OnFinalize, OnInitialize},
@@ -30,7 +31,7 @@ use sp_runtime::{
     impl_opaque_keys,
     testing::Header,
     traits::{BlakeTwo256, IdentityLookup},
-    BuildStorage, MultiSignature,
+    BuildStorage, ConsensusEngineId, MultiSignature,
 };
 
 // type AccountId = u64;
@@ -205,8 +206,18 @@ impl pallet_certification::Config for Test {
     type ValidityPeriod = ValidityPeriod;
 }
 
+pub struct AuthorGiven;
+impl FindAuthor<u64> for AuthorGiven {
+    fn find_author<'a, I>(digests: I) -> Option<u64>
+    where
+        I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,
+    {
+        Some(0)
+    }
+}
+
 impl pallet_authorship::Config for Test {
-    type FindAuthor = ();
+    type FindAuthor = AuthorGiven;
     type UncleGenerations = ();
     type FilterUncle = ();
     type EventHandler = ();
diff --git a/pallets/distance/src/tests.rs b/pallets/distance/src/tests.rs
index 44d3d2fab..93f433d18 100644
--- a/pallets/distance/src/tests.rs
+++ b/pallets/distance/src/tests.rs
@@ -17,6 +17,8 @@
 use crate::mock::*;
 use crate::{pallet, Error};
 use frame_support::{assert_noop, assert_ok};
+use sp_distance::ComputationResult;
+use sp_runtime::Perbill;
 use sp_std::collections::btree_map::BTreeMap;
 
 // To enable better IDE checks
@@ -25,7 +27,18 @@ type Distance = pallet::Pallet<Test, ()>;
 #[test]
 fn test_compilation() {
     new_test_ext().execute_with(|| {
+        // Session 1: we ask for evaluation
         run_to_block(1);
         assert_ok!(Distance::evaluate_distance(RuntimeOrigin::signed(0)));
+        // Session 2: distance is being computed
+        run_to_block(6); // session 2 wraps blocks [6, 10] because of SESSION_LENGTH
+                         // Session 3: distance results are supposed to be published
+        run_to_block(11); // session 3 wraps blocks [11, 15] because of SESSION_LENGTH
+        assert_ok!(Distance::update_evaluation(
+            RuntimeOrigin::none(),
+            ComputationResult {
+                distances: vec![Perbill::from_percent(100)]
+            }
+        ));
     });
 }
-- 
GitLab