From 3f99163eaa3bd7c233c552acf82f59c26aad68ca Mon Sep 17 00:00:00 2001 From: Sophie Dankel <47993817+sdankel@users.noreply.github.com> Date: Fri, 7 Jun 2024 12:56:09 -0700 Subject: [PATCH 1/4] fix: remove Forc.lock files from template projects (#6101) ## Description These projects are used as templates in `forc template` and having the lock files as part of the template could cause issues. The lock file should be generated on the fly by forc. ## 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. --- .gitignore | 3 ++- .../blockchain-development/access_control.md | 4 ++-- .../blockchain-development/native_assets.md | 22 +++++++++---------- docs/book/src/introduction/sway_standards.md | 22 +++++++++---------- docs/book/src/reference/sway_libs.md | 4 ++-- .../access-control/ownership/Forc.lock | 13 ----------- .../src/code/examples/counter/Forc.lock | 13 ----------- .../src/code/examples/fizzbuzz/Forc.lock | 13 ----------- .../code/examples/wallet_example/Forc.lock | 13 ----------- .../language/program-types/predicate.md | 2 +- sway-lib-std/src/alloc.sw | 2 +- sway-lib-std/src/call_frames.sw | 8 +++---- swayfmt/tests/mod.rs | 4 ++-- 13 files changed, 36 insertions(+), 87 deletions(-) delete mode 100644 docs/reference/src/code/examples/access-control/ownership/Forc.lock delete mode 100644 docs/reference/src/code/examples/counter/Forc.lock delete mode 100644 docs/reference/src/code/examples/fizzbuzz/Forc.lock delete mode 100644 docs/reference/src/code/examples/wallet_example/Forc.lock diff --git a/.gitignore b/.gitignore index b58ac9c06c6..3de2d377b4e 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,5 @@ sway-lsp/tests/**/Forc.lock forc-plugins/forc-debug/tests/**/Forc.lock # Generated files in example directories -examples/**/Forc.lock +examples/**/*/Forc.lock +docs/reference/src/code/examples/**/*/Forc.lock diff --git a/docs/book/src/blockchain-development/access_control.md b/docs/book/src/blockchain-development/access_control.md index ca4887f6b4c..3e8aad92479 100644 --- a/docs/book/src/blockchain-development/access_control.md +++ b/docs/book/src/blockchain-development/access_control.md @@ -27,7 +27,7 @@ The `msg_sender` function works as follows: ## Contract Ownership -Many contracts require some form of ownership for access control. The [SRC-5 Ownership Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-5.md) has been defined to provide an interoperable interface for ownership within contracts. +Many contracts require some form of ownership for access control. The [SRC-5 Ownership Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-5-ownership.md) has been defined to provide an interoperable interface for ownership within contracts. To accomplish this, use the [Ownership Library](https://fuellabs.github.io/sway-libs/book/ownership/index.html) to keep track of the owner. This allows setting and revoking ownership using the variants `Some(..)` and `None` respectively. This is better, safer, and more readable than using the `Identity` type directly where revoking ownership has to be done using some magic value such as `b256::zero()` or otherwise. @@ -67,7 +67,7 @@ Setting ownership can be done in one of two ways; During compile time or run tim [Sway-Libs](../reference/sway_libs.md) provides the following libraries to enable further access control. -- [Ownership Library](https://fuellabs.github.io/sway-libs/book/ownership/index.html); used to apply restrictions on functions such that only a **single** user may call them. This library provides helper functions for the [SRC-5; Ownership Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-5.md). +- [Ownership Library](https://fuellabs.github.io/sway-libs/book/ownership/index.html); used to apply restrictions on functions such that only a **single** user may call them. This library provides helper functions for the [SRC-5; Ownership Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-5-ownership.md). - [Admin Library](https://fuellabs.github.io/sway-libs/book/admin/index.html); used to apply restrictions on functions such that only a select few users may call them like a whitelist. - [Pausable Library](https://fuellabs.github.io/sway-libs/book/pausable/index.html); allows contracts to implement an emergency stop mechanism. - [Reentrancy Guard Library](https://fuellabs.github.io/sway-libs/book/reentrancy/index.html); used to detect and prevent reentrancy attacks. diff --git a/docs/book/src/blockchain-development/native_assets.md b/docs/book/src/blockchain-development/native_assets.md index 8adcf8fa72e..49b1b0bef79 100644 --- a/docs/book/src/blockchain-development/native_assets.md +++ b/docs/book/src/blockchain-development/native_assets.md @@ -14,7 +14,7 @@ On the FuelVM, _all_ assets are native and the process for sending _any_ native While you would still need a smart contract to handle the minting and burning of assets, the sending and receiving of these assets can be done independently of the asset contract. -Just like the EVM however, Fuel has a standard that describes a standard API for Native Assets using the Sway Language. The ERC-20 equivalent for the Sway Language is the [SRC-20; Native Asset Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-20.md). +Just like the EVM however, Fuel has a standard that describes a standard API for Native Assets using the Sway Language. The ERC-20 equivalent for the Sway Language is the [SRC-20; Native Asset Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-20-native-asset.md). > **NOTE** It is important to note that Fuel does not have tokens. @@ -22,7 +22,7 @@ Just like the EVM however, Fuel has a standard that describes a standard API for On the EVM, an ERC-721 token or NFT is a contract that contains multiple tokens which are non-fungible with one another. -On the FuelVM, the ERC-721 equivalent is a Native Asset where each asset has a supply of one. This is defined in the [SRC-20; Native Asset Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-20.md#non-fungible-asset-restrictions) under the Non-Fungible Asset Restrictions. +On the FuelVM, the ERC-721 equivalent is a Native Asset where each asset has a supply of one. This is defined in the [SRC-20; Native Asset Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-20-native-asset.md#non-fungible-asset-restrictions) under the Non-Fungible Asset Restrictions. In practice, this means all NFTs are treated the same as any other Native Asset on Fuel. When writing Sway code, no additional cases for handling non-fungible and fungible assets are required. @@ -106,7 +106,7 @@ You may also mint an asset to a specific entity with the `std::asset::mint_to()` {{#include ../../../../examples/native_asset/src/main.sw:mint_to_asset}} ``` -If you intend to allow external users to mint assets using your contract, the [SRC-3; Mint and Burn Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-3.md#fn-mintrecipient-identity-vault_sub_id-subid-amount-u64) defines a standard API for minting assets. The [Sway-Libs Asset Library](https://fuellabs.github.io/sway-libs/book/asset/supply.html) also provides an additional library to support implementations of the SRC-3 Standard into your contract. +If you intend to allow external users to mint assets using your contract, the [SRC-3; Mint and Burn Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-3-minting-and-burning.md#fn-mintrecipient-identity-vault_sub_id-subid-amount-u64) defines a standard API for minting assets. The [Sway-Libs Asset Library](https://fuellabs.github.io/sway-libs/book/asset/supply.html) also provides an additional library to support implementations of the SRC-3 Standard into your contract. ### Burning a Native Asset @@ -116,7 +116,7 @@ To burn an asset, the `std::asset::burn()` function must be called internally fr {{#include ../../../../examples/native_asset/src/main.sw:burn_asset}} ``` -If you intend to allow external users to burn assets using your contract, the [SRC-3; Mint and Burn Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-3.md#fn-mintrecipient-identity-vault_sub_id-subid-amount-u64) defines a standard API for burning assets. The [Sway-Libs Asset Library](https://fuellabs.github.io/sway-libs/book/asset/supply.html) also provides an additional library to support implementations of the SRC-3 Standard into your contract. +If you intend to allow external users to burn assets using your contract, the [SRC-3; Mint and Burn Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-3-minting-and-burning.md#fn-mintrecipient-identity-vault_sub_id-subid-amount-u64) defines a standard API for burning assets. The [Sway-Libs Asset Library](https://fuellabs.github.io/sway-libs/book/asset/supply.html) also provides an additional library to support implementations of the SRC-3 Standard into your contract. ### Transfer a Native Asset @@ -176,16 +176,16 @@ There are a number of standards developed to enable further functionality for Na We currently have the following standards for Native Assets: -- [SRC-20; Native Asset Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-20.md) defines the implementation of a standard API for Native Assets using the Sway Language. -- [SRC-3; Mint and Burn Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-3.md) is used to enable mint and burn functionality for Native Assets. -- [SRC-7; Arbitrary Asset Metadata Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-7.md) is used to store metadata for Native Assets. -- [SRC-6; Vault Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-6.md) defines the implementation of a standard API for asset vaults developed in Sway. +- [SRC-20; Native Asset Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-20-native-asset.md) defines the implementation of a standard API for Native Assets using the Sway Language. +- [SRC-3; Mint and Burn Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-3-minting-and-burning.md) is used to enable mint and burn functionality for Native Assets. +- [SRC-7; Arbitrary Asset Metadata Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-7-asset-metadata.md) is used to store metadata for Native Assets. +- [SRC-6; Vault Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-6-vault.md) defines the implementation of a standard API for asset vaults developed in Sway. ## Native Asset Libraries Additional Libraries have been developed to allow you to quickly create an deploy dApps that follow the [Sway Standards](https://github.com/FuelLabs/sway-standards). -- [Asset Library](https://fuellabs.github.io/sway-libs/book/asset/index.html) provides functionality to implement the [SRC-20; Native Asset Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-20.md), [SRC-3; Mint and Burn Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-3.md), and [SRC-7; Arbitrary Asset Metadata Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-7.md) standards. +- [Asset Library](https://fuellabs.github.io/sway-libs/book/asset/index.html) provides functionality to implement the [SRC-20; Native Asset Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-20-native-asset.md), [SRC-3; Mint and Burn Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-3-minting-and-burning.md), and [SRC-7; Arbitrary Asset Metadata Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-7-asset-metadata.md) standards. @@ -193,7 +193,7 @@ Additional Libraries have been developed to allow you to quickly create an deplo In this fully fleshed out example, we show a native asset contract which mints a single asset. This is the equivalent to the ERC-20 Standard use in Ethereum. Note there are no token approval functions. -It implements the [SRC-20; Native Asset](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-20.md), [SRC-3; Mint and Burn](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-3.md), and [SRC-5; Ownership](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-5.md) standards. It does not use any external libraries. +It implements the [SRC-20; Native Asset](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-20-native-asset.md), [SRC-3; Mint and Burn](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-3-minting-and-burning.md), and [SRC-5; Ownership](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-5-ownership.md) standards. It does not use any external libraries. ```sway // ERC20 equivalent in Sway. @@ -335,7 +335,7 @@ fn require_access_owner() { In this fully fleshed out example, we show a native asset contract which mints multiple assets. This is the equivalent to the ERC-1155 Standard use in Ethereum. Note there are no token approval functions. -It implements the [SRC-20; Native Asset](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-20.md), [SRC-3; Mint and Burn](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-3.md), and [SRC-5; Ownership](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-5.md) standards. It does not use any external libraries. +It implements the [SRC-20; Native Asset](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-20-native-asset.md), [SRC-3; Mint and Burn](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-3-minting-and-burning.md), and [SRC-5; Ownership](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-5-ownership.md) standards. It does not use any external libraries. ```sway // ERC1155 equivalent in Sway. diff --git a/docs/book/src/introduction/sway_standards.md b/docs/book/src/introduction/sway_standards.md index d51925c00bc..e421c0c6b20 100644 --- a/docs/book/src/introduction/sway_standards.md +++ b/docs/book/src/introduction/sway_standards.md @@ -8,32 +8,32 @@ For more information on using a Sway Standard, please refer to the [Sway-Standar ### Native Asset Standards -- [SRC-20; Native Asset Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-20.md) defines the implementation of a standard API for [Native Assets](../blockchain-development/native_assets.md) using the Sway Language. -- [SRC-3; Mint and Burn](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-3.md) is used to enable mint and burn functionality for Native Assets. -- [SRC-7; Arbitrary Asset Metadata Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-7.md) is used to store metadata for [Native Assets](../blockchain-development/native_assets.md), usually as NFTs. -- [SRC-9; Metadata Keys Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-9.md) is used to store standardized metadata keys for [Native Assets](../blockchain-development/native_assets.md) in combination with the SRC-7 standard. -- [SRC-6; Vault Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-6.md) defines the implementation of a standard API for asset vaults developed in Sway. +- [SRC-20; Native Asset Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-20-native-asset.md) defines the implementation of a standard API for [Native Assets](../blockchain-development/native_assets.md) using the Sway Language. +- [SRC-3; Mint and Burn](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-3-minting-and-burning.md) is used to enable mint and burn functionality for Native Assets. +- [SRC-7; Arbitrary Asset Metadata Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-7-asset-metadata.md) is used to store metadata for [Native Assets](../blockchain-development/native_assets.md), usually as NFTs. +- [SRC-9; Metadata Keys Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-9-metadata-keys.md) is used to store standardized metadata keys for [Native Assets](../blockchain-development/native_assets.md) in combination with the SRC-7 standard. +- [SRC-6; Vault Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-6-vault.md) defines the implementation of a standard API for asset vaults developed in Sway. ### Predicate Standards -- [SRC-13; Soulbound Address Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-13.md) defines a specific `Address` as a Soulbound Address for Soulbound Assets to become non-transferable. +- [SRC-13; Soulbound Address Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-13-soulbound-address.md) defines a specific `Address` as a Soulbound Address for Soulbound Assets to become non-transferable. ### Access Control Standards -- [SRC-5; Ownership Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-5.md) is used to restrict function calls to admin users in contracts. +- [SRC-5; Ownership Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-5-ownership.md) is used to restrict function calls to admin users in contracts. ### Contract Standards -- [SRC-12; Contract Factory](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-12.md) defines the implementation of a standard API for contract factories. +- [SRC-12; Contract Factory](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-12-contract-factory.md) defines the implementation of a standard API for contract factories. ### Bridge Standards -- [SRC-8; Bridged Asset](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-8.md) defines the metadata required for an asset bridged to the Fuel Network. -- [SRC-10; Native Bridge Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-10.md) defines the standard API for the Native Bridge between the Fuel Chain and the canonical base chain. +- [SRC-8; Bridged Asset](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-8-bridged-asset.md) defines the metadata required for an asset bridged to the Fuel Network. +- [SRC-10; Native Bridge Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-10-native-bridge.md) defines the standard API for the Native Bridge between the Fuel Chain and the canonical base chain. ### Documentation Standards -- [SRC-2; Inline Documentation](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-2.md) defines how to document your Sway files. +- [SRC-2; Inline Documentation](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-2-inline-documentation.md) defines how to document your Sway files. ## Standards Support diff --git a/docs/book/src/reference/sway_libs.md b/docs/book/src/reference/sway_libs.md index 507a15abe0d..8e5d237fe07 100644 --- a/docs/book/src/reference/sway_libs.md +++ b/docs/book/src/reference/sway_libs.md @@ -10,13 +10,13 @@ For more information on how to use a Sway-Libs library, please refer to the [Swa Asset Libraries are any libraries that use [Native Assets](../blockchain-development/native_assets.md) on the Fuel Network. -- [Asset Library](https://fuellabs.github.io/sway-libs/book/asset/index.html); provides helper functions for the [SRC-20](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-20.md), [SRC-3](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-3.md), and [SRC-7](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-7.md) standards. +- [Asset Library](https://fuellabs.github.io/sway-libs/book/asset/index.html); provides helper functions for the [SRC-20](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-20-native-asset.md), [SRC-3](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-3-minting-and-burning.md), and [SRC-7](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-7-asset-metadata.md) standards. ## Access Control and Security Libraries Access Control and Security Libraries are any libraries that are built and intended to provide additional safety when developing smart contracts. -- [Ownership Library](https://fuellabs.github.io/sway-libs/book/ownership/index.html); used to apply restrictions on functions such that only a **single** user may call them. This library provides helper functions for the [SRC-5; Ownership Standard](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-5.md). +- [Ownership Library](https://fuellabs.github.io/sway-libs/book/ownership/index.html); used to apply restrictions on functions such that only a **single** user may call them. This library provides helper functions for the [SRC-5; Ownership Standard](https://github.com/FuelLabs/sway-standards/blob/master/docs/src/src-5-ownership.md). - [Admin Library](https://fuellabs.github.io/sway-libs/book/admin/index.html); used to apply restrictions on functions such that only a select few users may call them like a whitelist. - [Pausable Library](https://fuellabs.github.io/sway-libs/book/pausable/index.html); allows contracts to implement an emergency stop mechanism. - [Reentrancy Guard Library](https://fuellabs.github.io/sway-libs/book/reentrancy/index.html); used to detect and prevent reentrancy attacks. diff --git a/docs/reference/src/code/examples/access-control/ownership/Forc.lock b/docs/reference/src/code/examples/access-control/ownership/Forc.lock deleted file mode 100644 index 29ac8935221..00000000000 --- a/docs/reference/src/code/examples/access-control/ownership/Forc.lock +++ /dev/null @@ -1,13 +0,0 @@ -[[package]] -name = 'core' -source = 'path+from-root-AE2967028D5567DA' - -[[package]] -name = 'ownership' -source = 'member' -dependencies = ['std'] - -[[package]] -name = 'std' -source = 'git+https://github.com/fuellabs/sway?tag=v0.31.1#c32b0759d25c0b515cbf535f9fb9b8e6fda38ff2' -dependencies = ['core'] diff --git a/docs/reference/src/code/examples/counter/Forc.lock b/docs/reference/src/code/examples/counter/Forc.lock deleted file mode 100644 index 815750e37b5..00000000000 --- a/docs/reference/src/code/examples/counter/Forc.lock +++ /dev/null @@ -1,13 +0,0 @@ -[[package]] -name = 'core' -source = 'path+from-root-AE2967028D5567DA' - -[[package]] -name = 'counter' -source = 'member' -dependencies = ['std'] - -[[package]] -name = 'std' -source = 'git+https://github.com/fuellabs/sway?tag=v0.31.1#c32b0759d25c0b515cbf535f9fb9b8e6fda38ff2' -dependencies = ['core'] diff --git a/docs/reference/src/code/examples/fizzbuzz/Forc.lock b/docs/reference/src/code/examples/fizzbuzz/Forc.lock deleted file mode 100644 index 4052c90315a..00000000000 --- a/docs/reference/src/code/examples/fizzbuzz/Forc.lock +++ /dev/null @@ -1,13 +0,0 @@ -[[package]] -name = 'core' -source = 'path+from-root-AE2967028D5567DA' - -[[package]] -name = 'fizzbuzz' -source = 'member' -dependencies = ['std'] - -[[package]] -name = 'std' -source = 'git+https://github.com/fuellabs/sway?tag=v0.31.1#c32b0759d25c0b515cbf535f9fb9b8e6fda38ff2' -dependencies = ['core'] diff --git a/docs/reference/src/code/examples/wallet_example/Forc.lock b/docs/reference/src/code/examples/wallet_example/Forc.lock deleted file mode 100644 index 633f2d6d9a2..00000000000 --- a/docs/reference/src/code/examples/wallet_example/Forc.lock +++ /dev/null @@ -1,13 +0,0 @@ -[[package]] -name = 'core' -source = 'path+from-root-AE2967028D5567DA' - -[[package]] -name = 'std' -source = 'git+https://github.com/fuellabs/sway?tag=v0.31.1#c32b0759d25c0b515cbf535f9fb9b8e6fda38ff2' -dependencies = ['core'] - -[[package]] -name = 'wallet' -source = 'member' -dependencies = ['std'] diff --git a/docs/reference/src/documentation/language/program-types/predicate.md b/docs/reference/src/documentation/language/program-types/predicate.md index c267acb619f..ea715888132 100644 --- a/docs/reference/src/documentation/language/program-types/predicate.md +++ b/docs/reference/src/documentation/language/program-types/predicate.md @@ -4,7 +4,7 @@ A predicate is an executable that represents a UTXO spending condition, such as It does not need to be deployed to a blockchain because it only exists during a transaction. That being said, the predicate root is on chain as the owner of one or more UTXOs. -Predicates can neither read from nor write to any contract state. Moreover, they cannot use any [contract instructions](https://fuellabs.github.io/fuel-specs/master/vm/instruction_set.html#contract-instructions). +Predicates can neither read from nor write to any contract state. Moreover, they cannot use any [contract instructions](https://docs.fuel.network/docs/specs/fuel-vm/instruction-set/#contract-instructions). ## Transfer Coins to a Predicate diff --git a/sway-lib-std/src/alloc.sw b/sway-lib-std/src/alloc.sw index 1e0958c0b4d..9841fe5e1e1 100644 --- a/sway-lib-std/src/alloc.sw +++ b/sway-lib-std/src/alloc.sw @@ -27,7 +27,7 @@ library; /// ▴ptr ▴VM_MAX_RAM /// ``` /// For more information, see the Fuel Spec for [VM Initialization](https://fuellabs.github.io/fuel-specs/master/vm#vm-initialization) -/// and the VM Instruction Set for [Memory Allocation](https://fuellabs.github.io/fuel-specs/master/vm/instruction_set.html#aloc-allocate-memory). +/// and the VM Instruction Set for [Memory Allocation](https://docs.fuel.network/docs/specs/fuel-vm/instruction-set#aloc-allocate-memory). /// /// # Arguments /// diff --git a/sway-lib-std/src/call_frames.sw b/sway-lib-std/src/call_frames.sw index 6ae7b2cdf19..8d69188204d 100644 --- a/sway-lib-std/src/call_frames.sw +++ b/sway-lib-std/src/call_frames.sw @@ -46,7 +46,7 @@ pub fn msg_asset_id() -> AssetId { /// # Additional Information /// /// More information on data from call frames can be found in the Fuel Specs. -/// https://specs.fuel.network/master/fuel-vm/index.html?search=#call-frames +/// https://docs.fuel.network/docs/specs/fuel-vm/#call-frames /// /// # Returns /// @@ -74,7 +74,7 @@ pub fn code_size() -> u64 { /// # Additional Information /// /// More information on data from call frames can be found in the Fuel Specs. -/// https://specs.fuel.network/master/fuel-vm/index.html?search=#call-frames +/// https://docs.fuel.network/docs/specs/fuel-vm/#call-frames /// /// # Returns /// @@ -99,7 +99,7 @@ pub fn first_param() -> u64 { /// # Additional Information /// /// More information on data from call frames can be found in the Fuel Specs. -/// https://specs.fuel.network/master/fuel-vm/index.html?search=#call-frames +/// https://docs.fuel.network/docs/specs/fuel-vm/#call-frames /// /// # Returns /// @@ -141,7 +141,7 @@ where /// # Additional Information /// /// More information on data from call frames can be found in the Fuel Specs. -/// https://specs.fuel.network/master/fuel-vm/index.html?search=#call-frames +/// https://docs.fuel.network/docs/specs/fuel-vm/#call-frames /// /// # Arguments /// diff --git a/swayfmt/tests/mod.rs b/swayfmt/tests/mod.rs index b71f2f148c4..13e063d7f81 100644 --- a/swayfmt/tests/mod.rs +++ b/swayfmt/tests/mod.rs @@ -2405,7 +2405,7 @@ fn long_doc_break_new_line() { /// ▴ptr ▴VM_MAX_RAM /// ``` /// For more information, see the Fuel Spec for [VM Initialization](https://fuellabs.github.io/fuel-specs/master/vm#vm-initialization) -/// and the VM Instruction Set for [Memory Allocation](https://fuellabs.github.io/fuel-specs/master/vm/instruction_set.html#aloc-allocate-memory). +/// and the VM Instruction Set for [Memory Allocation](https://docs.fuel.network/docs/specs/fuel-vm/instruction-set#aloc-allocate-memory). /// /// # Arguments /// @@ -2499,7 +2499,7 @@ pub fn alloc_bytes(count: u64) -> raw_ptr { /// ▴ptr ▴VM_MAX_RAM /// ``` /// For more information, see the Fuel Spec for [VM Initialization](https://fuellabs.github.io/fuel-specs/master/vm#vm-initialization) -/// and the VM Instruction Set for [Memory Allocation](https://fuellabs.github.io/fuel-specs/master/vm/instruction_set.html#aloc-allocate-memory). +/// and the VM Instruction Set for [Memory Allocation](https://docs.fuel.network/docs/specs/fuel-vm/instruction-set#aloc-allocate-memory). /// /// # Arguments /// From 970eb5d7895941f680a0dc3b6ed32ed4fcf3cb52 Mon Sep 17 00:00:00 2001 From: Sophie Dankel <47993817+sdankel@users.noreply.github.com> Date: Fri, 7 Jun 2024 18:34:55 -0700 Subject: [PATCH 2/4] chore: add issue templates (#6097) ## Description Borrowed from the templates in fuelup repo and modified slightly. When a user opens an issue with either the Bug Report or Enhancement template, it will have the appropriate label added as well as the `triage` label. Closes https://github.com/FuelLabs/sway/issues/2725 ## 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. --- .github/ISSUE_TEMPLATE/blank_issue.md | 4 ++ .github/ISSUE_TEMPLATE/bug_report.yml | 69 +++++++++++++++++++ .github/ISSUE_TEMPLATE/config.yml | 8 +++ .../ISSUE_TEMPLATE/enhancement_request.yml | 50 ++++++++++++++ 4 files changed, 131 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/blank_issue.md create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/enhancement_request.yml diff --git a/.github/ISSUE_TEMPLATE/blank_issue.md b/.github/ISSUE_TEMPLATE/blank_issue.md new file mode 100644 index 00000000000..9aef3ebe637 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/blank_issue.md @@ -0,0 +1,4 @@ +--- +name: Blank Issue +about: Create a blank issue. +--- diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 00000000000..77342d8b2ba --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,69 @@ +name: Bug Report +description: Create a report to help us improve. +labels: [bug, triage] +body: + - type: markdown + attributes: + value: > + **Thank you for filing a bug report!** + + - type: dropdown + id: component + attributes: + label: Related Component + description: Which component does this relate to? + options: + - compiler + - forc + - forc-deploy + - forc-lsp + - forc-fmt + - another forc plugin + - other + default: 0 + validations: + required: true + + - type: textarea + id: problem + attributes: + label: Problem + description: > + A clear and concise description of what the bug is, + including what currently happens and what you expected to happen. + validations: + required: true + + - type: textarea + id: steps + attributes: + label: Steps + description: The steps to reproduce the bug. + placeholder: | + 1. + 2. + 3. + validations: + required: true + + - type: textarea + id: solutions + attributes: + label: Possible Solution(s) + description: > + Not obligatory, but suggest a fix/reason for the bug, + or ideas how to implement the addition or change. + + - type: textarea + id: notes + attributes: + label: Notes + + - type: textarea + id: components + attributes: + label: Installed components + description: Output of `fuelup check`, if using `fuelup`. Otherwise, list the relevant component(s) and version(s). + render: console + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000000..da10d666447 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,8 @@ +blank_issues_enabled: true +contact_links: + - name: Fuel Network & Sway Language Community Support + url: https://forum.fuel.network/ + about: Please ask and answer questions here. + - name: Fuel Network Security Bug Bounty + url: https://immunefi.com/boost/fuel-network-attackathon/ + about: Please report security vulnerabilities here. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/enhancement_request.yml b/.github/ISSUE_TEMPLATE/enhancement_request.yml new file mode 100644 index 00000000000..04a3dc02acd --- /dev/null +++ b/.github/ISSUE_TEMPLATE/enhancement_request.yml @@ -0,0 +1,50 @@ +name: Enhancement Request +description: Suggest an enhancement for this project. +labels: [enhancement, triage] +body: + - type: markdown + attributes: + value: > + **Thank you for filing an enhancement request!** + + - type: dropdown + id: component + attributes: + label: Related Component + description: Which component does this relate to? + options: + - compiler + - forc + - forc-deploy + - forc-lsp + - forc-fmt + - another forc plugin + - other + default: 0 + validations: + required: true + + - type: textarea + id: problem + attributes: + label: Problem you are trying to solve + description: > + A clear and concise description of the problem this enhancement request is trying to solve. + validations: + required: true + + - type: textarea + id: solution + attributes: + label: Solution you'd like + description: > + A clear and concise description of what you want to happen. + validations: + required: true + + - type: textarea + id: notes + attributes: + label: Notes + description: > + Any additional context or information you feel may be relevant to the issue. From 59dcc10aaf281e3c0649b15d084fa93c6b022ffd Mon Sep 17 00:00:00 2001 From: Cameron Carstens Date: Sat, 8 Jun 2024 09:53:11 +0800 Subject: [PATCH 3/4] Update codeowners `application-dev` to `swayex` (#6095) ## Description The Application-dev team has been renamed to swayex. This change has been reflected in the codeowner file ## 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. - [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: IGI-111 --- .github/CODEOWNERS | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 81cb9b19051..bdb38dc2c31 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -2,12 +2,12 @@ * @FuelLabs/leads # Documentation -/docs/ @FuelLabs/tooling @FuelLabs/sway-compiler @FuelLabs/application-dev @FuelLabs/Devrel +/docs/ @FuelLabs/tooling @FuelLabs/sway-compiler @FuelLabs/swayex @FuelLabs/Devrel # Sway files and standard library -/examples/ @FuelLabs/sway-compiler @FuelLabs/application-dev -/sway-lib-core/ @FuelLabs/sway-compiler @FuelLabs/application-dev -/sway-lib-std/ @FuelLabs/sway-compiler @FuelLabs/application-dev +/examples/ @FuelLabs/sway-compiler @FuelLabs/swayex +/sway-lib-core/ @FuelLabs/sway-compiler @FuelLabs/swayex +/sway-lib-std/ @FuelLabs/sway-compiler @FuelLabs/swayex # Tooling /forc/ @FuelLabs/tooling From f4f9c1391330dde06ce47a94c6439965fff0cbda Mon Sep 17 00:00:00 2001 From: Daniel Frederico Lins Leite Date: Mon, 10 Jun 2024 08:54:22 +0100 Subject: [PATCH 4/4] Automatically import contract return type (#6089) ## Description This PR fixes https://github.com/FuelLabs/sway/issues/5936. To avoid the error, we are importing all impls for all types in the contract return, but we are NOT binding the type name. That means that the return type becomes usable (fields, methods and trait impls), but one cannot instantiate the type. For that, the type still needs to be imported manually. ## 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. --- .../src/language/ty/declaration/function.rs | 11 +++- .../typed_expression/method_application.rs | 11 ++++ .../semantic_analysis/namespace/trait_map.rs | 6 +- .../semantic_analysis/type_check_context.rs | 43 ++++++++++++- sway-core/src/type_system/id.rs | 31 ++++++--- sway-core/src/type_system/priv_prelude.rs | 2 +- .../call_abi_with_tuples/src/main.sw | 18 +++++- .../test_abis/abi_with_tuples/src/main.sw | 5 +- .../abi_with_tuples/src/some_module.sw | 11 ++++ .../json_abi_oracle_new_encoding.json | 64 ++++++++++++++----- .../abi_with_tuples_contract/src/main.sw | 6 +- 11 files changed, 172 insertions(+), 36 deletions(-) create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/test_abis/abi_with_tuples/src/some_module.sw diff --git a/sway-core/src/language/ty/declaration/function.rs b/sway-core/src/language/ty/declaration/function.rs index a199671465a..483e5e01bb3 100644 --- a/sway-core/src/language/ty/declaration/function.rs +++ b/sway-core/src/language/ty/declaration/function.rs @@ -253,11 +253,18 @@ impl UnconstrainedTypeParameters for TyFunctionDecl { .map(|type_param| type_param.type_id) .collect(); all_types.extend(self.parameters.iter().flat_map(|param| { - let mut inner = param.type_argument.type_id.extract_inner_types(engines); + let mut inner = param + .type_argument + .type_id + .extract_inner_types(engines, IncludeSelf::No); inner.insert(param.type_argument.type_id); inner })); - all_types.extend(self.return_type.type_id.extract_inner_types(engines)); + all_types.extend( + self.return_type + .type_id + .extract_inner_types(engines, IncludeSelf::No), + ); all_types.insert(self.return_type.type_id); let type_parameter_info = type_engine.get(type_parameter.type_id); all_types.iter().any(|type_id| { diff --git a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/method_application.rs b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/method_application.rs index c248cb9b117..05db87129ab 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/method_application.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/method_application.rs @@ -533,6 +533,17 @@ pub(crate) fn type_check_method_application( span: Span::dummy(), }); + // We need all impls of return type to be in scope, so that at call place we have access to its + // AbiDecode impl. + for type_id in method + .return_type + .type_id + .extract_inner_types(engines, IncludeSelf::Yes) + { + let handler = Handler::default(); + ctx.impls_import(&handler, engines, type_id); + } + let args = old_arguments.iter().skip(1).cloned().collect(); let contract_call = call_contract_call( &mut ctx, diff --git a/sway-core/src/semantic_analysis/namespace/trait_map.rs b/sway-core/src/semantic_analysis/namespace/trait_map.rs index e778acfdf54..2cd7d0dd3d6 100644 --- a/sway-core/src/semantic_analysis/namespace/trait_map.rs +++ b/sway-core/src/semantic_analysis/namespace/trait_map.rs @@ -22,7 +22,7 @@ use crate::{ CallPath, }, type_system::{SubstTypes, TypeId}, - TraitConstraint, TypeArgument, TypeEngine, TypeInfo, TypeSubstMap, UnifyCheck, + IncludeSelf, TraitConstraint, TypeArgument, TypeEngine, TypeInfo, TypeSubstMap, UnifyCheck, }; use super::TryInsertingTraitImplOnFailure; @@ -658,7 +658,7 @@ impl TraitMap { // a curried version of the decider protocol to use in the helper functions let decider = |left: TypeId, right: TypeId| unify_checker.check(left, right); - let mut all_types = type_id.extract_inner_types(engines); + let mut all_types = type_id.extract_inner_types(engines, IncludeSelf::No); all_types.insert(type_id); let all_types = all_types.into_iter().collect::>(); self.filter_by_type_inner(engines, all_types, decider) @@ -736,7 +736,7 @@ impl TraitMap { }; let mut trait_map = self.filter_by_type_inner(engines, vec![type_id], decider); let all_types = type_id - .extract_inner_types(engines) + .extract_inner_types(engines, IncludeSelf::No) .into_iter() .collect::>(); // a curried version of the decider protocol to use in the helper functions diff --git a/sway-core/src/semantic_analysis/type_check_context.rs b/sway-core/src/semantic_analysis/type_check_context.rs index a0692e15b97..4402f0aecfb 100644 --- a/sway-core/src/semantic_analysis/type_check_context.rs +++ b/sway-core/src/semantic_analysis/type_check_context.rs @@ -2,7 +2,7 @@ use std::collections::{HashMap, VecDeque}; use crate::{ build_config::ExperimentalFlags, - decl_engine::{DeclEngineInsert, DeclRefFunction}, + decl_engine::{DeclEngineGet, DeclEngineInsert, DeclRefFunction}, engine_threading::*, language::{ parsed::TreeType, @@ -11,7 +11,7 @@ use crate::{ }, namespace::{ IsExtendingExistingImpl, IsImplSelf, ModulePath, ResolvedDeclaration, - ResolvedTraitImplItem, TryInsertingTraitImplOnFailure, + ResolvedTraitImplItem, TraitMap, TryInsertingTraitImplOnFailure, }, semantic_analysis::{ ast_node::{AbiMode, ConstShadowingMode}, @@ -1398,6 +1398,45 @@ impl<'a> TypeCheckContext<'a> { .self_import(handler, engines, src, &mod_path, alias) } + // Import all impls for a struct/enum. Do nothing for other types. + pub(crate) fn impls_import(&mut self, handler: &Handler, engines: &Engines, type_id: TypeId) { + let type_info = engines.te().get(type_id); + + let decl_call_path = match &*type_info { + TypeInfo::Enum(decl_ref) => { + let decl = engines.de().get(decl_ref.id()); + decl.call_path.clone() + } + TypeInfo::Struct(decl_ref) => { + let decl = engines.de().get(decl_ref.id()); + decl.call_path.clone() + } + _ => return, + }; + + let mut impls_to_insert = TraitMap::default(); + + let root_mod = &self.namespace().root().module; + let Ok(src_mod) = root_mod.lookup_submodule(handler, engines, &decl_call_path.prefixes) + else { + return; + }; + + impls_to_insert.extend( + src_mod + .current_items() + .implemented_traits + .filter_by_type_item_import(type_id, engines), + engines, + ); + + let dst_mod = self.namespace_mut().module_mut(engines); + dst_mod + .current_items_mut() + .implemented_traits + .extend(impls_to_insert, engines); + } + /// Short-hand for performing a [Module::item_import] with `mod_path` as the destination. pub(crate) fn item_import( &mut self, diff --git a/sway-core/src/type_system/id.rs b/sway-core/src/type_system/id.rs index 4a00626d9f6..d28e59e87b6 100644 --- a/sway-core/src/type_system/id.rs +++ b/sway-core/src/type_system/id.rs @@ -27,6 +27,11 @@ use std::{ const EXTRACT_ANY_MAX_DEPTH: usize = 128; +pub enum IncludeSelf { + Yes, + No, +} + /// A identifier to uniquely refer to our type terms #[derive(PartialEq, Eq, Hash, Clone, Copy, Ord, PartialOrd, Debug)] pub struct TypeId(usize); @@ -106,7 +111,7 @@ impl UnconstrainedTypeParameters for TypeId { type_parameter: &TypeParameter, ) -> bool { let type_engine = engines.te(); - let mut all_types: BTreeSet = self.extract_inner_types(engines); + let mut all_types: BTreeSet = self.extract_inner_types(engines, IncludeSelf::No); all_types.insert(*self); let type_parameter_info = type_engine.get(type_parameter.type_id); all_types.iter().any(|type_id| { @@ -422,15 +427,23 @@ impl TypeId { } /// Given a `TypeId` `self`, analyze `self` and return all inner - /// `TypeId`'s of `self`, not including `self`. - pub(crate) fn extract_inner_types(&self, engines: &Engines) -> BTreeSet { - fn filter_fn(_type_info: &TypeInfo) -> bool { - true - } - self.extract_any(engines, &filter_fn, 0) + /// `TypeId`'s of `self`. + pub(crate) fn extract_inner_types( + &self, + engines: &Engines, + include_self: IncludeSelf, + ) -> BTreeSet { + let mut set: BTreeSet = self + .extract_any(engines, &|_| true, 0) .keys() .copied() - .collect() + .collect(); + + if matches!(include_self, IncludeSelf::Yes) { + set.insert(*self); + } + + set } pub(crate) fn extract_inner_types_with_trait_constraints( @@ -448,7 +461,7 @@ impl TypeId { pub(crate) fn extract_nested_types(self, engines: &Engines) -> Vec { let type_engine = engines.te(); let mut inner_types: Vec = self - .extract_inner_types(engines) + .extract_inner_types(engines, IncludeSelf::No) .into_iter() .map(|type_id| (*type_engine.get(type_id)).clone()) .collect(); diff --git a/sway-core/src/type_system/priv_prelude.rs b/sway-core/src/type_system/priv_prelude.rs index e5f4b977c79..bb40d738d00 100644 --- a/sway-core/src/type_system/priv_prelude.rs +++ b/sway-core/src/type_system/priv_prelude.rs @@ -16,6 +16,6 @@ pub use super::{ type_parameter::TypeParameter, }, engine::TypeEngine, - id::TypeId, + id::{IncludeSelf, TypeId}, info::{AbiEncodeSizeHint, AbiName, TypeInfo, TypeSourceInfo}, }; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_abi_with_tuples/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_abi_with_tuples/src/main.sw index 0af9f5921b1..fbb3720a34b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_abi_with_tuples/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_abi_with_tuples/src/main.sw @@ -1,11 +1,12 @@ script; -use abi_with_tuples::*; +use abi_with_tuples::{MyContract, Location, Person}; + #[cfg(experimental_new_encoding = false)] const CONTRACT_ID = 0xb351aff8258ce46d16a71be666dd2b0b09d72243105c51f4423765824e59cac9; #[cfg(experimental_new_encoding = true)] -const CONTRACT_ID = 0x33270c71961d901de6e1832cf24d5825afc05193a367fe2709e10ce9e1938057; +const CONTRACT_ID = 0x17d3f0c7895e749e9aea69b1b1c3b3774e8a84add7275de61065dfa3b9785dee; fn main() -> bool { let the_abi = abi(MyContract, CONTRACT_ID); @@ -26,5 +27,18 @@ fn main() -> bool { let bar = the_abi.bug2(param2); assert(bar); + // This fn returns some_module::SomeStruct, and this struct + // should not be manually imported + // We want the compiler to import its AbiDecode impl automatically + let a = the_abi.struct_at_return(); + assert(a.0.data == 1); + + // We should be able to call functions on the return type. + a.0.g(); + + // But we should not be able to reference the type name, + // because it is not bound. + // let a = SomeStruct { data: 2 }; // This will fail + true } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/abi_with_tuples/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/abi_with_tuples/src/main.sw index 81d62c68544..f133b6feb87 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/abi_with_tuples/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/abi_with_tuples/src/main.sw @@ -1,5 +1,7 @@ library; +pub mod some_module; + pub struct Person { pub age: u64 } @@ -8,8 +10,9 @@ pub enum Location { Earth: () } - abi MyContract { fn bug1(param: (Person, u64)) -> bool; fn bug2(param: (Location, u64)) -> bool; + + fn struct_at_return() -> (some_module::SomeStruct,); } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/abi_with_tuples/src/some_module.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/abi_with_tuples/src/some_module.sw new file mode 100644 index 00000000000..d48f1ca3af0 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/abi_with_tuples/src/some_module.sw @@ -0,0 +1,11 @@ +library; + +pub struct SomeStruct { + pub data: u64, +} + +impl SomeStruct { + pub fn g(self) { + + } +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_tuples_contract/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_tuples_contract/json_abi_oracle_new_encoding.json index d5d71b3d3b6..80d8e741055 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_tuples_contract/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_tuples_contract/json_abi_oracle_new_encoding.json @@ -7,14 +7,14 @@ "inputs": [ { "name": "_param", - "type": 1, + "type": 2, "typeArguments": null } ], "name": "bug1", "output": { "name": "", - "type": 3, + "type": 4, "typeArguments": null } }, @@ -23,14 +23,24 @@ "inputs": [ { "name": "_param", - "type": 2, + "type": 3, "typeArguments": null } ], "name": "bug2", "output": { "name": "", - "type": 3, + "type": 4, + "typeArguments": null + } + }, + { + "attributes": null, + "inputs": [], + "name": "struct_at_return", + "output": { + "name": "", + "type": 1, "typeArguments": null } } @@ -48,40 +58,52 @@ "components": [ { "name": "__tuple_element", - "type": 5, + "type": 7, "typeArguments": null - }, + } + ], + "type": "(_)", + "typeId": 1, + "typeParameters": null + }, + { + "components": [ { "name": "__tuple_element", "type": 6, "typeArguments": null + }, + { + "name": "__tuple_element", + "type": 8, + "typeArguments": null } ], "type": "(_, _)", - "typeId": 1, + "typeId": 2, "typeParameters": null }, { "components": [ { "name": "__tuple_element", - "type": 4, + "type": 5, "typeArguments": null }, { "name": "__tuple_element", - "type": 6, + "type": 8, "typeArguments": null } ], "type": "(_, _)", - "typeId": 2, + "typeId": 3, "typeParameters": null }, { "components": null, "type": "bool", - "typeId": 3, + "typeId": 4, "typeParameters": null }, { @@ -93,25 +115,37 @@ } ], "type": "enum abi_with_tuples::Location", - "typeId": 4, + "typeId": 5, "typeParameters": null }, { "components": [ { "name": "age", - "type": 6, + "type": 8, "typeArguments": null } ], "type": "struct abi_with_tuples::Person", - "typeId": 5, + "typeId": 6, + "typeParameters": null + }, + { + "components": [ + { + "name": "data", + "type": 8, + "typeArguments": null + } + ], + "type": "struct abi_with_tuples::some_module::SomeStruct", + "typeId": 7, "typeParameters": null }, { "components": null, "type": "u64", - "typeId": 6, + "typeId": 8, "typeParameters": null } ] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_tuples_contract/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_tuples_contract/src/main.sw index 0971fdcb79b..9897a565613 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_tuples_contract/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_tuples_contract/src/main.sw @@ -1,6 +1,6 @@ contract; -use abi_with_tuples::{MyContract, Person, Location}; +use abi_with_tuples::{MyContract, Person, Location, some_module::SomeStruct}; impl MyContract for Contract { fn bug1(_param: (Person, u64)) -> bool { @@ -10,4 +10,8 @@ impl MyContract for Contract { fn bug2(_param: (Location, u64)) -> bool { true } + + fn struct_at_return() -> (SomeStruct,) { + (SomeStruct { data: 1 },) + } }