-
Notifications
You must be signed in to change notification settings - Fork 715
test: aac add test coverage for ParseError variants
#6631
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
base: develop
Are you sure you want to change the base?
test: aac add test coverage for ParseError variants
#6631
Conversation
|
|
||
| /// ParserError: [`ParseErrors::Lexer`] | ||
| /// Caused by: unknown symbol | ||
| /// Outcome: block accepted. |
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.
I like your comments. Clear, concise, easy to follow/reason about.
|
I actually think it might be slightly easier to reason about the test name/be able to find tests if we did something like #[test]
fn test_parse_error_lexer() {
contract_deploy_consensus_test!(
function_name!(),
contract_name: "my-contract",
contract_code: &{"(use-trait)"},
);
}since when I initially looked at contract_deploy_consensus_test! macro it took me a bit to realize it was a #[test]. But I am not strongly one way or the other. Whichever makes it easier for you to reuse these functions in your test, go for it. If you need help fixing your errors, let me know. I will give it a look. |
Considering we have a macro, we should be able to use |
|
Based on the feedback, I've updated consensus macros as proposed in the PR description. By the way, adding more tests exposed a new issue related to the produce a non-deterministic
where the element listed in the paranthesis can have a different order and the flip/flop between them at each run. |
Codecov Report❌ Patch coverage is
❌ Your project check has failed because the head coverage (74.38%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #6631 +/- ##
===========================================
+ Coverage 64.85% 74.38% +9.52%
===========================================
Files 574 575 +1
Lines 355039 355145 +106
===========================================
+ Hits 230278 264188 +33910
+ Misses 124761 90957 -33804
... and 373 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
francesco-stacks
left a comment
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.
Good changes! Definitely fine with the named tests.
PS:I am sure you already noticed, but some unit tests are currently failing
...tests/snapshots/blockstack_lib__chainstate__tests__parse_tests__trait_reference_unknown.snap
Show resolved
Hide resolved
Yeah! This is due the |
27b1d56 to
a81db5d
Compare
I opted to manage this issue, forcing the |
e62cd5c to
d9c6948
Compare
1be51dc to
8c0a7fc
Compare
|
For @jacinta-stacks and @francesco-stacks, who reviewed the PR while it was in draft: I’ve updated the PR description to reflect the final state of the work. |
jacinta-stacks
left a comment
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.
Really clean. I like this a lot.
Description (UPDATED)
This PR adds consensus test coverage for the
ParseErrorand relatedParseErrorsenum variants (aliasParseErrorKind) in preparation for the upcoming refactor activities.What's done
ParseErrorsvariants for the scenarios that are functionally feaseable.variant_coverage_reportfunction trick).build_astfunction as support for writing the consensus ones. Also added a cost tracker facility that allow to use theLimitedCostTrackerand real cost functions.IllegalASCIIString(String)variant (when the string field is bigger then 1MB), ellipsing the string (only for test). This is caused by this info log statement that print the clarity error as debug:stacks-core/stackslib/src/chainstate/stacks/db/transactions.rs
Lines 1309 to 1312 in 12c8d14
CircularReference(Vec<String>)making the string list deterministic in terms of ordering (otherwise test result would flip/flop due to circular reference random ordering)contract_deploy_consensus_test!andcontract_call_consensus_test!so that now it is possible to encapsulate them in a "native"[test]function. By this we could now add proper rust documentation for test cases and having the IDE browsing support for the tests (e.g. outliner view, etc...)Heads-up
> Stack Depth
A note about how I succeeded to test the
VaryExpressionStackDepthTooDeep. It was only possible because of a "gap" on how the stack depth limit is managed while parsing:Parser::parse_node(..)withMAX_NESTING_DEPTH = AST_CALL_STACK_DEPTH_BUFFER + MAX_CALL_STACK_DEPTH + 1( total = 70) it is managed the nesting depth (with different rules for list and tuple) and if it pass,VaryStackDepthChecker::check_vary(..)a second check is done with depth to be< AST_CALL_STACK_DEPTH_BUFFER + MAX_CALL_STACK_DEPTH(total 69), applying same rule for list and tuple.Basically with this difference of 1 (70 vs 69), I succeeded to make the test case pass the first step and fail in the second step.
Just to make sure I understand: we already know that 64 is the stack limit and that we allow a bit of extra “space,” but I’d like to better understand why we’re using different stack limits for the two checks?
> Odd ParseErrors Conversion
I notice some cases where a
ParseErrors(aliasParseErrorKind) is obtained by converting from other error families.In this example,
Value::buff_from(bytes)produce anInterpreterError(aliasVmExecutionError), internally due to a possibleCheckErrors(aliasCheckErrorKind), which is then remapped to aParseErrors(aliasParseErrorKind) with the match expressionstacks-core/clarity/src/vm/ast/parser/v2/mod.rs
Lines 949 to 966 in 12c8d14
Maybe clarity types (in
clarity-types/src/types/mod.rs) should have their own error layer that could be then converted properly by the user.> ParseErrors::NameAlreadyUsed rename?
This error variant seems only used in case of Trait name. So it maybe renamed accordly (like
TraitNameAlreadyUsed)stacks-core/clarity/src/vm/ast/traits_resolver/mod.rs
Lines 57 to 68 in 12c8d14
> Duplicated MAX_STRING_LEN const
This constant seems to be duplicated in
clarityandclarity-typeswith different types, but same value:clarity::vm::ast::parser::v2::MAX_STRING_LEN: usize = 128;clarity-types::representations: MAX_STRING_LEN u8 = 128claritycrate asclarity::vm::representations::MAX_STRING_LENCould we merge the two? Maybe the usize one to u8 considering that the second is exposed by the clarity-types?
Possible Follow-ups
build_astfunction. I noticed that we miss unit test coverage for this function (a lot of parse error variants don't have related test cases), so could be a valuable tasks.IllegalASCIIString(String), a better approach would be to do it on theParseErrorsenum side, but that would require to implement a custom Debug trait implementation for the enum. To avoid to implement the debug format for each variant, it would be possible to use some crate likederive-debugthat allows to override the debug format selectively at variant level. If we are interested in this, then it could be a follow-up.ParseErrorsvariants to clarify better the code intent. (unreachable variants, separating parse error from cost error, remove if possible the From error traslation, etc...). NOTE: For sure before starting would be better to have "aac plowing" phase completed (with the enum renaming), to avoid a conflict hellDraft Description (OLD)
This PR adds consensus test coverage for the ParseError enum in preparation for the upcoming refactor of that enum. The PR is currently a draft to gather early feedback on test organization and macro usage.
The PR is currently a draft to gather early feedback about test organization and macro usage::
ParseErrorrelated tests in a dedicate moduleparse_tests.rscontract_deploy_consensus_test!andcontract_call_consensus_test!macros opting for:clarity_typescrate as test dependency for documentation purposes (doc referencing Parse error variants). This is just a preliminary attempt, and I open to remove it if it's not beneficial (I'm also trying understanding this)Currently, it doesn’t work properly with the macro, causing IDE warnings and broken hyperlinks (would function correctly with a standard test function)
I also noticed that with the macro we loose the Outline view (is empty)
So, apart the doc thing, I'm wondering if in general would be convenient having "native" test functions while keeping the macro just for configuring the test body. Something like this:
Applicable issues
ParseErrorenum #6627Additional info (benefits, drawbacks, caveats)
Checklist
docs/rpc/openapi.yamlandrpc-endpoints.mdfor v2 endpoints,event-dispatcher.mdfor new events)clarity-benchmarkingrepo