sway icon indicating copy to clipboard operation
sway copied to clipboard

Remove Rust integration testing behaviour from `forc test` in anticipation of unit testing support

Open mitchmindtree opened this issue 2 years ago • 3 comments

This PR is a WIP that aims to address the first 3 steps in #1833.

This is in anticipation of using forc test to support unit testing (rather than Rust integration testing) #1832.

The forc test command remains for now, but outputs a message explaining that the command is now reserved for unit testing and links to the issues above.

TODO

  • [ ] Create a new sway-test-rs repo or similar that can be used as a cargo generate template.
  • [ ] Create a forc-test-rs crate that re-exports and extends fuels with useful forc functionality for integration testing (e.g. re-exporting forc_pkg::build to ensure sway code is built and available under out/ at the start of testing).
  • [ ] Update Rust integration testing docs in the Sway book to describe how to use the cargo generate command to easily add Sway integration testing to an existing Rust project.

mitchmindtree avatar Jul 07 '22 08:07 mitchmindtree

Create a new sway-test-rs repo or similar that can be used as a cargo generate template.

Should this be a directory in fuels-rs proper?

adlerjohn avatar Jul 07 '22 12:07 adlerjohn

Create a new sway-test-rs repo or similar that can be used as a cargo generate template.

Should this be a directory in fuels-rs proper?

I think there's a chance that cargo generate can only handle the case where the crate is at the top-level of the repo, but I could be wrong! I'll do some reading and see if we can refer to a nested repo in a nice manner.

:thinking: If it turns out we can, we might want to consider providing the template from the sway repo rather than fuels-rs, particularly in the case that we want to include some functionality that allows a user to run forc build at the beginning of the test (e.g. to ensure contract ABI is available) as introducing forc also introduces an assumption of there being Sway code in the test.

Another motivator is that our existing test template already assumes things about there being a forc project anyway, i.e. the existence of a <project-name>/out/debug/ directory containing ABI JSON.

We could potentially provide another alternative test template from the fuels-rs that does not make any assumptions about there being a forc project. I'd imagine this might be more important in the future when there are alternative languages/compilers targeting the Fuel VM, or other means of generating Fuel VM bytecode/ABIs.

mitchmindtree avatar Jul 08 '22 00:07 mitchmindtree

Just an update for reviewers: Putting this on hold until we land wallet integration in forc deployment. Will come back to this PR after addressing https://github.com/FuelLabs/sway/issues/2412 and https://github.com/FuelLabs/sway/issues/2413.

mitchmindtree avatar Aug 03 '22 02:08 mitchmindtree

OK! Just transferred the sway-test-rs cargo generate template repository to FuelLabs, you can find it here: https://github.com/fuellabs/sway-test-rs. I've added some usage steps to its README, just need to update the Sway book to have something similar.

mitchmindtree avatar Oct 03 '22 07:10 mitchmindtree

This should be just about ready!

Notable updates:

  • The template has been moved from the new sway-test-rs repo into a new templates subdirectory within this repo. This allows us to make sure the template is always up to date by testing it under our CI.
  • The Test with Rust chapter has been re-written with a more thorough walk-through using the new cargo generate template.

mitchmindtree avatar Oct 06 '22 05:10 mitchmindtree

@camiinthisthang just cc'd you for review too in case you'd like to take a look at the Sway Book changes!

mitchmindtree avatar Oct 07 '22 00:10 mitchmindtree

@camiinthisthang just cc'd you for review too in case you'd like to take a look at the Sway Book changes!

That's so nice, thank you!

camiinthisthang avatar Oct 07 '22 00:10 camiinthisthang