-
Notifications
You must be signed in to change notification settings - Fork 123
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
feature: Add BasicSborAssertion
and ScryptoSborAssertion
macros
#1848
Merged
dhedey
merged 8 commits into
feature/schema-comparisons
from
feature/schema-comparisons-part-2a
Aug 7, 2024
Merged
feature: Add BasicSborAssertion
and ScryptoSborAssertion
macros
#1848
dhedey
merged 8 commits into
feature/schema-comparisons
from
feature/schema-comparisons-part-2a
Aug 7, 2024
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
These macros output tests which check for a fixed type schema, or a backwards compatible type schema.
dhedey
changed the title
feature: Add BasicSborAssertion and ScryptoSborAssertion macros
feature: Add Jul 2, 2024
BasicSborAssertion
and ScryptoSborAssertion
macros
Docker tags |
Benchmark for bb47750Click to view benchmark
|
iamyulong
approved these changes
Aug 7, 2024
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.
LGTM
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.
Summary
These macros output tests which check for a fixed type schema, or a backwards compatible type schema.
See
sbor-assert.rs
in the tests to see how the macros are used, and seetransaction_receipt.rs
andsystem_structure.rs
for how these are used in practice.What's rather cool is that Rust Analyzer / the VS Code extension spots the test and magically offers a "Run Test" button, which makes this much nicer / more magic than I was expecting :).
Details
You can start with
#[sbor_assert(generate("FILE:<relative_file_path.txt>")]
which will output a test which panics and gives you the current schema.You can then do this as new versions get added:
I've written rust docs for e.g.
ScryptoSborAssertion
, and the error messages aim to help you get the syntax right. Just start with adding#[derive(ScryptoSborAssertion)]
and the error messages should guide you.I also had to add a little extension to the
define_single_versioned!
/define_multi_versioned!
macros to be able to support adding attributes to only the outer / inner types. It's not the nicest, but it's functional.Testing
See
sbor-assert.rs
. Failing tests aren't included - because they're a bit painful to do.But they've been manually tested, and most of the underlying logic has already been tested as part of the
schema_comparisons.rs
tests.Update Recommendations
We can now start using these macros across scrypto and node.