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

Add support for multi-contract calls to unit testing #3571

Closed
mitchmindtree opened this issue Dec 11, 2022 · 2 comments · Fixed by #4156
Closed

Add support for multi-contract calls to unit testing #3571

mitchmindtree opened this issue Dec 11, 2022 · 2 comments · Fixed by #4156
Assignees
Labels
enhancement New feature or request forc-test Everything related to the `forc-test` lib and `forc test` command.

Comments

@mitchmindtree
Copy link
Contributor

mitchmindtree commented Dec 11, 2022

On slack it was mentioned that unit testing would be limited to calling into the current contract, however this doesn't need to be the case.

It should be possible to call into all contracts that were declared under [contract-dependencies] whether directly or transitively. We have their src, and can build and deploy them just like we can build and deploy a local contract.

This would make for a good followup to #3262 cc @kayagokalp. Rather than only deploying the project contract, we'd deploy all contract dependencies that exist within the graph.

We will still be limited in the case that a contract attempts to call into another contract that is not declared under [contract-dependencies], e.g. if a contract is constructed from a raw contract ID within Sway code.

This is something we should communicate in the [contract-dependencies] docs and under the Sway contract docs in general - to encourage users to always declare their contract dependencies under [contract-dependencies] if possible as it gives forc the power to do cool stuff like this.

It might be possible to support private contracts (where the src or salt is not known) by extending the [contract-dependencies] feature a little. I'll open a new issue with some thoughts. Edit: see #3572.

@mitchmindtree mitchmindtree added enhancement New feature or request forc-test Everything related to the `forc-test` lib and `forc test` command. labels Dec 11, 2022
@mitchmindtree
Copy link
Contributor Author

Deploying undeclared contract dependencies

Thinking on this more, a contract dependency must always be declared in the inputs of the transaction in order to call into it from a contract or script.

This implies that it should be possible for us to fetch and inspect the Create transactions of contract dependencies to detect any other transient contract dependencies so that we can fetch those, deploy them, check their transaction inputs for more contract dependencies, and so on. We can potentially integrate this fetching of undeclared contract dependencies during our package graph construction so that we can reason about them alongside the rest of our dependencies.

We should investigate how fuels currently determines what contracts should be present in the transaction inputs, as we can likely do something similar for detecting and determining the IDs of undeclared contract dependencies in workspace members before deploying them.


For now, we can stick to deploying declared [contract-dependencies] as we don't yet have infrastructure in forc for querying the fuel network. The package registry (#3752) will require such support, so perhaps we can revisit deploying undeclared contract dependencies in the future.

@mitchmindtree
Copy link
Contributor Author

On a related note: As scripts may also have [contract-dependencies], we should likely also support deploying all contract dependencies for script tests too (not just contract tests). This would allow for scripts to declare unit tests that test out certain contract interactions before running the real thing.

kayagokalp added a commit that referenced this issue Mar 16, 2023
## Description
closes #3571.
closes #4162.

This PR adds the ability of calling multiple contracts from sway unit
tests if they are added as `[contract-dependencies]`. This is limited
with contracts currently but I will be having a follow-up which builds
upon this to introduce this support to scripts as well.

As these contracts are already declared under `[contract-dependencies]`
their contract ids are injected into their namespace by `forc-pkg`. A
bug related to this step is fixed in #4159.

<img width="787" alt="image"
src="https://user-images.githubusercontent.com/20915464/224345002-92dc2bcb-823d-4971-9041-31111cf85e77.png">

### Follow-ups
- #4161
- ~#4162~
 
## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.

---------

Co-authored-by: Kaya Gokalp <kayagokalp@fuel.sh>
emilyaherbert pushed a commit that referenced this issue Mar 16, 2023
## Description
closes #3571.
closes #4162.

This PR adds the ability of calling multiple contracts from sway unit
tests if they are added as `[contract-dependencies]`. This is limited
with contracts currently but I will be having a follow-up which builds
upon this to introduce this support to scripts as well.

As these contracts are already declared under `[contract-dependencies]`
their contract ids are injected into their namespace by `forc-pkg`. A
bug related to this step is fixed in #4159.

<img width="787" alt="image"
src="https://user-images.githubusercontent.com/20915464/224345002-92dc2bcb-823d-4971-9041-31111cf85e77.png">

### Follow-ups
- #4161
- ~#4162~
 
## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.

---------

Co-authored-by: Kaya Gokalp <kayagokalp@fuel.sh>
emilyaherbert pushed a commit that referenced this issue Mar 20, 2023
closes #3571.
closes #4162.

This PR adds the ability of calling multiple contracts from sway unit
tests if they are added as `[contract-dependencies]`. This is limited
with contracts currently but I will be having a follow-up which builds
upon this to introduce this support to scripts as well.

As these contracts are already declared under `[contract-dependencies]`
their contract ids are injected into their namespace by `forc-pkg`. A
bug related to this step is fixed in #4159.

<img width="787" alt="image"
src="https://user-images.githubusercontent.com/20915464/224345002-92dc2bcb-823d-4971-9041-31111cf85e77.png">

- #4161
- ~#4162~

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.

---------

Co-authored-by: Kaya Gokalp <kayagokalp@fuel.sh>
emilyaherbert pushed a commit that referenced this issue Mar 20, 2023
closes #3571.
closes #4162.

This PR adds the ability of calling multiple contracts from sway unit
tests if they are added as `[contract-dependencies]`. This is limited
with contracts currently but I will be having a follow-up which builds
upon this to introduce this support to scripts as well.

As these contracts are already declared under `[contract-dependencies]`
their contract ids are injected into their namespace by `forc-pkg`. A
bug related to this step is fixed in #4159.

<img width="787" alt="image"
src="https://user-images.githubusercontent.com/20915464/224345002-92dc2bcb-823d-4971-9041-31111cf85e77.png">

- #4161
- ~#4162~

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.

---------

Co-authored-by: Kaya Gokalp <kayagokalp@fuel.sh>
anton-trunov pushed a commit that referenced this issue Mar 27, 2023
## Description
closes #3571.
closes #4162.

This PR adds the ability of calling multiple contracts from sway unit
tests if they are added as `[contract-dependencies]`. This is limited
with contracts currently but I will be having a follow-up which builds
upon this to introduce this support to scripts as well.

As these contracts are already declared under `[contract-dependencies]`
their contract ids are injected into their namespace by `forc-pkg`. A
bug related to this step is fixed in #4159.

<img width="787" alt="image"
src="https://user-images.githubusercontent.com/20915464/224345002-92dc2bcb-823d-4971-9041-31111cf85e77.png">

### Follow-ups
- #4161
- ~#4162~
 
## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.

---------

Co-authored-by: Kaya Gokalp <kayagokalp@fuel.sh>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request forc-test Everything related to the `forc-test` lib and `forc test` command.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants