Commit graph

536 commits

Author SHA1 Message Date
mitchmindtree
3d5698efda
refactor(forc-pkg): Attempt to simplify build/compile fns by introducing dedicated types (#4209)
## Description

This introduces the `CompiledPackage` and `CompiledContractDependency`
types in order to more accurately model the inputs and outputs of the
`compile` function.

We also move the `name` and `target` fields from `BuiltPackage` into the
`PackageDescriptor`, construct the descriptor earlier in the build
process, and use the descriptor to consolidate more of the `compile`
function arguments.

I started on refactoring some of the ABI generation related code, but
realised that this might involve a more dedicated effort and opened
#4208.

## 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.
2023-03-10 15:01:37 +00:00
IGI-111
0eaa3a6da9
Standardized module structure (#4232)
## Description

Implement RFC 0006, fix #4191.

Remove the `dep` reseved keyword in favor of `mod`.

Change path resolution for submodules to use an adjascent file at the
root and a folder named after the current module in other cases.

Remove the need for an argument to `library`, the LSP now points to
empty spans at the top of module files.

The library names are now determined by the file name, or the package
name at the top level.

## 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.
2023-03-09 19:14:52 +11:00
Mohammad Fawaz
49eae2dd93
Bump to v0.35.5 (#4242) 2023-03-08 13:12:24 -05:00
Mohammad Fawaz
3770dd8c21
bump to v0.35.4 (#4230) 2023-03-07 14:38:24 +00:00
Marcos Henrich
40cf1c2770
Implements json abi with call paths for structs and enums. (#4137)
## Description

Reference to external dependency struct now looks like: `"type": "struct
abi_with_tuples::Person",`
`"type": "enum std::option::Option",`

Struct reference in root module still looks like:
`"type": "struct MyStruct",`

Struct reference in sub modules looks like:
`"type": "struct dep_1::MyStruct1",`

` forc build` will not generate json ABI with call path by default to do
so we have to use the flag `--json-abi-with-callpaths`, one example is:

```cargo run --bin forc build --json-abi-with-callpaths --path `pwd`/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/```

This will generate `test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/out/debug/abi_with_same_name_types-abi.json` with call paths for structs and enums.

This is related to:
https://github.com/FuelLabs/fuel-specs/issues/450
https://github.com/FuelLabs/fuels-rs/issues/791

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand areas.
- [ ] 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.
2023-03-02 18:55:51 +00:00
Kaya Gökalp
64f7340470
feat: display gas used for unit tests (#4178)
## Description
closes #2411.

This PR adds used gas information to the output of `forc test`. An
example run can be seen below:

<img width="534" alt="Screen Shot 2023-02-24 at 4 47 29 PM"
src="https://user-images.githubusercontent.com/20915464/221198624-a3bdb264-2182-4b9d-9497-7d8cfe84132b.png">

This is done automatically without any flags. I felt like this should be
the default way but open to suggestions if you feel like it should be
behind a flag like `--gas-usage`.

Also by accessing `TestResult` structs new used gas field, we can add
this information into vscode plugin just like #513. We do not have a
line by line gas cast information just yet but we could show the whole
test's used gas info next to the run button or something in vscode.
Thoughts @JoshuaBatty @sdankel

Please let me know if anyone has any requests around the flag and the
way we are printing the used gas. Maybe @nfurfaro could have some ideas
as the prime user of `forc-test` 😄
## Checklist

- [ ] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [ ] 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).
- [ ] I have requested a review from the relevant team or maintainers.
2023-02-28 10:16:29 +11:00
Vaivaswatha N
8e797a1365
Add forc build flag to treat warnings as errors (#4177)
Closes #3190

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [ ] 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.
2023-02-24 05:15:13 +00:00
mitchmindtree
9346bf4fa6
refactor(forc-pkg): Abstract out source-related items from pkg (#4168)
## Description

In anticipation of the upcoming ipfs support (#3926), this PR refactors
`forc-pkg` to more clearly separate out the "source" abstraction from
the rest of the pkg-handling logic.

We do so by creating a common interface for sources in the form of
traits for pinning and fetching. This should allow for adding in the
upcoming ipfs implementation (or future alternative source kind) in a
manner that doesn't further complicate the rest of package handling.

There is still room for further refactor of `pkg.rs`, but this should do
enough to clear the way for ipfs support and closes #3927.

## 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: Joshua Batty <joshpbatty@gmail.com>
2023-02-24 08:44:37 +11:00
Mohammad Fawaz
5d2b10bd83
Bump to v0.35.3 (#4135)
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
Co-authored-by: João Matos <joao@tritao.eu>
2023-02-21 16:42:15 -05:00
Mohammad Fawaz
f05ecaf2de
Bump to v0.35.2 (#4123) 2023-02-17 15:08:34 -08:00
Kaya Gökalp
812608ca13
feat: Upon test failure, output revert code with human-readable label and associated logs (#3999)
## Description

closes #3952.

This PR adds:

1. Revert code for failing tests
2. Known error signals for failing tests
3. Logs for failing tests


## 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).
- [ ] 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.
2023-02-17 10:23:08 +00:00
Mohammad Fawaz
1f9debfaf9
Bump to v0.35.1 (#4088)
Co-authored-by: João Matos <joao@tritao.eu>
2023-02-15 16:56:49 -05:00
Mohammad Fawaz
dfdadf8bad
Change hyphens to underscores for library names when running forc new/init (#4048) 2023-02-12 22:09:26 +00:00
Kaya Gökalp
4d5fea688f
feat: only build relevant members for forc-client operations (#4008)
## Description

closes #3329.

This PR filters unrelevant member nodes for `forc-client` operations in
workspaces. `forc deploy` only builds contracts and `forc run` only
builds scripts. This is done by adding a filtering capability to
`forc-pkg`.

## 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.
2023-02-10 14:02:01 +03:00
João Matos
b6f19a3be7
Bump to v0.35.0 (#4024)
## Description

Bump to `v0.35.0` for a new release.

## 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.
2023-02-08 10:38:48 +00:00
Brandon Kite
67b37ce4cc
Fuel Core v0.17.0 Upgrade (#3961) 2023-02-08 20:01:12 +11:00
Mohammad Fawaz
f5867dcb28
Bump to v0.34.0 (#3943)
~~Waiting on https://github.com/FuelLabs/sway/pull/3942~~
2023-02-01 06:39:13 -05:00
mitchmindtree
bc700d5afd
Refactor forc-client in preparation for new forc submit command (#3941)
This is a small refactor of the `forc-client` crate in anticipation of
including the new `forc submit` command (see #3885) as a new binary
output for the crate.

This PR inverts the forc-client module hierarchy to follow `forc`'s
layout a little more closely.

It also refactors the command types in order to better share sets of
clap arguments between different commands with the aim of reducing code
duplication and providing a more uniform experience across all official
forc commands/plugins. This will be improved further once the `forc
submit` command is included, allowing us to share some of the networking
arguments too.

---------

Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
2023-01-31 21:55:45 +11:00
Joshua Batty
baa2fc2a35
Bump toml-edit and tower-lsp to latest versions (#3933) 2023-01-31 12:26:57 +11:00
Nick Furfaro
ed1bc39c67
Run cargo clippy --fix in the sway repo (#3903)
Co-authored-by: Sophie <sophiedankel@gmail.com>
2023-01-26 16:05:13 -05:00
Kaya Gökalp
76606cd930
feat: inject contract id into the namespace for tests automatically (#3729)
closes #3673.

## About this PR

This PR adds `CONTRACT_ID` injection while building contracts with `forc
build --test`. `CONTRACT_ID` is the id of the contract without the tests
added. To find out that id, we first compile the contract without tests
enabled.

The rough outline of stuff happening here:

1. We iterate over `BuildPlan` members to find out contracts and collect
their contract id into an injection map. In this step only the contracts
are built. To determine contract id we need to compile the contract
without tests. Since we also need the bytecode of the contract without
tests, we are collecting them as we come across them while iterating
over members.
2. With the injection map build and execute all the tests, so basically
after first step we are just doing the old `forc-test` behaviour.

So basically I added a pre-processing step for contract id collection
for those members that require it (contracts).

This enables the following test structure:

```rust
let caller = abi(MyContract, CONTRACT_ID);
let result = caller.test_function {}();
assert(result == true)
```
2023-01-24 10:32:04 +00:00
Kaya Gökalp
89c45ee845
Fix order of logs such that they are printed after tested function name (#3828)
closes #3824.


With this PR, different tests are emitting logs separately as pointed
out by @mitchmindtree in #3808.

(Github code block indentations are showing up weird)

## Before this PR
```console
fuel/test_projects/deploy [⏱ 4s]
❯ mforc test --logs
  Compiled library "core".
  Compiled library "std".
  Compiled library "deploy".
  Bytecode size is 52 bytes.
   Running 2 tests
[{"Log":{"id":"0000000000000000000000000000000000000000000000000000000000000000","is":10344,"pc":10368,"ra":1,"rb":0,"rc":0,"rd":0}}]
[{"Log":{"id":"0000000000000000000000000000000000000000000000000000000000000000","is":10344,"pc":10380,"ra":2,"rb":1,"rc":0,"rd":0}}]
      test my_test ... ok (393.833µs)
      test my_test2 ... ok (371.833µs)
   Result: OK. 2 passed. 0 failed. Finished in 765.666µs.
```


## After this PR
```console
fuel/test_projects/deploy [⏱ 4s]
❯ mforc test --logs
  Compiled library "core".
  Compiled library "std".
  Compiled library "deploy".
  Bytecode size is 52 bytes.
   Running 2 tests
      test my_test ... ok (608.041µs)
[{"Log":{"id":"0000000000000000000000000000000000000000000000000000000000000000","is":10344,"pc":10368,"ra":1,"rb":0,"rc":0,"rd":0}}]
      test my_test2 ... ok (360.041µs)
[{"Log":{"id":"0000000000000000000000000000000000000000000000000000000000000000","is":10344,"pc":10380,"ra":2,"rb":1,"rc":0,"rd":0}}]
   Result: OK. 2 passed. 0 failed. Finished in 968.082µs.
```
2023-01-20 10:36:01 +11:00
Kaya Gökalp
097fa69c1f
Add a flag to print Log and LogData receipts emitted from tests (#3808)
closes #3807.

- Moved `Log` and `LogData` formatting code from `forc-client` to
`forc-util` as `forc-test` needs it too.
- Added `--logs` and `--pretty-print` flags to `forc-test`
2023-01-19 10:37:58 +00:00
Kaya Gökalp
f18197f0c0
Introduce a way to inject items into project namespaces through forc-pkg (#3770)
This PR, refactor the `BuildPlan` generation a little to be able to
re-use some of the parts from other crates that requires to create
`BuildPlan` from build opts.

On top of that this PR also introduces a way to inject list of items
into the namespace of any member of the workspace.

This is done to unblock #3729

closes #3763.
2023-01-18 11:27:52 +00:00
Mohammad Fawaz
0122a1c700
Bump to v0.33.1 (#3806) 2023-01-18 06:00:31 -05:00
Kaya Gökalp
847cbccd32
feat: workspace support for forc clean (#3774)
closes #3641
2023-01-15 17:40:33 +00:00
Kaya Gökalp
26eeef0fc6
doc: update docs and forc new/init message to point to discourse instead of discord (#3775)
closes #3756.
2023-01-14 22:02:15 +00:00
João Matos
28899f8e5c
Bootstrap the EVM backend. (#3685)
This bootstraps the EVM backend via the following:

- [x] Add build target support. This is implemented as a `--build-target
/ --target` CLI flag in Forc.
- [x] Allow for multiple asm builders The existing architecture was
refactored to be trait-based, and the code was split into two
directories, for `fuel` and `evm` backends.
- [x] Add minimal EVM assembly output. 
- [x] Add `evm` target testing support.
- [x] Implement EVM smart contract memory loader
- [x] Implement basic Solidity ABI generation
2023-01-13 19:10:20 +00:00
Emily Herbert
b44d8ba1a1
Improve the declaration engine API (#3757)
The goal of this PR is to reduce code bloat. So it does a number of
things, although there are _no functional changes_.

1. Change the canonical code name from "declaration engine" to "decl
engine", including renaming `DeclarationEngine` to `DeclEngine`,
`DeclarationId` to `DeclId`, and `DeclarationWrapper` to `DeclWrapper`.
"`Declaration`" is a lot of syllables to say all the time haha 😅
2. Rename the `DeclEngine::look_up_decl_id` method to `DeclEngine::get`
and rename the `DeclEngine::replace_decl_id` method to
`DeclEngine::replace`.
3. Rename the `DeclEngine::insert` method to
`DeclEngine::insert_wrapper`.
4. Add a new `DeclEngine::insert` method with type param `T:
Into<DeclWrapper>` and add traits for `From<DeclWrapper>` for different
declarations. Replace and remove the dedicated "`insert`" methods with
the generic `DeclEngine::insert` method.

Co-authored-by: emilyaherbert <emily.herbert@fuel.sh>
2023-01-11 15:02:22 -05:00
Kaya Gökalp
970565901d
Exclude tests from ParseTree after parsing if they are not enabled (#3684)
closes #3622.
closes #3586.

unblocks #3673.

## About this PR

After parsing, I added a check to remove tests from `AstTree` if tests
are not enabled. Since all the other checks are done after this
exclusion of tests, this PR also prevents warnings and errors coming
from test functions to be emitted while using `forc build`. They are
still visible with `forc test` as they should be.
2023-01-05 22:58:48 +00:00
Mohammad Fawaz
2b2b4b117c
Bump to v0.33.0 (#3703)
Also ran `cargo update`
2023-01-05 15:27:38 -05:00
Joshua Batty
b21009e17d
Return the lexing stage produced by sway_parse from forc-pkg::check() (#3675)
Previous to this PR, `forc_pkg::check()` would only return the
`ParseProgram` and `TyProgram` AST's. In the language server, we now
also need access to the initial lexing stage produced by `sway_parse` in
order to get access to the sway keyword tokens.

This PR now returns the lexing stage of a program along with the parsed
and typed stages.

closes #3524
2023-01-03 16:39:23 -08:00
Dhaiwat / dhai.eth
ce353e7f03
Update link to TS SDK docs in the forc CLI (#3653) 2022-12-28 01:07:11 +00:00
Emily Herbert
978de4dd80
Remove the global DeclarationEngine (#3411)
This PR removes the global `DeclarationEngine` in favor of keeping a
local copy in the `TypeCheckContext`.

This PR is pretty big... there aren't any additional things added other
than what I """ had to add """ in order to complete this task. At a high
level:

- This PR introduces the `Engines` struct, which has two fields
`type_engine: &TypeEngine` and `declaration_engine: &DeclarationEngine`.
- For most/many of the traits introduced in #3353, this PR changes these
traits to take a `Engines` instead of a `&TypeEngine`

Closes #2063

Co-authored-by: emilyaherbert <emily.herbert@fuel.sh>
2022-12-22 12:43:03 +11:00
Mohammad Fawaz
b9996f1346
Bump to v0.32.2 (#3618)
Mainly to get
efd4518b6d
out as per the SDK team's request.
2022-12-15 22:04:28 -05:00
Emily Herbert
581b44ed12
Update repo in response to clippy update (#3611)
Co-authored-by: emilyaherbert <emily.herbert@fuel.sh>
2022-12-16 09:34:16 +11:00
Mohammad Fawaz
50c1b6c858
Bump to v0.32.1 (#3606)
Mainly to include https://github.com/FuelLabs/sway/pull/3605 so that we
can publish correctly.
2022-12-14 21:59:46 -05:00
Mohammad Fawaz
5bd25b8611
Bump to v0.32.0 (#3602)
- Bump to `v0.32.0`
- Run `cargo update`
- Bump `fuel-core` CI to `0.15.1` since `cargo update` updated `the
`fuel-core` version in `Cargo.lock`.
2022-12-14 16:42:16 -05:00
Kaya Gökalp
aaf04303db
feat: Implement workspace testing (#3361)
closes #3358.

## Summary

This PR adds workspace support to `forc-test`. Executing `forc test` in
a workspace runs all tests coming from the members of the workspace and
outputs them formatted separately. An example of the output can be seen
below. I also added workspace unit test support to testing suite and
added a `should_pass/unit_tests/` test with a workspace.

<img width="419" alt="image"
src="https://user-images.githubusercontent.com/20915464/206710608-b65fd509-6131-4ab0-8393-27bc220b220d.png">
2022-12-13 11:12:16 +11:00
Kaya Gökalp
3bb4e13b88
fix: reserved keywords are checked before creating dir with forc new (#3566) 2022-12-10 19:01:04 +00:00
Kaya Gökalp
6a16540feb
Include test function span information (file, line number) in forc test output (#3546) 2022-12-09 15:54:29 +11:00
João Matos
487770f695
Adds a new forc build flag to print the DCA graph. (#3493)
This adds a new `--print-dca-graph` to `forc build` which allows the
user to print the DCA graph.
2022-12-02 16:48:25 -05:00
Emily Herbert
12ad842381
Bump to v0.31.3 (#3479)
Co-authored-by: emilyaherbert <emily.herbert@fuel.sh>
2022-11-30 14:57:21 -06:00
Kaya Gökalp
01f2a71318
feat: forc command to init/new workspace (#3418)
closes #3405.
2022-11-30 23:24:44 +08:00
Mohammad Fawaz
12239f7d57
Bump to v0.31.2 (#3461) 2022-11-29 11:59:43 -05:00
Mazdak Farrokhzad
fe6b76e2c4
Nix the global TYPE_ENGINE (#3353) 2022-11-22 18:06:39 +00:00
Mohammad Fawaz
c32b0759d2
Bump to v0.31.1 (#3352)
Waiting on:
- [x] https://github.com/FuelLabs/sway/pull/3343
2022-11-11 20:55:57 -05:00
Mohammad Fawaz
7a389ddb35
Bump tov0.31.0 (#3335)
Also ran `cargo update`

Co-authored-by: Voxelot <brandonkite92@gmail.com>
2022-11-09 19:32:10 -05:00
mitchmindtree
aa56f73056
Add initial unit testing documentation to the Sway book (#3309)
This is a minimal start at documenting the Sway unit testing feature
provided via `forc test`.

We should continue to extend this as we land new features like contract
calling, dev-dependencies, `#[test(should_revert)]`, etc.
2022-11-07 21:51:34 +00:00
Mohammad Fawaz
dff5e4f0df
Bump to fuels 0.30 and fuel-core 0.14 (#3304) 2022-11-06 02:59:34 +00:00