-
Notifications
You must be signed in to change notification settings - Fork 425
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
State Not Reverted in Unit Tests when Error is Returned #1778
Comments
I've hit this bug too in my unit tests, can replicate. |
I'm not too familiar with the unit testing code, but this may not be super simple to fix. It looks like the method calls are just using the state of the struct as is and not emulating reading and writing from storage as a transaction. It may involve changing the codegen to generate message calls which emulate the transactional nature of |
Can confirm the issue |
Looking at the off-chain testing engine, any state mutations occur on the Rust struct directly, as pointed out by Andrew. I don't see much motivation adding overhead complexity by trying to encapsulate the struct into some storage struct. This will essentially break the "lightness" and "transparentness" of the unit testing. Unit tests are not intended to fully simulate the off-chain execution but rather test the functional correctness of the contract's logic. |
Closing due to inactivity |
Describe the bug
When a message / function returns a
Result::Err
any modified state up to that point should be reverted. When running on a live-chain this DOES happen. However, when this occurs while running unit tests (cargo test
) the state is NOT reverted.To clarify:
Please see the following repo to reproduce the issue: https://github.com/peterwht/ink-unit-test-bug/tree/main
The following code snippet showcases the issue
Expected behavior
When running unit tests, all state should be reverted when an error is returned from the called function.
Additional context
ink! v4.2.0
The text was updated successfully, but these errors were encountered: