Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aurexav committed Jan 10, 2025
1 parent 505e453 commit 2359bcc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 34 deletions.
7 changes: 5 additions & 2 deletions substrate/frame/society/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,11 @@ pub fn conclude_intake(allow_resignation: bool, judge_intake: Option<bool>) {
pub fn next_intake() {
let claim_period: u64 = <Test as Config>::ClaimPeriod::get();
match Society::period() {
Period::Voting { more, .. } => System::run_to_block::<AllPalletsWithSystem>(System::block_number() + more + claim_period),
Period::Claim { more, .. } => System::run_to_block::<AllPalletsWithSystem>(System::block_number() + more),
Period::Voting { more, .. } => System::run_to_block::<AllPalletsWithSystem>(
System::block_number() + more + claim_period,
),
Period::Claim { more, .. } =>
System::run_to_block::<AllPalletsWithSystem>(System::block_number() + more),
}
}

Expand Down
29 changes: 1 addition & 28 deletions substrate/frame/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl pallet_session::historical::Config for Test {
}
impl pallet_authorship::Config for Test {
type FindAuthor = Author11;
type EventHandler = Pallet<Test>;
type EventHandler = ();
}

impl pallet_timestamp::Config for Test {
Expand Down Expand Up @@ -544,19 +544,13 @@ impl ExtBuilder {
let mut ext = sp_io::TestExternalities::from(storage);

if self.initialize_first_session {
// We consider all test to start after timestamp is initialized This must be ensured by
// having `timestamp::on_initialize` called before `staking::on_initialize`. Also, if
// session length is 1, then it is already triggered.
ext.execute_with(|| {
System::run_to_block_with::<AllPalletsWithSystem>(
1,
frame_system::RunToBlockHooks::default().after_initialize(|_| {
Timestamp::set_timestamp(INIT_TIMESTAMP);
}),
);

// Skip the genesis reward.
ErasRewardPoints::<Test>::remove(0);
});
}

Expand Down Expand Up @@ -639,30 +633,9 @@ pub(crate) fn start_session(end_session_idx: SessionIndex) {
} else {
Offset::get() + (end_session_idx.saturating_sub(1) as u64) * period
};
let start_session_idx = Session::current_index();

run_to_block(end);

let sessions_per_era = SessionsPerEra::get();

// Revert the `Authorship::OnInitialize`'s `note_author` reward for easy testing.
for i in start_session_idx..end_session_idx {
let blocks_per_session = if i == 0 {
// Skip block 0.
period - 1
} else {
period
};
let extra_reward_points = blocks_per_session as RewardPoint * 20;

ErasRewardPoints::<Test>::mutate(i / sessions_per_era, |p| {
if let Some(author_11) = p.individual.get_mut(&11) {
p.total = p.total.saturating_sub(extra_reward_points);
*author_11 = (*author_11).saturating_sub(extra_reward_points);
}
});
}

let curr_session_idx = Session::current_index();

// session must have progressed properly.
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2395,7 +2395,7 @@ fn reward_from_authorship_event_handler_works() {

#[test]
fn add_reward_points_fns_works() {
ExtBuilder::default().initialize_first_session(false).build_and_execute(|| {
ExtBuilder::default().build_and_execute(|| {
// Not mandatory but must be coherent with rewards
assert_eq_uvec!(Session::validators(), vec![21, 11]);

Expand Down
7 changes: 4 additions & 3 deletions substrate/frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1975,7 +1975,10 @@ impl<T: Config> Pallet<T> {
}

/// Simulate the execution of a block sequence up to a specified height, injecting the
/// provided closures at each block.
/// provided hooks at each block.
///
/// `on_finalize` is always called before `on_initialize` with the current block number.
/// `on_initalize` is always called with the next block number.
///
/// These hooks allows custom logic to be executed at each block at specific location.
/// For example, you might use one of them to set a timestamp for each block.
Expand Down Expand Up @@ -2399,7 +2402,6 @@ where
after_initialize: Box<dyn 'a + FnMut(BlockNumberFor<T>)>,
before_finalize: Box<dyn 'a + FnMut(BlockNumberFor<T>)>,
after_finalize: Box<dyn 'a + FnMut(BlockNumberFor<T>)>,
_marker: PhantomData<&'a T>,
}
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
impl<'a, T> RunToBlockHooks<'a, T>
Expand Down Expand Up @@ -2450,7 +2452,6 @@ where
after_initialize: Box::new(|_| {}),
before_finalize: Box::new(|_| {}),
after_finalize: Box::new(|_| {}),
_marker: Default::default(),
}
}
}
Expand Down

0 comments on commit 2359bcc

Please sign in to comment.