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

Automatic checking try_state hooks in tests #210

Open
ggwpez opened this issue Feb 24, 2023 · 8 comments
Open

Automatic checking try_state hooks in tests #210

ggwpez opened this issue Feb 24, 2023 · 8 comments
Labels
I5-enhancement An additional feature request. T1-FRAME This PR/Issue is related to core FRAME, the framework.

Comments

@ggwpez
Copy link
Member

ggwpez commented Feb 24, 2023

Currently we have this setup of a try_state hook per pallet which can check storage invariants.
This is very good, but the hook has to be invoked manually in tests or placed at the end once in a modified new_test_ext.

It would be nice if we could check these invariants more often. For example on every 100th storage modification.
One way to achieve this could be to hook into the storage functions of TestExternalities and register a post-modify hook which can then be set to try_state. Do you think that would work?

@ggwpez ggwpez changed the title Automatically checking try_state hooks in tests Automatic checking try_state hooks in tests Feb 24, 2023
@bkchr
Copy link
Member

bkchr commented Feb 27, 2023

We could also build a special runtime with try_state enabled and let the node run with this runtime as override. Then we have some external tool that triggers the try_state runtime call on every nth block import.

@xlc
Copy link
Contributor

xlc commented Feb 27, 2023

The external tool could be chopsticks. AcalaNetwork/chopsticks#70

@ggwpez
Copy link
Member Author

ggwpez commented Feb 27, 2023

We could also build a special runtime with try_state enabled and let the node run with this runtime as override. Then we have some external tool that triggers the try_state runtime call on every nth block import.

This is exactly what try-runtime follow-chain does if I am not mistaken. It loops through the pallets and try_states them on each new imported block.

@bkchr
Copy link
Member

bkchr commented Feb 27, 2023

Then this issue would be solved?

@ggwpez
Copy link
Member Author

ggwpez commented Feb 28, 2023

Then this issue would be solved?

This issue is for checking the try_state inside of unit tests. The follow-chain is for actually running a live node.

@bkchr
Copy link
Member

bkchr commented Feb 28, 2023

Ahh now I get your comment "on every 100th storage modification". Hmm. This could be breaking stuff as an invariant is only required to hold after a function has finished or even multiple. I think the idea to check try_state after each test is much better.

@kianenigma
Copy link
Contributor

We could also build a special runtime with try_state enabled and let the node run with this runtime as override. Then we have some external tool that triggers the try_state runtime call on every nth block import.

paritytech/substrate#13563 waiting to see the SDK team close this sir @bkchr :D

@kianenigma
Copy link
Contributor

For tests, we don't have a good way to do this. Perhaps someday we can create a framework for building test setup that does this for us. Think constuct_runtime_with_ext_builder. This will generate a shit ton of other code for you, including a fn build_and_execute that will call try_state automatically.

Also, as I am grooming issues today, if we have #261, then we can automatically call try_state on post_dispatch given #[cfg(test)]

Lastly, perhaps we can leverage impl Drop of ExtBuilder or TestExternalities to achieve this.

@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
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: Backlog
Development

No branches or pull requests

5 participants