Skip to content
Snippets Groups Projects
Commit 31343727 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

wip: feat: distance blockchain events

parent d7c408f1
No related branches found
No related tags found
No related merge requests found
Pipeline #32559 waiting for manual action
......@@ -146,8 +146,9 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config<I>, I: 'static = ()> {
/// TODO: define
EvalutionSuccess,
EvaluationSuccess(IdtyIndex),
EvaluationFailure(IdtyIndex),
EvaluationNotProcessed(IdtyIndex),
}
// ERRORS //
......@@ -294,6 +295,7 @@ pub mod pallet {
.try_push((idty_index, median::MedianAcc::new()))
.map_err(|_| Error::<T, I>::QueueFull)?; // TODO: never raised because of preceding ensure!()?
IdentitiesDistanceStatus::<T, I>::insert(idty_index, DistanceStatus::Pending);
Ok(())
},
)
......@@ -373,16 +375,19 @@ pub mod pallet {
&account_id,
<T as Config<I>>::EvaluationPrice::get(),
);
Self::deposit_event(Event::EvaluationSuccess(idty));
} else {
IdentitiesDistanceStatus::<T, I>::remove(idty);
<T as Config<I>>::Currency::slash_reserved(
&account_id,
<T as Config<I>>::EvaluationPrice::get(),
);
Self::deposit_event(Event::EvaluationFailure(idty));
}
} else {
IdentitiesDistanceStatus::<T, I>::remove(idty);
T::Currency::unreserve(&account_id, <T as Config<I>>::EvaluationPrice::get());
Self::deposit_event(Event::EvaluationNotProcessed(idty));
}
}
Weight::zero()
......
......@@ -65,6 +65,11 @@ fn basic_single_distance() {
// Other pools have never been used
assert_eq!(pallet::EvaluationPool0::<Test>::get().0.len(), 0);
assert_eq!(pallet::EvaluationPool1::<Test>::get().0.len(), 0);
run_to_block(SESSION_3_START);
System::assert_has_event(RuntimeEvent::Distance(pallet::Event::EvaluationSuccess {
0: *IDTY_0,
}));
});
}
......@@ -165,6 +170,9 @@ fn multiple_authors() {
pallet::IdentitiesDistanceStatus::<Test>::get(IDTY_0),
Some(Valid)
); // now valid!
System::assert_has_event(RuntimeEvent::Distance(pallet::Event::EvaluationSuccess {
0: *IDTY_0,
}));
});
}
......@@ -198,8 +206,11 @@ fn distance_failure() {
// Finally session 4
run_to_block(SESSION_3_START);
assert_eq!(pallet::IdentitiesDistanceStatus::<Test>::get(IDTY_0), None);
// distance failure
assert_eq!(pallet::IdentitiesDistanceStatus::<Test>::get(IDTY_0), None);
System::assert_has_event(RuntimeEvent::Distance(pallet::Event::EvaluationFailure {
0: *IDTY_0,
}));
// TODO: test: variant Two
});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment