cadence icon indicating copy to clipboard operation
cadence copied to clipboard

[Test Framework] Add support for loading programs from local files

Open SupunS opened this issue 3 years ago • 0 comments

Work towards https://github.com/onflow/cadence/issues/331

Description

⚠️ NOTE: Added this as an experimental feature.

One of the major pain points in executing transactions/script or deploying contracts during tests is, having to construct the source-code string inline. Since multi-line string is also not supported this can become a real hassle.

Hence, this PR introduces a utility method to load programs from local files. Works similar to resolving the imports from a local file, and also leverages the same file resolver as imports. The resolver has to be provided by the user of the test runner (i.e: CLI etc.).

let script = Test.readFile("./sample/script.cdc")

The program/test will terminate upon an error in reading the file.

Future Improvements:

  • Maybe provide support for having placeholders in the file content, and dynamically fill them during reading the file (something similar to sprintf()). Can be useful to inject import addresses etc.

  • [ ] Targeted PR against master branch
  • [x] Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • [x] Code follows the standards mentioned here
  • [x] Updated relevant documentation
  • [x] Re-reviewed Files changed in the Github PR explorer
  • [x] Added appropriate labels

SupunS avatar Aug 09 '22 17:08 SupunS