-
Notifications
You must be signed in to change notification settings - Fork 875
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
Allow writing unit tests for WASM applications #341
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use the test runner binary source code from the `webassembly-test-runner` crate version 0.1.0.
Provide a brief description of its purpose and how to use it.
And rename variables to make clearer their purpose.
Separate loading the WebAssembly test module.
Simplify so that the loop only returns `TestMeta` as items.
Simplify the name a little.
Move code to parse test information from exported function name into the constructor.
Use `tests.len()` to be clearer.
Replace loop with iterators for conciseness.
Collect all test report handling code in a new type.
Ensure CI fails if any of the tests executed fail.
Reset the runtime environment after every test.
Move code related to running a test into the new method.
A helper method that updates the report based on the result of a test function execution.
Prepare to be able to add exported APIs to the test environment.
Allow executing the test module even if the imports it depends on aren't available. Tests that try to use those imports will fail.
ma2bd
approved these changes
Jan 17, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Let's land this to unblock everyone (@MathieuDutSik ?) and iterate later if needed.
Make it easier for tests to compare instances of those types.
Check that it returns the serialized value in the application's state.
Pass some garbage data as the query parameter and check that it results in an error.
Application should initialize correctly with a provided initial value and increment it after executing an operation.
Check that an error is returned if an effect is requested to be executed.
Should treat it exactly like an operation.
An error should be returned because the application doesn't support sessions.
Use the custom test runner in `linera-sdk` to run the unit tests.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Developers writing applications for Linera should be able to write unit tests with minimal divergence from their usual workflow.
Solution
Based on the ideas from near/near-sdk-rs#467 (more specifically, the
webassembly-test
andwebassembly-test-runner
crates discussed here), a custom test runner inlinera-sdk
was created that is able to execute specially annotated unit tests in WASM application modules.To verify this works, some unit tests were written for the Counter example application. The "wasm" CI job was updated to run those tests.
Related issues
Closes #272