1

Trying to establish this function to be able to run to a specific block to test progressive extrinsics across blocks to simulate real execution within benchmarks:

    while System::block_number() < n {
        if System::block_number() > 1 {
            Proposals::on_finalize(System::block_number());
            System::on_finalize(System::block_number());
        }
        System::set_block_number(System::block_number() + 1);
        System::on_initialize(System::block_number());
        Proposals::on_initialize(System::block_number());
    }
}```

Unfortunately not able to compile with System within benchmark
1

2 Answers 2

3

You can jump to a block number using frame_system, just pass in the block number you want to jump to

e.g.

fn run_to_block<T: Config>(new_block: <T as frame_system::Config>::BlockNumber) {
    frame_system::Pallet::<T>::set_block_number(new_block);
}

https://github.com/paritytech/cumulus/blob/HEAD/pallets/collator-selection/src/benchmarking.rs#L199

2

It depends on which pallets are deployed in your mocked runtime.
In the easiest case you can just set the block number.
But often you also have to call the hooks of the deployed pallets.
In the way that you tried, other example here.
Could you maybe also include the error message and the mocked runtime if this does not answer your question?

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.