I want to test my pallet that get digest info to collect the author of the current block. So, is it possible to set, for example, Alice as a block author in the mock.rs so I can test it?

I set up the mock.rs in this way configuring pallet_session, pallet_node_authorization and pallet_aura.

but when I try to call a test with cargo test:

fn hash_work() {
    new_test_ext().execute_with(|| {


I get this error:

thread 'tests::check_x_block_index_change_by_1' panicked at 'called `Option::unwrap()` on a `None` value', pallets/computational-work/src/lib.rs:140:62

the lines that cause the error:

// Get the block author.
let block_digest = <frame_system::Pallet<T>>::digest();
let digests = block_digest.logs.iter().filter_map(|d| d.as_pre_runtime());
let author = T::FindAuthor::find_author(digests).unwrap();

I think the problem is author that is none in this context.

1 Answer 1


Add these to your mock file.

impl pallet_computational_work::Config for Test {
    type Event = Event;
    type FindAuthor = AuthorGiven;

pub struct AuthorGiven;
impl frame_support::traits::FindAuthor<YourAccountIdType> for AuthorGiven {
    fn find_author<'a, I>(digests: I) -> Option<YourAccountIdType>
        I: 'a + IntoIterator<Item = (sp_runtime::ConsensusEngineId, &'a [u8])>,
  • Ok it's working, thank you!
    – viac92
    Oct 17, 2022 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.