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

AST-based randomized testing of Tact parser/pretty-printer #642

Open
anton-trunov opened this issue Jul 31, 2024 · 0 comments · May be fixed by #1248
Open

AST-based randomized testing of Tact parser/pretty-printer #642

anton-trunov opened this issue Jul 31, 2024 · 0 comments · May be fixed by #1248
Assignees
Labels
kind: fuzzing Application of fuzzing to testing kind: testing Tests (*.spec.ts)
Milestone

Comments

@anton-trunov
Copy link
Member

anton-trunov commented Jul 31, 2024

Summary

We generate random Tact ASTs and test the following property:

  • pretty-printed AST when parsed should provide the original AST.

One more property would be nice to test:

  • the pretty-printer produces text with the minimum possible parentheses.

Some pointers for testing Tact expressions

Goal: implement automated tests to ensure the correctness of the Tact pretty-printer for expressions using the property-based randomized testing approach, also known as quickchecking.

The idea here is to randomly generate abstract syntax trees (AST) that represent Tact language constructions after parsing.

The fully blown implementation would start with generating abstract Tact AST modules, essentially generating a Tact file with multiple structures/messages, top-level functions, contracts and traits. But this is a pretty large task, so we just would like to do it for a small subset of Tact, namely expressions.

As a property based testing framework we could recommend using fast-check.

The approach here is as follows:

  • generate a random AST for expression,
  • pretty-print it, i.e. convert it to plain text representation,
  • parse it, turning again into an AST,
  • compare the originally generated AST and the parsed one: those must be the same, otherwise there is a bug (most likely in the pretty-printer),
  • if the ASTs are the same, repeat the process.

More formally, for every generated Tact expression AST ast you need to check the following property:

parseExpression(prettyPrint(ast)) = ast

Note that you cannot use the builtin TS equality ===, because Tact ASTs contain the location information loc and AST identifiers id, so you will most likely need to implement your own equality comparison operation which would ignore that information.

Note that often times the generated counter-example is too large for a human to understand where the bug is, so if you implement a shrinker which tries to minimize the counter-example, that gives bonus points, but it's not strictly necessary for this test assignment.

Useful links

@anton-trunov anton-trunov added the kind: testing Tests (*.spec.ts) label Jul 31, 2024
@anton-trunov anton-trunov added this to the v1.6.0 milestone Jul 31, 2024
@anton-trunov anton-trunov modified the milestones: v1.6.0, v1.7.0 Oct 16, 2024
@anton-trunov anton-trunov assigned xpyctumo and unassigned novusnota Dec 23, 2024
@anton-trunov anton-trunov added the kind: fuzzing Application of fuzzing to testing label Dec 25, 2024
@anton-trunov anton-trunov changed the title Randomized testing of Tact parser/pretty-printer AST-based randomized testing of Tact parser/pretty-printer Dec 25, 2024
@anton-trunov anton-trunov modified the milestones: v1.7.0, v1.6.0 Dec 30, 2024
@xpyctumo xpyctumo linked a pull request Jan 20, 2025 that will close this issue
32 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: fuzzing Application of fuzzing to testing kind: testing Tests (*.spec.ts)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants