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

tests: check initOf and codeOf reachability #2083

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

jeshecdom
Copy link
Contributor

@jeshecdom jeshecdom commented Feb 28, 2025

Issue

Towards #2030.
Closes #2383.

This PR uses the script src/test/autogenerated/gen-initof-reachability.ts to generate ASTs for the reachability test of initOf.

It tries to generate all possible combinations where a 'initOf` could be placed. It chains fast-check generators in order to generate all possible combinations (up to a certain depth in function calls). Then, it compiles the ASTs, runs the contracts in Sandbox and checks that the contracts send the appropriate messages to the correct contracts and no error exit codes are produced.

The current version has the following limitations, some of which will be addressed in subsequent PRs:

  • It does not generate code for codeof.
  • It does not generate complex expressions because I would need to generate well-typed expressions. For example, it does not generate cases where there is a function that does an initOf and such function is called inside an integer expression:
fun test(): Int {
   let a = initOf Deployer();
   send(.....)
   return 10;
}

contract A {
   init(v: Int) {
       let a: Int = 45 + test() + v;
   }
}

At the moment, it only generates function calls that return StateInit, like this:

fun test(): StateInit {
   let a = initOf Deployer();
   return a;
}

contract A {
   init(v: Int) {
       let a: StateInit = test();
      send(......)
   }
}

but I plan to add more complex expressions.

  • Method calls, foreach loops, initOf in receivers will be added later.

The fuzzer can be invoked with:
yarn gen-initof-tests

The statistics can be invoked with:
yarn gen-initof-tests stats

Checklist

  • I have updated CHANGELOG.md
  • I have run all the tests locally and no test failure was reported
  • I have run the linter, formatter and spellchecker
  • I did not do unrelated and/or undiscussed refactorings

@jeshecdom
Copy link
Contributor Author

This PR depends on PR: #2311. To make the AST generator script work, I included the change in the aforementioned PR. So, probably the PRs should be merged. Opinions?

@jeshecdom jeshecdom marked this pull request as ready for review March 7, 2025 03:52
@jeshecdom jeshecdom requested a review from a team as a code owner March 7, 2025 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Post swarm testing activities for initof script
1 participant