diff --git a/.docs/contributing-book/src/code/bad_documentation/src/lib.sw b/.docs/contributing-book/src/code/bad_documentation/src/lib.sw index a690e7a2..b374a6e2 100644 --- a/.docs/contributing-book/src/code/bad_documentation/src/lib.sw +++ b/.docs/contributing-book/src/code/bad_documentation/src/lib.sw @@ -1,4 +1,4 @@ -library bad_documentation; +library; // ANCHOR: data_structures // This is bad. It's repeating the names of the fields which can be easily read diff --git a/.docs/contributing-book/src/code/connect_four/src/data_structures.sw b/.docs/contributing-book/src/code/connect_four/src/data_structures.sw index 7a523bbd..d04b190b 100644 --- a/.docs/contributing-book/src/code/connect_four/src/data_structures.sw +++ b/.docs/contributing-book/src/code/connect_four/src/data_structures.sw @@ -1,4 +1,4 @@ -library data_structures; +library; pub struct Game { player_one: Player, diff --git a/.docs/contributing-book/src/code/connect_four/src/errors.sw b/.docs/contributing-book/src/code/connect_four/src/errors.sw index 8966f52f..45b6a6de 100644 --- a/.docs/contributing-book/src/code/connect_four/src/errors.sw +++ b/.docs/contributing-book/src/code/connect_four/src/errors.sw @@ -1,4 +1,4 @@ -library errors; +library; // ANCHOR: error pub enum MoveError { diff --git a/.docs/contributing-book/src/code/connect_four/src/events.sw b/.docs/contributing-book/src/code/connect_four/src/events.sw index f0444623..56462054 100644 --- a/.docs/contributing-book/src/code/connect_four/src/events.sw +++ b/.docs/contributing-book/src/code/connect_four/src/events.sw @@ -1,4 +1,4 @@ -library events; +library; // ANCHOR: event pub struct WinnerEvent { diff --git a/.docs/contributing-book/src/code/connect_four/src/interface.sw b/.docs/contributing-book/src/code/connect_four/src/interface.sw index 57f83d06..4e203ba6 100644 --- a/.docs/contributing-book/src/code/connect_four/src/interface.sw +++ b/.docs/contributing-book/src/code/connect_four/src/interface.sw @@ -1,9 +1,7 @@ // ANCHOR: interface -library interface; +library; -dep data_structures; - -use data_structures::{Game, Player}; +use ::data_structures::{Game, Player}; abi ConnectFour { /// Creates a new game diff --git a/.docs/contributing-book/src/code/connect_four/src/main.sw b/.docs/contributing-book/src/code/connect_four/src/main.sw index 54d09989..e4bb5e24 100644 --- a/.docs/contributing-book/src/code/connect_four/src/main.sw +++ b/.docs/contributing-book/src/code/connect_four/src/main.sw @@ -1,7 +1,7 @@ contract; -dep data_structures; -dep interface; +mod data_structures; +mod interface; use data_structures::{Game, Player}; use interface::ConnectFour; diff --git a/.docs/contributing-book/src/code/connect_four/src/utils.sw b/.docs/contributing-book/src/code/connect_four/src/utils.sw index 0ce2e30f..958a1f61 100644 --- a/.docs/contributing-book/src/code/connect_four/src/utils.sw +++ b/.docs/contributing-book/src/code/connect_four/src/utils.sw @@ -1,8 +1,6 @@ -library utils; +library; -dep data_structures; - -use data_structures::Game; +use ::data_structures::Game; pub fn validate_move(column: u64, game: Game) -> bool { true diff --git a/.docs/contributing-book/src/code/style_guide/src/lib.sw b/.docs/contributing-book/src/code/style_guide/src/lib.sw index 9f3ce81d..3e10ea4b 100644 --- a/.docs/contributing-book/src/code/style_guide/src/lib.sw +++ b/.docs/contributing-book/src/code/style_guide/src/lib.sw @@ -1,5 +1,5 @@ // ANCHOR: module -library style_guide; +library; // ANCHOR_END: module // ANCHOR: const const MAXIMUM_DEPOSIT = 10; diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe91f837..cdf64217 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,9 +15,9 @@ concurrency: env: CARGO_TERM_COLOR: always REGISTRY: ghcr.io - RUST_VERSION: 1.67.0 - FORC_VERSION: 0.35.3 - CORE_VERSION: 0.17.3 + RUST_VERSION: 1.68.2 + FORC_VERSION: 0.37.0 + CORE_VERSION: 0.17.8 PATH_TO_SCRIPTS: .github/scripts jobs: diff --git a/README.md b/README.md index 7c768ff6..0b46e091 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ - - + + @@ -87,7 +87,7 @@ cargo test Any instructions related to using a specific library should be found within the README.md of that library. > **Note** -> All projects currently use `forc v0.35.3`, `fuels-rs v0.36.1` and `fuel-core 0.17.3`. +> All projects currently use `forc v0.37.0`, `fuels-rs v0.36.1` and `fuel-core 0.17.8`. ## Contributing diff --git a/libs/fixed_point/src/ifp128.sw b/libs/fixed_point/src/ifp128.sw index 494a44be..7f95e189 100644 --- a/libs/fixed_point/src/ifp128.sw +++ b/libs/fixed_point/src/ifp128.sw @@ -1,4 +1,4 @@ -library ifp128; +library; // A wrapper library around the type for mathematical functions operating with signed 128-bit fixed point numbers. use std::math::{Exponent, Power, Root}; use ::ufp64::UFP64; diff --git a/libs/fixed_point/src/ifp256.sw b/libs/fixed_point/src/ifp256.sw index 3285ed0b..e6ea3813 100644 --- a/libs/fixed_point/src/ifp256.sw +++ b/libs/fixed_point/src/ifp256.sw @@ -1,4 +1,4 @@ -library ifp256; +library; // A wrapper library around the type for mathematical functions operating with signed 256-bit fixed point numbers. use std::math::{Exponent, Power, Root}; use ::ufp128::UFP128; diff --git a/libs/fixed_point/src/ifp64.sw b/libs/fixed_point/src/ifp64.sw index ae563cd5..2baa4cb2 100644 --- a/libs/fixed_point/src/ifp64.sw +++ b/libs/fixed_point/src/ifp64.sw @@ -1,4 +1,4 @@ -library ifp64; +library; // A wrapper library around the u32 type for mathematical functions operating with signed 64-bit fixed point numbers. use std::math::*; use ::ufp32::UFP32; diff --git a/libs/fixed_point/src/lib.sw b/libs/fixed_point/src/lib.sw index 290d74df..5d619caf 100644 --- a/libs/fixed_point/src/lib.sw +++ b/libs/fixed_point/src/lib.sw @@ -1,9 +1,9 @@ -library fixed_point; +library; -dep ufp32; -dep ufp64; -dep ufp128; +mod ufp32; +mod ufp64; +mod ufp128; -dep ifp64; -dep ifp128; -dep ifp256; +mod ifp64; +mod ifp128; +mod ifp256; diff --git a/libs/fixed_point/src/ufp128.sw b/libs/fixed_point/src/ufp128.sw index 44066383..ae344ded 100644 --- a/libs/fixed_point/src/ufp128.sw +++ b/libs/fixed_point/src/ufp128.sw @@ -1,4 +1,4 @@ -library ufp128; +library; // A wrapper around U128 type for a library for Sway for mathematical functions operating with signed 64.64-bit fixed point numbers. use std::{math::{Exponent, Power, Root}, u128::U128, u256::U256}; diff --git a/libs/fixed_point/src/ufp32.sw b/libs/fixed_point/src/ufp32.sw index d1a02d68..b085250b 100644 --- a/libs/fixed_point/src/ufp32.sw +++ b/libs/fixed_point/src/ufp32.sw @@ -1,4 +1,4 @@ -library ufp32; +library; // A wrapper library around the u32 type for mathematical functions operating with signed 32-bit fixed point numbers. use std::math::*; @@ -211,7 +211,7 @@ impl Root for UFP32 { /// Sqaure root for UFP32 fn sqrt(self) -> Self { let nominator_root = self.value.sqrt(); - // Need to multiply over 2 ^ 16, as the square root of the denominator + // Need to multiply over 2 ^ 16, as the square root of the denominator // is also taken and we need to ensure that the denominator is constant let nominator = nominator_root << 16; Self { diff --git a/libs/fixed_point/src/ufp64.sw b/libs/fixed_point/src/ufp64.sw index 2fac5fb0..4207f68d 100644 --- a/libs/fixed_point/src/ufp64.sw +++ b/libs/fixed_point/src/ufp64.sw @@ -1,4 +1,4 @@ -library ufp64; +library; // A wrapper library around the u64 type for mathematical functions operating with signed 64-bit fixed point numbers. use std::{math::{Exponent, Power, Root}, u128::U128}; @@ -211,7 +211,7 @@ impl Root for UFP64 { /// Sqaure root for UFP64 fn sqrt(self) -> Self { let nominator_root = self.value.sqrt(); - // Need to multiply over 2 ^ 16, as the square root of the denominator + // Need to multiply over 2 ^ 16, as the square root of the denominator // is also taken and we need to ensure that the denominator is constant let nominator = nominator_root << 16; Self { diff --git a/libs/merkle_proof/src/binary_merkle_proof.sw b/libs/merkle_proof/src/binary_merkle_proof.sw index f50bede5..f9bec0e9 100644 --- a/libs/merkle_proof/src/binary_merkle_proof.sw +++ b/libs/merkle_proof/src/binary_merkle_proof.sw @@ -1,4 +1,4 @@ -library binary_merkle_proof; +library; use std::{bytes::Bytes, hash::sha256}; diff --git a/libs/merkle_proof/src/lib.sw b/libs/merkle_proof/src/lib.sw index 31d3caf1..4ee2a2b6 100644 --- a/libs/merkle_proof/src/lib.sw +++ b/libs/merkle_proof/src/lib.sw @@ -1,3 +1,3 @@ -library merkle_proof; +library; -dep binary_merkle_proof; +mod binary_merkle_proof; diff --git a/libs/nft/src/extensions.sw b/libs/nft/src/extensions.sw new file mode 100644 index 00000000..8db24fd5 --- /dev/null +++ b/libs/nft/src/extensions.sw @@ -0,0 +1,6 @@ +library; + +mod administrator; +mod burnable; +mod supply; +mod token_metadata; diff --git a/libs/nft/src/extensions/administrator/administrator.sw b/libs/nft/src/extensions/administrator.sw similarity index 87% rename from libs/nft/src/extensions/administrator/administrator.sw rename to libs/nft/src/extensions/administrator.sw index f4f10758..bc575bd3 100644 --- a/libs/nft/src/extensions/administrator/administrator.sw +++ b/libs/nft/src/extensions/administrator.sw @@ -1,12 +1,12 @@ -library administrator; +library; -dep administrator_errors; -dep administrator_events; +mod administrator_errors; +mod administrator_events; use administrator_errors::AdminError; use administrator_events::AdminEvent; -use ::nft_storage::ADMIN; -use std::{auth::msg_sender, logging::log, storage::{get, store}}; +use ::nft_core::nft_storage::ADMIN; +use std::{auth::msg_sender, storage::{get, store}}; abi Administrator { #[storage(read)] diff --git a/libs/nft/src/extensions/administrator/administrator_errors.sw b/libs/nft/src/extensions/administrator/administrator_errors.sw index 2616d896..6ad85f82 100644 --- a/libs/nft/src/extensions/administrator/administrator_errors.sw +++ b/libs/nft/src/extensions/administrator/administrator_errors.sw @@ -1,4 +1,4 @@ -library administrator_errors; +library; pub enum AdminError { SenderNotAdmin: (), diff --git a/libs/nft/src/extensions/administrator/administrator_events.sw b/libs/nft/src/extensions/administrator/administrator_events.sw index 7f51f072..5a6d3707 100644 --- a/libs/nft/src/extensions/administrator/administrator_events.sw +++ b/libs/nft/src/extensions/administrator/administrator_events.sw @@ -1,4 +1,4 @@ -library administrator_events; +library; pub struct AdminEvent { /// The user which is now the admin of this contract. diff --git a/libs/nft/src/extensions/burnable/burnable.sw b/libs/nft/src/extensions/burnable.sw similarity index 85% rename from libs/nft/src/extensions/burnable/burnable.sw rename to libs/nft/src/extensions/burnable.sw index 84e5feee..30ff9983 100644 --- a/libs/nft/src/extensions/burnable/burnable.sw +++ b/libs/nft/src/extensions/burnable.sw @@ -1,10 +1,10 @@ -library burnable; +library; -dep burnable_events; +mod burnable_events; use burnable_events::BurnEvent; -use ::{errors::{AccessError, InputError}, nft_core::NFTCore, nft_storage::{BALANCES, TOKENS}}; -use std::{auth::msg_sender, hash::sha256, logging::log, storage::{get, store}}; +use ::nft_core::{errors::{AccessError, InputError}, nft_storage::{BALANCES, TOKENS}, NFTCore}; +use std::{auth::msg_sender, hash::sha256, storage::{get, store}}; abi Burn { #[storage(read, write)] diff --git a/libs/nft/src/extensions/burnable/burnable_events.sw b/libs/nft/src/extensions/burnable/burnable_events.sw index e4907eb5..84de9329 100644 --- a/libs/nft/src/extensions/burnable/burnable_events.sw +++ b/libs/nft/src/extensions/burnable/burnable_events.sw @@ -1,4 +1,4 @@ -library burnable_events; +library; pub struct BurnEvent { /// The user that has burned their token. diff --git a/libs/nft/src/extensions/supply/supply.sw b/libs/nft/src/extensions/supply.sw similarity index 88% rename from libs/nft/src/extensions/supply/supply.sw rename to libs/nft/src/extensions/supply.sw index d001f63d..4297b987 100644 --- a/libs/nft/src/extensions/supply/supply.sw +++ b/libs/nft/src/extensions/supply.sw @@ -1,10 +1,10 @@ -library supply; +library; -dep supply_errors; -dep supply_events; +mod supply_errors; +mod supply_events; -use ::nft_storage::MAX_SUPPLY; -use std::{logging::log, storage::{get, store}}; +use ::nft_core::nft_storage::MAX_SUPPLY; +use std::storage::{get, store}; use supply_errors::SupplyError; use supply_events::SupplyEvent; diff --git a/libs/nft/src/extensions/supply/supply_errors.sw b/libs/nft/src/extensions/supply/supply_errors.sw index 01c194e7..f194c0a2 100644 --- a/libs/nft/src/extensions/supply/supply_errors.sw +++ b/libs/nft/src/extensions/supply/supply_errors.sw @@ -1,4 +1,4 @@ -library supply_errors; +library; pub enum SupplyError { CannotReinitializeSupply: (), diff --git a/libs/nft/src/extensions/supply/supply_events.sw b/libs/nft/src/extensions/supply/supply_events.sw index 85bd37a3..e6c88ef3 100644 --- a/libs/nft/src/extensions/supply/supply_events.sw +++ b/libs/nft/src/extensions/supply/supply_events.sw @@ -1,4 +1,4 @@ -library supply_events; +library; pub struct SupplyEvent { /// The new supply amount that has been set. diff --git a/libs/nft/src/extensions/token_metadata/token_metadata.sw b/libs/nft/src/extensions/token_metadata.sw similarity index 93% rename from libs/nft/src/extensions/token_metadata/token_metadata.sw rename to libs/nft/src/extensions/token_metadata.sw index d1f87040..c06eb7b5 100644 --- a/libs/nft/src/extensions/token_metadata/token_metadata.sw +++ b/libs/nft/src/extensions/token_metadata.sw @@ -1,9 +1,9 @@ -library token_metadata; +library; -dep token_metadata_structures; +mod token_metadata_structures; use token_metadata_structures::NFTMetadata; -use ::{errors::InputError, nft_core::NFTCore, nft_storage::{TOKEN_METADATA, TOKENS}}; +use ::nft_core::{errors::InputError, nft_storage::{TOKEN_METADATA, TOKENS}, NFTCore}; use std::{hash::sha256, storage::{get, store}}; pub trait TokenMetadata { diff --git a/libs/nft/src/extensions/token_metadata/token_metadata_structures.sw b/libs/nft/src/extensions/token_metadata/token_metadata_structures.sw index 5bbdf332..3def0290 100644 --- a/libs/nft/src/extensions/token_metadata/token_metadata_structures.sw +++ b/libs/nft/src/extensions/token_metadata/token_metadata_structures.sw @@ -1,4 +1,4 @@ -library token_metadata_structures; +library; pub struct NFTMetadata { // This is left as an example. Support for StorageVec in struct is needed here. diff --git a/libs/nft/src/lib.sw b/libs/nft/src/lib.sw index 8c0c028b..9a574585 100644 --- a/libs/nft/src/lib.sw +++ b/libs/nft/src/lib.sw @@ -1,20 +1,21 @@ -library nft; +library; // TODO: Move these into alphabetical order once https://github.com/FuelLabs/sway/issues/409 is resolved -dep nft_storage; -dep nft_core; -dep errors; -dep events; -dep extensions/administrator/administrator; -dep extensions/burnable/burnable; -dep extensions/token_metadata/token_metadata; -dep extensions/supply/supply; - -use errors::InputError; -use events::OperatorEvent; -use nft_core::NFTCore; -use nft_storage::{BALANCES, OPERATOR_APPROVAL, TOKENS, TOKENS_MINTED}; -use std::{auth::msg_sender, hash::sha256, logging::log, storage::{get, store}}; +mod nft_core; +mod extensions; + +use nft_core::{ + errors::InputError, + events::OperatorEvent, + nft_storage::{ + BALANCES, + OPERATOR_APPROVAL, + TOKENS, + TOKENS_MINTED, + }, + NFTCore, +}; +use std::{auth::msg_sender, hash::sha256, storage::{get, store}}; abi NFT { #[storage(read, write)] diff --git a/libs/nft/src/nft_core.sw b/libs/nft/src/nft_core.sw index a30b3c2c..719abcae 100644 --- a/libs/nft/src/nft_core.sw +++ b/libs/nft/src/nft_core.sw @@ -1,12 +1,12 @@ -library nft_core; +library; -dep errors; -dep events; -dep nft_storage; +mod errors; +mod events; +mod nft_storage; use errors::{AccessError, InputError}; use events::{ApprovalEvent, MintEvent, OperatorEvent, TransferEvent}; -use std::{auth::msg_sender, hash::sha256, logging::log, storage::{get, store}}; +use std::{auth::msg_sender, hash::sha256, storage::{get, store}}; use nft_storage::{BALANCES, OPERATOR_APPROVAL, TOKENS, TOKENS_MINTED}; pub struct NFTCore { diff --git a/libs/nft/src/errors.sw b/libs/nft/src/nft_core/errors.sw similarity index 92% rename from libs/nft/src/errors.sw rename to libs/nft/src/nft_core/errors.sw index bee36ce8..751b67c6 100644 --- a/libs/nft/src/errors.sw +++ b/libs/nft/src/nft_core/errors.sw @@ -1,4 +1,4 @@ -library errors; +library; pub enum AccessError { OwnerDoesNotExist: (), diff --git a/libs/nft/src/events.sw b/libs/nft/src/nft_core/events.sw similarity index 98% rename from libs/nft/src/events.sw rename to libs/nft/src/nft_core/events.sw index 4a4743e4..7f44cd32 100644 --- a/libs/nft/src/events.sw +++ b/libs/nft/src/nft_core/events.sw @@ -1,4 +1,4 @@ -library events; +library; pub struct ApprovalEvent { /// The user that has gotten approval to transfer the specified token. diff --git a/libs/nft/src/nft_storage.sw b/libs/nft/src/nft_core/nft_storage.sw similarity index 97% rename from libs/nft/src/nft_storage.sw rename to libs/nft/src/nft_core/nft_storage.sw index c7ef998a..24ae1ef2 100644 --- a/libs/nft/src/nft_storage.sw +++ b/libs/nft/src/nft_core/nft_storage.sw @@ -1,4 +1,4 @@ -library nft_storage; +library; // TODO: These are temporary storage keys for manual storage management. These should be removed once // https://github.com/FuelLabs/sway/issues/2585 is resolved. diff --git a/libs/ownership/Forc.toml b/libs/ownership/Forc.toml index ad6c50d6..2cdcc830 100644 --- a/libs/ownership/Forc.toml +++ b/libs/ownership/Forc.toml @@ -1,5 +1,5 @@ [project] authors = ["Fuel Labs "] -entry = "lib.sw" +entry = "ownable.sw" license = "Apache-2.0" name = "ownership" diff --git a/libs/ownership/src/data_structures.sw b/libs/ownership/src/data_structures.sw index a3119aea..da80e3a9 100644 --- a/libs/ownership/src/data_structures.sw +++ b/libs/ownership/src/data_structures.sw @@ -1,4 +1,4 @@ -library data_structures; +library; pub enum State { Uninitialized: (), diff --git a/libs/ownership/src/errors.sw b/libs/ownership/src/errors.sw index eb2c656d..7da997bc 100644 --- a/libs/ownership/src/errors.sw +++ b/libs/ownership/src/errors.sw @@ -1,4 +1,4 @@ -library errors; +library; pub enum AccessError { CannotReinitialized: (), diff --git a/libs/ownership/src/events.sw b/libs/ownership/src/events.sw index 8eecd953..fcf73e3e 100644 --- a/libs/ownership/src/events.sw +++ b/libs/ownership/src/events.sw @@ -1,4 +1,4 @@ -library events; +library; pub struct OwnershipRenounced { previous_owner: Identity, diff --git a/libs/ownership/src/lib.sw b/libs/ownership/src/lib.sw deleted file mode 100644 index 1c3ee4c8..00000000 --- a/libs/ownership/src/lib.sw +++ /dev/null @@ -1,3 +0,0 @@ -library ownership; - -dep ownable; diff --git a/libs/ownership/src/ownable.sw b/libs/ownership/src/ownable.sw index 19490101..72610578 100644 --- a/libs/ownership/src/ownable.sw +++ b/libs/ownership/src/ownable.sw @@ -1,15 +1,15 @@ -library ownable; +library; -dep data_structures; -dep errors; -dep events; -dep ownable_storage; +mod data_structures; +mod errors; +mod events; +mod ownable_storage; use data_structures::State; use errors::AccessError; use events::{OwnershipRenounced, OwnershipSet, OwnershipTransferred}; use ownable_storage::OWNER; -use std::{auth::msg_sender, hash::sha256, logging::log, storage::{get, store}}; +use std::{auth::msg_sender, hash::sha256, storage::{get, store}}; /// Ensures that the sender is the owner. /// diff --git a/libs/ownership/src/ownable_storage.sw b/libs/ownership/src/ownable_storage.sw index 594de013..22b9d743 100644 --- a/libs/ownership/src/ownable_storage.sw +++ b/libs/ownership/src/ownable_storage.sw @@ -1,4 +1,4 @@ -library ownable_storage; +library; // TODO: These are temporary storage keys for manual storage management. These should be removed once // https://github.com/FuelLabs/sway/issues/2585 is resolved. diff --git a/libs/reentrancy/src/lib.sw b/libs/reentrancy/src/lib.sw index 44e56170..edb96250 100644 --- a/libs/reentrancy/src/lib.sw +++ b/libs/reentrancy/src/lib.sw @@ -1,4 +1,4 @@ -library reentrancy; +library; // This has been moved due to https://github.com/FuelLabs/sway/issues/4160 //! A reentrancy check for use in Sway contracts. //! Note that this only works in internal contexts. diff --git a/libs/signed_integers/src/common.sw b/libs/signed_integers/src/common.sw index c01050ad..25debe21 100644 --- a/libs/signed_integers/src/common.sw +++ b/libs/signed_integers/src/common.sw @@ -1,4 +1,4 @@ -library common; +library; pub trait TwosComplement { fn twos_complement(self) -> Self; diff --git a/libs/signed_integers/src/errors.sw b/libs/signed_integers/src/errors.sw index 89025f49..cf0ab2d6 100644 --- a/libs/signed_integers/src/errors.sw +++ b/libs/signed_integers/src/errors.sw @@ -1,4 +1,4 @@ -library errors; +library; pub enum Error { ZeroDivisor: (), diff --git a/libs/signed_integers/src/i128.sw b/libs/signed_integers/src/i128.sw index c8eddf63..3034e826 100644 --- a/libs/signed_integers/src/i128.sw +++ b/libs/signed_integers/src/i128.sw @@ -1,4 +1,4 @@ -library i128; +library; use std::u128::U128; use ::common::TwosComplement; diff --git a/libs/signed_integers/src/i16.sw b/libs/signed_integers/src/i16.sw index 5838110c..ed111cdc 100644 --- a/libs/signed_integers/src/i16.sw +++ b/libs/signed_integers/src/i16.sw @@ -1,4 +1,4 @@ -library i16; +library; use ::errors::Error; use ::common::TwosComplement; diff --git a/libs/signed_integers/src/i256.sw b/libs/signed_integers/src/i256.sw index 31126201..f9d1842c 100644 --- a/libs/signed_integers/src/i256.sw +++ b/libs/signed_integers/src/i256.sw @@ -1,4 +1,4 @@ -library i256; +library; use std::u256::U256; use ::common::TwosComplement; diff --git a/libs/signed_integers/src/i32.sw b/libs/signed_integers/src/i32.sw index 6d458d2f..c5f4e4f1 100644 --- a/libs/signed_integers/src/i32.sw +++ b/libs/signed_integers/src/i32.sw @@ -1,4 +1,4 @@ -library i32; +library; use ::common::TwosComplement; use ::errors::Error; diff --git a/libs/signed_integers/src/i64.sw b/libs/signed_integers/src/i64.sw index 7e7441db..ad06c8d7 100644 --- a/libs/signed_integers/src/i64.sw +++ b/libs/signed_integers/src/i64.sw @@ -1,4 +1,4 @@ -library i64; +library; use ::common::TwosComplement; use ::errors::Error; diff --git a/libs/signed_integers/src/i8.sw b/libs/signed_integers/src/i8.sw index c2a9dc8d..af8e2777 100644 --- a/libs/signed_integers/src/i8.sw +++ b/libs/signed_integers/src/i8.sw @@ -1,4 +1,4 @@ -library i8; +library; use ::errors::Error; use ::common::TwosComplement; diff --git a/libs/signed_integers/src/lib.sw b/libs/signed_integers/src/lib.sw index c0fbbcc9..49c720e5 100644 --- a/libs/signed_integers/src/lib.sw +++ b/libs/signed_integers/src/lib.sw @@ -1,11 +1,11 @@ -library signed_integers; +library; -dep common; -dep errors; +mod common; +mod errors; -dep i8; -dep i16; -dep i32; -dep i64; -dep i128; -dep i256; +mod i8; +mod i16; +mod i32; +mod i64; +mod i128; +mod i256; diff --git a/libs/storagemapvec/src/lib.sw b/libs/storagemapvec/src/lib.sw index 08c71b27..c8b058e6 100644 --- a/libs/storagemapvec/src/lib.sw +++ b/libs/storagemapvec/src/lib.sw @@ -1,4 +1,4 @@ -library storagemapvec; +library; use std::{hash::sha256, storage::{get, store}}; @@ -414,7 +414,7 @@ impl StorageMapVec { #[storage(read, write)] pub fn remove(self, key: K, index: u64) -> V { // get the key to the length of the vector - let len_key = sha256((key, __get_storage_key())); + let len_key = sha256((key, __get_storage_key())); // get the length of the vector let len = get::(len_key).unwrap_or(0); diff --git a/libs/string/README.md b/libs/string/README.md index 3f6e281e..a4ac222e 100644 --- a/libs/string/README.md +++ b/libs/string/README.md @@ -19,6 +19,9 @@ For more information please see the [specification](./SPECIFICATION.md). The `append()` function currently causes an internal compiler error when used. It has been commented out until https://github.com/FuelLabs/sway/issues/4158 is resolved. + +Until https://github.com/FuelLabs/sway/issues/4158 is resolved, developers must directly access the underlying `Bytes` type to make modifications to the `String` type. + It is important to note that unlike Rust's `String`, this `String` library does **not** guarantee a valid UTF-8 string. The `String` currently behaves only as a `vec` and does not perform any validation. This intended to be supported in the future with the introduction of [`char`](https://github.com/FuelLabs/sway/issues/2937) to the Sway language. # Using the Library diff --git a/libs/string/src/lib.sw b/libs/string/src/lib.sw index 71525ed6..88647bb7 100644 --- a/libs/string/src/lib.sw +++ b/libs/string/src/lib.sw @@ -1,4 +1,4 @@ -library string; +library; use std::{bytes::Bytes, convert::From}; @@ -144,12 +144,10 @@ impl String { /// # Arguments /// /// * `other` - The String to join to self. - - // pub fn append(ref mut self, mut other: self) { + // pub fn append(ref mut self, mut other: self) { // self.bytes.append(other.into()) // } - -/// Divides one Bytes into two at an index. + /// Divides one Bytes into two at an index. /// /// # Arguments /// diff --git a/standards/frc20/src/lib.sw b/standards/frc20/src/lib.sw index ee2fe2fd..b037fb4f 100644 --- a/standards/frc20/src/lib.sw +++ b/standards/frc20/src/lib.sw @@ -1,4 +1,4 @@ -library frc20_abi; +library; use std::u256::U256; diff --git a/standards/frc721/src/extensions.sw b/standards/frc721/src/extensions.sw new file mode 100644 index 00000000..71937b1c --- /dev/null +++ b/standards/frc721/src/extensions.sw @@ -0,0 +1,3 @@ +library; + +mod frc721_metadata; diff --git a/standards/frc721/src/extensions/frc721_metadata.sw b/standards/frc721/src/extensions/frc721_metadata.sw index 3add9fac..f946b9c4 100644 --- a/standards/frc721/src/extensions/frc721_metadata.sw +++ b/standards/frc721/src/extensions/frc721_metadata.sw @@ -1,10 +1,4 @@ -library frc721_metadata; - -/** -The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, -“SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be -interpreted as described in RFC 2119: https://www.ietf.org/rfc/rfc2119.txt -*/ +library; /// Any contract that implements FRC721_metadata SHALL also implement FRC721. abi FRC721_metadata { diff --git a/standards/frc721/src/frc_721.sw b/standards/frc721/src/frc_721.sw index 922a4749..f22a7bb5 100644 --- a/standards/frc721/src/frc_721.sw +++ b/standards/frc721/src/frc_721.sw @@ -1,10 +1,4 @@ -library frc721; - -/** -The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, -“SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be -interpreted as described in RFC 2119: https://www.ietf.org/rfc/rfc2119.txt -*/ +library; /// This event MUST be logged when the approved Identity for an NFT is changed or modified. /// Option::None indicates there is no approved Identity. @@ -13,6 +7,7 @@ pub struct ApprovalEvent { owner: Identity, token_id: u64, } + /// This event MUST be logged when an operator is enabled or disabled for an owner. /// The operator can manage all NFTs of the owner. pub struct OperatorEvent { @@ -20,6 +15,7 @@ pub struct OperatorEvent { operator: Identity, owner: Identity, } + /// This event MUST be logged when ownership of any NFT changes between two Identities. /// Exception: Cases where there is no new or previous owner, formally known as minting and burning, /// the event SHALL NOT be logged. @@ -53,6 +49,7 @@ abi FRC721 { /// /// * The TransferEvent event MUST be emitted when the function is not reverted. fn transfer(to: Identity, token_id: u64); + /// Set or reafirm the approved Identity for an NFT. /// The approved Identity for the specified NFT MAY transfer the token to a new owner. /// @@ -69,6 +66,7 @@ abi FRC721 { /// /// * The ApprovalEvent event MUST be emitted when the function is not reverted. fn approve(approved: Option, token_id: u64); + /// Enable or disable approval for a third party "Operator" to manage all /// of `msg_sender()`'s NFTs. /// An operator for an Identity MAY transfer and MAY set approved Identities for all tokens @@ -85,6 +83,7 @@ abi FRC721 { /// /// * The OperatorEvent event MUST be emitted. fn set_approval_for_all(approve: bool, operator: Identity); + /// Get the approved Identity for a single NFT. /// Option::None indicates there is no approved Identity. /// @@ -96,12 +95,14 @@ abi FRC721 { /// /// * It is REQUIRED that `token_id` is valid NFT. fn approved(token_id: u64) -> Option; + /// The number of NFTs owned by an Identity. /// /// # Arguments /// /// * `owner` - The Identity of which to query the balance. fn balance_of(owner: Identity) -> u64; + /// Query if an Identity is an authorized operator for another Identity. /// /// # Arguments @@ -109,6 +110,7 @@ abi FRC721 { /// * `operator` - The Identity that acts on behalf of the owner. /// * `owner` - The Identity that owns the NFT/NFTs. fn is_approved_for_all(operator: Identity, owner: Identity) -> bool; + /// Query the owner of an NFT. /// Option::None indicates there is no owner Identity. /// diff --git a/standards/frc721/src/lib.sw b/standards/frc721/src/lib.sw index c9c09223..ad85a061 100644 --- a/standards/frc721/src/lib.sw +++ b/standards/frc721/src/lib.sw @@ -1,4 +1,4 @@ -library frc721; +library; -dep frc_721; -dep extensions/frc721_metadata; +mod frc_721; +mod extensions; diff --git a/tests/src/nft/nft_extensions/src/main.sw b/tests/src/nft/nft_extensions/src/main.sw index ca57e586..599f02d9 100644 --- a/tests/src/nft/nft_extensions/src/main.sw +++ b/tests/src/nft/nft_extensions/src/main.sw @@ -1,28 +1,30 @@ contract; use nft::{ - administrator::{ - admin, - Administrator, - set_admin, - }, balance_of, - burnable::{ - burn, - Burn, + extensions::{ + administrator::{ + admin, + Administrator, + set_admin, + }, + burnable::{ + burn, + Burn, + }, + supply::{ + max_supply, + set_max_supply, + Supply, + }, + token_metadata::{ + set_token_metadata, + token_metadata, + token_metadata_structures::NFTMetadata, + }, }, mint, owner_of, - supply::{ - max_supply, - set_max_supply, - Supply, - }, - token_metadata::{ - set_token_metadata, - token_metadata, - token_metadata_structures::NFTMetadata, - }, tokens_minted, }; diff --git a/tests/src/ownership/src/main.sw b/tests/src/ownership/src/main.sw index 28716f16..0781260b 100644 --- a/tests/src/ownership/src/main.sw +++ b/tests/src/ownership/src/main.sw @@ -1,6 +1,6 @@ contract; -use ownership::ownable::{ +use ownership::{ data_structures::State, only_owner, owner, diff --git a/tests/src/reentrancy/reentrancy_attacker_abi/src/main.sw b/tests/src/reentrancy/reentrancy_attacker_abi/src/main.sw index bc9b275b..9852c7bb 100644 --- a/tests/src/reentrancy/reentrancy_attacker_abi/src/main.sw +++ b/tests/src/reentrancy/reentrancy_attacker_abi/src/main.sw @@ -1,4 +1,4 @@ -library reentrancy_attacker_abi; +library; abi Attacker { fn launch_attack(target: ContractId) -> bool; diff --git a/tests/src/reentrancy/reentrancy_target_abi/src/main.sw b/tests/src/reentrancy/reentrancy_target_abi/src/main.sw index 50376f5f..5ea8b1a8 100644 --- a/tests/src/reentrancy/reentrancy_target_abi/src/main.sw +++ b/tests/src/reentrancy/reentrancy_target_abi/src/main.sw @@ -1,4 +1,4 @@ -library reentrancy_target_abi; +library; abi Target { fn reentrancy_detected() -> bool; diff --git a/tests/src/string/src/main.sw b/tests/src/string/src/main.sw index 1b3f14dc..41aa51e4 100644 --- a/tests/src/string/src/main.sw +++ b/tests/src/string/src/main.sw @@ -55,33 +55,36 @@ impl StringTest for Contract { // assert(string1.nth(3).unwrap() == NUMBER3); // assert(string1.nth(4).unwrap() == NUMBER4); // assert(string1.nth(5).unwrap() == NUMBER5); - } +} fn test_as_vec() { + // Uncomment when https://github.com/FuelLabs/sway/issues/4408 is resolved let mut string = String::new(); let bytes = string.as_vec(); assert(bytes.len() == string.len()); assert(bytes.capacity() == string.capacity()); - string.push(NUMBER0); - let bytes = string.as_vec(); - assert(bytes.len() == string.len()); - assert(bytes.capacity() == string.capacity()); - assert(bytes.get(0).unwrap() == string.nth(0).unwrap()); - string.push(NUMBER1); - let mut bytes = string.as_vec(); - assert(bytes.len() == string.len()); - assert(bytes.capacity() == string.capacity()); - assert(bytes.get(1).unwrap() == string.nth(1).unwrap()); - let result_string = string.pop().unwrap(); - let result_bytes = bytes.pop().unwrap(); - assert(result_bytes == result_string); - assert(bytes.len() == string.len()); - assert(bytes.capacity() == string.capacity()); - assert(bytes.get(0).unwrap() == string.nth(0).unwrap()); + // string.push(NUMBER0); + // let bytes = string.as_vec(); + // assert(bytes.len() == string.len()); + // assert(bytes.capacity() == string.capacity()); + // assert(bytes.get(0).unwrap() == string.nth(0).unwrap()); + + // string.push(NUMBER1); + // let mut bytes = string.as_vec(); + // assert(bytes.len() == string.len()); + // assert(bytes.capacity() == string.capacity()); + // assert(bytes.get(1).unwrap() == string.nth(1).unwrap()); + + // let result_string = string.pop().unwrap(); + // let result_bytes = bytes.pop().unwrap(); + // assert(result_bytes == result_string); + // assert(bytes.len() == string.len()); + // assert(bytes.capacity() == string.capacity()); + // assert(bytes.get(0).unwrap() == string.nth(0).unwrap()); } fn test_capacity() { @@ -89,33 +92,40 @@ impl StringTest for Contract { assert(string.capacity() == 0); - string.push(NUMBER0); - assert(string.capacity() == 1); - string.push(NUMBER1); - assert(string.capacity() == 2); - string.push(NUMBER2); - assert(string.capacity() == 4); - string.push(NUMBER3); - assert(string.capacity() == 4); - string.push(NUMBER4); - assert(string.capacity() == 8); - string.push(NUMBER5); - assert(string.capacity() == 8); - string.push(NUMBER6); - string.push(NUMBER7); - assert(string.capacity() == 8); - string.push(NUMBER8); - assert(string.capacity() == 16); - string.clear(); - assert(string.capacity() == 0); - string.push(NUMBER0); - assert(string.capacity() == 1); + // Uncomment when https://github.com/FuelLabs/sway/issues/4408 is resolved + // string.push(NUMBER0); + // assert(string.capacity() == 1); + + // string.push(NUMBER1); + // assert(string.capacity() == 2); + + // string.push(NUMBER2); + // assert(string.capacity() == 4); + // string.push(NUMBER3); + // assert(string.capacity() == 4); + + // string.push(NUMBER4); + // assert(string.capacity() == 8); + // string.push(NUMBER5); + // assert(string.capacity() == 8); + // string.push(NUMBER6); + // string.push(NUMBER7); + // assert(string.capacity() == 8); + + // string.push(NUMBER8); + // assert(string.capacity() == 16); + + // string.clear(); + // assert(string.capacity() == 0); + + // string.push(NUMBER0); + // assert(string.capacity() == 1); } fn test_clear() { @@ -126,89 +136,106 @@ impl StringTest for Contract { string.clear(); assert(string.is_empty()); - string.push(NUMBER0); - assert(!string.is_empty()); - string.clear(); - assert(string.is_empty()); - string.push(NUMBER0); - string.push(NUMBER1); - string.push(NUMBER2); - string.push(NUMBER3); - string.push(NUMBER4); - string.push(NUMBER5); - string.push(NUMBER6); - string.push(NUMBER7); - string.push(NUMBER8); - assert(!string.is_empty()); - string.clear(); - assert(string.is_empty()); - string.clear(); - assert(string.is_empty()); - string.push(NUMBER0); - assert(!string.is_empty()); - string.clear(); - assert(string.is_empty()); + // Uncomment when https://github.com/FuelLabs/sway/issues/4408 is resolved + // string.push(NUMBER0); + // assert(!string.is_empty()); + + // string.clear(); + // assert(string.is_empty()); + + // string.push(NUMBER0); + // string.push(NUMBER1); + // string.push(NUMBER2); + // string.push(NUMBER3); + // string.push(NUMBER4); + // string.push(NUMBER5); + // string.push(NUMBER6); + // string.push(NUMBER7); + // string.push(NUMBER8); + // assert(!string.is_empty()); + + // string.clear(); + // assert(string.is_empty()); + + // string.clear(); + // assert(string.is_empty()); + + // string.push(NUMBER0); + // assert(!string.is_empty()); + + // string.clear(); + // assert(string.is_empty()); } fn test_from() { - let mut bytes = Bytes::new(); - - bytes.push(NUMBER0); - bytes.push(NUMBER1); - bytes.push(NUMBER2); - bytes.push(NUMBER3); - bytes.push(NUMBER4); - - let string_from_bytes = String::from(bytes); - assert(bytes.len() == string_from_bytes.len()); - assert(bytes.capacity() == string_from_bytes.capacity()); - assert(bytes.get(0).unwrap() == string_from_bytes.nth(0).unwrap()); - assert(bytes.get(1).unwrap() == string_from_bytes.nth(1).unwrap()); - assert(bytes.get(2).unwrap() == string_from_bytes.nth(2).unwrap()); - } + + + // Uncomment when https://github.com/FuelLabs/sway/issues/4408 is resolved + // let mut bytes = Bytes::new(); + + // bytes.push(NUMBER0); + // bytes.push(NUMBER1); + // bytes.push(NUMBER2); + // bytes.push(NUMBER3); + // bytes.push(NUMBER4); + + // let string_from_bytes = String::from(bytes); + // assert(bytes.len() == string_from_bytes.len()); + // assert(bytes.capacity() == string_from_bytes.capacity()); + // assert(bytes.get(0).unwrap() == string_from_bytes.nth(0).unwrap()); + // assert(bytes.get(1).unwrap() == string_from_bytes.nth(1).unwrap()); + // assert(bytes.get(2).unwrap() == string_from_bytes.nth(2).unwrap()); +} fn test_from_utf8() { - let mut vec: Vec = Vec::new(); - - vec.push(NUMBER0); - vec.push(NUMBER1); - vec.push(NUMBER2); - vec.push(NUMBER3); - vec.push(NUMBER4); - - let string_from_uft8 = String::from_utf8(vec); - assert(vec.len() == string_from_uft8.len()); - assert(vec.capacity() == string_from_uft8.capacity()); - assert(vec.get(0).unwrap() == string_from_uft8.nth(0).unwrap()); - assert(vec.get(1).unwrap() == string_from_uft8.nth(1).unwrap()); - assert(vec.get(2).unwrap() == string_from_uft8.nth(2).unwrap()); - } + + + // Uncomment when https://github.com/FuelLabs/sway/issues/4408 is resolved + // let mut vec: Vec = Vec::new(); + + // vec.push(NUMBER0); + // vec.push(NUMBER1); + // vec.push(NUMBER2); + // vec.push(NUMBER3); + // vec.push(NUMBER4); + + // let string_from_uft8 = String::from_utf8(vec); + // assert(vec.len() == string_from_uft8.len()); + // assert(vec.capacity() == string_from_uft8.capacity()); + // assert(vec.get(0).unwrap() == string_from_uft8.nth(0).unwrap()); + // assert(vec.get(1).unwrap() == string_from_uft8.nth(1).unwrap()); + // assert(vec.get(2).unwrap() == string_from_uft8.nth(2).unwrap()); +} fn test_insert() { let mut string = String::new(); assert(string.len() == 0); - string.insert(NUMBER0, 0); - assert(string.len() == 1); - assert(string.nth(0).unwrap() == NUMBER0); - string.push(NUMBER1); - string.push(NUMBER2); - string.insert(NUMBER3, 0); - assert(string.len() == 4); - assert(string.nth(0).unwrap() == NUMBER3); - string.insert(NUMBER4, 1); - assert(string.nth(1).unwrap() == NUMBER4); - string.insert(NUMBER5, string.len() - 1); - assert(string.nth(string.len() - 2).unwrap() == NUMBER5); + // Uncomment when https://github.com/FuelLabs/sway/issues/4408 is resolved + // string.insert(NUMBER0, 0); + // assert(string.len() == 1); + // assert(string.nth(0).unwrap() == NUMBER0); + + // string.push(NUMBER1); + // string.push(NUMBER2); + // string.insert(NUMBER3, 0); + // assert(string.len() == 4); + // assert(string.nth(0).unwrap() == NUMBER3); + + // string.insert(NUMBER4, 1); + // assert(string.nth(1).unwrap() == NUMBER4); + + // string.insert(NUMBER5, string.len() - 1); + // assert(string.nth(string.len() - 2).unwrap() == NUMBER5); } fn test_into() { @@ -218,24 +245,27 @@ impl StringTest for Contract { assert(bytes.len() == string.len()); assert(bytes.capacity() == string.capacity()); - string.push(NUMBER0); - let bytes = string.into(); - assert(bytes.len() == string.len()); - assert(bytes.capacity() == string.capacity()); - assert(bytes.get(0).unwrap() == string.nth(0).unwrap()); - string.push(NUMBER1); - let mut bytes = string.into(); - assert(bytes.len() == string.len()); - assert(bytes.capacity() == string.capacity()); - assert(bytes.get(1).unwrap() == string.nth(1).unwrap()); - let result_string = string.pop().unwrap(); - let result_bytes = bytes.pop().unwrap(); - assert(result_bytes == result_string); - assert(bytes.len() == string.len()); - assert(bytes.capacity() == string.capacity()); - assert(bytes.get(0).unwrap() == string.nth(0).unwrap()); + // Uncomment when https://github.com/FuelLabs/sway/issues/4408 is resolved + // string.push(NUMBER0); + // let bytes = string.into(); + // assert(bytes.len() == string.len()); + // assert(bytes.capacity() == string.capacity()); + // assert(bytes.get(0).unwrap() == string.nth(0).unwrap()); + + // string.push(NUMBER1); + // let mut bytes = string.into(); + // assert(bytes.len() == string.len()); + // assert(bytes.capacity() == string.capacity()); + // assert(bytes.get(1).unwrap() == string.nth(1).unwrap()); + + // let result_string = string.pop().unwrap(); + // let result_bytes = bytes.pop().unwrap(); + // assert(result_bytes == result_string); + // assert(bytes.len() == string.len()); + // assert(bytes.capacity() == string.capacity()); + // assert(bytes.get(0).unwrap() == string.nth(0).unwrap()); } fn test_is_empty() { @@ -243,26 +273,33 @@ impl StringTest for Contract { assert(string.is_empty()); - string.push(NUMBER0); - assert(!string.is_empty()); - string.push(NUMBER1); - assert(!string.is_empty()); - string.clear(); - assert(string.is_empty()); - string.push(NUMBER0); - assert(!string.is_empty()); - string.push(NUMBER1); - assert(!string.is_empty()); - let _result = string.pop(); - assert(!string.is_empty()); - let _result = string.pop(); - assert(string.is_empty()); + // Uncomment when https://github.com/FuelLabs/sway/issues/4408 is resolved + // string.push(NUMBER0); + // assert(!string.is_empty()); + + // string.push(NUMBER1); + // assert(!string.is_empty()); + + // string.clear(); + // assert(string.is_empty()); + + // string.push(NUMBER0); + // assert(!string.is_empty()); + + // string.push(NUMBER1); + // assert(!string.is_empty()); + + // let _result = string.pop(); + // assert(!string.is_empty()); + + // let _result = string.pop(); + // assert(string.is_empty()); } fn test_len() { @@ -270,37 +307,47 @@ impl StringTest for Contract { assert(string.len() == 0); - string.push(NUMBER0); - assert(string.len() == 1); - string.push(NUMBER1); - assert(string.len() == 2); - string.push(NUMBER2); - assert(string.len() == 3); - string.push(NUMBER3); - assert(string.len() == 4); - string.push(NUMBER4); - assert(string.len() == 5); - string.push(NUMBER5); - assert(string.len() == 6); - string.push(NUMBER6); - assert(string.len() == 7); - string.push(NUMBER7); - assert(string.len() == 8); - string.push(NUMBER8); - assert(string.len() == 9); - let _result = string.pop(); - assert(string.len() == 8); - string.clear(); - assert(string.len() == 0); + // Uncomment when https://github.com/FuelLabs/sway/issues/4408 is resolved + // string.push(NUMBER0); + // assert(string.len() == 1); + + // string.push(NUMBER1); + // assert(string.len() == 2); + + // string.push(NUMBER2); + // assert(string.len() == 3); + + // string.push(NUMBER3); + // assert(string.len() == 4); + + // string.push(NUMBER4); + // assert(string.len() == 5); + + // string.push(NUMBER5); + // assert(string.len() == 6); + // string.push(NUMBER6); + // assert(string.len() == 7); + + // string.push(NUMBER7); + // assert(string.len() == 8); + + // string.push(NUMBER8); + // assert(string.len() == 9); + // let _result = string.pop(); + // assert(string.len() == 8); + + // string.clear(); + // assert(string.len() == 0); } + fn test_new() { let mut string = String::new(); @@ -310,70 +357,85 @@ impl StringTest for Contract { } fn test_nth() { - let mut string = String::new(); - string.push(NUMBER0); - assert(string.nth(0).unwrap() == NUMBER0); - string.push(NUMBER1); - assert(string.nth(0).unwrap() == NUMBER0); - assert(string.nth(1).unwrap() == NUMBER1); - string.push(NUMBER2); - assert(string.nth(0).unwrap() == NUMBER0); - assert(string.nth(1).unwrap() == NUMBER1); - assert(string.nth(2).unwrap() == NUMBER2); - string.push(NUMBER3); - assert(string.nth(0).unwrap() == NUMBER0); - assert(string.nth(1).unwrap() == NUMBER1); - assert(string.nth(2).unwrap() == NUMBER2); - assert(string.nth(3).unwrap() == NUMBER3); - string.push(NUMBER4); - assert(string.nth(0).unwrap() == NUMBER0); - assert(string.nth(1).unwrap() == NUMBER1); - assert(string.nth(2).unwrap() == NUMBER2); - assert(string.nth(3).unwrap() == NUMBER3); - assert(string.nth(4).unwrap() == NUMBER4); - string.clear(); - string.push(NUMBER5); - string.push(NUMBER6); - assert(string.nth(0).unwrap() == NUMBER5); - assert(string.nth(1).unwrap() == NUMBER6); - assert(string.nth(2).is_none()); - } + // Uncomment when https://github.com/FuelLabs/sway/issues/4408 is resolved + // let mut string = String::new(); + + // string.push(NUMBER0); + // assert(string.nth(0).unwrap() == NUMBER0); + + // string.push(NUMBER1); + // assert(string.nth(0).unwrap() == NUMBER0); + // assert(string.nth(1).unwrap() == NUMBER1); + + // string.push(NUMBER2); + // assert(string.nth(0).unwrap() == NUMBER0); + // assert(string.nth(1).unwrap() == NUMBER1); + // assert(string.nth(2).unwrap() == NUMBER2); + + // string.push(NUMBER3); + // assert(string.nth(0).unwrap() == NUMBER0); + // assert(string.nth(1).unwrap() == NUMBER1); + // assert(string.nth(2).unwrap() == NUMBER2); + // assert(string.nth(3).unwrap() == NUMBER3); + + // string.push(NUMBER4); + // assert(string.nth(0).unwrap() == NUMBER0); + // assert(string.nth(1).unwrap() == NUMBER1); + // assert(string.nth(2).unwrap() == NUMBER2); + // assert(string.nth(3).unwrap() == NUMBER3); + // assert(string.nth(4).unwrap() == NUMBER4); + + // string.clear(); + // string.push(NUMBER5); + // string.push(NUMBER6); + // assert(string.nth(0).unwrap() == NUMBER5); + // assert(string.nth(1).unwrap() == NUMBER6); + + // assert(string.nth(2).is_none()); +} fn test_pop() { - let mut string = String::new(); - string.push(NUMBER0); - string.push(NUMBER1); - string.push(NUMBER2); - string.push(NUMBER3); - string.push(NUMBER4); - assert(string.len() == 5); - assert(string.pop().unwrap() == NUMBER4); - assert(string.len() == 4); - assert(string.pop().unwrap() == NUMBER3); - assert(string.len() == 3); - assert(string.pop().unwrap() == NUMBER2); - assert(string.len() == 2); - assert(string.pop().unwrap() == NUMBER1); - assert(string.len() == 1); - assert(string.pop().unwrap() == NUMBER0); - assert(string.len() == 0); - assert(string.pop().is_none()); - string.push(NUMBER5); - assert(string.pop().unwrap() == NUMBER5); - } + // Uncomment when https://github.com/FuelLabs/sway/issues/4408 is resolved + // let mut string = String::new(); + + // string.push(NUMBER0); + // string.push(NUMBER1); + // string.push(NUMBER2); + // string.push(NUMBER3); + // string.push(NUMBER4); + + // assert(string.len() == 5); + // assert(string.pop().unwrap() == NUMBER4); + + // assert(string.len() == 4); + // assert(string.pop().unwrap() == NUMBER3); + + // assert(string.len() == 3); + // assert(string.pop().unwrap() == NUMBER2); + + // assert(string.len() == 2); + // assert(string.pop().unwrap() == NUMBER1); + // assert(string.len() == 1); + // assert(string.pop().unwrap() == NUMBER0); + + // assert(string.len() == 0); + // assert(string.pop().is_none()); + // string.push(NUMBER5); + // assert(string.pop().unwrap() == NUMBER5); +} fn test_push() { let mut string = String::new(); @@ -382,161 +444,198 @@ impl StringTest for Contract { assert(string.is_empty()); assert(string.capacity() == 0); - string.push(NUMBER0); - assert(string.nth(0).unwrap() == NUMBER0); - assert(string.len() == 1); - string.push(NUMBER1); - assert(string.nth(1).unwrap() == NUMBER1); - assert(string.len() == 2); - string.push(NUMBER2); - assert(string.nth(2).unwrap() == NUMBER2); - assert(string.len() == 3); - string.push(NUMBER3); - assert(string.nth(3).unwrap() == NUMBER3); - assert(string.len() == 4); - string.push(NUMBER4); - assert(string.nth(4).unwrap() == NUMBER4); - assert(string.len() == 5); - string.push(NUMBER5); - assert(string.nth(5).unwrap() == NUMBER5); - assert(string.len() == 6); - string.push(NUMBER6); - assert(string.nth(6).unwrap() == NUMBER6); - assert(string.len() == 7); - string.push(NUMBER7); - assert(string.nth(7).unwrap() == NUMBER7); - assert(string.len() == 8); - string.push(NUMBER8); - assert(string.nth(8).unwrap() == NUMBER8); - assert(string.len() == 9); - string.push(NUMBER1); - assert(string.nth(9).unwrap() == NUMBER1); - assert(string.len() == 10); - string.clear(); - assert(string.len() == 0); - assert(string.is_empty()); - string.push(NUMBER1); - assert(string.nth(0).unwrap() == NUMBER1); - assert(string.len() == 1); - string.push(NUMBER1); - assert(string.nth(1).unwrap() == NUMBER1); - assert(string.len() == 2); - string.push(NUMBER0); - assert(string.nth(2).unwrap() == NUMBER0); - assert(string.len() == 3); + // Uncomment when https://github.com/FuelLabs/sway/issues/4408 is resolved + // string.push(NUMBER0); + // assert(string.nth(0).unwrap() == NUMBER0); + // assert(string.len() == 1); + + // string.push(NUMBER1); + // assert(string.nth(1).unwrap() == NUMBER1); + // assert(string.len() == 2); + + // string.push(NUMBER2); + // assert(string.nth(2).unwrap() == NUMBER2); + // assert(string.len() == 3); + + // string.push(NUMBER3); + // assert(string.nth(3).unwrap() == NUMBER3); + // assert(string.len() == 4); + + // string.push(NUMBER4); + // assert(string.nth(4).unwrap() == NUMBER4); + // assert(string.len() == 5); + + // string.push(NUMBER5); + // assert(string.nth(5).unwrap() == NUMBER5); + // assert(string.len() == 6); + + // string.push(NUMBER6); + // assert(string.nth(6).unwrap() == NUMBER6); + // assert(string.len() == 7); + + // string.push(NUMBER7); + // assert(string.nth(7).unwrap() == NUMBER7); + // assert(string.len() == 8); + + // string.push(NUMBER8); + // assert(string.nth(8).unwrap() == NUMBER8); + // assert(string.len() == 9); + + // string.push(NUMBER1); + // assert(string.nth(9).unwrap() == NUMBER1); + // assert(string.len() == 10); + + // string.clear(); + // assert(string.len() == 0); + // assert(string.is_empty()); + // string.push(NUMBER1); + // assert(string.nth(0).unwrap() == NUMBER1); + // assert(string.len() == 1); + + // string.push(NUMBER1); + // assert(string.nth(1).unwrap() == NUMBER1); + // assert(string.len() == 2); + + // string.push(NUMBER0); + // assert(string.nth(2).unwrap() == NUMBER0); + // assert(string.len() == 3); } fn test_set() { - let mut string = String::new(); - string.push(NUMBER0); - string.push(NUMBER1); - string.push(NUMBER2); - assert(string.nth(0).unwrap() == NUMBER0); - assert(string.nth(1).unwrap() == NUMBER1); - assert(string.nth(2).unwrap() == NUMBER2); - string.set(0, NUMBER3); - string.set(1, NUMBER4); - string.set(2, NUMBER5); - assert(string.len() == 3); - assert(string.nth(0).unwrap() == NUMBER3); - assert(string.nth(1).unwrap() == NUMBER4); - assert(string.nth(2).unwrap() == NUMBER5); - } + // Uncomment when https://github.com/FuelLabs/sway/issues/4408 is resolved + // let mut string = String::new(); + + // string.push(NUMBER0); + // string.push(NUMBER1); + // string.push(NUMBER2); + + // assert(string.nth(0).unwrap() == NUMBER0); + // assert(string.nth(1).unwrap() == NUMBER1); + // assert(string.nth(2).unwrap() == NUMBER2); + + // string.set(0, NUMBER3); + // string.set(1, NUMBER4); + // string.set(2, NUMBER5); + + // assert(string.len() == 3); + // assert(string.nth(0).unwrap() == NUMBER3); + // assert(string.nth(1).unwrap() == NUMBER4); + // assert(string.nth(2).unwrap() == NUMBER5); +} fn test_split_at() { - let mut string1 = String::new(); - string1.push(NUMBER0); - string1.push(NUMBER1); - string1.push(NUMBER2); - string1.push(NUMBER3); - let (string2, string3) = string1.split_at(2); - assert(string2.len() == 2); - assert(string3.len() == 2); - assert(string2.nth(0).unwrap() == NUMBER0); - assert(string2.nth(1).unwrap() == NUMBER1); - assert(string3.nth(0).unwrap() == NUMBER2); - assert(string3.nth(1).unwrap() == NUMBER3); - } + // Uncomment when https://github.com/FuelLabs/sway/issues/4408 is resolved + // let mut string1 = String::new(); + + // string1.push(NUMBER0); + // string1.push(NUMBER1); + // string1.push(NUMBER2); + // string1.push(NUMBER3); + + // let (string2, string3) = string1.split_at(2); + + // assert(string2.len() == 2); + // assert(string3.len() == 2); + + // assert(string2.nth(0).unwrap() == NUMBER0); + // assert(string2.nth(1).unwrap() == NUMBER1); + // assert(string3.nth(0).unwrap() == NUMBER2); + // assert(string3.nth(1).unwrap() == NUMBER3); +} fn test_swap() { - let mut string = String::new(); - string.push(NUMBER0); - string.push(NUMBER1); - string.push(NUMBER2); - - assert(string.nth(0).unwrap() == NUMBER0); - assert(string.nth(1).unwrap() == NUMBER1); - string.swap(0, 1); - assert(string.nth(0).unwrap() == NUMBER1); - assert(string.nth(1).unwrap() == NUMBER0); - - assert(string.nth(1).unwrap() == NUMBER0); - assert(string.nth(2).unwrap() == NUMBER2); - string.swap(1, 2); - assert(string.nth(1).unwrap() == NUMBER2); - assert(string.nth(2).unwrap() == NUMBER0); - - assert(string.nth(0).unwrap() == NUMBER1); - assert(string.nth(2).unwrap() == NUMBER0); - string.swap(0, 2); - assert(string.nth(0).unwrap() == NUMBER0); - assert(string.nth(2).unwrap() == NUMBER1); - } + + + + // Uncomment when https://github.com/FuelLabs/sway/issues/4408 is resolved + // let mut string = String::new(); + + // string.push(NUMBER0); + // string.push(NUMBER1); + // string.push(NUMBER2); + + // assert(string.nth(0).unwrap() == NUMBER0); + // assert(string.nth(1).unwrap() == NUMBER1); + // string.swap(0, 1); + // assert(string.nth(0).unwrap() == NUMBER1); + // assert(string.nth(1).unwrap() == NUMBER0); + + // assert(string.nth(1).unwrap() == NUMBER0); + // assert(string.nth(2).unwrap() == NUMBER2); + // string.swap(1, 2); + // assert(string.nth(1).unwrap() == NUMBER2); + // assert(string.nth(2).unwrap() == NUMBER0); + + // assert(string.nth(0).unwrap() == NUMBER1); + // assert(string.nth(2).unwrap() == NUMBER0); + // string.swap(0, 2); + // assert(string.nth(0).unwrap() == NUMBER0); + // assert(string.nth(2).unwrap() == NUMBER1); +} fn test_remove() { - let mut string = String::new(); - string.push(NUMBER0); - string.push(NUMBER1); - string.push(NUMBER2); - string.push(NUMBER3); - string.push(NUMBER4); - string.push(NUMBER5); - assert(string.len() == 6); - assert(string.remove(0) == NUMBER0); - assert(string.len() == 5); - assert(string.remove(0) == NUMBER1); - assert(string.len() == 4); - assert(string.remove(1) == NUMBER3); - assert(string.len() == 3); - assert(string.remove(string.len() - 1) == NUMBER5); - assert(string.len() == 2); - assert(string.remove(1) == NUMBER4); - assert(string.len() == 1); - assert(string.remove(0) == NUMBER2); - assert(string.len() == 0); - string.push(NUMBER6); - assert(string.remove(0) == NUMBER6); - assert(string.len() == 0); - } + // Uncomment when https://github.com/FuelLabs/sway/issues/4408 is resolved + // let mut string = String::new(); + + // string.push(NUMBER0); + // string.push(NUMBER1); + // string.push(NUMBER2); + // string.push(NUMBER3); + // string.push(NUMBER4); + // string.push(NUMBER5); + + // assert(string.len() == 6); + + // assert(string.remove(0) == NUMBER0); + // assert(string.len() == 5); + // assert(string.remove(0) == NUMBER1); + // assert(string.len() == 4); + + // assert(string.remove(1) == NUMBER3); + // assert(string.len() == 3); + + // assert(string.remove(string.len() - 1) == NUMBER5); + // assert(string.len() == 2); + + // assert(string.remove(1) == NUMBER4); + // assert(string.len() == 1); + + // assert(string.remove(0) == NUMBER2); + // assert(string.len() == 0); + + // string.push(NUMBER6); + // assert(string.remove(0) == NUMBER6); + // assert(string.len() == 0); +} fn test_with_capacity() { let mut iterator = 0; @@ -550,33 +649,42 @@ impl StringTest for Contract { let mut string = String::with_capacity(0); assert(string.capacity() == 0); - string.push(NUMBER0); - assert(string.capacity() == 1); - string.push(NUMBER1); - assert(string.capacity() == 2); - string.push(NUMBER2); - assert(string.capacity() == 4); - string.clear(); - assert(string.capacity() == 0); - let mut string = String::with_capacity(4); - assert(string.capacity() == 4); - string.push(NUMBER0); - assert(string.capacity() == 4); - string.push(NUMBER1); - assert(string.capacity() == 4); - string.push(NUMBER2); - assert(string.capacity() == 4); - string.push(NUMBER3); - assert(string.capacity() == 4); - string.push(NUMBER4); - assert(string.capacity() == 8); + // Uncomment when https://github.com/FuelLabs/sway/issues/4408 is resolved + // string.push(NUMBER0); + // assert(string.capacity() == 1); + + // string.push(NUMBER1); + // assert(string.capacity() == 2); + + // string.push(NUMBER2); + // assert(string.capacity() == 4); + + // string.clear(); + // assert(string.capacity() == 0); + // let mut string = String::with_capacity(4); + + // assert(string.capacity() == 4); + + // string.push(NUMBER0); + // assert(string.capacity() == 4); + // string.push(NUMBER1); + // assert(string.capacity() == 4); + + // string.push(NUMBER2); + // assert(string.capacity() == 4); + + // string.push(NUMBER3); + // assert(string.capacity() == 4); + + // string.push(NUMBER4); + // assert(string.capacity() == 8); } } diff --git a/tests/src/unsigned_numbers/ifp64_test/src/main.sw b/tests/src/unsigned_numbers/ifp64_test/src/main.sw index 9c07ec19..43a94395 100644 --- a/tests/src/unsigned_numbers/ifp64_test/src/main.sw +++ b/tests/src/unsigned_numbers/ifp64_test/src/main.sw @@ -30,7 +30,7 @@ fn main() -> bool { value: 1u32 << 16 + 3, }; let mut value = IFP64::from(u_value); - + res = IFP64::recip(value); assert(IFP64::from(UFP32 { value: 8192u32,