Commit graph

20 commits

Author SHA1 Message Date
SwayStar123
a5d9d2835f
Merge std and core libraries (#6729)
## Description
Merges the two libraries. They were initially separate to separate the
core logic and fuel vm specific functionality, but that separation is no
longer maintained so having a merged library is better.

Closes #6708

## 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] 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.

---------

Co-authored-by: Sophie <47993817+sdankel@users.noreply.github.com>
Co-authored-by: Igor Rončević <ironcev@hotmail.com>
2025-03-12 23:52:38 +01:00
Daniel Frederico Lins Leite
1aec319e31
set new encoding as true by default and allow it to be disabled (#5915)
## Description

This PR sets the "new encoding" (from now on will be called "encoding
v1") as the default. We can still disable it using `no_encoding_v1`,
which switches back to "encoding v0".

Actions that needs to be done after this being merged will exist in
https://github.com/FuelLabs/sway/issues/5727

New features
  - ABI Super traits;
  - AbiEncode buffer dynamic sizing;

Bugs Fixed
- `ContractCall` intrinsic interaction effect was not set correctly;

Fixing warnings and error messages
- Better error message when core-lib is not available for
scripts/contracts/predicates;
- Better error message when main inputs/outputs are unknown or error
types;
- Better error message when main inputs/outputs do not implement
AbiEncode/AbiDecode;
- Don't warn impurity attributes on the "__entry" fn;
- Don't warn CEI on the "__entry" fn. Our CEI analysis, currently, does
not recognize `Never`. This means it does not realize it is impossible
to call two contract functions;

Test Disabled (needs to be enabled again in the future)
- should_pass/language/name_resolution_after_monomorphization
- should_pass/language/shadowing/shadowed_glob_imports
- should_pass/language/name_resolution_inside_intrinsics
- sdk-harness/external_proxy test is not working. I am assuming it is
the LDC bug that is already fixed on version 0.25. What is happening is
that the literal "double_value" has the correct length, but some random
data. Which makes the method selector fails. Only after we call LDC. The
proxy contract is working.

Test generating more warnings than before
- should_pass/dca/contract/superabi_contract_calls
What happens here is that when we implement a trait for `Contract`, we
actually generate two functions: one prefixed `__contract_entry` that is
called by the method selector; and another one normal, that can be
called freely. So, if the trait method is never called manually, it is
marked as dead.
- should_pass/dca/contract/abi_fn_params
I actually think the new warning is correct and nothing here needs to be
done.

Test with fewer warnings than before
- should_pass/dca/unused_fields
auto-impl is making all fields being used. so no dead code warnings are
being generated. We need to fix this.

Changes to std-lib
- Functions that return data about call context changed the semantic.
`first_param` and `second_param` return the value as the VM sees them.
We now have `called_method` and `called_args`. This means that we can
change the protocol later and still keep these four functions always
working and with meaningful names.
- 
- predicate_data also was updated to use encoding v1 protocol.

ICE
- increase_buffer_if_needed implementation is a little bit strange
because does not work as a method inside `Buffer`. For some reason, it
is generating an ICE. I need to create an issue so we can fix, and
improve the implementation here.
- `Buffer` used by AbiEncode needs a `push_bytes` so we can be more
efficient when encoding Bytes and others.

## 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] 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.
2024-04-25 20:37:50 +04:00
mitchmindtree
4ffa867b3d
refactor: Move the examples workspace manifest into examples directory. Use it in CI. (#4145)
## Description

This moves the examples workspace manifest introduced in #4118 into the
`examples/` directory and cleans it up a bit.

We also now integrate the examples workspace into CI, making the old
`examples-checker` script redundant. This old script is also removed as
a part of this PR.

## 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-21 11:15:29 +11:00
Mohammad Fawaz
d613be1f8f
Update lock files for all examples (#3307) 2022-11-06 20:29:02 -05:00
Mohammad Fawaz
cfecaf4c40
Generic trait From<T> in the standard library (#3241)
Closes #1078 

* New trait `From<T>` in a new library called `convert.rs`
* Most changes are trivial
* Added `From` to the prelude
* Had to modify `from()` in `U128`, `U256`, and `B512` to take a tuple
of components instead of multiple arguments to conform to the trait.
This is a breaking change of course.
* Updating lock files for all the examples.
2022-11-02 15:41:06 +00:00
Nick Furfaro
f1632e5437
Furnic/revert b256 add (#1961)
* feat: Implement Add for b256

* modify: make U128 functions public

* feat: add b256_ops module to stdlib

* docs: add comments

* reorganize: move b256_ops tests to e2e harness

* test: stuff

* refactor: cleanup unneeded mut variables

* feat: add core-utils lib

* fixup

* refactor: use new lib for compostion

* chore: fix manifest project name

* refactor: rename module to compose

* cleanup

* refactor: rename to core_utils

* fixup

* chore: rename new lib and update manifests

* test: fix last assert

* docs: add module level docs

* fixup

* chore: remove and rebuild for lock files

* fixup

* test: cleanup

* chore: rebuild basic_predicate

* chore: rebuild

* fix: restore test project

* fix: add oracle file

* chore: rebuild sdk-harness tests

* Revert "Implement Add for b256 (#1707)"

This reverts commit 560ca4b4c6.

* chore: rebuild lockfiles
2022-06-13 16:05:16 -05:00
Nick Furfaro
560ca4b4c6
Implement Add for b256 (#1707)
* feat: Implement Add for b256

* modify: make U128 functions public

* feat: add b256_ops module to stdlib

* docs: add comments

* reorganize: move b256_ops tests to e2e harness

* test: stuff

* refactor: cleanup unneeded mut variables

* feat: add core-utils lib

* fixup

* refactor: use new lib for compostion

* chore: fix manifest project name

* refactor: rename module to compose

* cleanup

* refactor: rename to core_utils

* fixup

* chore: rename new lib and update manifests

* test: fix last assert

* docs: add module level docs

* fixup

* chore: remove and rebuild for lock files

* fixup

* test: cleanup

* chore: rebuild basic_predicate

* chore: rebuild

* fix: restore test project

* fix: add oracle file

* chore: rebuild sdk-harness tests
2022-06-10 18:24:27 -07:00
mitchmindtree
fb4bc7a8ef
Disambiguate path dependencies using the ID of the package at the path root (#1790)
* Disambiguate `path` dependencies using the parent package ID

Implements and closes #1789.

TODO:

- [x] Disambiguate `path` dependencies using parent package ID.
- [ ] Impl `Display` and `FromStr` for `PinnedId` to convert it to and
  from hex for path source string in lock file.
- [ ] Address #1637 now to reduce this PR adding even more noise in the
  lock file `dependencies` lists.
- [ ] Refactor `fetch_deps` slightly to better accomodate new `Root`
  source variant.
- [ ] Update lock files of all examples and tests in repository.

* Swap `ToString` impls for `Display`. Add `PinnedId` impls.

Also removes the `lock::source_from_str/source_to_string` impls in
favour of implementing `Display` and `FromStr` for `SourcePinned`.

* Only disambiguate pkg lock dependencies if the name requires it

Closes #1637.

* Update new add_deps function for changes applied to pin_pkg

* Fix path dependency disambiguation using a path root rather than parent

Improves path dependency disambiguation by using the ID of the package
that is the root of the subgraph of path dependencies.

* Update `examples` forc lock files for path disambiguation changes

* Update E2E test forc lock files for path disambiguation changes

* Update stdlib test lock files for path dependency disambiguation changes

* Update new lock files introduced since previous rebase
2022-06-08 16:14:48 +10:00
Mohammad Fawaz
8b7665c22b
Update Sway book examples to use new features (#1208)
* Updated counter, hello_world, and wallet_smart_contract

* subcurrency

* fizzbuzz

* changes to the docs

* addressing comments

* revert a small change to the Sway book... to be made in a separate PR
2022-04-11 10:13:57 -04:00
mitchmindtree
fbdce29268
Merge sway-lib-core and sway-lib-std into this repository (#1052)
* Initial commit

* Initial commit

* initial commit

* intial commit

* update manifest to use git core dependency

* add README

* Add README

* Fix link to forc (#1)

* Fix link to forc (#1)

* Add basic build CI workflow (#2)

* Add basic build CI workflow.

* Remove installation and use of fuel-core.

* Implement Modulo (#3)

Added "modulo" function so the % operator works

Very simple implementation to all the other functions just wrapping the mod opcode

* .gitattributes to highlight .sw syntax as rust (#3)

* .gitattributes to highlight .sw syntax as rust (#5)

* Add Result type (#6)

* Add Result type.

* Fix syntax.

* Add basic build CI workflow. (#8)

* Add in rsh and lsh operations (#6)

* Update ops.sw

* Weird spacing thing

* ec-recover (#5)

* Add ecr lib

* Add todo comment

* Add recover_pubkey and refactor ecr

* Fixup

* Update comments

* Add comments to ec-recover asm block

* Modify asm

* Clean up asm

* Fix B512 field assignment

* Fix ordering of lib deps

* Remove ec_recover, to be added in separate PR

* Clean up comments

* Adding the missing `ec_recover`functionality (#18)

* Add todo comment

* Add working ec_recover implementation

* Format manifest file. (#10)

* Adding the `mint` and `burn` token operations. (#26)

* Add token lib

* Add todo comment

* Rename token_id to asset_id

* Rename token_id to asset_id

* Rename token_id to asset_id

* Fix register names in asm block

* Fixup

* Refactor ugly  while loop

* Fixup

* Remove ecr from branch

* Fix review issues

* Modify type definition to silence warning re losing precision via type-cast

* Fix asm block registers

* Add only the mint function

* Ad burn to token lib

* "fix toml file"

* Split `eq` out of `Ord` and put it in `Eq` (#9)

* Moved eq into its own trait (Eq)

Moved eq into it's own trait (Eq) and then added all the implementations for u64, u32, u16, u8, and b256

* Forgot to delete u16's old Eq implementation

* Move le to a test implementation

* Fixed ge, le, and neq to not use eq and instead use inline assembly

* Update ops.sw

* Formatting changes

* Adding the force_transfer function to the token lib. (#27)

* Add force_transfer function to token lib

* Add import of ContractID type

* Implement the Eq trait for Address (#25)

* Impl Ord for Address

* Fix todo comment

* Fix toml formatting

* Add comment to use meq

* Impl Eq for Address

* Fix formatting

* Remove todo

* Add more methods to Result. (#16)

* Add more methods to Result.

* Don't use catch all.

* Use catch up, but fix typo.

* Fix return type.

* Compile workarounds.

* fmt

* Remove todo comments.

* fmt

* Make Result public.

* Add Option type & is_some/is_none methods (#31)

* Feat:Add Option type & is_some/is_none methods

* Doc:Improve module-level docs

* Fix:Add generic type T to match

* Simplify the B512 (and therefore ECR) code. (#33)

* Simplify the B512 (and therefore ECR) code.

Instead of 2 b256 fields in a struct we can use a 2 element array
instead.

I found that both the assumptions about memory layout and all the
copying was producing brittle code, and simplifying the ASM blocks as
much as possible is a good thing.

* Do a `forc fmt`.

* Adding the transfer_to_output function to token library (#32)

* Add force_transfer function to token lib

* Add import of ContractID type

* Add transfer_to_output function to token lib

* Add imports and temp remove constants

* Add else clause to if branch

* Add better comment

* Add final else clause to if branch

* Add semicolons to if-else

* style: add a comment and remove trailing semicolon from if statement in return position

* fix: make some comments internal

* fix: re-enable constants

* fix: change OUTPUT_LENGTH_LOCATION from 48 to 56

* fix: clean up assembly and incorporate PR review feedback

* docs: fix comments to reflect change to OUTPUT_LENGTH_LOCATION

* fix: remove redundent local variable assignment

* refactor: split asm blocks to avoid a second usage of the xos opcode

* style: forc fmt

* fix:change offset to 40 for getting amount

* Implementing an initial version of a msg_sender function (#30)

* Add module level docstring description

* Rearrange lib.sw order

* Use result type and add Sender type

* Improve function documentation

* refactor: improve clarity by removing the ! operator

* refactor: pass in constants to asm blocks

* fix: remove redundent `dep address;` from lib.sw

* fix: switch consts to enum

* refactor: revert to using constants for now but added TODO

* Minimal viable test harness for the stdlib (#37)

* config:update gitignore to ignore all tagket dirs

* feat:add working demo of test harness

* fix:add modules

* Add new demo_script_test project

* build:update dep versions in manifest files

* fix:update code in mod and main

* fix:change author email

* fixup

* fix:use local path to ttest current stdlib

* test:remove dummy test

* cleanup:remove dummy tests in prep for merge

* style:cargo fmt

* Porting token ops tests to the new stdlib test harness (#42)

* test:add token-ops tests

* test:update structure

* test:add more test

* test:adds more comments to failing tests

* test:remove failing tests from PR

* style:cargo fmt

* stle:forc fmt

* style:fix formatting I missed

* test:cleanup and remove logs

* bugfix: remove second register from gm opcode (#46)

* fix:remove second register from gm opcode

* docs:add link to gm opcode spec

* Add out directory to gitignore. (#50)

* Implement Square Root into the Standard Library (#49)

* Implement Square Root Function for uint types

* Update math.sw

* Update lib.sw

* Update math.sw

* Update math.sw

* Update math.sw

* Add Square Trait to uint

* Fix fmt

* Update math.sw

* Update math.sw

* Bump test dependencies. (#52)

* Bump test dependencies.

* Remove patch version.

* Use `t` instead of `T` for `Result` matches. (#53)

* Use t instead of T for Result matches.

* Update option.sw

* change author to authors in Forc.toml (#11)

* change author to authors in Forc.toml files (#56)

* switch from matches to if lets for enum destructuring (#62)

* switch from matches to if lets

* fmt

* Temporarily remove the Option and Result implementations (#63)

* fix:temp removal of result & option implementations

* fix:remove option & result from lib.sw

* fix:remove import of Result & change return type of msg_sender temporarily

* Fix return types of context::contract_id & context::msg_asset_id (#59)

* style:fix weird forc fmt issue

* fix:correct the return type for context module funcs

* test:add contract and json abi file

* test:add module to harness

* build:add manifest file

* test:add tests for context module

* style:forc fmt

* style:cargo fmt

* style:formatting

* fix:remove context test_project, coming in follow-up PR

* style:forc fmt

* Update token ops tests (#64)

* cleanup:remove duplicate abi

* build:update deps for sdk

* build:bump fuels-rs versions

* fix:remove salt field

* test:update to use newest syntax

* style:cargo fmt

* Adding a registers.sw module (#61)

* feat:add bare module registers

* feat:add registers.sw to expose16 reserved registers

* test:add new test project "registers"

* build:update forc manifest file

* test:add contract and abi.json

* test:add test file and empty tests

* test:temp disable ret & retl, add simple tests

* test:enable ret & retl again

* build:update manifest authors field

* build:remove redundant abi file

* fix:remove unneeded zero and one functions

* fix:remove zero and one funcs from abi and contract

* test:remove tests for zero and one & updates paths to abi file

* test:fix expected values and function calls

* style:forc fmt

* fix: add dep registers to context.sw

* style: forc fmt

* build:bump sdk version and add fuels-signers as a dep

* update tests to use new syntax

* style:cargo fmt & forc fmt

* Avoid implicit cast warning (#65)

* avoid implicit cast warning

* minor variable naming change

Co-authored-by: Mohammad <mohammad@Mohammads-MacBook-Pro.local>

* Fix test formatting. (#51)

* Ignore Forc lockfile (#69)

* Use new contract call syntax. (#70)

* Use new contract call syntax.

* Missed one

* Make core branch explicit (#71)

* Make core branch explicit

* Update Forc.toml

* fix:correct inline docs for registers.sw (#72)

* Fix some `path`s in the test project dependencies (#73)

The `path`s of dependencies should be point to the directory containing
the dependency's `Forc.toml` (not the `src`). This commit fixes the
`Forc.toml`s of the test projects to account for this.

There was also a spuriuos Forc.toml at `tests/Forc.toml` which has been
removed.

* Rename param in the ContractId::into() implementation (#76)

* fix:rename param

* docs:update comment and link tracking issue

* fixup

* Prefer `https` over `http` for forc git dependency URLs (#77)

This helps to resolve some dependency double-ups pending a proper
solution fix in `forc`.

See https://github.com/FuelLabs/sway/issues/931 and https://github.com/FuelLabs/fuels-rs/pull/150#discussion_r825312119

* Add `out` and `Forc.lock` to gitignore (#13)

* Bump SDK version (#78)

* build:bump SDK and dep versions

* test;update tests to use new SDK version syntax

* style:cargo fmt

* build:add fule-vm as a dep

* test:add an is_within_range() function to avoid hardcoded vals

* style:cargo fmt

* Rename ETH_ID to NATIVE_ASSET_ID (#79)

* b256 -> contractId params for context functions which get balance from a contract (this or other) (#81)

* hotfix:complete param type changes (#82)

* Implement the `EQ` trait for `ContractId` (#83)

* feat:impl eq for ContractId

* test:add test project for contractId eq implementation

* test:wip on sscript test

* test:add script call draft

* test: finish script test

* test:finish test for contractId eq impl

* fix: remove comment

* style: cargo fmt

* build:remove core as unneeded dep

* Change `[project]` name from `lib-std` to `std` (#80)

See https://github.com/FuelLabs/sway/issues/977 for motivation.

* bump sdk to 0.7. Use test-helpers to cut down on boilerplate (#84)

* Cleanup stdlib tests (#85)

* cleanup: remove compiler warnings

* style: cargo fmt

* Adding a call_frames module (#66)

* test:add new test project call_frames

* test:add bare call_frames module

* feat:add initial call_frames.sw module

* feat:add new call frame access constants

* feat:add call_frames.sw and refactor context mod

* fix:reorder lib.sw

* style:cleanup comments'

* style:forc fmt

* refactor:reorganize functions by module and expose under context namespace

* cleanup:remove unneeded files from test project

* test:add initial draft test

* test:add first test

* temp:remove use of constants

* test:setup test project and artifact for call_frames

* test:outline primary tests

* test:fix test assertions

* cleanup:remove helper functions from call_frames until they can be tested

* style:cargo fmt & forc fmt

* test:cleanup forc tomls

* test:use new contract call syntax

* fix:update return types for call_frames functions

* test:update to SDK v 0.6

* test:update tests

* style: cargo fmt

* fix:rename var to satisfy compiler

* style: forc fmt

* cleanup: remove unused CONSTs until needed

* build: remove core as a dep

* Disable default features from fuel-core (#86)

* Implement Eq for bool (#14)

* Re-add Option and Result. (#68)

* Re-add Option and Result.

* Re-add to auth.

* fmt

* Fix option and result, and add tests.

* Remove redundant gitignores.

* Fix tests.

* Fix to actually compile.

* Fix function naming.

* Fix test.

* Add missing semicolon.

* move option dep up

* Add `Result.unwrap()` (#90)

* Refactor panic into separate library.

* Update tests to use new panic.

* Implement unwrap.

* Add test.

* Add Option.unwrap() (#91)

* Bump fuels-rs to v0.8 (#92)

* Refactor the context module & port tests to SDK (#89)

* test:add new context test project

* test:add context module to harness

* test:add context testing contract and abi

* test:add context_testing_abi

* test:add the first tests

* test:fix contract path

* refactor:context.sw balance functions now use a common balance func

* test:add context_caller_contract to test_artifacts

* temp:ignore failing tests

* reorg:remove tests which belong elsewhere

* build:fix manifest fields

* test:add get_global_gas to context contract

* test:update context_testing_abi

* test:update context_caller abi & contract

* test:add and fix tests for context

* fix:fix types in context module

* build:cleanup/fix forc toml files

* test:cleanup types & contract calls

* build:update deps in cargo toml

* fix:update types in token_ops

* test:update to new sdk version

* test:update import paths to use .bin files

* test:update more tests to use new build path and comparison values

* test:cleanup

* fix:update contract call in caller contract

* test:fix test call to use correct contract

* build: bump SDK to 7

* style: forc fmt

* style: forc fmt

* test: refactor & bump to SDK 7

* style: cargo fmt

* test: update SDK usage to use latest features

* test:work on fixing tests

* improvement: rename contract_id to target

* fix: rename balance() and refactor imports

* style: use multi import syntax

* test: refactor test helper funcs

* test: fix function call names

* refactor: rename functions for clarity

* test: remove use of helper funcs bc/ContractNotFound

* style: cargo fmt

* fix: add gas param to all inter-contract calls

* test: refactor helper to share provider

* fix: update abis and contracts

* test: fix balance test

* fix: remove minting from contract functions

* test: add minting step to tests

* test: cleanup tests

* test: get all tests passing

* test:remove failing duplicate test

* style: cargo fmt && forc fmt

* build: remove core as a dep

* refactor: balance reg & balance_of funcs

* fix: update function names in contracts

* style: forc fmt

* test: fix tests by removing call_params

* style: cargo fmt

* cleanup: remove all compiler warnings

* Walk git dependency repo to discover nested forc dependencies

Closes #952.

This should be complete for the most part, though depends on implementing #977 first.

* Remove implied pkg from names of pkg discovery fns

* Update `Cargo.lock` for the addition of `walkdir`

`walkdir` is used to traverse the git repository when searching for
dependency packages.

* Change `std`'s `core` dep to use the local path

Yet to test whether `forc` can handle `path` dependencies within
dependencies. In theory I these should work provided that the `path` is
relative and points to a location within the same git repository. If
this *does* work, the behaviour should be discussed, documented and
enforced by `forc`.

* Update examples `std` dependency declarations to use local `path`

* Update all tests to depend on `std` via local `path`

This should assist in ensuring that all tests must always pass for any
change to `sway`, `lib-core`, `lib-std` or `forc`.

* Build sway-lib-core and sway-lib-std under unique CI jobs

* Add successful `sway-lib-core` and `sway-lib-std` reqs for publish

* Add tx module. (#93)

* Add tx module.

* Add functions.

* Clean up.

* Add skeleton test artifact project.

* Use hard-coded constants since compiler can't handle consts.

* Fill in skeleton.

* Make untested get typed script data non-pub.

* Add output functions.

* Comment out unreachable.

* Improve name.

* Add remaining functions.

* Fix name.

* Register tests to harness.

* Add tests.

* Fix script start offset test.

* Fix script start offset get.

* Fix test with todo.

* Add non-working test for input coin owner.

* Return wallet.

* Fix test.

* Update transfer to output (#94)

* fixing transfer_to_output

* Update transfer_to_output

* Improving a comment

* fmt

* Auth method 3 (#54)

* Add changes from prior work

* Remove import of ops

* Cleanup and format

* Rename functions to match opcode naming

* Re-order lib.sw

* Fix types to use ContractId

* Refactor and cleanup

* Reorder lib.sw

* Clean up comments and types

* FIx lib deps ordering

* cleanup

* congig:update gitignore

* Commit stashed changes with get_coin_owner WIP

* Fix:cleanup merge conflict resolution mistake

* Clean up a bit and use Result.

* General cleanup.

* Improve comment.

* Fix a bunch of type errors.

* Add missed assert.

* Fix order to make compile.

* Refactor.

* fix

* Fix build errors.

* Update offsets for 255 max inputs.

* Remove warnings.

* Improve error name.

* Fix some asm.

* Fix more asm

* space

* Fix comment

* Fix offsets.

* Refactor to use new tx module.

* test: add auth test project

* test: register auth tests

* test: add tests to mod.rs

* test: add auth testing abi & contract

* test: add auth caller contract & script

* test: fix enum variant name

* test: fix import of result

* test: refactor types to workaround MissingData error from SDK

* test: fix number of args passed

* test: ignore script test

* style: forc fmt

* style: cargo fmt

* test: work on script test

* Remove redundant assert.

* Clean up tests, not working yet.

* Fix test for some reason.

* Fix test.

Co-authored-by: Nick Furfaro <nfurfaro33@gmail.com>

* Update path to assert (#97)

* test: update path to assert

* Delete build.sh

Added by accident.

* test: remove redundant test (#99)

* Update examples and tests for chain::assert -> assert::assert

* Update newly merged test for chain::assert -> assert::assert

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: ControlCplusControlV <44706811+ControlCplusControlV@users.noreply.github.com>
Co-authored-by: wolflo <33909953+wolflo@users.noreply.github.com>
Co-authored-by: Nick Furfaro <nfurfaro33@gmail.com>
Co-authored-by: Toby Hutton <toby@grusly.com>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: Mohammad <mohammad@Mohammads-MacBook-Pro.local>
Co-authored-by: Simon Roberts <46566889+simonr0204@users.noreply.github.com>
Co-authored-by: Brandon Kite <brandonkite92@gmail.com>
2022-03-29 12:30:23 +11:00
mitchmindtree
cf5c3d1fe1
Improve support for git reference kinds (branch, tag, rev), improve fetching behaviour (#1045)
* Add proper support for git reference kinds (`branch`, `tag`, `rev`)

Works toward resolving #1019, however tests and examples still need to
be updated.

Previously, we initialised the temporary git repository with a `clone`
operation. By default, this only fetches a subset of git references,
meaning that using references other than those provided by default with
`clone` failed to resolve.

Inspired by cargo, this commit updates the behaviour to instead first
initialise the repository, then attempt to fetch only those references
that are relevant to the user specified git reference.

In order to construct an accurate set of `refspecs` and fetch only the
relevant commits, its useful to retain knowledge about the *kind* of git
reference. This introduces a new `GitReference` type and updates the git
source lock file serialization to account for this.

* Update example `Forc.lock` files for git reference changes

* Update E2E test `Forc.lock` files for git reference changes

* Validate the commit hash while parsing `SourceGitPinned` from str
2022-03-28 15:05:13 +11:00
John Adler
437ed137c3
Remove unused Rust files for examples. (#1040) 2022-03-27 14:15:09 -04:00
Ren
804a1fbf8b
Reorganize Sway docs and compress some sections (#980)
* Add instructions to show how to link the libraries

* Reorganize docs

* Add comments and logging

* Remove the missing else syntax

* Remove the println statements

* Cast address

* Update docs/src/sway-program-types/libraries.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update docs/src/basics/control_flow.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update docs/src/basics/comments_and_logging.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update docs/src/basics/comments_and_logging.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update docs/src/basics/comments_and_logging.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update docs/src/sway-program-types/smart_contracts.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update examples with Address and ContractId

* Comment out storage syntax section

* Fix subcurrency example so it builds

* Constants cannot be addresses right now

* Update docs/src/basics/control_flow.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update docs/src/basics/control_flow.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update docs/src/basics/comments_and_logging.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update docs/src/basics/control_flow.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update docs/src/reference/rust_differences.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update docs/src/basics/control_flow.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update docs/src/sway-program-types/index.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update control flow and make small edits

* Update examples/subcurrency/src/main.sw

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update docs/src/basics/methods_and_associated_functions.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update docs/src/basics/control_flow.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update docs/src/basics/control_flow.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update docs/src/basics/control_flow.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

* Update docs/src/sway-program-types/libraries.md

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>

Co-authored-by: Yiren Lu <yirenlu@Yirens-MBP.lan>
Co-authored-by: Yiren Lu <yirenlu@Yirens-Mac-mini.local>
Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
2022-03-25 14:00:19 -04:00
John Adler
6ea31817fc
Remove core dependency from example projects. (#991) 2022-03-22 13:45:45 -04:00
John Adler
7be6efacde
Use https for std and core deps. (#984) 2022-03-22 12:01:54 +11:00
mitchmindtree
46a62d7c9b
Update examples and E2E tests to use master branch of std, core (#876)
* Update examples and E2E tests to use master branch of std, core

This speeds up the E2E tests quite a bit, as previously many of them
compiled two versions of `core` (e.g. `v0.0.1` as listed in
`[dependencies]`, and `master` via the `std` dependency).

Many tests have also had declared dependencies removed where unnecessary
and irrelevant to the test.

I did run into a couple issues:

- I was unable to update `b512_panic_test`, `b512_test` and
  `empty_method_initializer` as the `lo` and `hi` bits fields no longer
  appear to be accessible on the `b512` type. For now I've left these
  pinned to the old versions.
- The `context_testing_contract` test fails with: expected: `b256`, found:
  struct `ContractId<b256>`.

Closes #875.

* Fix `context_testing_contract` E2E test

* Fix type mismatch in caller_context_test assertions due to new ContractId type

* Update b512-related tests for removal of lo, hi fields in favour of bytes

* Fix missed `key` -> `KEY` change in `increment_contract` when rebasing
2022-03-07 16:44:41 -05:00
mitchmindtree
45250e46d5
Add forc BuildPlan. Change GitHub dependencies to general git support. Add Forc.lock for more deterministic builds. (#825)
* Construct `pkg_graph` at beginning of `forc build`

This is a start at separating the construction of the dependency graph
and fetching of dependency source from the compilation process. This is
done under a new `fetch_pkgs` function where, given the manifest of the
package we're compiling, it produces a graph where each node represents
a package at a known, pinned version/commit along with a `Path` to a
local copy of their source (under `.forc/git/checkouts` for git deps).

The `pkg_graph` also contains our root-level package, allowing us to
treat all packages in the compilation process as equal, avoiding special
case code for the top-level program.

The compilation order of packages is determined by performing a toposort
of the `pkg_graph`. By compiling packages in this order, each node is
always guaranteed to have access to the compiled artifacts of each of
its dependencies.

This PR also introduces the `git2` crate for fetching and working with
git dependencies. This should allow us to remove the current
github-specific dependency handling in favour of more general git
support.

---

I think the next step in this PR will be replacing the existing
`dependency_graph` mutable hash map reference with an immutable
reference to the newly constructed `pkg_graph`. It seems this may also
involve populating the `Namespace` prior to the rest of compilation too?
I'm still familiarising myself with `sway-core`, so will need to dive a
bit deeper to be sure.

* Replace old dependency compilation with new `pkg_graph` approach

This removes the old dependency-specific compilation logic in favour of
flattening the graph into a list of compilation steps and using the same
`compile_pkg` function to compile all packages, including at the
top-level package.

* Move `pkg`-specific code into a new `pkg` submodule

* Address cargo fmt and clippy nits

* Remove implied pkg from idents in pkg submodule

* Add support for specifying git dependency via tag

* Fix dependency path handling to be relative to parent

* Remove github-specific logic in favour of new git pkg handling

See #829.

This also temporarily disables `forc update` and the related
`forc_dep_check` module pending more general `git` support and
committing updates to a `Forc.lock` file.

* Improve support for determinism and cachability with `Forc.lock`

This adds a `Forc.lock` file that for the most part mirrors the
`Cargo.lock` file.

If a `Forc.lock` doesn't exist, a `Lock` structure is created from the
package graph and serialised to TOML before being written to the
`Forc.lock` file path.

If a `Forc.lock` *does* exist, we construct the build graph from the
`Lock` structure, re-using the previously fetched source for the pinned
dependencies.

TODO:

- Make `forc update` update the lock file.
- Add support for updating individual packages.

* Move `BuildPlan` under `pkg` module in anticipation for `forc update`

* Update `forc update` for lock. Print removed and added deps.

A new `lock::Diff` type is added to collect added/removed packages.

* Address doc comment nits

* Validate `Lock` in accordance with `Manifest`

This ensures that if any `Forc.toml` dependencies are added, removed or
modified, the change is detected during `forc build` and the `Forc.lock`
file is updated accordingly.

* Improve formatting of `Forc.lock` related stdout

* Update sway-core petgraph version so that it matches forc

* Update test and examples to pin via git tag rather than version field

Addresses #829.

Also allows for putting off #831 while we discuss #830.

* Update some E2E tests due to unpinned `core` dep in `std`

None of the `std` releases so far pin `core` to a version. As a result,
it pulls the `core` master branch by default, despite the top-level
project also dependending on `core` at a specific version. Most E2E
tests seemt to work regardless, but this subset requires updating.
Following the lock file work landing, we should update versioned `std`
releases to refer to versioned `core` via git tag.

* Only fetch pkgs that are missing, rather than whole pkg graph

Previously if any of the pkgs that exist in `Forc.lock` were not already
available in `~/.forc/git/checkouts`, we would update the entire lock
file and re-fetch all dependencies. Now, if the local copy of a pkg is
missing, we just fetch that individual pkg and continue.

This commit also updates the `fetch_pkgs` code to re-use pre-fetched git
commits. Previously, all packages would be re-fetched when the
`Forc.lock` file was updated. Now, we only fetch if the path for that
commit doesn't already exist.

* Update forc git dep from 0.13 to 0.14

* Fix forc Cargo.toml dependency order

* Update Cargo.lock for the addition of git2, petgraph

* Add Forc.lock files for sway examples

* Ensure `Namespace` only contains a package's dependencies

Previously one namespace was used to collect *all* items. This meant
that when passed to the package that was being compiled, the namespace
contained not only the names for its dependencies, but sometimes other
unrelated names that happened to be earlier in the compilation order.

This commit fixes this issue, creating a fresh namespace purely for each
package in order to collect only its dependencies. This fixes some
shadowing errors that were appearing in the E2E tests.

* Pin tests by adding their `Forc.lock` files for reproducibility

As a follow-up, we should update all of the tests to depend on `master`
and then update the lock files. This will save us from having to change
versions tags to pin all the time.

Note: You can clear all test lock files with

```
rm ./test/src/e2e_vm_tests/test_programs/*/Forc.lock
```

* Temporarily warn about `version` field in dependencies

We no longer use the GitHub REST API and in turn no longer map the
`version` field to GitHub "release"s. Instead, we now support git more
generally. Warn about appearances of the `version` field in dependencies
and suggest using `branch` or `tag` as an alternative.

* Address nits uncaught in anyhow PR review

* Fix formatting following rebase onto forc anyhow PR
2022-03-04 14:34:27 +11:00
Joshua Batty
2c14dc6a3f
change Forc.toml to take an array of authors (#822)
* change Forc.toml to take an array of authors

* author and authors are optional. added deprecation notice to author

* removed duplicate entry fields
2022-02-28 13:05:13 +11:00
Emily Herbert
6faf43f863
CI is failing because the examples are trying to use a version of the standard library that is too advanced. (#839) 2022-02-24 15:41:22 -06:00
mitchmindtree
e10acd64b6
Move book examples into standalone projects. Include them in book via mdbook preprocessor. (#766)
* Extract `hello_world` example from the book into a standalone project

Related to #544.
Follows the example set in #731.
Tested with `mdbook serve`.

Also adds the `hello_world` and `subcurrency` examples to the Sway
workspace so that we can test both projects under CI.

* Fix hello_world example project name in forc manifest

* Move fizzbuzz and wallet_smart_contract examples to standalone projects

* Add `build-all-examples` script and associated CI passes

This script walks the examples directory and, for every directory
containing a `forc.toml` file, runs `forc build` for that directory.
Examples that encounter a failure of some kind have their `stdout` and
`stderr` piped through so we can easily identify cause of failure in CI.

This also removes the examples from the workspace.

Currently unsure whether or not the added CI pass to install `forc` will
result in `forc` actually being available on the PATH in the CI worker,
but will find out soon.

Still need to work out how to run `forc test` for each project without
having cargo complain about building within the parent sway workspace.

* Add a clear build summary at the end of `build-all-examples`

Currently, it's tricky to get an idea of how many successes/failures
there were without combing through the stdout/stderr. This adds a little
summary to the end that looks something like this:

```
Build all examples summary:
  [✓]: /home/mindtree/programming/rust/fuel/sway/examples/fizzbuzz succeeded!
  [✓]: /home/mindtree/programming/rust/fuel/sway/examples/hello_world succeeded!
  [x]: /home/mindtree/programming/rust/fuel/sway/examples/wallet_smart_contract failed!
  [✓]: /home/mindtree/programming/rust/fuel/sway/examples/subcurrency succeeded!
3 successes, 1 failure
```

* Set build-all-examples script version to 0.0.0

* Exclude examples from workspace, Fix hello_world test harness path

* Temporarily comment out storage related code in wallet example

This example should be updated after #646 lands.

* Install forc with `--debug` to share build artifacts

Currently it takes CI another 7 mins to build and install forc from
scratch. This should allow `cargo` to re-use the artifacts it has
already built during the sway building and testing steps earlier in the
CI job.

* Change author field in examples from mindtree -> Fuel Labs
2022-02-15 11:53:48 +11:00