Skip to content

Commit

Permalink
implement registering in attestation phase (#224)
Browse files Browse the repository at this point in the history
Co-authored-by: brenzi <brenzi@users.noreply.github.com>
  • Loading branch information
pifragile and brenzi committed Jun 3, 2022
1 parent 88254b2 commit 4922d08
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
14 changes: 11 additions & 3 deletions ceremonies/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,23 @@ pub mod pallet {
proof: Option<ProofOfAttendance<T::Signature, T::AccountId>>,
) -> DispatchResultWithPostInfo {
let sender = ensure_signed(origin)?;
let current_phase = <encointer_scheduler::Pallet<T>>::current_phase();
ensure!(
<encointer_scheduler::Pallet<T>>::current_phase() == CeremonyPhaseType::Registering,
Error::<T>::RegisteringPhaseRequired
vec![CeremonyPhaseType::Registering, CeremonyPhaseType::Attesting]
.contains(&current_phase),
Error::<T>::RegisteringOrAttestationPhaseRequired
);

ensure!(
<encointer_communities::Pallet<T>>::community_identifiers().contains(&cid),
Error::<T>::InexistentCommunity
);

let cindex = <encointer_scheduler::Pallet<T>>::current_ceremony_index();
let mut cindex = <encointer_scheduler::Pallet<T>>::current_ceremony_index();

if current_phase == CeremonyPhaseType::Attesting {
cindex += 1
};

if Self::is_registered(cid, cindex, &sender) {
return Err(<Error<T>>::ParticipantAlreadyRegistered.into())
Expand Down Expand Up @@ -538,6 +544,8 @@ pub mod pallet {
RegisteringPhaseRequired,
/// the action can only be performed during ATTESTING phase
AttestationPhaseRequired,
/// the action can only be performed during REGISTERING or ATTESTING phase
RegisteringOrAttestationPhaseRequired,
/// CommunityIdentifier not found
InexistentCommunity,
/// proof is outdated
Expand Down
32 changes: 32 additions & 0 deletions ceremonies/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,38 @@ fn endorsing_after_registration_works() {
});
}

#[test]
fn registering_in_attestation_phase_works() {
new_test_ext().execute_with(|| {
let cid = register_test_community::<TestRuntime>(None, 0.0, 0.0);
let yran = account_id(&sr25519::Pair::from_entropy(&[8u8; 32], None).0);
let cindex = EncointerScheduler::current_ceremony_index();
assert!(EncointerBalances::issue(cid, &yran, NominalIncome::from_num(1)).is_ok());

run_to_next_phase();
run_to_next_phase();
register(yran.clone(), cid, None);

assert!(NewbieIndex::<TestRuntime>::contains_key((cid, cindex + 1), &yran));
});
}

#[test]
fn registering_in_assigning_phase_fails() {
new_test_ext().execute_with(|| {
let cid = register_test_community::<TestRuntime>(None, 0.0, 0.0);
let yran = account_id(&sr25519::Pair::from_entropy(&[8u8; 32], None).0);
assert!(EncointerBalances::issue(cid, &yran, NominalIncome::from_num(1)).is_ok());

run_to_next_phase();

assert_err!(
register(yran.clone(), cid, None),
Error::<TestRuntime>::RegisteringOrAttestationPhaseRequired,
);
});
}

// integration tests ////////////////////////////////

#[rstest(lat_micro, lon_micro, meetup_time_offset,
Expand Down

0 comments on commit 4922d08

Please sign in to comment.