Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vision: Simplify test setup #367

Closed
xlc opened this issue Aug 8, 2019 · 6 comments
Closed

Vision: Simplify test setup #367

xlc opened this issue Aug 8, 2019 · 6 comments
Labels
I5-enhancement An additional feature request. T1-FRAME This PR/Issue is related to core FRAME, the framework.

Comments

@xlc
Copy link
Contributor

xlc commented Aug 8, 2019

They are many duplicated setup code required for any new modules, mostly config system::Trait. There must be a way to avoid duplicate this code all over the places.
It also make any modification to system::Trait tedious as it have to change every single module test setup.

I am not sure what is the best way, but at least a macro can avoid most of the duplications.

All those code are duplicated and irrelevant for most of the tests

https://github.com/paritytech/substrate/blob/9b3e9f32cd5243d2eeff3d5d8337033aa64c091b/srml/aura/src/mock.rs#L35-L63

@kianenigma
Copy link
Contributor

I cannot agree more. The system::Trait is becoming a bottleneck.

Ideally, I imagine this as the least that we can do:

  • Each module must expose its default Trait implementation and types.
  • When module x with runtime Test wants to have tests, it can implement Trait for Test or fallback to the default.

With a bit more effort we can also probably generalize the Builder() pattern with proc-macros to enable all tests to have it.

At some point if I have the time, I would really like to work on this.

@stale
Copy link

stale bot commented Jul 7, 2021

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A5-stale label Jul 7, 2021
@kianenigma
Copy link
Contributor

I have a vague guess that maybe @KiChjang would be interested in this.

@stale stale bot removed the A5-stale label Jul 8, 2021
@KiChjang KiChjang self-assigned this Jul 21, 2021
@KiChjang
Copy link
Contributor

Indeed, it looks to me that a derive macro like DefaultTestSetup could generate all the necessary code for the default test framework setup. Let me see what I can do here.

@kianenigma
Copy link
Contributor

Re-posting my suggestion paritytech/substrate#12130 (comment) since I think it might be a good starting point for this.

@KiChjang KiChjang removed their assignment Dec 23, 2022
@kianenigma kianenigma changed the title Simplify test setup Vision: Simplify test setup Mar 10, 2023
@kianenigma
Copy link
Contributor

The vision in paritytech/substrate#12130 (comment) can also be achieved with something like this:

  • #[pallet::genesis_config] is structurally very similar to a pallet's hypothetical ExtBuilder.
  • Why not have #[pallet::genesis_config] generate a basic ExtBuilder for you, that you can extend?
  • crucially, this ExtBuilder would have a given fn build_and_execute(..) that can automatically call into try_state and such for you.

@juangirini juangirini transferred this issue from paritytech/substrate Aug 24, 2023
@the-right-joyce the-right-joyce added I5-enhancement An additional feature request. T1-FRAME This PR/Issue is related to core FRAME, the framework. and removed J0-enhancement labels Aug 25, 2023
claravanstaden pushed a commit to Snowfork/polkadot-sdk that referenced this issue Dec 8, 2023
helin6 pushed a commit to boolnetwork/polkadot-sdk that referenced this issue Feb 5, 2024
@xlc xlc closed this as completed Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I5-enhancement An additional feature request. T1-FRAME This PR/Issue is related to core FRAME, the framework.
Projects
Status: Done
5 participants