1

I set up a state via

impl ExtBuilder {
 pub fn build(self) -> sp_io::TestExternalities {
  let mut t = system::GenesisConfig::default().build_storage::<TestRuntime>().unwrap();
  let mut ext = sp_io::TestExternalities::new(t);
  ext.execute_with(|| 
      System::set_block_number(1));
      ThirdPartyModule::createAsset { ... }
  ext
 }
}

In the "normal" unit tests, I call Externalities::build().execute_with(|| {...}) to access the store.

Now I want to do benchmark testing via impl_benchmark_test_suite! and I pass the storage as the second parameter:

impl_benchmark_test_suite!(Pallet, Externalities::build() , Test,);. However, the store doesn't contain the same information as with the Unit tests, and createAsset doesn't get triggered or at least, it is not part of the store. I wonder how I would "register" this module or this content into my store for the benchmark tests?

1
  • How are you running the benchmarks? Do the tests work cargo t -p your-pallet --features runtime-benchmarks? There is a difference between executing the benchmarks and the testing that impl_benchmark_test_suite does. Would you mind sharing the code? You can probably even put a panic in there and it will not execute. Commented Aug 24, 2022 at 14:46

1 Answer 1

1

I don't think you should rely on Externalities::build() to do the environment setup for your benchmarks, because it will not be called when you run your benchmarks (opposed to running benchmark test suite). AFAIK people usually use separate setup-helper functions for benchmarks. You can have a look a this file. There's setup_bounty, setup_child_bounty, activate_bounty, etc. I think that's the way to go.

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.