Skip to content
Snippets Groups Projects
Unverified Commit 8eedb255 authored by bgallois's avatar bgallois
Browse files

make tests independent of EvaluationPeriod

parent fea328f2
No related branches found
No related tags found
1 merge request!252Change distance evaluation period from Sessions to Blocks
......@@ -524,7 +524,7 @@ type RuntimeFreezeReason = ();
}
impl pallet_distance::Config for Runtime {
type Currency = Balances;
type EvaluationPeriod = frame_support::traits::ConstU32<25>;
type EvaluationPeriod = frame_support::traits::ConstU32<7>;
type EvaluationPrice = frame_support::traits::ConstU64<1000>;
type MaxRefereeDistance = frame_support::traits::ConstU32<5>;
type MinAccessibleReferees = MinAccessibleReferees;
......
......@@ -359,8 +359,9 @@ fn test_validate_identity_when_claim() {
frame_system::RawOrigin::Signed(AccountKeyring::Eve.to_account_id()).into(),
));
// Pass 2 sessions
run_to_block(51);
// Pass 2nd evaluation period
let eval_period: u32 = <Runtime as pallet_distance::Config>::EvaluationPeriod::get();
run_to_block(2 * eval_period);
// simulate an evaluation published by smith Alice
assert_ok!(Distance::force_update_evaluation(
frame_system::RawOrigin::Root.into(),
......@@ -369,7 +370,8 @@ fn test_validate_identity_when_claim() {
distances: vec![Perbill::one()],
}
));
run_to_block(75); // Pass 1 session
// Pass 3rd evalaution period
run_to_block(3 * eval_period);
System::assert_has_event(RuntimeEvent::Distance(
pallet_distance::Event::EvaluatedValid { idty_index: 5 },
));
......@@ -387,7 +389,8 @@ fn test_validate_identity_when_claim() {
System::assert_has_event(RuntimeEvent::Membership(
pallet_membership::Event::MembershipAdded {
member: 5,
expire_on: 75 + <Runtime as pallet_membership::Config>::MembershipPeriod::get(),
expire_on: 3 * eval_period
+ <Runtime as pallet_membership::Config>::MembershipPeriod::get(),
},
));
});
......@@ -461,8 +464,9 @@ fn test_identity_creation_workflow() {
Some(AccountKeyring::Charlie.to_account_id(),)
);
// Pass 2 sessions
run_to_block(51);
// Pass 2nd evaluation period
let eval_period: u32 = <Runtime as pallet_distance::Config>::EvaluationPeriod::get();
run_to_block(2 * eval_period);
// simulate evaluation published by smith Alice
assert_ok!(Distance::force_update_evaluation(
frame_system::RawOrigin::Root.into(),
......@@ -471,28 +475,30 @@ fn test_identity_creation_workflow() {
distances: vec![Perbill::one()],
}
));
// Pass 1 session
run_to_block(75);
// Pass 3rd evaluation period
run_to_block(3 * eval_period);
// eve should not even have to claim her membership
System::assert_has_event(RuntimeEvent::Membership(
pallet_membership::Event::MembershipAdded {
member: 5,
expire_on: 75 + <Runtime as pallet_membership::Config>::MembershipPeriod::get(),
expire_on: 3 * eval_period
+ <Runtime as pallet_membership::Config>::MembershipPeriod::get(),
},
));
// test state coherence
// block time is 6_000 ms
// ud creation period is 60_000 ms ~ 10 blocks
// first ud is at 24_000 ms ~ 4 blocks
// at current block this is UD number current_block/10 + 1
let first_eligible = ((3 * eval_period) / 10 + 1) as u16;
assert_eq!(
Identity::identity(5),
Some(pallet_identity::IdtyValue {
data: IdtyData {
// block time is 6_000 ms
// ud creation period is 60_000 ms ~ 10 blocks
// first ud is at 24_000 ms ~ 4 blocks
// at block 75 this is UD number 8, so next is 9
first_eligible_ud: pallet_universal_dividend::FirstEligibleUd(Some(
sp_std::num::NonZeroU16::new(9).unwrap()
sp_std::num::NonZeroU16::new(first_eligible).unwrap()
))
},
next_creatable_identity_on: 0u32,
......@@ -508,7 +514,7 @@ fn test_identity_creation_workflow() {
pallet_universal_dividend::Event::NewUdCreated {
amount: 1000,
index: 9,
monetary_mass: 50_000, // 13_000 (initial) + 4 * 1000 * 8 (produced) + 5000
monetary_mass: 49_000 + (10 - first_eligible as u64) * 1_000, // 13_000 (initial) + 4 * 1000 * 9 (produced) + (10-first_eligible)*1_000
members_count: 5,
},
));
......@@ -517,8 +523,8 @@ fn test_identity_creation_workflow() {
));
System::assert_has_event(RuntimeEvent::UniversalDividend(
pallet_universal_dividend::Event::UdsClaimed {
count: 1,
total: 1000,
count: (10 - first_eligible),
total: (10 - first_eligible as u64) * 1_000,
who: AccountKeyring::Eve.to_account_id(),
},
));
......@@ -614,7 +620,9 @@ fn test_membership_renewal() {
frame_system::RawOrigin::Signed(AccountKeyring::Alice.to_account_id()).into(),
));
run_to_block(51); // Pass 5 sessions
// Pass 3rd evaluation period
let eval_period: u32 = <Runtime as pallet_distance::Config>::EvaluationPeriod::get();
run_to_block(3 * eval_period);
assert_ok!(Distance::force_update_evaluation(
frame_system::RawOrigin::Root.into(),
AccountKeyring::Alice.to_account_id(),
......@@ -622,16 +630,17 @@ fn test_membership_renewal() {
distances: vec![Perbill::one()],
}
));
// Pass 1 session, membership is renewed automatically
run_to_block(75);
// Pass to 4th evaluation period
run_to_block(4 * eval_period);
System::assert_has_event(RuntimeEvent::Membership(
pallet_membership::Event::MembershipRenewed {
member: 1,
expire_on: 75 + <Runtime as pallet_membership::Config>::MembershipPeriod::get(),
expire_on: 4 * eval_period
+ <Runtime as pallet_membership::Config>::MembershipPeriod::get(),
},
));
run_to_block(76);
run_to_block(4 * eval_period + 1);
// not possible to renew manually
// can not ask renewal when period is not respected
assert_noop!(
......@@ -641,8 +650,10 @@ fn test_membership_renewal() {
pallet_duniter_wot::Error::<Runtime>::MembershipRenewalPeriodNotRespected,
);
// should expire at block 175 = 75+100
run_to_block(175);
// should expire at block 3nd EvaluationPeriod + MembershipPeriod
run_to_block(
4 * eval_period + <Runtime as pallet_membership::Config>::MembershipPeriod::get(),
);
System::assert_has_event(RuntimeEvent::Membership(
pallet_membership::Event::MembershipRemoved {
member: 1,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment