substrate icon indicating copy to clipboard operation
substrate copied to clipboard

`TryState`: automatically execute after each migration

Open kianenigma opened this issue 1 year ago • 2 comments

Not automatically yet, I think it is okay to leave it up to the pallet to do so, which is what you are seeing here.

We can make a follow-up and once try_state is a bit more standard, make it execute upon all migrations.

Originally posted by @kianenigma in https://github.com/paritytech/substrate/pull/10174#discussion_r956728563


Ofc, IFF feature = try-runtime

kianenigma avatar Aug 28 '22 13:08 kianenigma

wild dream: have a standard testing framework, call it automatically after each TEST.

kianenigma avatar Oct 11 '22 12:10 kianenigma

To achieve executing this after each test:

have a new macro construct_runtime_with_ext_builder.

This generates, per pallet (e.g. staking)

  1. For each filed of GenesisBuild, a struct StakingBuilder { genesis_field_1, genesis_filed_2, .. }
  2. For each type in Config that's Get<u32>, a parameter_types! { static Config1: _ = .., Config2: _ = .. }
  3. And setter functions for all of the above.

lastly, it implements functions such as build and execute_with on Runtime, so at the end we would do:

Runtime::build().exeucte_with(|| {
  
}) 

in each test.

and this Runtime::execute_with would execute try_state() of the pallet after each test.

I really like this idea. It solves legacy issues like https://github.com/paritytech/polkadot-sdk/issues/367. The shitty thing about this is more hidden code, more magic, flying in the face of https://github.com/paritytech/polkadot-sdk/issues/32.

kianenigma avatar Oct 18 '22 09:10 kianenigma