diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 9fedbb14..4db7ac16 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.77.0
- FORC_VERSION: 0.60.0
- CORE_VERSION: 0.26.0
+ RUST_VERSION: 1.80.1
+ FORC_VERSION: 0.66.2
+ CORE_VERSION: 0.40.0
jobs:
build-sway-lib:
diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml
index ef0b3769..29d37f03 100644
--- a/.github/workflows/gh-pages.yml
+++ b/.github/workflows/gh-pages.yml
@@ -8,9 +8,9 @@ on:
- v*
env:
- RUST_VERSION: 1.77.0
- FORC_VERSION: 0.60.0
- CORE_VERSION: 0.26.0
+ RUST_VERSION: 1.80.1
+ FORC_VERSION: 0.66.2
+ CORE_VERSION: 0.40.0
jobs:
deploy-contributing:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f69f3343..23e1db58 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
+Description of the upcoming release here.
+
### Added
- Something new here 1
@@ -14,20 +16,63 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed
-- Something changed here 1
-- Something changed here 2
+- [#305](https://github.com/FuelLabs/sway-libs/pull/305) Updates to forc `v0.66.2`, fuel-core `v0.40.0`, and fuels-rs `v0.66.9`.
+- [#306](https://github.com/FuelLabs/sway-libs/pull/306) Updates the SRC-7 naming to Onchain Native Asset Metadata Standard.
### Fixed
-- Some fix here 1
-- Some fix here 2
+- [#297](https://github.com/FuelLabs/sway-libs/pull/297) Fixes docs anchor in basic SRC-7 example.
+- [#298](https://github.com/FuelLabs/sway-libs/pull/298) Fixes the README headers on Upgradability Libraries from an `h2` to an `h4`.
+- [#302](https://github.com/FuelLabs/sway-libs/pull/302) Fixes typos in documentation.
+- [#303](https://github.com/FuelLabs/sway-libs/pull/304) Fixes links in the Upgradability Library documenation.
-### Breaking
+#### Breaking
- Some breaking change here 1
- Some breaking change here 2
-## [v0.23.1]
+## [Version 0.24.0]
+
+### Added v0.24.0
+
+- [#293](https://github.com/FuelLabs/sway-libs/pull/293) Adds the `BytecodeRoot` and `ContractConfigurables` types to the Bytecode Library.
+- [#286](https://github.com/FuelLabs/sway-libs/pull/286) Adds the `_metadata()` function to the Asset Library.
+
+### Changed v0.24.0
+
+- [#286](https://github.com/FuelLabs/sway-libs/pull/286) Updates the repository to Sway-Standards v0.6.0 and implements the new SRC-20 and SRC-7 logging specifications.
+- [#286](https://github.com/FuelLabs/sway-libs/pull/286) `_set_metadata()`, `_set_name()` and `_set_symbol()` now revert if the metadata is an empty string.
+- [#286](https://github.com/FuelLabs/sway-libs/pull/286) `_set_metadata()` now reverts if the metadata is empty bytes.
+- [#286](https://github.com/FuelLabs/sway-libs/pull/286) `_mint()` and `_burn()` now revert if the `amount` argument is zero.
+- [#289](https://github.com/FuelLabs/sway-libs/pull/289) Bumps Sway-Libs to forc `v0.63.3`, fuel-core `v0.34.0`, and fuels `v0.66.2`.
+- [#290](https://github.com/FuelLabs/sway-libs/pull/290) Update the Upgradeability library to use a specific storage slot for owner functionality.
+- [#291](https://github.com/FuelLabs/sway-libs/pull/291) Prepares for the `v0.24.0` release.
+
+### Breaking v0.24.0
+
+- [#290](https://github.com/FuelLabs/sway-libs/pull/290) The `_proxy_owner()`, `only_proxy_owner()` and `_set_proxy_owner()` functions no longer take `storage.proxy_owner` as a parameter. Instead they directly read and write to the storage slot `0xbb79927b15d9259ea316f2ecb2297d6cc8851888a98278c0a2e03e1a091ea754` which is `sha256("storage_SRC14_1")`.
+
+Before:
+
+```sway
+fn foo() {
+ let stored_proxy_owner = _proxy_owner(storage.proxy_owner);
+ only_proxy_owner(storage.proxy_owner);
+ _set_proxy_owner(new_proxy_owner, storage.proxy_owner);
+}
+```
+
+After:
+
+```sway
+fn foo() {
+ let stored_proxy_owner = _proxy_owner();
+ only_proxy_owner();
+ _set_proxy_owner(new_proxy_owner);
+}
+```
+
+## [Version 0.23.1]
### Added v0.23.1
@@ -46,7 +91,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- None
-## [v0.23.0]
+## [Version 0.23.0]
### Added v0.23.0
diff --git a/Cargo.toml b/Cargo.toml
index 63e5bc11..65004cf8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,4 +1,4 @@
[package]
name = "sway-libs"
-version = "0.23.1"
+version = "0.24.0"
edition = "2021"
diff --git a/README.md b/README.md
index da12f023..323cc2bc 100644
--- a/README.md
+++ b/README.md
@@ -9,8 +9,8 @@
-
-
+
+
@@ -66,7 +66,7 @@ For implementation details on the libraries please see the [Sway Libs Docs](http
- [Queue](https://docs.fuel.network/docs/sway-libs/queue/) is a linear data structure that provides First-In-First-Out (FIFO) operations.
-## Upgradability Libraries
+#### Upgradability Libraries
- [Upgradability](https://docs.fuel.network/docs/sway-libs/upgradability/) provides functions that can be used to implement contract upgrades via simple upgradable proxies.
@@ -75,7 +75,7 @@ For implementation details on the libraries please see the [Sway Libs Docs](http
To import a library, the following dependency should be added to the project's `Forc.toml` file under `[dependencies]`.
```rust
-sway_libs = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.23.1" }
+sway_libs = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.24.0" }
```
> **NOTE:**
@@ -97,7 +97,7 @@ For more information about implementation please refer to the [Sway Libs Docs Hu
## Running Tests
-There are two sets of tests that should be run: inline tests and sdk-harness tests. Please make sure you are using `forc v0.60.0` and `fuel-core v0.26.0`. You can check what version you are using by running the `fuelup show` command.
+There are two sets of tests that should be run: inline tests and sdk-harness tests. Please make sure you are using `forc v0.66.2` and `fuel-core v0.40.0`. You can check what version you are using by running the `fuelup show` command.
Make sure you are in the source directory of this repository `sway-libs/`.
@@ -119,7 +119,7 @@ forc test --path tests --release --locked && cargo test --manifest-path tests/Ca
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.60.0`, `fuels-rs v0.62.0` and `fuel-core v0.26.0`.
+> All projects currently use `forc v0.66.2`, `fuels-rs v0.66.9` and `fuel-core v0.40.0`.
## Contributing
diff --git a/docs/book/spell-check-custom-words.txt b/docs/book/spell-check-custom-words.txt
index d066d8e8..1044e280 100644
--- a/docs/book/spell-check-custom-words.txt
+++ b/docs/book/spell-check-custom-words.txt
@@ -209,4 +209,5 @@ StorageMetadata
functionly
verifiably
upgradable
-upgradability
\ No newline at end of file
+upgradability
+Onchain
\ No newline at end of file
diff --git a/docs/book/src/asset/base.md b/docs/book/src/asset/base.md
index 227779ba..c4d3aa0f 100644
--- a/docs/book/src/asset/base.md
+++ b/docs/book/src/asset/base.md
@@ -42,7 +42,7 @@ The following ABI and functions are also provided to set your [SRC-20](https://d
## Setting Up Storage
-Once imported, the Asset Library's base functionality should be available. To use them, be sure to add the storage block bellow to your contract which enables the [SRC-20](https://docs.fuel.network/docs/sway-standards/src-20-native-asset/) standard.
+Once imported, the Asset Library's base functionality should be available. To use them, be sure to add the storage block below to your contract which enables the [SRC-20](https://docs.fuel.network/docs/sway-standards/src-20-native-asset/) standard.
```sway
{{#include ../../../../examples/asset/base_docs/src/main.sw:src20_storage}}
@@ -60,6 +60,8 @@ To use the Asset Library's base functionly, simply pass the `StorageKey` from th
To set some the asset attributes for an Asset, use the `SetAssetAttributes` ABI provided by the Asset Library. The example below shows the implementation of the `SetAssetAttributes` ABI with no user defined restrictions or custom functionality. It is recommended that the [Ownership Library](../ownership/index.md) is used in conjunction with the `SetAssetAttributes` ABI to ensure only a single user has permissions to set an Asset's attributes.
+The `_set_name()`, `_set_symbol()`, and `_set_decimals()` functions follows the SRC-20 standard for logging and will emit their respective log when called.
+
```sway
{{#include ../../../../examples/asset/setting_src20_attributes/src/main.sw:setting_src20_attributes}}
```
diff --git a/docs/book/src/asset/index.md b/docs/book/src/asset/index.md
index c9c1f6d2..ee8fe64e 100644
--- a/docs/book/src/asset/index.md
+++ b/docs/book/src/asset/index.md
@@ -14,4 +14,4 @@ The [SRC-3; Mint and Burn Standard](https://docs.fuel.network/docs/sway-standard
## [SRC-7 Functionality](./metadata.md)
-The [SRC-7; Arbitrary Asset Metadata Standard](https://docs.fuel.network/docs/sway-standards/src-7-asset-metadata/) prescribes an ABI for metadata associated with Native Assets on the Fuel Network. The Asset Library's [metadata](./metadata.md) section supports the [SRC-7](https://docs.fuel.network/docs/sway-standards/src-7-asset-metadata/)'s implementation.
+The [SRC-7; Onchain Asset Metadata Standard](https://docs.fuel.network/docs/sway-standards/src-7-asset-metadata/) prescribes an ABI for stateful metadata associated with Native Assets on the Fuel Network. The Asset Library's [metadata](./metadata.md) section supports the [SRC-7](https://docs.fuel.network/docs/sway-standards/src-7-asset-metadata/)'s implementation.
diff --git a/docs/book/src/asset/metadata.md b/docs/book/src/asset/metadata.md
index ccd442ff..9b90ff6e 100644
--- a/docs/book/src/asset/metadata.md
+++ b/docs/book/src/asset/metadata.md
@@ -14,7 +14,7 @@ To import the Asset Library Base Functionality and [SRC-7](https://docs.fuel.net
## Integration with the SRC-7 Standard
-The [SRC-7](https://docs.fuel.network/docs/sway-standards/src-7-asset-metadata/) definition states that the following abi implementation is required for any Native Asset on Fuel:
+The [SRC-7](https://docs.fuel.network/docs/sway-standards/src-7-asset-metadata/) definition states that the following abi implementation is required for any Native Asset on Fuel which uses stateful metadata:
```sway
{{#include ../../../../examples/asset/metadata_docs/src/main.sw:src7_abi}}
@@ -24,20 +24,9 @@ The Asset Library has the following complimentary data type for the [SRC-7](http
- `StorageMetadata`
-The following additional functionality for the [SRC-7](https://docs.fuel.network/docs/sway-standards/src-7-asset-metadata/)'s `Metadata` type is provided:
-
-- `as_string()`
-- `is_string()`
-- `as_u64()`
-- `is_u64()`
-- `as_bytes()`
-- `is_bytes()`
-- `as_b256()`
-- `is_b256()`
-
## Setting Up Storage
-Once imported, the Asset Library's metadata functionality should be available. To use them, be sure to add the storage block bellow to your contract which enables the [SRC-7](https://docs.fuel.network/docs/sway-standards/src-7-asset-metadata/) standard.
+Once imported, the Asset Library's metadata functionality should be available. To use them, be sure to add the storage block below to your contract which enables the [SRC-7](https://docs.fuel.network/docs/sway-standards/src-7-asset-metadata/) standard.
```sway
{{#include ../../../../examples/asset/metadata_docs/src/main.sw:src7_storage}}
@@ -47,7 +36,9 @@ Once imported, the Asset Library's metadata functionality should be available. T
### Setting Metadata
-To set some metadata for an Asset, use the `SetAssetMetadata` ABI provided by the Asset Library. Be sure to follow the [SRC-9](https://docs.fuel.network/docs/sway-standards/src-9-metadata-keys/) standard for your `key`. It is recommended that the [Ownership Library](../ownership/index.md) is used in conjunction with the `SetAssetMetadata` ABI to ensure only a single user has permissions to set an Asset's metadata.
+To set some metadata for an Asset, use the `SetAssetMetadata` ABI provided by the Asset Library with the `_set_metadata()` function. Be sure to follow the [SRC-9](https://docs.fuel.network/docs/sway-standards/src-9-metadata-keys/) standard for your `key`. It is recommended that the [Ownership Library](../ownership/index.md) is used in conjunction with the `SetAssetMetadata` ABI to ensure only a single user has permissions to set an Asset's metadata.
+
+The `_set_metadata()` function follows the SRC-7 standard for logging and will emit the `SetMetadataEvent` when called.
```sway
{{#include ../../../../examples/asset/setting_src7_attributes/src/main.sw:setting_src7_attributes}}
@@ -57,59 +48,8 @@ To set some metadata for an Asset, use the `SetAssetMetadata` ABI provided by th
### Implementing the SRC-7 Standard with StorageMetadata
-To use the `StorageMetadata` type, simply get the stored metadata with the associated `key` and `AssetId`. The example below shows the implementation of the [SRC-7](https://docs.fuel.network/docs/sway-standards/src-7-asset-metadata/) standard in combination with the Asset Library's `StorageMetadata` type with no user defined restrictions or custom functionality.
+To use the `StorageMetadata` type, simply get the stored metadata with the associated `key` and `AssetId` using the provided `_metadata()` convenience function. The example below shows the implementation of the [SRC-7](https://docs.fuel.network/docs/sway-standards/src-7-asset-metadata/) standard in combination with the Asset Library's `StorageMetadata` type and the `_metadata()` function with no user defined restrictions or custom functionality.
```sway
{{#include ../../../../examples/asset/basic_src7/src/main.sw:basic_src7}}
```
-
-## Using the `Metadata` Extensions
-
-The `Metadata` type defined by the [SRC-7](https://docs.fuel.network/docs/sway-standards/src-7-asset-metadata/) standard can be one of 4 states:
-
-```sway
-pub enum Metadata {
- B256: b256,
- Bytes: Bytes,
- Int: u64,
- String: String,
-}
-```
-
-The Asset Library enables the following functionality for the `Metadata` type:
-
-### `is_b256()` and `as_b256()`
-
-The `is_b256()` check enables checking whether the `Metadata` type is a `b256`.
-The `as_b256()` returns the `b256` of the `Metadata` type.
-
-```sway
-{{#include ../../../../examples/asset/metadata_docs/src/main.sw:as_b256}}
-```
-
-### `is_bytes()` and `as_bytes()`
-
-The `is_bytes()` check enables checking whether the `Metadata` type is a `Bytes`.
-The `as_bytes()` returns the `Bytes` of the `Metadata` type.
-
-```sway
-{{#include ../../../../examples/asset/metadata_docs/src/main.sw:as_bytes}}
-```
-
-### `is_u64()` and `as_u64()`
-
-The `is_u64()` check enables checking whether the `Metadata` type is a `u64`.
-The `as_u64()` returns the `u64` of the `Metadata` type.
-
-```sway
-{{#include ../../../../examples/asset/metadata_docs/src/main.sw:as_u64}}
-```
-
-### `is_string()` and `as_string()`
-
-The `is_string()` check enables checking whether the `Metadata` type is a `String`.
-The `as_string()` returns the `String` of the `Metadata` type.
-
-```sway
-{{#include ../../../../examples/asset/metadata_docs/src/main.sw:as_string}}
-```
diff --git a/docs/book/src/asset/supply.md b/docs/book/src/asset/supply.md
index 1d63c298..cb3fcf82 100644
--- a/docs/book/src/asset/supply.md
+++ b/docs/book/src/asset/supply.md
@@ -29,7 +29,7 @@ The Asset Library has the following complimentary functions for each function in
## Setting Up Storage
-Once imported, the Asset Library's supply functionality should be available. To use them, be sure to add the storage block bellow to your contract which enables the [SRC-3](https://docs.fuel.network/docs/sway-standards/src-3-minting-and-burning/) standard.
+Once imported, the Asset Library's supply functionality should be available. To use them, be sure to add the storage block below to your contract which enables the [SRC-3](https://docs.fuel.network/docs/sway-standards/src-3-minting-and-burning/) standard.
```sway
{{#include ../../../../examples/asset/supply_docs/src/main.sw:src3_storage}}
@@ -37,7 +37,9 @@ Once imported, the Asset Library's supply functionality should be available. To
## Implementing the SRC-3 Standard with the Asset Library
-To use a base function, simply pass the `StorageKey` from the prescribed storage block. The example below shows the implementation of the [SRC-3](https://docs.fuel.network/docs/sway-standards/src-3-minting-and-burning/) standard in combination with the Asset Library with no user defined restrictions or custom functionality. It is recommended that the [Ownership Library](../ownership/index.md) is used in conjunction with the Asset Library;s supply functionality to ensure only a single user has permissions to mint an Asset.
+To use either function, simply pass the `StorageKey` from the prescribed storage block. The example below shows the implementation of the [SRC-3](https://docs.fuel.network/docs/sway-standards/src-3-minting-and-burning/) standard in combination with the Asset Library with no user defined restrictions or custom functionality. It is recommended that the [Ownership Library](../ownership/index.md) is used in conjunction with the Asset Library's supply functionality to ensure only a single user has permissions to mint an Asset.
+
+The `_mint()` and `_burn()` functions follows the SRC-20 standard for logging and will emit the `TotalSupplyEvent` when called.
```sway
{{#include ../../../../examples/asset/basic_src3/src/main.sw:basic_src3}}
diff --git a/docs/book/src/bytecode/index.md b/docs/book/src/bytecode/index.md
index 0bebfc3c..e6ff36a1 100644
--- a/docs/book/src/bytecode/index.md
+++ b/docs/book/src/bytecode/index.md
@@ -73,7 +73,7 @@ To verify a contract's bytecode root you may call `verify_bytecode_root()` or `v
### Computing the Address from Bytecode
-To compute a predicates's address you may call the `compute_predicate_address()` or `compute_predicate_address_with_configurables()` functions.
+To compute a predicate's address you may call the `compute_predicate_address()` or `compute_predicate_address_with_configurables()` functions.
```sway
{{#include ../../../../examples/bytecode/src/main.sw:compute_predicate_address}}
diff --git a/docs/book/src/getting_started/index.md b/docs/book/src/getting_started/index.md
index 39d89f84..e57c5e38 100644
--- a/docs/book/src/getting_started/index.md
+++ b/docs/book/src/getting_started/index.md
@@ -5,7 +5,7 @@
To import any library, the following dependency should be added to the project's `Forc.toml` file under `[dependencies]`.
```sway
-sway_libs = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.23.1" }
+sway_libs = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.24.0" }
```
For reference, here is a complete `Forc.toml` file:
@@ -18,7 +18,7 @@ license = "Apache-2.0"
name = "MyProject"
[dependencies]
-sway_libs = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.23.1" }
+sway_libs = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.24.0" }
```
> **NOTE:** Be sure to set the tag to the latest release.
@@ -38,7 +38,7 @@ use sway_libs::ownership::only_owner;
```
> **NOTE:**
-> All projects currently use `forc v0.60.0`, `fuels-rs v0.62.0` and `fuel-core 0.26.0`.
+> All projects currently use `forc 0.63.3`, `fuels-rs v0.66.2` and `fuel-core 0.34.0`.
## Using Sway Libs
diff --git a/docs/book/src/getting_started/running_tests.md b/docs/book/src/getting_started/running_tests.md
index 5bea15e2..c1b110d5 100644
--- a/docs/book/src/getting_started/running_tests.md
+++ b/docs/book/src/getting_started/running_tests.md
@@ -1,6 +1,6 @@
# Running Tests
-There are two sets of tests that should be run: inline tests and sdk-harness tests. Please make sure you are using `forc v0.60.0` and `fuel-core v0.26.0`. You can check what version you are using by running the `fuelup show` command.
+There are two sets of tests that should be run: inline tests and sdk-harness tests. Please make sure you are using `forc v0.63.3` and `fuel-core v0.34.0`. You can check what version you are using by running the `fuelup show` command.
Make sure you are in the source directory of this repository `sway-libs/`.
diff --git a/docs/book/src/index.md b/docs/book/src/index.md
index b5fa21ae..27e68d9b 100644
--- a/docs/book/src/index.md
+++ b/docs/book/src/index.md
@@ -2,7 +2,7 @@
The purpose of Sway Libraries is to contain libraries which users can import and use that are not part of the standard library.
-There are several types of libraries that Sway Libs encompases. These include libraries that provide convenience functions, [Sway-Standards](https://github.com/FuelLabs/sway-standards) supporting libraries, data type libraries, security functionality libraries, and other tools valuable to blockchain development.
+There are several types of libraries that Sway Libs encompasses. These include libraries that provide convenience functions, [Sway-Standards](https://github.com/FuelLabs/sway-standards) supporting libraries, data type libraries, security functionality libraries, and other tools valuable to blockchain development.
For implementation details on the libraries please see the [Sway Libs Docs](https://fuellabs.github.io/sway-libs/master/sway_libs/).
diff --git a/docs/book/src/pausable/index.md b/docs/book/src/pausable/index.md
index ee72d18b..f0a56569 100644
--- a/docs/book/src/pausable/index.md
+++ b/docs/book/src/pausable/index.md
@@ -47,7 +47,7 @@ When developing a contract, you may want to lock functions down to a specific st
It is highly recommended to integrate the [Ownership Library](../ownership/index.md) with the Pausable Library and apply restrictions the `pause()` and `unpause()` functions. This will ensure that only a single user may pause and unpause a contract in cause of emergency. Failure to apply this restriction will allow any user to obstruct a contract's functionality.
-The follow example implements the `Pausable` abi and applies restrictions to it's pause/unpause functions. The owner of the contract must be set in an constructor defined by `MyConstructor` in this example.
+The follow example implements the `Pausable` abi and applies restrictions to it's pause/unpause functions. The owner of the contract must be set in a constructor defined by `MyConstructor` in this example.
```sway
{{#include ../../../../examples/pausable/pausable_with_ownership/src/main.sw:impl_with_ownership}}
diff --git a/docs/book/src/signed_integers/index.md b/docs/book/src/signed_integers/index.md
index e15e290b..4a601401 100644
--- a/docs/book/src/signed_integers/index.md
+++ b/docs/book/src/signed_integers/index.md
@@ -16,7 +16,7 @@ To import the Signed Integer Number Library to your Sway Smart Contract, add the
{{#include ../../../../examples/signed_integers/src/main.sw:import}}
```
-In order to use the any of the Signed Integer types, import them into your Sway project like so:
+In order to use any of the Signed Integer types, import them into your Sway project like so:
```sway
{{#include ../../../../examples/signed_integers/src/main.sw:import_8}}
diff --git a/docs/book/src/upgradability/index.md b/docs/book/src/upgradability/index.md
index bb070909..11f20c00 100644
--- a/docs/book/src/upgradability/index.md
+++ b/docs/book/src/upgradability/index.md
@@ -1,6 +1,6 @@
# Upgradability Library
-The Upgradability Library provides functions that can be used to implement contract upgrades via simple upgradable proxies. The Upgradability Library implements the required and optional functionality from [SRC-14](https://docs.fuel.network/docs/sway-standards/src-14-simple-upgradable-proxies/) as well as additional functionality for ownership of the proxy contract.
+The Upgradability Library provides functions that can be used to implement contract upgrades via simple upgradable proxies. The Upgradability Library implements the required and optional functionality from [SRC-14](https://docs.fuel.network/docs/sway-standards/src-14-simple-upgradeable-proxies/) as well as additional functionality for ownership of the proxy contract.
For implementation details on the Upgradability Library please see the [Sway Libs Docs](https://fuellabs.github.io/sway-libs/master/sway_libs/upgradability/index.html).
@@ -8,7 +8,7 @@ For implementation details on the Upgradability Library please see the [Sway Lib
In order to use the Upgradability library, Sway Libs and [Sway Standards](https://docs.fuel.network/docs/sway-standards/) must be added to the `Forc.toml` file and then imported into your Sway project. To add Sway Libs as a dependency to the `Forc.toml` file in your project please see the [Getting Started](../getting_started/index.md). To add Sway Standards as a dependency please see the [Sway Standards Book](https://docs.fuel.network/docs/sway-standards/#using-a-standard).
-To import the Upgradability Library and [SRC-14](https://docs.fuel.network/docs/sway-standards/src-14-simple-upgradable-proxies/) Standard to your Sway Smart Contract, add the following to your Sway file:
+To import the Upgradability Library and [SRC-14](https://docs.fuel.network/docs/sway-standards/src-14-simple-upgradeable-proxies/) Standard to your Sway Smart Contract, add the following to your Sway file:
```sway
{{#include ../../../../examples/upgradability/src/main.sw:import}}
@@ -16,7 +16,7 @@ To import the Upgradability Library and [SRC-14](https://docs.fuel.network/docs/
## Integrating the Upgradability Library into the SRC-14 Standard
-To implement the [SRC-14](https://docs.fuel.network/docs/sway-standards/src-14-simple-upgradable-proxies/) standard with the Upgradability library, be sure to add the Sway Standards dependency to your contract. The following demonstrates the integration of the Ownership library with the SRC-14 standard.
+To implement the [SRC-14](https://docs.fuel.network/docs/sway-standards/src-14-simple-upgradeable-proxies/) standard with the Upgradability library, be sure to add the Sway Standards dependency to your contract. The following demonstrates the integration of the Ownership library with the SRC-14 standard.
```sway
{{#include ../../../../examples/upgradability/src/main.sw:integrate_with_src14}}
diff --git a/examples/Cargo.toml b/examples/Cargo.toml
index be271caf..ef5e8afb 100644
--- a/examples/Cargo.toml
+++ b/examples/Cargo.toml
@@ -8,7 +8,7 @@ license = "Apache-2.0"
[dependencies]
fuel-merkle = { version = "0.50.0" }
sha2 = { version = "0.10" }
-fuels = { version = "0.62.0", features = ["fuel-core-lib"] }
+fuels = { version = "0.66.2" }
tokio = { version = "1.12", features = ["rt", "macros"] }
[[test]]
diff --git a/examples/Forc.lock b/examples/Forc.lock
index b9587a52..b02db3b9 100644
--- a/examples/Forc.lock
+++ b/examples/Forc.lock
@@ -53,7 +53,7 @@ dependencies = [
[[package]]
name = "core"
-source = "path+from-root-E19CE48B3E858B72"
+source = "path+from-root-7053AAA90CC5E690"
[[package]]
name = "merkle_examples"
@@ -141,12 +141,12 @@ dependencies = [
[[package]]
name = "standards"
-source = "git+https://github.com/FuelLabs/sway-standards?tag=v0.5.2#270350e69bd7455b7e99f0aae2e29a94d42324bd"
+source = "git+https://github.com/FuelLabs/sway-standards?tag=v0.6.0#65e09f95ea8b9476b171a66c8a47108f352fa32c"
dependencies = ["std"]
[[package]]
name = "std"
-source = "git+https://github.com/fuellabs/sway?tag=v0.60.0#2f0392ee35a1e4dd80bd8034962d5b4083dfb8b6"
+source = "git+https://github.com/fuellabs/sway?tag=v0.66.2#31486c0b47669612acb7c64d66ecb50aea281282"
dependencies = ["core"]
[[package]]
diff --git a/examples/admin/Forc.toml b/examples/admin/Forc.toml
index c01483cf..7cc2ca3c 100644
--- a/examples/admin/Forc.toml
+++ b/examples/admin/Forc.toml
@@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "admin_examples"
[dependencies]
-standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.5.2" }
+standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.0" }
sway_libs = { path = "../../libs" }
diff --git a/examples/asset/base_docs/Forc.toml b/examples/asset/base_docs/Forc.toml
index 6dc4619a..2d6a05b3 100644
--- a/examples/asset/base_docs/Forc.toml
+++ b/examples/asset/base_docs/Forc.toml
@@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "base_docs"
[dependencies]
-standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.5.2" }
+standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.0" }
sway_libs = { path = "../../../libs" }
diff --git a/examples/asset/basic_src20/Forc.toml b/examples/asset/basic_src20/Forc.toml
index b7659901..d7aac164 100644
--- a/examples/asset/basic_src20/Forc.toml
+++ b/examples/asset/basic_src20/Forc.toml
@@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "basic_src20"
[dependencies]
-standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.5.2" }
+standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.0" }
sway_libs = { path = "../../../libs" }
diff --git a/examples/asset/basic_src3/Forc.toml b/examples/asset/basic_src3/Forc.toml
index b4871c59..f40716f6 100644
--- a/examples/asset/basic_src3/Forc.toml
+++ b/examples/asset/basic_src3/Forc.toml
@@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "basic_src3"
[dependencies]
-standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.5.2" }
+standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.0" }
sway_libs = { path = "../../../libs" }
diff --git a/examples/asset/basic_src3/src/main.sw b/examples/asset/basic_src3/src/main.sw
index 2835b13c..c2caf72f 100644
--- a/examples/asset/basic_src3/src/main.sw
+++ b/examples/asset/basic_src3/src/main.sw
@@ -14,7 +14,7 @@ storage {
// Implement the SRC-3 Standard for this contract
impl SRC3 for Contract {
#[storage(read, write)]
- fn mint(recipient: Identity, sub_id: SubId, amount: u64) {
+ fn mint(recipient: Identity, sub_id: Option, amount: u64) {
// Pass the StorageKeys to the `_mint()` function from the Asset Library.
_mint(
storage
@@ -22,7 +22,8 @@ impl SRC3 for Contract {
storage
.total_supply,
recipient,
- sub_id,
+ sub_id
+ .unwrap_or(b256::zero()),
amount,
);
}
diff --git a/examples/asset/basic_src7/Forc.toml b/examples/asset/basic_src7/Forc.toml
index d6d7244a..ed59196f 100644
--- a/examples/asset/basic_src7/Forc.toml
+++ b/examples/asset/basic_src7/Forc.toml
@@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "basic_src7"
[dependencies]
-standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.5.2" }
+standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.0" }
sway_libs = { path = "../../../libs" }
diff --git a/examples/asset/metadata_docs/Forc.toml b/examples/asset/metadata_docs/Forc.toml
index f429e97a..ef132d46 100644
--- a/examples/asset/metadata_docs/Forc.toml
+++ b/examples/asset/metadata_docs/Forc.toml
@@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "metadata_docs"
[dependencies]
-standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.5.2" }
+standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.0" }
sway_libs = { path = "../../../libs" }
diff --git a/examples/asset/metadata_docs/src/main.sw b/examples/asset/metadata_docs/src/main.sw
index 57eb7cc3..e09ed4d0 100644
--- a/examples/asset/metadata_docs/src/main.sw
+++ b/examples/asset/metadata_docs/src/main.sw
@@ -3,7 +3,7 @@ contract;
use std::{bytes::Bytes, string::String};
// ANCHOR: import
-use sway_libs::asset::metadata::*;
+use sway_libs::asset::metadata::{_metadata, _set_metadata, SetAssetMetadata, StorageMetadata};
use standards::src7::*;
// ANCHOR_END: import
@@ -20,34 +20,20 @@ storage {
}
// ANCHOR_END: src7_storage
-// ANCHOR: as_b256
-fn b256_type(my_metadata: Metadata) {
- assert(my_metadata.is_b256());
-
- let my_b256: b256 = my_metadata.as_b256().unwrap();
-}
-// ANCHOR_END: as_b256
-
-// ANCHOR: as_bytes
-fn bytes_type(my_metadata: Metadata) {
- assert(my_metadata.is_bytes());
-
- let my_bytes: Bytes = my_metadata.as_bytes().unwrap();
-}
-// ANCHOR_END: as_bytes
-
-// ANCHOR: as_u64
-fn u64_type(my_metadata: Metadata) {
- assert(my_metadata.is_u64());
-
- let my_u64: u64 = my_metadata.as_u64().unwrap();
+// ANCHOR: src7_metadata_convenience_function
+impl SRC7 for Contract {
+ #[storage(read)]
+ fn metadata(asset: AssetId, key: String) -> Option {
+ _metadata(storage.metadata, asset, key)
+ }
}
-// ANCHOR_END: as_u64
-
-// ANCHOR: as_string
-fn string_type(my_metadata: Metadata) {
- assert(my_metadata.is_string());
-
- let my_string: String = my_metadata.as_string().unwrap();
+// ANCHOR_END: src7_metadata_convenience_function
+
+// ANCHOR: src7_set_metadata
+impl SetAssetMetadata for Contract {
+ #[storage(read, write)]
+ fn set_metadata(asset: AssetId, key: String, metadata: Metadata) {
+ _set_metadata(storage.metadata, asset, key, metadata);
+ }
}
-// ANCHOR_END: as_string
+// ANCHOR_END: src7_set_metadata
diff --git a/examples/asset/setting_src20_attributes/Forc.toml b/examples/asset/setting_src20_attributes/Forc.toml
index 109673c5..cebfd6e3 100644
--- a/examples/asset/setting_src20_attributes/Forc.toml
+++ b/examples/asset/setting_src20_attributes/Forc.toml
@@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "setting_src20_attributes"
[dependencies]
-standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.5.2" }
+standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.0" }
sway_libs = { path = "../../../libs" }
diff --git a/examples/asset/setting_src7_attributes/Forc.toml b/examples/asset/setting_src7_attributes/Forc.toml
index f1dc4f94..57cacdfc 100644
--- a/examples/asset/setting_src7_attributes/Forc.toml
+++ b/examples/asset/setting_src7_attributes/Forc.toml
@@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "setting_src7_attributes"
[dependencies]
-standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.5.2" }
+standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.0" }
sway_libs = { path = "../../../libs" }
diff --git a/examples/asset/supply_docs/Forc.toml b/examples/asset/supply_docs/Forc.toml
index 2722843b..102751a2 100644
--- a/examples/asset/supply_docs/Forc.toml
+++ b/examples/asset/supply_docs/Forc.toml
@@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "supply_docs"
[dependencies]
-standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.5.2" }
+standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.0" }
sway_libs = { path = "../../../libs" }
diff --git a/examples/asset/supply_docs/src/main.sw b/examples/asset/supply_docs/src/main.sw
index 2575e5bc..30ede1dd 100644
--- a/examples/asset/supply_docs/src/main.sw
+++ b/examples/asset/supply_docs/src/main.sw
@@ -10,7 +10,7 @@ use standards::src3::*;
// ANCHOR: src3_abi
abi SRC3 {
#[storage(read, write)]
- fn mint(recipient: Identity, vault_sub_id: SubId, amount: u64);
+ fn mint(recipient: Identity, sub_id: Option, amount: u64);
#[payable]
#[storage(read, write)]
fn burn(vault_sub_id: SubId, amount: u64);
diff --git a/examples/bytecode/src/main.sw b/examples/bytecode/src/main.sw
index 2ff05080..d12a481e 100644
--- a/examples/bytecode/src/main.sw
+++ b/examples/bytecode/src/main.sw
@@ -23,7 +23,10 @@ fn make_mutable(not_mutable_bytecode: Vec) {
// ANCHOR_END: known_issue
// ANCHOR: swap_configurables
-fn swap(my_bytecode: Vec, my_configurables: Vec<(u64, Vec)>) {
+fn swap(
+ my_bytecode: Vec,
+ my_configurables: ContractConfigurables,
+) {
let mut my_bytecode = my_bytecode;
let resulting_bytecode: Vec = swap_configurables(my_bytecode, my_configurables);
}
@@ -31,12 +34,15 @@ fn swap(my_bytecode: Vec, my_configurables: Vec<(u64, Vec)>) {
// ANCHOR: compute_bytecode_root
fn compute_bytecode(my_bytecode: Vec) {
- let root: b256 = compute_bytecode_root(my_bytecode);
+ let root: BytecodeRoot = compute_bytecode_root(my_bytecode);
}
-fn compute_bytecode_configurables(my_bytecode: Vec, my_configurables: Vec<(u64, Vec)>) {
+fn compute_bytecode_configurables(
+ my_bytecode: Vec,
+ my_configurables: ContractConfigurables,
+) {
let mut my_bytecode = my_bytecode;
- let root: b256 = compute_bytecode_root_with_configurables(my_bytecode, my_configurables);
+ let root: BytecodeRoot = compute_bytecode_root_with_configurables(my_bytecode, my_configurables);
}
// ANCHOR_END: compute_bytecode_root
@@ -49,7 +55,7 @@ fn verify_contract(my_contract: ContractId, my_bytecode: Vec) {
fn verify_contract_configurables(
my_contract: ContractId,
my_bytecode: Vec,
- my_configurables: Vec<(u64, Vec)>,
+ my_configurables: ContractConfigurables,
) {
let mut my_bytecode = my_bytecode;
verify_contract_bytecode_with_configurables(my_contract, my_bytecode, my_configurables);
@@ -62,14 +68,17 @@ fn compute_predicate(my_bytecode: Vec) {
let address: Address = compute_predicate_address(my_bytecode);
}
-fn compute_predicate_configurables(my_bytecode: Vec, my_configurables: Vec<(u64, Vec)>) {
+fn compute_predicate_configurables(
+ my_bytecode: Vec,
+ my_configurables: ContractConfigurables,
+) {
let mut my_bytecode = my_bytecode;
let address: Address = compute_predicate_address_with_configurables(my_bytecode, my_configurables);
}
// ANCHOR_END: compute_predicate_address
// ANCHOR: predicate_address_from_root
-fn predicate_address(my_root: b256) {
+fn predicate_address(my_root: BytecodeRoot) {
let address: Address = predicate_address_from_root(my_root);
}
// ANCHOR_END: predicate_address_from_root
@@ -83,7 +92,7 @@ fn verify_predicate(my_predicate: Address, my_bytecode: Vec) {
fn verify_predicate_configurables(
my_predicate: Address,
my_bytecode: Vec,
- my_configurables: Vec<(u64, Vec)>,
+ my_configurables: ContractConfigurables,
) {
let mut my_bytecode = my_bytecode;
verify_predicate_address_with_configurables(my_predicate, my_bytecode, my_configurables);
diff --git a/examples/merkle/mod.rs b/examples/merkle/mod.rs
index b889c3f0..e225d337 100644
--- a/examples/merkle/mod.rs
+++ b/examples/merkle/mod.rs
@@ -36,7 +36,7 @@ async fn get_contract_instance() -> (MerkleExample, WalletUnlock
.await
.unwrap();
- let instance = MerkleExample::new(id.clone(), wallet.clone());
+ let instance = MerkleExample::new(id, wallet.clone());
(instance, wallet)
}
@@ -48,12 +48,12 @@ async fn rust_setup_example() {
// ANCHOR: generating_a_tree
// Create a new Merkle Tree and define leaves
let mut tree = MerkleTree::new();
- let leaves = ["A".as_bytes(), "B".as_bytes(), "C".as_bytes()].to_vec();
+ let leaves = [b"A", b"B", b"C"].to_vec();
// Hash the leaves and then push to the merkle tree
- for datum in leaves.iter() {
+ for datum in &leaves {
let mut hasher = Sha256::new();
- hasher.update(&datum);
+ hasher.update(datum);
let hash = hasher.finalize();
tree.push(&hash);
}
@@ -69,14 +69,14 @@ async fn rust_setup_example() {
// Convert the proof set from Vec to Vec
let mut bits256_proof: Vec = Vec::new();
for itterator in proof_set {
- bits256_proof.push(Bits256(itterator.clone()));
+ bits256_proof.push(Bits256(itterator));
}
// ANCHOR_END: generating_proof
// ANCHOR: verify_proof
// Create the merkle leaf
let mut leaf_hasher = Sha256::new();
- leaf_hasher.update(&leaves[key as usize]);
+ leaf_hasher.update(leaves[key as usize]);
let hashed_leaf_data = leaf_hasher.finalize();
let merkle_leaf = leaf_sum(&hashed_leaf_data);
@@ -104,7 +104,7 @@ async fn rust_setup_example() {
pub fn leaf_sum(data: &[u8]) -> [u8; 32] {
let mut hash = Sha256::new();
- hash.update(&[LEAF]);
+ hash.update([LEAF]);
hash.update(data);
hash.finalize().into()
diff --git a/examples/ownership/Forc.toml b/examples/ownership/Forc.toml
index 72adea04..93c78a21 100644
--- a/examples/ownership/Forc.toml
+++ b/examples/ownership/Forc.toml
@@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "ownership_examples"
[dependencies]
-standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.5.2" }
+standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.0" }
sway_libs = { path = "../../libs" }
diff --git a/examples/upgradability/Forc.toml b/examples/upgradability/Forc.toml
index c4364b2c..df6aa50d 100644
--- a/examples/upgradability/Forc.toml
+++ b/examples/upgradability/Forc.toml
@@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "upgradability_examples"
[dependencies]
-standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.5.2" }
+standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.0" }
sway_libs = { path = "../../libs" }
diff --git a/examples/upgradability/src/main.sw b/examples/upgradability/src/main.sw
index 26ebf40f..f7ec5a32 100644
--- a/examples/upgradability/src/main.sw
+++ b/examples/upgradability/src/main.sw
@@ -9,11 +9,21 @@ use standards::{src14::*, src5::*};
use sway_libs::upgradability::{_proxy_owner, _proxy_target, _set_proxy_target};
use standards::{src14::{SRC14, SRC14Extension}, src5::State};
-#[namespace(SRC14)]
storage {
- // target is at sha256("storage_SRC14_0")
- target: Option = None,
- proxy_owner: State = State::Uninitialized,
+ SRC14 {
+ /// The [ContractId] of the target contract.
+ ///
+ /// # Additional Information
+ ///
+ /// `target` is stored at sha256("storage_SRC14_0")
+ target in 0x7bb458adc1d118713319a5baa00a2d049dd64d2916477d2688d76970c898cd55: Option = None,
+ /// The [State] of the proxy owner.
+ ///
+ /// # Additional Information
+ ///
+ /// `proxy_owner` is stored at sha256("storage_SRC14_1")
+ proxy_owner in 0xbb79927b15d9259ea316f2ecb2297d6cc8851888a98278c0a2e03e1a091ea754: State = State::Uninitialized,
+ },
}
impl SRC14 for Contract {
@@ -31,7 +41,7 @@ impl SRC14 for Contract {
impl SRC14Extension for Contract {
#[storage(read)]
fn proxy_owner() -> State {
- _proxy_owner(storage.proxy_owner)
+ _proxy_owner()
}
}
// ANCHOR_END: integrate_with_src14
@@ -53,21 +63,21 @@ fn proxy_target() -> Option {
// ANCHOR: set_proxy_owner
#[storage(write)]
fn set_proxy_owner(new_proxy_owner: State) {
- _set_proxy_owner(new_proxy_owner, storage.proxy_owner);
+ _set_proxy_owner(new_proxy_owner);
}
// ANCHOR_END: set_proxy_owner
// ANCHOR: proxy_owner
#[storage(read)]
fn proxy_owner() -> State {
- _proxy_owner(storage.proxy_owner)
+ _proxy_owner()
}
// ANCHOR_END: proxy_owner
// ANCHOR: only_proxy_owner
#[storage(read)]
fn only_proxy_owner_may_call() {
- only_proxy_owner(storage.proxy_owner);
+ only_proxy_owner();
// Only the proxy's owner may reach this line.
}
// ANCHOR_END: only_proxy_owner
diff --git a/libs/Forc.lock b/libs/Forc.lock
index a516af41..7ac14885 100644
--- a/libs/Forc.lock
+++ b/libs/Forc.lock
@@ -1,15 +1,15 @@
[[package]]
name = "core"
-source = "path+from-root-E19CE48B3E858B72"
+source = "path+from-root-7053AAA90CC5E690"
[[package]]
name = "standards"
-source = "git+https://github.com/FuelLabs/sway-standards?tag=v0.5.2#270350e69bd7455b7e99f0aae2e29a94d42324bd"
+source = "git+https://github.com/FuelLabs/sway-standards?tag=v0.6.0#65e09f95ea8b9476b171a66c8a47108f352fa32c"
dependencies = ["std"]
[[package]]
name = "std"
-source = "git+https://github.com/fuellabs/sway?tag=v0.60.0#2f0392ee35a1e4dd80bd8034962d5b4083dfb8b6"
+source = "git+https://github.com/fuellabs/sway?tag=v0.66.2#31486c0b47669612acb7c64d66ecb50aea281282"
dependencies = ["core"]
[[package]]
diff --git a/libs/Forc.toml b/libs/Forc.toml
index 4db34db5..abc5f2ec 100644
--- a/libs/Forc.toml
+++ b/libs/Forc.toml
@@ -5,4 +5,4 @@ license = "Apache-2.0"
name = "sway_libs"
[dependencies]
-standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.5.2" }
+standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.0" }
diff --git a/libs/src/asset/base.sw b/libs/src/asset/base.sw
index b4f73cfa..40c53e40 100644
--- a/libs/src/asset/base.sw
+++ b/libs/src/asset/base.sw
@@ -1,6 +1,8 @@
library;
use std::{hash::{Hash, sha256}, storage::storage_string::*, string::String};
+use standards::src20::{SetDecimalsEvent, SetNameEvent, SetSymbolEvent};
+use ::asset::errors::SetMetadataError;
/// Returns the total number of individual assets for a contract.
///
@@ -201,6 +203,10 @@ pub fn _decimals(
/// * `asset`: [AssetId] - The asset of which to set the name.
/// * `name`: [String] - The name of the asset.
///
+/// # Reverts
+///
+/// * When passing an empty string.
+///
/// # Number of Storage Accesses
///
/// * Writes: `2`
@@ -218,7 +224,7 @@ pub fn _decimals(
/// fn foo(asset: AssetId) {
/// let name = String::from_ascii_str("Ether");
/// _set_name(storage.name, asset, name);
-/// assert(_name(storage.name, asset) == name);
+/// assert(_name(storage.name, asset).unwrap() == name);
/// }
/// ```
#[storage(write)]
@@ -227,8 +233,16 @@ pub fn _set_name(
asset: AssetId,
name: String,
) {
+ require(!name.is_empty(), SetMetadataError::EmptyString);
+
name_key.insert(asset, StorageString {});
name_key.get(asset).write_slice(name);
+
+ log(SetNameEvent {
+ asset,
+ name: Some(name),
+ sender: msg_sender().unwrap(),
+ });
}
/// Unconditionally sets the symbol of an asset.
@@ -243,6 +257,10 @@ pub fn _set_name(
/// * `asset`: [AssetId] - The asset of which to set the symbol.
/// * `symbol`: [String] - The symbol of the asset.
///
+/// # Reverts
+///
+/// * When passing an empty string.
+///
/// # Number of Storage Accesses
///
/// * Writes: `2`
@@ -260,7 +278,7 @@ pub fn _set_name(
/// fn foo(asset: AssetId) {
/// let symbol = String::from_ascii_str("ETH");
/// _set_symbol(storage.symbol, asset, symbol);
-/// assert(_symbol(storage.symbol, asset) == symbol);
+/// assert(_symbol(storage.symbol, asset).unwrap() == symbol);
/// }
/// ```
#[storage(write)]
@@ -269,8 +287,16 @@ pub fn _set_symbol(
asset: AssetId,
symbol: String,
) {
+ require(!symbol.is_empty(), SetMetadataError::EmptyString);
+
symbol_key.insert(asset, StorageString {});
symbol_key.get(asset).write_slice(symbol);
+
+ log(SetSymbolEvent {
+ asset,
+ symbol: Some(symbol),
+ sender: msg_sender().unwrap(),
+ });
}
/// Unconditionally sets the decimals of an asset.
@@ -293,7 +319,6 @@ pub fn _set_symbol(
///
/// ```sway
/// use sway_libs::asset::base::{_set_decimals, _decimals};
-/// use std::string::String;
///
/// storage {
/// decimals: StorageMap = StorageMap {},
@@ -302,7 +327,7 @@ pub fn _set_symbol(
/// fn foo(asset: AssetId) {
/// let decimals = 8u8;
/// _set_decimals(storage.decimals, asset, decimals);
-/// assert(_decimals(storage.decimals, asset) == decimals);
+/// assert(_decimals(storage.decimals, asset).unwrap() == decimals);
/// }
/// ```
#[storage(write)]
@@ -312,13 +337,78 @@ pub fn _set_decimals(
decimals: u8,
) {
decimals_key.insert(asset, decimals);
+
+ log(SetDecimalsEvent {
+ asset,
+ decimals,
+ sender: msg_sender().unwrap(),
+ });
}
abi SetAssetAttributes {
+ /// Stores the name for a specific asset.
+ ///
+ /// # Arguments
+ ///
+ /// * `asset`: [AssetId] - The asset for the name to be stored.
+ /// * `name`: [String] - The name which to be stored.
+ ///
+ /// # Example
+ ///
+ /// ```sway
+ /// use standards::src20::SRC20;
+ /// use sway_libs::asset::base::*;
+ /// use std::string::String;
+ ///
+ /// fn foo(contract_id: ContractId, asset: AssetId, name: String) {
+ /// let contract_abi = abi(SetAssetAttributes, contract_id.bits());
+ /// contract_abi.set_name(asset, name);
+ /// assert(contract_abi.name(asset) == name);
+ /// }
+ /// ```
#[storage(write)]
fn set_name(asset: AssetId, name: String);
+ /// Stores the symbol for a specific asset.
+ ///
+ /// # Arguments
+ ///
+ /// * `asset`: [AssetId] - The asset for the symbol to be stored.
+ /// * `symbol`: [String] - The symbol which to be stored.
+ ///
+ /// # Example
+ ///
+ /// ```sway
+ /// use standards::src20::SRC20;
+ /// use sway_libs::asset::base::*;
+ /// use std::string::String;
+ ///
+ /// fn foo(contract_id: ContractId, asset: AssetId, symbol: String) {
+ /// let contract_abi = abi(SetAssetAttributes, contract_id.bits());
+ /// contract_abi.set_symbol(asset, symbol);
+ /// assert(contract_abi.symbol(asset) == symbol);
+ /// }
+ /// ```
#[storage(write)]
fn set_symbol(asset: AssetId, symbol: String);
+ /// Stores the decimals for a specific asset.
+ ///
+ /// # Arguments
+ ///
+ /// * `asset`: [AssetId] - The asset for the symbol to be stored.
+ /// * `decimals`: [u8] - The decimals which to be stored.
+ ///
+ /// # Example
+ ///
+ /// ```sway
+ /// use standards::src20::SRC20;
+ /// use sway_libs::asset::base::*;
+ ///
+ /// fn foo(contract_id: ContractId, asset: AssetId, decimals: u8) {
+ /// let contract_abi = abi(SetAssetAttributes, contract_id.bits());
+ /// contract_abi.set_decimals(asset, decimals);
+ /// assert(contract_abi.decimals(asset).unwrap() == decimals);
+ /// }
+ /// ```
#[storage(write)]
fn set_decimals(asset: AssetId, decimals: u8);
}
diff --git a/libs/src/asset/errors.sw b/libs/src/asset/errors.sw
index 0f74207e..53dc36ea 100644
--- a/libs/src/asset/errors.sw
+++ b/libs/src/asset/errors.sw
@@ -4,4 +4,20 @@ library;
pub enum BurnError {
/// Emitted when there are not enough coins owned by the contract to burn.
NotEnoughCoins: (),
+ /// Emitted when attempting to burn zero coins.
+ ZeroAmount: (),
+}
+
+/// Error log for when something goes wrong when minting assets.
+pub enum MintError {
+ /// Emitted when attempting to mint zero coins.
+ ZeroAmount: (),
+}
+
+/// Error log for when something goes wrong when setting metadata.
+pub enum SetMetadataError {
+ /// Emitted when the metadata is an empty string.
+ EmptyString: (),
+ /// Emitted when the metadata is empty bytes.
+ EmptyBytes: (),
}
diff --git a/libs/src/asset/metadata.sw b/libs/src/asset/metadata.sw
index 4af81c82..ae3a01ec 100644
--- a/libs/src/asset/metadata.sw
+++ b/libs/src/asset/metadata.sw
@@ -1,6 +1,6 @@
library;
-use standards::src7::Metadata;
+use standards::src7::{Metadata, SetMetadataEvent};
use std::{
auth::msg_sender,
bytes::Bytes,
@@ -18,18 +18,7 @@ use std::{
},
string::String,
};
-
-/// The event emitted when metadata is set via the `_set_metadata()` function.
-pub struct SetMetadataEvent {
- /// The asset for which metadata is set.
- asset: AssetId,
- /// The `Identity` of the caller that set the metadata.
- sender: Identity,
- /// The Metadata that is set.
- metadata: Metadata,
- /// The key used for the metadata.
- key: String,
-}
+use ::asset::errors::SetMetadataError;
/// A persistent storage type to store the SRC-7; Metadata Standard type.
///
@@ -47,6 +36,11 @@ impl StorageKey {
/// * `key`: [String] - The key for the metadata to be stored.
/// * `metadata`: [Metadata] - The metadata which to be stored.
///
+ /// # Reverts
+ ///
+ /// * When the metadata is an empty string.
+ /// * When the metadata is an empty bytes.
+ ///
/// # Number of Storage Accesses
///
/// * Writes: `2`
@@ -56,6 +50,7 @@ impl StorageKey {
/// ```sway
/// use standards::src7::Metadata;
/// use sway_libs::asset::metadata::*;
+ /// use std::string::String;
///
/// storage {
/// metadata: StorageMetadata = StorageMetadata {}
@@ -72,23 +67,34 @@ impl StorageKey {
match metadata {
Metadata::Int(data) => {
write(hashed_key, 0, data);
- write(sha256((hashed_key, self.slot())), 0, 0);
+ write(sha256((hashed_key, self.slot())), 0, 1);
},
Metadata::B256(data) => {
write(hashed_key, 0, data);
- write(sha256((hashed_key, self.slot())), 0, 1);
+ write(sha256((hashed_key, self.slot())), 0, 2);
},
Metadata::String(data) => {
+ require(!data.is_empty(), SetMetadataError::EmptyString);
+
let storage_string: StorageKey = StorageKey::new(hashed_key, 0, hashed_key);
storage_string.write_slice(data);
- write(sha256((hashed_key, self.slot())), 0, 2);
+ write(sha256((hashed_key, self.slot())), 0, 3);
},
Metadata::Bytes(data) => {
+ require(!data.is_empty(), SetMetadataError::EmptyBytes);
+
let storage_bytes: StorageKey = StorageKey::new(hashed_key, 0, hashed_key);
storage_bytes.write_slice(data);
- write(sha256((hashed_key, self.slot())), 0, 3);
- }
+ write(sha256((hashed_key, self.slot())), 0, 4);
+ },
}
+
+ log(SetMetadataEvent {
+ asset,
+ metadata: Some(metadata),
+ key,
+ sender: msg_sender().unwrap(),
+ });
}
/// Returns metadata for a specific asset and key pair.
@@ -111,6 +117,7 @@ impl StorageKey {
/// ```sway
/// use standards::src7::Metadata;
/// use sway_libs::asset::metadata::*;
+ /// use std::string::String;
///
/// storage {
/// metadata: StorageMetadata = StorageMetadata {}
@@ -126,21 +133,21 @@ impl StorageKey {
let hashed_key = sha256((asset, key));
match read::(sha256((hashed_key, self.slot())), 0) {
- Option::Some(0) => {
- Option::Some(Metadata::Int(read::(hashed_key, 0).unwrap()))
+ Some(1) => {
+ Some(Metadata::Int(read::(hashed_key, 0).unwrap()))
},
- Option::Some(1) => {
- Option::Some(Metadata::B256(read::(hashed_key, 0).unwrap()))
+ Some(2) => {
+ Some(Metadata::B256(read::(hashed_key, 0).unwrap()))
},
- Option::Some(2) => {
+ Some(3) => {
let storage_string: StorageKey = StorageKey::new(hashed_key, 0, hashed_key);
- Option::Some(Metadata::String(storage_string.read_slice().unwrap()))
+ Some(Metadata::String(storage_string.read_slice().unwrap_or(String::new())))
},
- Option::Some(3) => {
+ Some(4) => {
let storage_bytes: StorageKey = StorageKey::new(hashed_key, 0, hashed_key);
- Option::Some(Metadata::Bytes(storage_bytes.read_slice().unwrap()))
+ Some(Metadata::Bytes(storage_bytes.read_slice().unwrap_or(Bytes::new())))
},
- _ => Option::None,
+ _ => None,
}
}
}
@@ -151,8 +158,8 @@ impl StorageKey {
///
/// * `metadata_key`: [StorageKey] - The storage location for metadata.
/// * `asset`: [AssetId] - The asset for the metadata to be stored.
+/// * `metadata`: [Option] - The metadata which to be stored.
/// * `key`: [String] - The key for the metadata to be stored.
-/// * `metadata`: [Metadata] - The metadata which to be stored.
///
/// # Number of Storage Accesses
///
@@ -163,13 +170,14 @@ impl StorageKey {
/// ```sway
/// use standards::src7::Metadata;
/// use sway_libs::asset::metadata::*;
+/// use std::string::String;
///
/// storage {
/// metadata: StorageMetadata = StorageMetadata {}
/// }
///
-/// fn foo(asset: AssetId, key: String, metadata: Metadata) {
-/// _set_metadata(storage.metadata, asset, key, metadata);
+/// fn foo(asset: AssetId, key: String, metadata: Option) {
+/// _set_metadata(storage.metadata, asset, metadata, key);
/// }
/// ```
#[storage(read, write)]
@@ -179,16 +187,67 @@ pub fn _set_metadata(
key: String,
metadata: Metadata,
) {
- log(SetMetadataEvent {
- asset,
- sender: msg_sender().unwrap(),
- metadata,
- key,
- });
metadata_key.insert(asset, key, metadata);
}
+/// Returns metadata for a specific asset and key pair.
+///
+/// # Arguments
+///
+/// * `metadata_key`: [StorageKey] - The storage location for metadata.
+/// * `asset`: [AssetId] - The asset for the metadata to be read.
+/// * `metadata`: [Option] - The metadata which to be read.
+/// * `key`: [String] - The key for the metadata to be read.
+///
+/// # Number of Storage Accesses
+///
+/// * Reads: `2`
+///
+/// # Example
+///
+/// ```sway
+/// use standards::src7::Metadata;
+/// use sway_libs::asset::metadata::*;
+/// use std::string::String;
+///
+/// storage {
+/// metadata: StorageMetadata = StorageMetadata {}
+/// }
+///
+/// fn foo(asset: AssetId, key: String) {
+/// let result: Option = _metadata(storage.metadata, asset, key);
+/// }
+/// ```
+#[storage(read)]
+pub fn _metadata(
+ metadata_key: StorageKey,
+ asset: AssetId,
+ key: String,
+) -> Option {
+ metadata_key.get(asset, key)
+}
abi SetAssetMetadata {
+ /// Stores metadata for a specific asset and key pair.
+ ///
+ /// # Arguments
+ ///
+ /// * `asset`: [AssetId] - The asset for the metadata to be stored.
+ /// * `metadata`: [Metadata] - The metadata which to be stored.
+ /// * `key`: [String] - The key for the metadata to be stored.
+ ///
+ /// # Example
+ ///
+ /// ```sway
+ /// use standards::src7::{SRC7, Metadata};
+ /// use sway_libs::asset::metadata::*;
+ /// use std::string::String;
+ ///
+ /// fn foo(contract_id: ContractId, asset: AssetId, key: String, metadata: Metadata) {
+ /// let contract_abi = abi(SetAssetMetadata, contract_id.bits());
+ /// contract_abi.set_metadata(asset, metadata, key);
+ /// assert(contract_abi.metadata(asset, key).unwrap() == Metadata);
+ /// }
+ /// ```
#[storage(read, write)]
fn set_metadata(asset: AssetId, key: String, metadata: Metadata);
}
diff --git a/libs/src/asset/supply.sw b/libs/src/asset/supply.sw
index bce20fcd..b30b043c 100644
--- a/libs/src/asset/supply.sw
+++ b/libs/src/asset/supply.sw
@@ -1,6 +1,6 @@
library;
-use ::asset::errors::BurnError;
+use ::asset::errors::{BurnError, MintError};
use ::asset::base::{_total_assets, _total_supply};
use std::{
asset::{
@@ -16,12 +16,14 @@ use std::{
storage::storage_string::*,
string::String,
};
+use standards::src20::TotalSupplyEvent;
/// Unconditionally mints new assets using the `sub_id` sub-identifier.
///
/// # Additional Information
///
/// **Warning** This function increases the total supply by the number of coins minted.
+/// **Note:** If `None` is passed for the `sub_id` argument, `b256::zero()` is used as the `SubId`.
///
/// # Arguments
///
@@ -35,6 +37,10 @@ use std::{
///
/// * [AssetId] - The `AssetId` of the newly minted asset.
///
+/// # Reverts
+///
+/// * When `amount` is zero.
+///
/// # Number of Storage Accesses
///
/// * Reads: `2`
@@ -65,6 +71,8 @@ pub fn _mint(
sub_id: SubId,
amount: u64,
) -> AssetId {
+ require(amount > 0, MintError::ZeroAmount);
+
let asset_id = AssetId::new(ContractId::this(), sub_id);
let supply = _total_supply(total_supply_key, asset_id);
@@ -77,6 +85,12 @@ pub fn _mint(
total_supply_key.insert(asset_id, current_supply + amount);
mint_to(recipient, sub_id, amount);
+ log(TotalSupplyEvent {
+ asset: asset_id,
+ supply: current_supply + amount,
+ sender: msg_sender().unwrap(),
+ });
+
asset_id
}
@@ -96,6 +110,7 @@ pub fn _mint(
/// # Reverts
///
/// * When the calling contract does not have enough assets.
+/// * When `amount` is zero.
///
/// # Number of Storage Accesses
///
@@ -124,6 +139,7 @@ pub fn _burn(
sub_id: SubId,
amount: u64,
) {
+ require(amount > 0, BurnError::ZeroAmount);
let asset_id = AssetId::new(ContractId::this(), sub_id);
require(this_balance(asset_id) >= amount, BurnError::NotEnoughCoins);
@@ -133,4 +149,9 @@ pub fn _burn(
total_supply_key.insert(asset_id, supply - amount);
burn(sub_id, amount);
+ log(TotalSupplyEvent {
+ asset: asset_id,
+ supply: supply - amount,
+ sender: msg_sender().unwrap(),
+ });
}
diff --git a/libs/src/bytecode.sw b/libs/src/bytecode.sw
index c691fcfc..04a1b723 100644
--- a/libs/src/bytecode.sw
+++ b/libs/src/bytecode.sw
@@ -6,6 +6,9 @@ pub mod utils;
use std::external::bytecode_root;
use ::bytecode::utils::{_compute_bytecode_root, _predicate_address_from_root, _swap_configurables};
+pub type BytecodeRoot = b256;
+pub type ContractConfigurables = Vec<(u64, Vec)>;
+
/// Takes the bytecode of a contract or predicate and computes the bytecode root.
///
/// # Arguments
@@ -23,14 +26,14 @@ use ::bytecode::utils::{_compute_bytecode_root, _predicate_address_from_root, _s
/// # Examples
///
/// ```sway
-/// use sway_libs::bytecode::compute_bytecode_root;
+/// use sway_libs::bytecode::{compute_bytecode_root, BytecodeRoot};
///
/// fn foo(my_bytecode: Vec) {
-/// let bytecode_root = compute_bytecode_root(my_bytecode);
+/// let bytecode_root: BytecodeRoot = compute_bytecode_root(my_bytecode);
/// assert(bytecode_root != b256::zero());
/// }
/// ```
-pub fn compute_bytecode_root(bytecode: Vec) -> b256 {
+pub fn compute_bytecode_root(bytecode: Vec) -> BytecodeRoot {
_compute_bytecode_root(bytecode.as_raw_slice())
}
@@ -39,7 +42,7 @@ pub fn compute_bytecode_root(bytecode: Vec) -> b256 {
/// # Arguments
///
/// * `bytecode`: [Vec] - The bytecode of a contract or predicate.
-/// * `configurables`: [Vec<(u64, Vec)] - The configurable values to swap.
+/// * `configurables`: [ContractConfigurables] - The configurable values to swap.
///
/// # Returns
///
@@ -52,18 +55,18 @@ pub fn compute_bytecode_root(bytecode: Vec) -> b256 {
/// # Examples
///
/// ```sway
-/// use sway_libs::bytecode::compute_bytecode_root_with_configurables;
+/// use sway_libs::bytecode::{compute_bytecode_root_with_configurables, BytecodeRoot, ContractConfigurables};
///
-/// fn foo(my_bytecode: Vec, my_configurables: Vec<(u64, Vec)>) {
+/// fn foo(my_bytecode: Vec, my_configurables: ContractConfigurables) {
/// let mut my_bytecode = my_bytecode;
-/// let bytecode_root = compute_bytecode_root_with_configurables(my_bytecode, my_configurables);
+/// let bytecode_root: BytecodeRoot = compute_bytecode_root_with_configurables(my_bytecode, my_configurables);
/// assert(bytecode_root != b256::zero());
/// }
/// ```
pub fn compute_bytecode_root_with_configurables(
ref mut bytecode: Vec,
- configurables: Vec<(u64, Vec)>,
-) -> b256 {
+ configurables: ContractConfigurables,
+) -> BytecodeRoot {
let mut bytecode_slice = bytecode.as_raw_slice();
_swap_configurables(bytecode_slice, configurables);
_compute_bytecode_root(bytecode_slice)
@@ -90,7 +93,7 @@ pub fn compute_bytecode_root_with_configurables(
/// use sway_libs::bytecode::compute_predicate_address;
///
/// fn foo(my_bytecode: Vec) {
-/// let predicate_address = compute_predicate_address(my_bytecode);
+/// let predicate_address: Address = compute_predicate_address(my_bytecode);
/// assert(predicate_address != Address::zero());
/// }
/// ```
@@ -104,7 +107,7 @@ pub fn compute_predicate_address(bytecode: Vec) -> Address {
/// # Arguments
///
/// * `bytecode`: [Vec] - The bytecode of a predicate.
-/// * `configurables`: [Vec<(u64, Vec)] - The configurable values to swap.
+/// * `configurables`: [ContractConfigurables] - The configurable values to swap.
///
/// # Returns
///
@@ -117,17 +120,17 @@ pub fn compute_predicate_address(bytecode: Vec) -> Address {
/// # Examples
///
/// ```sway
-/// use sway_libs::bytecode::compute_predicate_address;
+/// use sway_libs::bytecode::{compute_predicate_address, ContractConfigurables};
///
-/// fn foo(my_bytecode: Vec, my_configurables: Vec<(u64, Vec)>) {
+/// fn foo(my_bytecode: Vec, my_configurables: ContractConfigurables) {
/// let mut my_bytecode = my_bytecode;
-/// let predicate_address = compute_predicate_address(my_bytecode, my_configurables);
+/// let predicate_address: Address = compute_predicate_address(my_bytecode, my_configurables);
/// assert(predicate_address != Address::zero());
/// }
/// ```
pub fn compute_predicate_address_with_configurables(
ref mut bytecode: Vec,
- configurables: Vec<(u64, Vec)>,
+ configurables: ContractConfigurables,
) -> Address {
let mut bytecode_slice = bytecode.as_raw_slice();
_swap_configurables(bytecode_slice, configurables);
@@ -139,7 +142,7 @@ pub fn compute_predicate_address_with_configurables(
///
/// # Arguments
///
-/// * `bytecode_root`: [b256] - The bytecode root of a predicate.
+/// * `bytecode_root`: [BytecodeRoot] - The bytecode root of a predicate.
///
/// # Returns
///
@@ -148,14 +151,14 @@ pub fn compute_predicate_address_with_configurables(
/// # Examples
///
/// ```sway
-/// use sway_libs::bytecode::predicate_address_from_root;
+/// use sway_libs::bytecode::{predicate_address_from_root, BytecodeRoot};
///
-/// fn foo(predicate_bytecode_root: b256) {
-/// let predicate_address = predicate_address_from_root(predicate_bytecode_root);
+/// fn foo(predicate_bytecode_root: BytecodeRoot) {
+/// let predicate_address: Address = predicate_address_from_root(predicate_bytecode_root);
/// assert(predicate_address != Address::zero());
/// }
/// ```
-pub fn predicate_address_from_root(bytecode_root: b256) -> Address {
+pub fn predicate_address_from_root(bytecode_root: BytecodeRoot) -> Address {
_predicate_address_from_root(bytecode_root)
}
@@ -164,7 +167,7 @@ pub fn predicate_address_from_root(bytecode_root: b256) -> Address {
/// # Arguments
///
/// * `bytecode`: [Vec] - The bytecode of a contract or predicate.
-/// * `configurables`: [Vec<(u64, Vec)] - The configurable values to swap.
+/// * `configurables`: [ContractConfigurables] - The configurable values to swap.
///
/// # Returns
///
@@ -173,9 +176,9 @@ pub fn predicate_address_from_root(bytecode_root: b256) -> Address {
/// # Examples
///
/// ```sway
-/// use sway_libs::bytecode::sway_configurables;
+/// use sway_libs::bytecode::{sway_configurables, ContractConfigurables};
///
-/// fn foo(my_bytecode: Vec, my_configurables: Vec<(u64, Vec)>) {
+/// fn foo(my_bytecode: Vec, my_configurables: ContractConfigurables) {
/// let mut my_bytecode = my_bytecode;
/// let resulting_bytecode = swap_configurables(my_bytecode, my_configurables);
/// assert(resulting_bytecode != my_bytecode);
@@ -183,7 +186,7 @@ pub fn predicate_address_from_root(bytecode_root: b256) -> Address {
/// ```
pub fn swap_configurables(
ref mut bytecode: Vec,
- configurables: Vec<(u64, Vec)>,
+ configurables: ContractConfigurables,
) -> Vec {
let mut bytecode_slice = bytecode.as_raw_slice();
_swap_configurables(bytecode_slice, configurables);
@@ -225,7 +228,7 @@ pub fn verify_contract_bytecode(contract_id: ContractId, bytecode: Vec) {
///
/// * `contract_id`: [ContractId] - The contract that the bytecode should match.
/// * `bytecode`: [Vec] - The bytecode of the contract.
-/// * `configurables`: [Vec<(u6, Vec)>] - The configurable values to swap.
+/// * `configurables`: [ContractConfigurables] - The configurable values to swap.
///
/// # Reverts
///
@@ -235,9 +238,9 @@ pub fn verify_contract_bytecode(contract_id: ContractId, bytecode: Vec) {
/// # Examples
///
/// ```sway
-/// use sway_libs::bytecode::verify_contract_bytecode_with_configurables;
+/// use sway_libs::bytecode::{verify_contract_bytecode_with_configurables, ContractConfigurables};
///
-/// fn foo(my_contract_id: ContractId, my_bytecode: Vec, my_configurables: Vec<(u64, Vec)>) {
+/// fn foo(my_contract_id: ContractId, my_bytecode: Vec, my_configurables: ContractConfigurables) {
/// let mut my_bytecode = my_bytecode;
/// verify_contract_bytecode_with_configurables(my_contract_id, my_bytecode, my_configurables);
/// // This line will only be reached if the contract's bytecode root and the computed bytecode root match.
@@ -246,7 +249,7 @@ pub fn verify_contract_bytecode(contract_id: ContractId, bytecode: Vec) {
pub fn verify_contract_bytecode_with_configurables(
contract_id: ContractId,
ref mut bytecode: Vec,
- configurables: Vec<(u64, Vec)>,
+ configurables: ContractConfigurables,
) {
let root = bytecode_root(contract_id);
let mut bytecode_slice = bytecode.as_raw_slice();
@@ -291,7 +294,7 @@ pub fn verify_predicate_address(predicate_id: Address, bytecode: Vec) {
///
/// * `predicate_id`: [Address] - The predicate address that the bytecode should match.
/// * `bytecode`: [Vec] - The bytecode of the predicate.
-/// * `configurables`: [Vec<(u64, Vec)>] - The configurable values to swap.
+/// * `configurables`: [ContractConfigurables] - The configurable values to swap.
///
/// # Reverts
///
@@ -303,7 +306,7 @@ pub fn verify_predicate_address(predicate_id: Address, bytecode: Vec) {
/// ```sway
/// use sway_libs::bytecode::verify_predicate_address_with_configurables;
///
-/// fn foo(my_predicate_id: Address, my_bytecode: Vec, my_configurables: Vec<(u64, Vec)>) {
+/// fn foo(my_predicate_id: Address, my_bytecode: Vec, my_configurables: ContractConfigurables) {
/// let mut my_bytecode = my_bytecode;
/// verify_predicate_address_with_configurables(my_predicate_id, my_bytecode, my_configurables);
/// // This line will only be reached if the predicates's address and the computed address match.
@@ -312,7 +315,7 @@ pub fn verify_predicate_address(predicate_id: Address, bytecode: Vec) {
pub fn verify_predicate_address_with_configurables(
predicate_id: Address,
ref mut bytecode: Vec,
- configurables: Vec<(u64, Vec)>,
+ configurables: ContractConfigurables,
) {
let mut bytecode_slice = bytecode.as_raw_slice();
_swap_configurables(bytecode_slice, configurables);
diff --git a/libs/src/upgradability.sw b/libs/src/upgradability.sw
index 829ed7f6..23c31b49 100644
--- a/libs/src/upgradability.sw
+++ b/libs/src/upgradability.sw
@@ -7,6 +7,11 @@ use ::upgradability::{errors::SetProxyOwnerError, events::{ProxyOwnerSet, ProxyT
use std::{auth::msg_sender, storage::storage_api::{read, write}};
use standards::{src14::SRC14_TARGET_STORAGE, src5::{AccessError, State}};
+/// The storage slot to store the proxy owner State.
+///
+/// Value is `sha256("storage_SRC14_1")`.
+pub const PROXY_OWNER_STORAGE: b256 = 0xbb79927b15d9259ea316f2ecb2297d6cc8851888a98278c0a2e03e1a091ea754;
+
/// Returns the proxy target.
///
/// # Returns
@@ -66,10 +71,6 @@ pub fn _set_proxy_target(new_target: ContractId) {
/// Returns the owner of the proxy.
///
-/// # Arguments
-///
-/// * `proxy_owner_storage_key`: [StorageKey] - The storage key of the stored proxy owner.
-///
/// # Returns
///
/// * [State] - The state of the proxy ownership.
@@ -83,25 +84,19 @@ pub fn _set_proxy_target(new_target: ContractId) {
/// ```sway
/// use sway_libs::upgradability::_proxy_owner;
///
-/// storage {
-/// proxy_owner: State = State::Uninitialized,
-/// }
///
/// fn foo() {
-/// let stored_proxy_owner = _proxy_owner(storage.proxy_owner);
+/// let stored_proxy_owner = _proxy_owner();
/// }
/// ```
#[storage(read)]
-pub fn _proxy_owner(proxy_owner_storage_key: StorageKey) -> State {
- proxy_owner_storage_key.read()
+pub fn _proxy_owner() -> State {
+ let proxy_owner_key = StorageKey::new(PROXY_OWNER_STORAGE, 0, PROXY_OWNER_STORAGE);
+ proxy_owner_key.read()
}
/// Ensures that the sender is the proxy owner.
///
-/// # Arguments
-///
-/// * `proxy_owner_storage_key`: [StorageKey] - The storage key of the stored proxy owner.
-///
/// # Reverts
///
/// * When the sender is not the proxy owner.
@@ -115,19 +110,15 @@ pub fn _proxy_owner(proxy_owner_storage_key: StorageKey) -> State {
/// ```sway
/// use sway_libs::ownership::only_proxy_owner;
///
-/// storage {
-/// proxy_owner: State = State::Uninitialized,
-/// }
-///
/// fn foo() {
-/// only_proxy_owner(storage.proxy_owner);
+/// only_proxy_owner();
/// // Do stuff here if the sender is the proxy owner
/// }
/// ```
#[storage(read)]
-pub fn only_proxy_owner(proxy_owner_storage_key: StorageKey) {
+pub fn only_proxy_owner() {
require(
- _proxy_owner(proxy_owner_storage_key) == State::Initialized(msg_sender().unwrap()),
+ _proxy_owner() == State::Initialized(msg_sender().unwrap()),
AccessError::NotOwner,
);
}
@@ -141,7 +132,6 @@ pub fn only_proxy_owner(proxy_owner_storage_key: StorageKey) {
/// # Arguments
///
/// * `new_proxy_owner`: [State] - The new state of the proxy ownership.
-/// * `proxy_owner_storage_key`: [StorageKey] - The storage key of the stored proxy owner.
///
/// # Reverts
///
@@ -157,31 +147,26 @@ pub fn only_proxy_owner(proxy_owner_storage_key: StorageKey) {
/// ```sway
/// use sway_libs::upgradability::{_proxy_owner, _set_proxy_owner};
///
-/// storage {
-/// proxy_owner: State = State::Uninitialized,
-/// }
-///
/// fn foo(new_owner: Identity) {
-/// assert(_proxy_owner(storage.proxy_owner) == State::Initialized(Identity::Address(Address::zero()));
+/// assert(_proxy_owner() == State::Initialized(Identity::Address(Address::zero()));
///
/// let new_proxy_owner = State::Initialized(new_owner);
-/// _set_proxy_owner(new_proxy_owner, storage.proxy_owner);
+/// _set_proxy_owner(new_proxy_owner);
///
-/// assert(_proxy_owner(storage.proxy_owner) == State::Initialized(new_owner));
+/// assert(_proxy_owner() == State::Initialized(new_owner));
/// }
/// ```
#[storage(write)]
-pub fn _set_proxy_owner(
- new_proxy_owner: State,
- proxy_owner_storage_key: StorageKey,
-) {
- only_proxy_owner(proxy_owner_storage_key);
+pub fn _set_proxy_owner(new_proxy_owner: State) {
+ only_proxy_owner();
+
require(
new_proxy_owner != State::Uninitialized,
SetProxyOwnerError::CannotUninitialize,
);
- proxy_owner_storage_key.write(new_proxy_owner);
+ let proxy_owner_key = StorageKey::new(PROXY_OWNER_STORAGE, 0, PROXY_OWNER_STORAGE);
+ proxy_owner_key.write(new_proxy_owner);
log(ProxyOwnerSet {
new_proxy_owner,
diff --git a/tests/Cargo.toml b/tests/Cargo.toml
index fcdee262..96fe727c 100644
--- a/tests/Cargo.toml
+++ b/tests/Cargo.toml
@@ -6,15 +6,15 @@ edition = "2021"
license = "Apache-2.0"
[dependencies]
-fuel-merkle = { version = "0.49.0" }
-fuels = { version = "0.62.0", features = ["fuel-core-lib"] }
+fuel-merkle = { version = "0.56.0" }
+fuels = { version = "0.66.9" }
sha2 = { version = "0.10" }
tokio = { version = "1.12", features = ["rt", "macros"] }
rand = { version = "0.8.5", default-features = false, features = [
"std_rng",
"getrandom",
] }
-fuel-tx = { version = "0.43.1" }
+fuel-tx = { version = "0.56.0" }
[[test]]
harness = true
diff --git a/tests/Forc.lock b/tests/Forc.lock
index 3f4107b2..969f0721 100644
--- a/tests/Forc.lock
+++ b/tests/Forc.lock
@@ -22,7 +22,7 @@ dependencies = ["std"]
[[package]]
name = "core"
-source = "path+from-root-E19CE48B3E858B72"
+source = "path+from-root-7053AAA90CC5E690"
[[package]]
name = "i128_test"
@@ -210,12 +210,12 @@ dependencies = ["std"]
[[package]]
name = "standards"
-source = "git+https://github.com/FuelLabs/sway-standards?tag=v0.5.2#270350e69bd7455b7e99f0aae2e29a94d42324bd"
+source = "git+https://github.com/FuelLabs/sway-standards?tag=v0.6.0#65e09f95ea8b9476b171a66c8a47108f352fa32c"
dependencies = ["std"]
[[package]]
name = "std"
-source = "git+https://github.com/fuellabs/sway?tag=v0.60.0#2f0392ee35a1e4dd80bd8034962d5b4083dfb8b6"
+source = "git+https://github.com/fuellabs/sway?tag=v0.66.2#31486c0b47669612acb7c64d66ecb50aea281282"
dependencies = ["core"]
[[package]]
diff --git a/tests/src/admin/Forc.toml b/tests/src/admin/Forc.toml
index 82663096..5319dd7a 100644
--- a/tests/src/admin/Forc.toml
+++ b/tests/src/admin/Forc.toml
@@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "admin_test"
[dependencies]
-standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.5.2" }
+standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.0" }
sway_libs = { path = "../../../libs" }
diff --git a/tests/src/admin/tests/utils/mod.rs b/tests/src/admin/tests/utils/mod.rs
index 214021e0..53a4aa8e 100644
--- a/tests/src/admin/tests/utils/mod.rs
+++ b/tests/src/admin/tests/utils/mod.rs
@@ -3,7 +3,7 @@ use fuels::{
abigen, launch_custom_provider_and_get_wallets, Contract, LoadConfiguration,
StorageConfiguration, TxPolicies, WalletUnlocked, WalletsConfig,
},
- programs::call_response::FuelCallResponse,
+ programs::responses::CallResponse,
types::Identity,
};
@@ -25,7 +25,7 @@ pub mod abi_calls {
pub async fn add_admin(
contract: &AdminLib,
new_admin: Identity,
- ) -> FuelCallResponse<()> {
+ ) -> CallResponse<()> {
contract
.methods()
.add_admin(new_admin)
@@ -37,7 +37,7 @@ pub mod abi_calls {
pub async fn remove_admin(
contract: &AdminLib,
old_admin: Identity,
- ) -> FuelCallResponse<()> {
+ ) -> CallResponse<()> {
contract
.methods()
.remove_admin(old_admin)
@@ -56,11 +56,11 @@ pub mod abi_calls {
.value
}
- pub async fn only_admin(contract: &AdminLib) -> FuelCallResponse<()> {
+ pub async fn only_admin(contract: &AdminLib) -> CallResponse<()> {
contract.methods().only_admin().call().await.unwrap()
}
- pub async fn only_owner_or_admin(contract: &AdminLib) -> FuelCallResponse<()> {
+ pub async fn only_owner_or_admin(contract: &AdminLib) -> CallResponse<()> {
contract
.methods()
.only_owner_or_admin()
@@ -72,7 +72,7 @@ pub mod abi_calls {
pub async fn set_ownership(
contract: &AdminLib,
new_owner: Identity,
- ) -> FuelCallResponse<()> {
+ ) -> CallResponse<()> {
contract
.methods()
.set_ownership(new_owner)
diff --git a/tests/src/bytecode/tests/functions/compute_predicate_address_with_configurables.rs b/tests/src/bytecode/tests/functions/compute_predicate_address_with_configurables.rs
index 24ce883e..dda74d1d 100644
--- a/tests/src/bytecode/tests/functions/compute_predicate_address_with_configurables.rs
+++ b/tests/src/bytecode/tests/functions/compute_predicate_address_with_configurables.rs
@@ -45,7 +45,7 @@ mod revert {
#[tokio::test]
#[should_panic]
async fn when_bytecode_is_empty() {
- let (test_contract_instance, wallet) = test_contract_instance().await;
+ let (test_contract_instance, _wallet) = test_contract_instance().await;
let empty_bytecode: Vec = Vec::new();
let my_configurables: Vec<(u64, Vec)> = Vec::new();
diff --git a/tests/src/bytecode/tests/functions/swap_configurables.rs b/tests/src/bytecode/tests/functions/swap_configurables.rs
index fdd820f8..57595550 100644
--- a/tests/src/bytecode/tests/functions/swap_configurables.rs
+++ b/tests/src/bytecode/tests/functions/swap_configurables.rs
@@ -142,7 +142,7 @@ mod failure {
#[tokio::test]
#[should_panic]
async fn able_to_buffer_overflow() {
- let (test_contract_instance, wallet) = test_contract_instance().await;
+ let (test_contract_instance, _wallet) = test_contract_instance().await;
let (_contract_offset, _predicate_offset, config_value) = defaults();
// Get the bytecode for the contract
@@ -152,7 +152,7 @@ mod failure {
let my_configurables = build_simple_configurables(file_bytecode.len() as u64, config_value);
// Call the contract to swap the configurables
- let result_bytecode = swap_configurables(
+ let _result_bytecode = swap_configurables(
&test_contract_instance,
file_bytecode.clone(),
my_configurables.clone(),
diff --git a/tests/src/bytecode/tests/utils/mod.rs b/tests/src/bytecode/tests/utils/mod.rs
index a1011c2f..91f7f026 100644
--- a/tests/src/bytecode/tests/utils/mod.rs
+++ b/tests/src/bytecode/tests/utils/mod.rs
@@ -2,7 +2,7 @@ use fuels::{
accounts::predicate::Predicate,
core::codec::{DecoderConfig, EncoderConfig},
prelude::*,
- programs::call_response::FuelCallResponse,
+ programs::responses::CallResponse,
tx::StorageSlot,
types::{Bits256, Bytes32},
};
@@ -37,14 +37,14 @@ const PREDICATE_BYTECODE_PATH: &str =
"src/bytecode/test_artifacts/simple_predicate/out/release/simple_predicate.bin";
const DEFAULT_PREDICATE_BALANCE: u64 = 512;
-const HEX_STR_1: &str = "0xacbe4bfc77e55c071db31f2e37c824d75794867d88499107dc8318cb22aceea5";
-const HEX_STR_2: &str = "0x0b1af92ac5a3e8cfeafede9586a1f853a9e0258e7cdccae5e5181edac081f2c1b";
-const HEX_STR_3: &str = "0x0345c74edfb0ce0820409176d0cbc2c44eac1e5e4c7382ee7e7c38d611d9ba767";
-const SIMPLE_PREDICATE_OFFSET: u64 = 408;
-const SIMPLE_CONTRACT_OFFSET: u64 = 1432;
-const COMPLEX_CONTRACT_OFFSET_1: u64 = 23344;
-const COMPLEX_CONTRACT_OFFSET_2: u64 = 23360;
-const COMPLEX_CONTRACT_OFFSET_3: u64 = 23400;
+const HEX_STR_1: &str = "0xb4ca495f61ac3433e9a78cbf3adfb0e4486913bb548029cef99d1de2cf606d52";
+const HEX_STR_2: &str = "0x5d617010b482b54332741fab0dfd1b15dfad07e8895360af0fb9f3e3a04b0c74";
+const HEX_STR_3: &str = "0xfebf0fdda20de46a0f2261a69556b0f9fdeea85759af1edb322831cf7d0dc8d5";
+const SIMPLE_PREDICATE_OFFSET: u64 = 376;
+const SIMPLE_CONTRACT_OFFSET: u64 = 1384;
+const COMPLEX_CONTRACT_OFFSET_1: u64 = 22584;
+const COMPLEX_CONTRACT_OFFSET_2: u64 = 22544;
+const COMPLEX_CONTRACT_OFFSET_3: u64 = 22472;
pub mod abi_calls {
@@ -177,7 +177,7 @@ pub mod abi_calls {
bytecode: Vec,
contract_id: ContractId,
simple_contract_instance: SimpleContract,
- ) -> FuelCallResponse<()> {
+ ) -> CallResponse<()> {
contract
.methods()
.verify_contract_bytecode(contract_id, bytecode)
@@ -192,7 +192,7 @@ pub mod abi_calls {
bytecode: Vec,
contract_id: ContractId,
complex_contract_instance: ComplexContract,
- ) -> FuelCallResponse<()> {
+ ) -> CallResponse<()> {
contract
.clone()
.with_encoder_config(EncoderConfig {
@@ -213,7 +213,7 @@ pub mod abi_calls {
configurables: Vec<(u64, Vec)>,
contract_id: ContractId,
simple_contract_instance: SimpleContract,
- ) -> FuelCallResponse<()> {
+ ) -> CallResponse<()> {
contract
.methods()
.verify_contract_bytecode_with_configurables(contract_id, bytecode, configurables)
@@ -229,7 +229,7 @@ pub mod abi_calls {
configurables: Vec<(u64, Vec)>,
contract_id: ContractId,
complex_contract_instance: ComplexContract,
- ) -> FuelCallResponse<()> {
+ ) -> CallResponse<()> {
contract
.clone()
.with_encoder_config(EncoderConfig {
@@ -248,7 +248,7 @@ pub mod abi_calls {
contract: &BytecodeTestContract,
bytecode: Vec,
predicate_id: Address,
- ) -> FuelCallResponse<()> {
+ ) -> CallResponse<()> {
contract
.methods()
.verify_predicate_address(predicate_id, bytecode)
@@ -262,7 +262,7 @@ pub mod abi_calls {
bytecode: Vec,
configurables: Vec<(u64, Vec)>,
predicate_id: Address,
- ) -> FuelCallResponse<()> {
+ ) -> CallResponse<()> {
contract
.methods()
.verify_predicate_address_with_configurables(predicate_id, bytecode, configurables)
@@ -341,7 +341,7 @@ pub mod test_helpers {
let rng = &mut StdRng::seed_from_u64(2322u64);
let salt: [u8; 32] = rng.gen();
let storage_vec = Vec::::new();
- let result_id = Contract::new(bytecode, salt.into(), storage_vec)
+ let result_id = Contract::regular(bytecode, salt.into(), storage_vec)
.deploy(&wallet, TxPolicies::default())
.await
.unwrap();
@@ -426,7 +426,7 @@ pub mod test_helpers {
let rng = &mut StdRng::seed_from_u64(2323u64);
let salt: [u8; 32] = rng.gen();
let storage_vec = Vec::::new();
- let result_id = Contract::new(bytecode, salt.into(), storage_vec)
+ let result_id = Contract::regular(bytecode, salt.into(), storage_vec)
.deploy(&wallet, TxPolicies::default())
.await
.unwrap();
diff --git a/tests/src/native_asset/Forc.toml b/tests/src/native_asset/Forc.toml
index feaebf2b..1040f253 100644
--- a/tests/src/native_asset/Forc.toml
+++ b/tests/src/native_asset/Forc.toml
@@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "native_asset_lib"
[dependencies]
-standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.5.2" }
+standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.0" }
sway_libs = { path = "../../../libs" }
diff --git a/tests/src/native_asset/src/main.sw b/tests/src/native_asset/src/main.sw
index bc019e00..0bff7605 100644
--- a/tests/src/native_asset/src/main.sw
+++ b/tests/src/native_asset/src/main.sw
@@ -59,14 +59,15 @@ impl SRC20 for Contract {
impl SRC3 for Contract {
#[storage(read, write)]
- fn mint(recipient: Identity, sub_id: SubId, amount: u64) {
+ fn mint(recipient: Identity, sub_id: Option, amount: u64) {
_mint(
storage
.total_assets,
storage
.total_supply,
recipient,
- sub_id,
+ sub_id
+ .unwrap_or(b256::zero()),
amount,
);
}
@@ -81,7 +82,7 @@ impl SRC3 for Contract {
impl SRC7 for Contract {
#[storage(read)]
fn metadata(asset: AssetId, key: String) -> Option {
- storage.metadata.get(asset, key)
+ _metadata(storage.metadata, asset, key)
}
}
@@ -120,10 +121,10 @@ fn test_total_assets() {
assert(src20_abi.total_assets() == 0);
- src3_abi.mint(recipient, sub_id1, 10);
+ src3_abi.mint(recipient, Some(sub_id1), 10);
assert(src20_abi.total_assets() == 1);
- src3_abi.mint(recipient, sub_id2, 10);
+ src3_abi.mint(recipient, Some(sub_id2), 10);
assert(src20_abi.total_assets() == 2);
}
@@ -138,10 +139,10 @@ fn test_total_supply() {
assert(src20_abi.total_supply(asset_id).is_none());
- src3_abi.mint(recipient, sub_id, 10);
+ src3_abi.mint(recipient, Some(sub_id), 10);
assert(src20_abi.total_supply(asset_id).unwrap() == 10);
- src3_abi.mint(recipient, sub_id, 10);
+ src3_abi.mint(recipient, Some(sub_id), 10);
assert(src20_abi.total_supply(asset_id).unwrap() == 20);
}
@@ -206,7 +207,7 @@ fn test_mint() {
assert(balance_of(ContractId::from(CONTRACT_ID), asset_id) == 0);
- src3_abi.mint(recipient, sub_id, 10);
+ src3_abi.mint(recipient, Some(sub_id), 10);
assert(balance_of(ContractId::from(CONTRACT_ID), asset_id) == 10);
}
@@ -221,7 +222,7 @@ fn test_burn() {
let sub_id = SubId::zero();
let asset_id = AssetId::new(ContractId::from(CONTRACT_ID), sub_id);
- src3_abi.mint(recipient, sub_id, 10);
+ src3_abi.mint(recipient, Some(sub_id), 10);
assert(balance_of(ContractId::from(CONTRACT_ID), asset_id) == 10);
src3_abi.burn(sub_id, 10);
@@ -369,7 +370,7 @@ fn total_assets_only_incremented_once() {
assert(src20_abi.total_assets() == 0);
- src3_abi.mint(recipient, sub_id, 10);
+ src3_abi.mint(recipient, Some(sub_id), 10);
assert(balance_of(ContractId::from(CONTRACT_ID), asset_id) == 10);
assert(src20_abi.total_assets() == 1);
@@ -379,7 +380,7 @@ fn total_assets_only_incremented_once() {
assert(src20_abi.total_assets() == 1);
- src3_abi.mint(recipient, sub_id, 10);
+ src3_abi.mint(recipient, Some(sub_id), 10);
assert(balance_of(ContractId::from(CONTRACT_ID), asset_id) == 10);
assert(src20_abi.total_assets() == 1);
diff --git a/tests/src/native_asset/tests/functions/burn.rs b/tests/src/native_asset/tests/functions/burn.rs
index 85b9fa39..a6107259 100644
--- a/tests/src/native_asset/tests/functions/burn.rs
+++ b/tests/src/native_asset/tests/functions/burn.rs
@@ -1,7 +1,8 @@
use crate::native_asset::tests::utils::{
interface::{burn, mint, total_assets, total_supply},
- setup::{defaults, get_wallet_balance, setup},
+ setup::{defaults, get_wallet_balance, setup, TotalSupplyEvent},
};
+use fuels::types::Identity;
mod success {
@@ -11,82 +12,287 @@ mod success {
async fn burn_assets() {
let (owner_wallet, other_wallet, id, instance_1, instance_2) = setup().await;
let (asset_id_1, _asset_id_2, sub_id_1, _sub_id_2, _owner_identity, identity2) =
- defaults(id, owner_wallet, other_wallet.clone());
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let mint_amount_1 = 100;
+ let burn_amount_1 = 25;
+
+ assert!(mint_amount_1 >= burn_amount_1);
+
+ mint(&instance_1, identity2, Some(sub_id_1), mint_amount_1).await;
+
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id_1).await,
+ mint_amount_1
+ );
+ assert_eq!(
+ total_supply(&instance_1, asset_id_1).await,
+ Some(mint_amount_1)
+ );
+ assert_eq!(total_assets(&instance_1).await, 1);
- mint(&instance_1, identity2, sub_id_1, 100).await;
+ let response = burn(&instance_2, asset_id_1, sub_id_1, burn_amount_1).await;
- assert_eq!(get_wallet_balance(&other_wallet, &asset_id_1).await, 100);
- assert_eq!(total_supply(&instance_1, asset_id_1).await, Some(100));
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id_1).await,
+ mint_amount_1 - burn_amount_1
+ );
+ assert_eq!(
+ total_supply(&instance_1, asset_id_1).await,
+ Some(mint_amount_1 - burn_amount_1)
+ );
assert_eq!(total_assets(&instance_1).await, 1);
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ TotalSupplyEvent {
+ asset: asset_id_1,
+ supply: mint_amount_1 - burn_amount_1,
+ sender: Identity::Address(other_wallet.address().into()),
+ }
+ );
+ }
- burn(&instance_2, asset_id_1, sub_id_1, 50).await;
+ #[tokio::test]
+ async fn burn_twice() {
+ let (owner_wallet, other_wallet, id, instance_1, instance_2) = setup().await;
+ let (asset_id_1, _asset_id_2, sub_id_1, _sub_id_2, _owner_identity, identity2) =
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let mint_amount_1 = 100;
+ let burn_amount_1 = 25;
+ let burn_amount_2 = 30;
+ let burn_amount_3 = 3;
+
+ assert!(mint_amount_1 >= burn_amount_1 + burn_amount_2 + burn_amount_3);
+
+ mint(&instance_1, identity2, Some(sub_id_1), mint_amount_1).await;
+
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id_1).await,
+ mint_amount_1
+ );
+ assert_eq!(
+ total_supply(&instance_1, asset_id_1).await,
+ Some(mint_amount_1)
+ );
+ assert_eq!(total_assets(&instance_1).await, 1);
- assert_eq!(get_wallet_balance(&other_wallet, &asset_id_1).await, 50);
- assert_eq!(total_supply(&instance_1, asset_id_1).await, Some(50));
+ let response = burn(&instance_2, asset_id_1, sub_id_1, burn_amount_1).await;
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id_1).await,
+ mint_amount_1 - burn_amount_1
+ );
+ assert_eq!(
+ total_supply(&instance_1, asset_id_1).await,
+ Some(mint_amount_1 - burn_amount_1)
+ );
assert_eq!(total_assets(&instance_1).await, 1);
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ TotalSupplyEvent {
+ asset: asset_id_1,
+ supply: mint_amount_1 - burn_amount_1,
+ sender: Identity::Address(other_wallet.address().into()),
+ }
+ );
+
+ let response = burn(&instance_2, asset_id_1, sub_id_1, burn_amount_2).await;
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id_1).await,
+ mint_amount_1 - burn_amount_1 - burn_amount_2
+ );
+ assert_eq!(
+ total_supply(&instance_1, asset_id_1).await,
+ Some(mint_amount_1 - burn_amount_1 - burn_amount_2)
+ );
+ assert_eq!(total_assets(&instance_1).await, 1);
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ TotalSupplyEvent {
+ asset: asset_id_1,
+ supply: mint_amount_1 - burn_amount_1 - burn_amount_2,
+ sender: Identity::Address(other_wallet.address().into()),
+ }
+ );
+
+ let response = burn(&instance_2, asset_id_1, sub_id_1, burn_amount_3).await;
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id_1).await,
+ mint_amount_1 - burn_amount_1 - burn_amount_2 - burn_amount_3
+ );
+ assert_eq!(
+ total_supply(&instance_1, asset_id_1).await,
+ Some(mint_amount_1 - burn_amount_1 - burn_amount_2 - burn_amount_3)
+ );
+ assert_eq!(total_assets(&instance_1).await, 1);
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ TotalSupplyEvent {
+ asset: asset_id_1,
+ supply: mint_amount_1 - burn_amount_1 - burn_amount_2 - burn_amount_3,
+ sender: Identity::Address(other_wallet.address().into()),
+ }
+ );
}
#[tokio::test]
async fn burns_multiple_assets() {
let (owner_wallet, other_wallet, id, instance_1, instance_2) = setup().await;
let (asset_id_1, asset_id_2, sub_id_1, sub_id_2, _owner_identity, identity2) =
- defaults(id, owner_wallet, other_wallet.clone());
-
- mint(&instance_1, identity2.clone(), sub_id_1, 100).await;
- mint(&instance_1, identity2, sub_id_2, 200).await;
-
- assert_eq!(get_wallet_balance(&other_wallet, &asset_id_1).await, 100);
- assert_eq!(get_wallet_balance(&other_wallet, &asset_id_2).await, 200);
- assert_eq!(total_supply(&instance_1, asset_id_1).await, Some(100));
- assert_eq!(total_supply(&instance_1, asset_id_2).await, Some(200));
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let mint_amount_1 = 100;
+ let mint_amount_2 = 200;
+ let burn_amount_1 = 25;
+ let burn_amount_2 = 150;
+
+ assert!(mint_amount_1 >= burn_amount_1);
+ assert!(mint_amount_2 >= burn_amount_2);
+
+ mint(
+ &instance_1,
+ identity2.clone(),
+ Some(sub_id_1),
+ mint_amount_1,
+ )
+ .await;
+ mint(&instance_1, identity2, Some(sub_id_2), mint_amount_2).await;
+
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id_1).await,
+ mint_amount_1
+ );
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id_2).await,
+ mint_amount_2
+ );
+ assert_eq!(
+ total_supply(&instance_1, asset_id_1).await,
+ Some(mint_amount_1)
+ );
+ assert_eq!(
+ total_supply(&instance_1, asset_id_2).await,
+ Some(mint_amount_2)
+ );
assert_eq!(total_assets(&instance_1).await, 2);
- burn(&instance_2, asset_id_1, sub_id_1, 50).await;
-
- assert_eq!(get_wallet_balance(&other_wallet, &asset_id_1).await, 50);
- assert_eq!(get_wallet_balance(&other_wallet, &asset_id_2).await, 200);
- assert_eq!(total_supply(&instance_1, asset_id_1).await, Some(50));
- assert_eq!(total_supply(&instance_1, asset_id_2).await, Some(200));
+ let response = burn(&instance_2, asset_id_1, sub_id_1, burn_amount_1).await;
+
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id_1).await,
+ mint_amount_1 - burn_amount_1
+ );
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id_2).await,
+ mint_amount_2
+ );
+ assert_eq!(
+ total_supply(&instance_1, asset_id_1).await,
+ Some(mint_amount_1 - burn_amount_1)
+ );
+ assert_eq!(
+ total_supply(&instance_1, asset_id_2).await,
+ Some(mint_amount_2)
+ );
assert_eq!(total_assets(&instance_1).await, 2);
-
- burn(&instance_2, asset_id_2, sub_id_2, 100).await;
-
- assert_eq!(get_wallet_balance(&other_wallet, &asset_id_1).await, 50);
- assert_eq!(get_wallet_balance(&other_wallet, &asset_id_2).await, 100);
- assert_eq!(total_supply(&instance_1, asset_id_1).await, Some(50));
- assert_eq!(total_supply(&instance_1, asset_id_2).await, Some(100));
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ TotalSupplyEvent {
+ asset: asset_id_1,
+ supply: mint_amount_1 - burn_amount_1,
+ sender: Identity::Address(other_wallet.address().into()),
+ }
+ );
+
+ let response = burn(&instance_2, asset_id_2, sub_id_2, burn_amount_2).await;
+
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id_1).await,
+ mint_amount_1 - burn_amount_1
+ );
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id_2).await,
+ mint_amount_2 - burn_amount_2
+ );
+ assert_eq!(
+ total_supply(&instance_1, asset_id_1).await,
+ Some(mint_amount_1 - burn_amount_1)
+ );
+ assert_eq!(
+ total_supply(&instance_1, asset_id_2).await,
+ Some(mint_amount_2 - burn_amount_2)
+ );
assert_eq!(total_assets(&instance_1).await, 2);
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ TotalSupplyEvent {
+ asset: asset_id_2,
+ supply: mint_amount_2 - burn_amount_2,
+ sender: Identity::Address(other_wallet.address().into()),
+ }
+ );
}
#[tokio::test]
async fn burn_to_zero() {
let (owner_wallet, other_wallet, id, instance_1, instance_2) = setup().await;
let (asset_id_1, _asset_id_2, sub_id_1, _sub_id_2, _owner_identity, identity2) =
- defaults(id, owner_wallet, other_wallet.clone());
-
- mint(&instance_1, identity2, sub_id_1, 100).await;
-
- assert_eq!(get_wallet_balance(&other_wallet, &asset_id_1).await, 100);
- assert_eq!(total_supply(&instance_1, asset_id_1).await, Some(100));
- assert_eq!(total_assets(&instance_1).await, 1);
-
- burn(&instance_2, asset_id_1, sub_id_1, 50).await;
-
- assert_eq!(get_wallet_balance(&other_wallet, &asset_id_1).await, 50);
- assert_eq!(total_supply(&instance_1, asset_id_1).await, Some(50));
- assert_eq!(total_assets(&instance_1).await, 1);
-
- burn(&instance_2, asset_id_1, sub_id_1, 25).await;
-
- assert_eq!(get_wallet_balance(&other_wallet, &asset_id_1).await, 25);
- assert_eq!(total_supply(&instance_1, asset_id_1).await, Some(25));
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let mint_amount_1 = 100;
+ let burn_amount_1 = 100;
+
+ assert!(mint_amount_1 == burn_amount_1);
+
+ mint(&instance_1, identity2, Some(sub_id_1), mint_amount_1).await;
+
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id_1).await,
+ mint_amount_1
+ );
+ assert_eq!(
+ total_supply(&instance_1, asset_id_1).await,
+ Some(mint_amount_1)
+ );
assert_eq!(total_assets(&instance_1).await, 1);
- burn(&instance_2, asset_id_1, sub_id_1, 25).await;
+ let response = burn(&instance_2, asset_id_1, sub_id_1, burn_amount_1).await;
assert_eq!(get_wallet_balance(&other_wallet, &asset_id_1).await, 0);
assert_eq!(total_supply(&instance_1, asset_id_1).await, Some(0));
assert_eq!(total_assets(&instance_1).await, 1);
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ TotalSupplyEvent {
+ asset: asset_id_1,
+ supply: 0,
+ sender: Identity::Address(other_wallet.address().into()),
+ }
+ );
}
}
@@ -100,17 +306,48 @@ mod revert {
#[tokio::test]
#[should_panic(expected = "NotEnoughCoins")]
- async fn when_not_enough_coins() {
+ async fn when_not_enough_coins_in_transaction() {
+ let (owner_wallet, other_wallet, id, instance_1, instance_2) = setup().await;
+ let (asset_id_1, _asset_id_2, sub_id_1, _sub_id_2, _identity1, identity2) =
+ defaults(id, owner_wallet, other_wallet.clone());
+ let mint_amount = 100;
+ let sent_burn_amount = 50;
+ let claimed_burn_amount = 75;
+
+ assert!(sent_burn_amount < claimed_burn_amount);
+
+ mint(&instance_1, identity2, Some(sub_id_1), mint_amount).await;
+
+ let call_params = CallParameters::new(sent_burn_amount, asset_id_1, 1_000_000);
+ instance_2
+ .methods()
+ .burn(sub_id_1, claimed_burn_amount)
+ .with_tx_policies(TxPolicies::default().with_script_gas_limit(2_000_000))
+ .call_params(call_params)
+ .unwrap()
+ .call()
+ .await
+ .unwrap();
+ }
+
+ #[tokio::test]
+ #[should_panic(expected = "NotEnoughCoins")]
+ async fn when_greater_than_supply() {
let (owner_wallet, other_wallet, id, instance_1, instance_2) = setup().await;
let (asset_id_1, _asset_id_2, sub_id_1, _sub_id_2, _identity1, identity2) =
defaults(id, owner_wallet, other_wallet.clone());
+ let mint_amount = 100;
+ let sent_burn_amount = 100;
+ let claimed_burn_amount = 150;
- mint(&instance_1, identity2, sub_id_1, 100).await;
+ assert!(mint_amount < claimed_burn_amount);
- let call_params = CallParameters::new(50, asset_id_1, 1_000_000);
+ mint(&instance_1, identity2, Some(sub_id_1), mint_amount).await;
+
+ let call_params = CallParameters::new(sent_burn_amount, asset_id_1, 1_000_000);
instance_2
.methods()
- .burn(sub_id_1, 150)
+ .burn(sub_id_1, claimed_burn_amount)
.with_tx_policies(TxPolicies::default().with_script_gas_limit(2_000_000))
.call_params(call_params)
.unwrap()
@@ -125,13 +362,18 @@ mod revert {
let (owner_wallet, other_wallet, id, instance_1, instance_2) = setup().await;
let (asset_id_1, _asset_id_2, sub_id_1, sub_id_2, _identity1, identity2) =
defaults(id, owner_wallet, other_wallet.clone());
+ let mint_amount = 100;
+ let sent_burn_amount = 50;
+ let claimed_burn_amount = 50;
+
+ assert!(sent_burn_amount == claimed_burn_amount);
- mint(&instance_1, identity2, sub_id_1, 100).await;
+ mint(&instance_1, identity2, Some(sub_id_1), mint_amount).await;
- let call_params = CallParameters::new(50, asset_id_1, 1_000_000);
+ let call_params = CallParameters::new(sent_burn_amount, asset_id_1, 1_000_000);
instance_2
.methods()
- .burn(sub_id_2, 50)
+ .burn(sub_id_2, claimed_burn_amount)
.with_tx_policies(TxPolicies::default().with_script_gas_limit(2_000_000))
.call_params(call_params)
.unwrap()
@@ -146,13 +388,18 @@ mod revert {
let (owner_wallet, other_wallet, id, instance_1, instance_2) = setup().await;
let (_asset_id_1, _asset_id_2, sub_id_1, _sub_id_2, _identity1, identity2) =
defaults(id, owner_wallet, other_wallet.clone());
+ let mint_amount = 100;
+ let sent_burn_amount = 50;
+ let claimed_burn_amount = 50;
- mint(&instance_1, identity2, sub_id_1, 100).await;
+ assert!(sent_burn_amount == claimed_burn_amount);
- let call_params = CallParameters::new(50, AssetId::zeroed(), 1_000_000);
+ mint(&instance_1, identity2, Some(sub_id_1), mint_amount).await;
+
+ let call_params = CallParameters::new(sent_burn_amount, AssetId::zeroed(), 1_000_000);
instance_2
.methods()
- .burn(sub_id_1, 50)
+ .burn(sub_id_1, claimed_burn_amount)
.with_tx_policies(TxPolicies::default().with_script_gas_limit(2_000_000))
.call_params(call_params)
.unwrap()
@@ -160,4 +407,20 @@ mod revert {
.await
.unwrap();
}
+
+ #[tokio::test]
+ #[should_panic(expected = "ZeroAmount")]
+ async fn when_burn_zero() {
+ let (owner_wallet, other_wallet, id, instance_1, instance_2) = setup().await;
+ let (asset_id_1, _asset_id_2, sub_id_1, _sub_id_2, _owner_identity, identity2) =
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let mint_amount_1 = 100;
+ let burn_amount_1 = 0;
+
+ assert!(burn_amount_1 == 0);
+
+ mint(&instance_1, identity2, Some(sub_id_1), mint_amount_1).await;
+
+ burn(&instance_2, asset_id_1, sub_id_1, burn_amount_1).await;
+ }
}
diff --git a/tests/src/native_asset/tests/functions/decimals.rs b/tests/src/native_asset/tests/functions/decimals.rs
index d1377f00..397258be 100644
--- a/tests/src/native_asset/tests/functions/decimals.rs
+++ b/tests/src/native_asset/tests/functions/decimals.rs
@@ -13,11 +13,12 @@ mod success {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
let (asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
defaults(id, owner_wallet, other_wallet.clone());
+ let decimals_1 = 9u8;
assert_eq!(decimals(&instance_1, asset_id_1).await, None);
- set_decimals(&instance_1, asset_id_1, 9u8).await;
- assert_eq!(decimals(&instance_1, asset_id_1).await, Some(9u8));
+ set_decimals(&instance_1, asset_id_1, decimals_1).await;
+ assert_eq!(decimals(&instance_1, asset_id_1).await, Some(decimals_1));
}
#[tokio::test]
@@ -25,28 +26,31 @@ mod success {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
let (asset_id_1, asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
defaults(id, owner_wallet, other_wallet.clone());
+ let decimals_1 = 9u8;
+ let decimals_2 = u8::MIN;
+ let decimals_3 = u8::MAX;
+ let decimals_4 = 16u8;
+ let decimals_5 = 9u8;
+ let asset_id_3 = get_asset_id(Bytes32::from([3u8; 32]), id);
+ let asset_id_4 = get_asset_id(Bytes32::from([4u8; 32]), id);
+ let asset_id_5 = get_asset_id(Bytes32::from([5u8; 32]), id);
assert_eq!(decimals(&instance_1, asset_id_1).await, None);
- set_decimals(&instance_1, asset_id_1, 9u8).await;
- assert_eq!(decimals(&instance_1, asset_id_1).await, Some(9u8));
-
assert_eq!(decimals(&instance_1, asset_id_2).await, None);
- set_decimals(&instance_1, asset_id_2, 8u8).await;
- assert_eq!(decimals(&instance_1, asset_id_2).await, Some(8u8));
-
- let asset_id_3 = get_asset_id(Bytes32::from([3u8; 32]), id);
assert_eq!(decimals(&instance_1, asset_id_3).await, None);
- set_decimals(&instance_1, asset_id_3, 7u8).await;
- assert_eq!(decimals(&instance_1, asset_id_3).await, Some(7u8));
-
- let asset_id_4 = get_asset_id(Bytes32::from([4u8; 32]), id);
assert_eq!(decimals(&instance_1, asset_id_4).await, None);
- set_decimals(&instance_1, asset_id_4, 6u8).await;
- assert_eq!(decimals(&instance_1, asset_id_4).await, Some(6u8));
-
- let asset_id_5 = get_asset_id(Bytes32::from([5u8; 32]), id);
assert_eq!(decimals(&instance_1, asset_id_5).await, None);
- set_decimals(&instance_1, asset_id_5, 5u8).await;
- assert_eq!(decimals(&instance_1, asset_id_5).await, Some(5u8));
+
+ set_decimals(&instance_1, asset_id_1, decimals_1).await;
+ set_decimals(&instance_1, asset_id_2, decimals_2).await;
+ set_decimals(&instance_1, asset_id_3, decimals_3).await;
+ set_decimals(&instance_1, asset_id_4, decimals_4).await;
+ set_decimals(&instance_1, asset_id_5, decimals_5).await;
+
+ assert_eq!(decimals(&instance_1, asset_id_1).await, Some(decimals_1));
+ assert_eq!(decimals(&instance_1, asset_id_2).await, Some(decimals_2));
+ assert_eq!(decimals(&instance_1, asset_id_3).await, Some(decimals_3));
+ assert_eq!(decimals(&instance_1, asset_id_4).await, Some(decimals_4));
+ assert_eq!(decimals(&instance_1, asset_id_5).await, Some(decimals_5));
}
}
diff --git a/tests/src/native_asset/tests/functions/metadata.rs b/tests/src/native_asset/tests/functions/metadata.rs
index 19a7c5a0..ca79648f 100644
--- a/tests/src/native_asset/tests/functions/metadata.rs
+++ b/tests/src/native_asset/tests/functions/metadata.rs
@@ -2,12 +2,22 @@ use crate::native_asset::tests::utils::{
interface::{metadata, set_metadata},
setup::{defaults, get_asset_id, setup, Metadata},
};
-use fuels::types::{Bytes, Bytes32};
+use fuels::types::{Bits256, Bytes, Bytes32};
mod success {
use super::*;
+ #[tokio::test]
+ async fn gets_none_set() {
+ let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
+ let (asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
+ defaults(id, owner_wallet, other_wallet.clone());
+ let key = String::from("key1");
+
+ assert_eq!(metadata(&instance_1, asset_id_1, key.clone()).await, None);
+ }
+
#[tokio::test]
async fn gets_one_asset() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
@@ -18,7 +28,13 @@ mod success {
assert_eq!(metadata(&instance_1, asset_id_1, key.clone()).await, None);
- set_metadata(&instance_1, asset_id_1, key.clone(), metadata1.clone()).await;
+ set_metadata(
+ &instance_1,
+ asset_id_1,
+ key.clone(),
+ Some(metadata1.clone()),
+ )
+ .await;
assert_eq!(
metadata(&instance_1, asset_id_1, key).await,
Some(metadata1)
@@ -33,25 +49,43 @@ mod success {
let metadata1 = Metadata::String(String::from("Fuel NFT Metadata 1"));
let metadata2 = Metadata::String(String::from("Fuel NFT Metadata 2"));
let metadata3 = Metadata::String(String::from("Fuel NFT Metadata 3"));
+ let asset_id_3 = get_asset_id(Bytes32::from([3u8; 32]), id);
let key = String::from("key1");
assert_eq!(metadata(&instance_1, asset_id_1, key.clone()).await, None);
- set_metadata(&instance_1, asset_id_1, key.clone(), metadata1.clone()).await;
+ assert_eq!(metadata(&instance_1, asset_id_2, key.clone()).await, None);
+ assert_eq!(metadata(&instance_1, asset_id_3, key.clone()).await, None);
+
+ set_metadata(
+ &instance_1,
+ asset_id_1,
+ key.clone(),
+ Some(metadata1.clone()),
+ )
+ .await;
+ set_metadata(
+ &instance_1,
+ asset_id_2,
+ key.clone(),
+ Some(metadata2.clone()),
+ )
+ .await;
+ set_metadata(
+ &instance_1,
+ asset_id_3,
+ key.clone(),
+ Some(metadata3.clone()),
+ )
+ .await;
+
assert_eq!(
metadata(&instance_1, asset_id_1, key.clone()).await,
Some(metadata1)
);
-
- assert_eq!(metadata(&instance_1, asset_id_2, key.clone()).await, None);
- set_metadata(&instance_1, asset_id_2, key.clone(), metadata2.clone()).await;
assert_eq!(
metadata(&instance_1, asset_id_2, key.clone()).await,
Some(metadata2)
);
-
- let asset_id_3 = get_asset_id(Bytes32::from([3u8; 32]), id);
- assert_eq!(metadata(&instance_1, asset_id_3, key.clone()).await, None);
- set_metadata(&instance_1, asset_id_3, key.clone(), metadata3.clone()).await;
assert_eq!(
metadata(&instance_1, asset_id_3, key).await,
Some(metadata3)
@@ -69,41 +103,61 @@ mod success {
Bytes::from_hex_str("0101010101010101010101010101010101010101010101010101010101010101")
.expect("failed to convert to bytes"),
);
+ let metadata4 = Metadata::B256(Bits256([1u8; 32]));
let key1 = String::from("key1");
let key2 = String::from("key2");
let key3 = String::from("key3");
+ let key4 = String::from("key4");
assert_eq!(metadata(&instance_1, asset_id_1, key1.clone()).await, None);
- set_metadata(&instance_1, asset_id_1, key1.clone(), metadata1.clone()).await;
+ assert_eq!(metadata(&instance_1, asset_id_1, key2.clone()).await, None);
+ assert_eq!(metadata(&instance_1, asset_id_1, key3.clone()).await, None);
+ assert_eq!(metadata(&instance_1, asset_id_1, key4.clone()).await, None);
+
+ set_metadata(
+ &instance_1,
+ asset_id_1,
+ key1.clone(),
+ Some(metadata1.clone()),
+ )
+ .await;
+ set_metadata(
+ &instance_1,
+ asset_id_1,
+ key2.clone(),
+ Some(metadata2.clone()),
+ )
+ .await;
+ set_metadata(
+ &instance_1,
+ asset_id_1,
+ key3.clone(),
+ Some(metadata3.clone()),
+ )
+ .await;
+ set_metadata(
+ &instance_1,
+ asset_id_1,
+ key4.clone(),
+ Some(metadata4.clone()),
+ )
+ .await;
+
assert_eq!(
metadata(&instance_1, asset_id_1, key1.clone()).await,
- Some(metadata1.clone())
+ Some(metadata1)
);
-
- assert_eq!(metadata(&instance_1, asset_id_1, key2.clone()).await, None);
- set_metadata(&instance_1, asset_id_1, key2.clone(), metadata2.clone()).await;
assert_eq!(
metadata(&instance_1, asset_id_1, key2.clone()).await,
- Some(metadata2.clone())
- );
- assert_eq!(
- metadata(&instance_1, asset_id_1, key1.clone()).await,
- Some(metadata1.clone())
+ Some(metadata2)
);
-
- assert_eq!(metadata(&instance_1, asset_id_1, key3.clone()).await, None);
- set_metadata(&instance_1, asset_id_1, key3.clone(), metadata3.clone()).await;
assert_eq!(
metadata(&instance_1, asset_id_1, key3).await,
Some(metadata3)
);
assert_eq!(
- metadata(&instance_1, asset_id_1, key2.clone()).await,
- Some(metadata2)
- );
- assert_eq!(
- metadata(&instance_1, asset_id_1, key1.clone()).await,
- Some(metadata1)
+ metadata(&instance_1, asset_id_1, key4).await,
+ Some(metadata4)
);
}
}
diff --git a/tests/src/native_asset/tests/functions/mint.rs b/tests/src/native_asset/tests/functions/mint.rs
index a98b0fc2..2669c4aa 100644
--- a/tests/src/native_asset/tests/functions/mint.rs
+++ b/tests/src/native_asset/tests/functions/mint.rs
@@ -1,7 +1,8 @@
use crate::native_asset::tests::utils::{
interface::{mint, total_assets, total_supply},
- setup::{defaults, get_wallet_balance, setup},
+ setup::{defaults, get_asset_id, get_wallet_balance, setup, TotalSupplyEvent},
};
+use fuels::types::{Bytes32, Identity};
mod success {
@@ -11,39 +12,250 @@ mod success {
async fn mints_assets() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
let (asset_id_1, _asset_id_2, sub_id_1, _sub_id_2, _identity1, identity2) =
- defaults(id, owner_wallet, other_wallet.clone());
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let mint_amount = 100;
assert_eq!(get_wallet_balance(&other_wallet, &asset_id_1).await, 0);
assert_eq!(total_supply(&instance_1, asset_id_1).await, None);
assert_eq!(total_assets(&instance_1).await, 0);
- mint(&instance_1, identity2, sub_id_1, 100).await;
+ let response = mint(&instance_1, identity2, Some(sub_id_1), mint_amount).await;
- assert_eq!(get_wallet_balance(&other_wallet, &asset_id_1).await, 100);
- assert_eq!(total_supply(&instance_1, asset_id_1).await, Some(100));
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id_1).await,
+ mint_amount
+ );
+ assert_eq!(
+ total_supply(&instance_1, asset_id_1).await,
+ Some(mint_amount)
+ );
assert_eq!(total_assets(&instance_1).await, 1);
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ TotalSupplyEvent {
+ asset: asset_id_1,
+ supply: mint_amount,
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
+ }
+
+ #[tokio::test]
+ async fn mints_twice() {
+ let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
+ let (asset_id_1, _asset_id_2, sub_id_1, _sub_id_2, _identity1, identity2) =
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let mint_amount_1 = 100;
+ let mint_amount_2 = 200;
+
+ let response = mint(&instance_1, identity2, Some(sub_id_1), mint_amount_1).await;
+
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id_1).await,
+ mint_amount_1
+ );
+ assert_eq!(
+ total_supply(&instance_1, asset_id_1).await,
+ Some(mint_amount_1)
+ );
+ assert_eq!(total_assets(&instance_1).await, 1);
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ TotalSupplyEvent {
+ asset: asset_id_1,
+ supply: mint_amount_1,
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
+
+ let response = mint(&instance_1, identity2, Some(sub_id_1), mint_amount_2).await;
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id_1).await,
+ mint_amount_1 + mint_amount_2
+ );
+ assert_eq!(
+ total_supply(&instance_1, asset_id_1).await,
+ Some(mint_amount_1 + mint_amount_2)
+ );
+ assert_eq!(total_assets(&instance_1).await, 1);
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ TotalSupplyEvent {
+ asset: asset_id_1,
+ supply: mint_amount_1 + mint_amount_2,
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
+ }
+
+ #[tokio::test]
+ async fn mints_max() {
+ let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
+ let (asset_id_1, _asset_id_2, sub_id_1, _sub_id_2, _identity1, identity2) =
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let mint_amount = u64::MAX;
+
+ assert_eq!(get_wallet_balance(&other_wallet, &asset_id_1).await, 0);
+ assert_eq!(total_supply(&instance_1, asset_id_1).await, None);
+ assert_eq!(total_assets(&instance_1).await, 0);
+
+ let response = mint(&instance_1, identity2, Some(sub_id_1), mint_amount).await;
+
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id_1).await,
+ mint_amount
+ );
+ assert_eq!(
+ total_supply(&instance_1, asset_id_1).await,
+ Some(mint_amount)
+ );
+ assert_eq!(total_assets(&instance_1).await, 1);
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ TotalSupplyEvent {
+ asset: asset_id_1,
+ supply: mint_amount,
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
+ }
+
+ #[tokio::test]
+ async fn mints_sub_id_none_assets() {
+ let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
+ let (_asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, identity2) =
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let mint_amount = 100;
+ let asset_id = get_asset_id(Bytes32::zeroed(), id);
+
+ assert_eq!(get_wallet_balance(&other_wallet, &asset_id).await, 0);
+ assert_eq!(total_supply(&instance_1, asset_id).await, None);
+ assert_eq!(total_assets(&instance_1).await, 0);
+
+ let response = mint(&instance_1, identity2, None, mint_amount).await;
+
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id).await,
+ mint_amount
+ );
+ assert_eq!(total_supply(&instance_1, asset_id).await, Some(mint_amount));
+ assert_eq!(total_assets(&instance_1).await, 1);
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ TotalSupplyEvent {
+ asset: asset_id,
+ supply: mint_amount,
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
}
#[tokio::test]
async fn mints_multiple_assets() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
let (asset_id_1, asset_id_2, sub_id_1, sub_id_2, _identity1, identity2) =
- defaults(id, owner_wallet, other_wallet.clone());
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let mint_amount_1 = 100;
+ let mint_amount_2 = 200;
- mint(&instance_1, identity2.clone(), sub_id_1, 100).await;
+ let response = mint(
+ &instance_1,
+ identity2.clone(),
+ Some(sub_id_1),
+ mint_amount_1,
+ )
+ .await;
- assert_eq!(get_wallet_balance(&other_wallet, &asset_id_1).await, 100);
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id_1).await,
+ mint_amount_1
+ );
assert_eq!(get_wallet_balance(&other_wallet, &asset_id_2).await, 0);
- assert_eq!(total_supply(&instance_1, asset_id_1).await, Some(100));
+ assert_eq!(
+ total_supply(&instance_1, asset_id_1).await,
+ Some(mint_amount_1)
+ );
assert_eq!(total_supply(&instance_1, asset_id_2).await, None);
assert_eq!(total_assets(&instance_1).await, 1);
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ TotalSupplyEvent {
+ asset: asset_id_1,
+ supply: mint_amount_1,
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
- mint(&instance_1, identity2, sub_id_2, 200).await;
+ let response = mint(&instance_1, identity2, Some(sub_id_2), mint_amount_2).await;
- assert_eq!(get_wallet_balance(&other_wallet, &asset_id_1).await, 100);
- assert_eq!(get_wallet_balance(&other_wallet, &asset_id_2).await, 200);
- assert_eq!(total_supply(&instance_1, asset_id_1).await, Some(100));
- assert_eq!(total_supply(&instance_1, asset_id_2).await, Some(200));
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id_1).await,
+ mint_amount_1
+ );
+ assert_eq!(
+ get_wallet_balance(&other_wallet, &asset_id_2).await,
+ mint_amount_2
+ );
+ assert_eq!(
+ total_supply(&instance_1, asset_id_1).await,
+ Some(mint_amount_1)
+ );
+ assert_eq!(
+ total_supply(&instance_1, asset_id_2).await,
+ Some(mint_amount_2)
+ );
assert_eq!(total_assets(&instance_1).await, 2);
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ TotalSupplyEvent {
+ asset: asset_id_2,
+ supply: mint_amount_2,
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
+ }
+}
+
+mod revert {
+
+ use super::*;
+
+ #[tokio::test]
+ #[should_panic(expected = "ZeroAmount")]
+ async fn mints_zero() {
+ let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
+ let (_asset_id_1, _asset_id_2, sub_id_1, _sub_id_2, _identity1, identity2) =
+ defaults(id, owner_wallet, other_wallet);
+ let mint_amount = 0;
+
+ mint(&instance_1, identity2, Some(sub_id_1), mint_amount).await;
}
}
diff --git a/tests/src/native_asset/tests/functions/name.rs b/tests/src/native_asset/tests/functions/name.rs
index 75312b1b..d7bf607d 100644
--- a/tests/src/native_asset/tests/functions/name.rs
+++ b/tests/src/native_asset/tests/functions/name.rs
@@ -9,88 +9,57 @@ mod success {
use super::*;
#[tokio::test]
- async fn one_asset() {
+ async fn get_none_asset_name() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
let (asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
- defaults(id, owner_wallet, other_wallet.clone());
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
assert_eq!(name(&instance_1, asset_id_1).await, None);
-
- set_name(&instance_1, asset_id_1, String::from("Fuel Asset 1")).await;
- assert_eq!(
- name(&instance_1, asset_id_1).await,
- Some(String::from("Fuel Asset 1"))
- );
}
#[tokio::test]
- async fn multiple_assets() {
+ async fn get_one_asset_name() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
- let (asset_id_1, asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
- defaults(id, owner_wallet, other_wallet.clone());
+ let (asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let name_1 = String::from("Fuel Asset 1");
assert_eq!(name(&instance_1, asset_id_1).await, None);
- set_name(&instance_1, asset_id_1, String::from("Fuel Asset 1")).await;
- assert_eq!(
- name(&instance_1, asset_id_1).await,
- Some(String::from("Fuel Asset 1"))
- );
-
- assert_eq!(name(&instance_1, asset_id_2).await, None);
- set_name(&instance_1, asset_id_2, String::from("Fuel Asset 2")).await;
- assert_eq!(
- name(&instance_1, asset_id_2).await,
- Some(String::from("Fuel Asset 2"))
- );
-
- let asset_id_3 = get_asset_id(Bytes32::from([3u8; 32]), id);
- assert_eq!(name(&instance_1, asset_id_3).await, None);
- set_name(&instance_1, asset_id_3, String::from("Fuel Asset 3")).await;
- assert_eq!(
- name(&instance_1, asset_id_3).await,
- Some(String::from("Fuel Asset 3"))
- );
-
- let asset_id_4 = get_asset_id(Bytes32::from([4u8; 32]), id);
- assert_eq!(name(&instance_1, asset_id_4).await, None);
- set_name(&instance_1, asset_id_4, String::from("Fuel Asset 4")).await;
- assert_eq!(
- name(&instance_1, asset_id_4).await,
- Some(String::from("Fuel Asset 4"))
- );
- let asset_id_5 = get_asset_id(Bytes32::from([5u8; 32]), id);
- assert_eq!(name(&instance_1, asset_id_5).await, None);
- set_name(&instance_1, asset_id_5, String::from("Fuel Asset 5")).await;
- assert_eq!(
- name(&instance_1, asset_id_5).await,
- Some(String::from("Fuel Asset 5"))
- );
+ set_name(&instance_1, asset_id_1, Some(name_1.clone())).await;
+ assert_eq!(name(&instance_1, asset_id_1).await, Some(name_1));
}
#[tokio::test]
- async fn does_not_overwrite_other_names() {
+ async fn get_multiple_assets_name() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
let (asset_id_1, asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
- defaults(id, owner_wallet, other_wallet.clone());
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let name_1 = String::from("Fuel Asset 1");
+ let name_2 = String::from("Fuel Asset 2");
+ let name_3 = String::from("Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3");
+ let name_4 = String::from("4");
+ let name_5 = String::from("Fuel Asset 1");
+ let asset_id_3 = get_asset_id(Bytes32::from([3u8; 32]), id);
+ let asset_id_4 = get_asset_id(Bytes32::from([4u8; 32]), id);
+ let asset_id_5 = get_asset_id(Bytes32::from([5u8; 32]), id);
assert_eq!(name(&instance_1, asset_id_1).await, None);
- set_name(&instance_1, asset_id_1, String::from("Fuel Asset 1")).await;
- assert_eq!(
- name(&instance_1, asset_id_1).await,
- Some(String::from("Fuel Asset 1"))
- );
-
assert_eq!(name(&instance_1, asset_id_2).await, None);
- set_name(&instance_1, asset_id_2, String::from("Fuel Asset 2")).await;
+ assert_eq!(name(&instance_1, asset_id_3).await, None);
+ assert_eq!(name(&instance_1, asset_id_4).await, None);
+ assert_eq!(name(&instance_1, asset_id_5).await, None);
+
+ set_name(&instance_1, asset_id_1, Some(name_1.clone())).await;
+ set_name(&instance_1, asset_id_2, Some(name_2.clone())).await;
+ set_name(&instance_1, asset_id_3, Some(name_3.clone())).await;
+ set_name(&instance_1, asset_id_4, Some(name_4.clone())).await;
+ set_name(&instance_1, asset_id_5, Some(name_5.clone())).await;
- assert_eq!(
- name(&instance_1, asset_id_1).await,
- Some(String::from("Fuel Asset 1"))
- );
- assert_eq!(
- name(&instance_1, asset_id_2).await,
- Some(String::from("Fuel Asset 2"))
- );
+ assert_eq!(name(&instance_1, asset_id_1).await, Some(name_1));
+ assert_eq!(name(&instance_1, asset_id_2).await, Some(name_2));
+ assert_eq!(name(&instance_1, asset_id_3).await, Some(name_3));
+ assert_eq!(name(&instance_1, asset_id_4).await, Some(name_4));
+ assert_eq!(name(&instance_1, asset_id_5).await, Some(name_5));
}
}
diff --git a/tests/src/native_asset/tests/functions/set_decimals.rs b/tests/src/native_asset/tests/functions/set_decimals.rs
index feef6b62..9a1e457a 100644
--- a/tests/src/native_asset/tests/functions/set_decimals.rs
+++ b/tests/src/native_asset/tests/functions/set_decimals.rs
@@ -1,8 +1,8 @@
use crate::native_asset::tests::utils::{
interface::{decimals, set_decimals},
- setup::{defaults, get_asset_id, setup},
+ setup::{defaults, get_asset_id, setup, SetDecimalsEvent},
};
-use fuels::types::Bytes32;
+use fuels::types::{Bytes32, Identity};
mod success {
@@ -12,58 +12,201 @@ mod success {
async fn sets_one_asset() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
let (asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
- defaults(id, owner_wallet, other_wallet.clone());
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let decimals_1 = 9u8;
assert_eq!(decimals(&instance_1, asset_id_1).await, None);
- set_decimals(&instance_1, asset_id_1, 9u8).await;
- assert_eq!(decimals(&instance_1, asset_id_1).await, Some(9u8));
+ let response = set_decimals(&instance_1, asset_id_1, decimals_1).await;
+ assert_eq!(decimals(&instance_1, asset_id_1).await, Some(decimals_1));
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetDecimalsEvent {
+ asset: asset_id_1,
+ decimals: decimals_1,
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
+ }
+
+ #[tokio::test]
+ async fn sets_decimals_twice() {
+ let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
+ let (asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let decimals_1 = 9u8;
+ let decimals_2 = 8u8;
+
+ let response = set_decimals(&instance_1, asset_id_1, decimals_1).await;
+ assert_eq!(decimals(&instance_1, asset_id_1).await, Some(decimals_1));
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetDecimalsEvent {
+ asset: asset_id_1,
+ decimals: decimals_1,
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
+
+ let response = set_decimals(&instance_1, asset_id_1, decimals_2).await;
+ assert_eq!(decimals(&instance_1, asset_id_1).await, Some(decimals_2));
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetDecimalsEvent {
+ asset: asset_id_1,
+ decimals: decimals_2,
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
}
#[tokio::test]
async fn sets_multiple_assets() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
let (asset_id_1, asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
- defaults(id, owner_wallet, other_wallet.clone());
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let decimals_1 = 9u8;
+ let decimals_2 = u8::MIN;
+ let decimals_3 = u8::MAX;
+ let decimals_4 = 16u8;
+ let decimals_5 = 9u8;
+ let asset_id_3 = get_asset_id(Bytes32::from([3u8; 32]), id);
+ let asset_id_4 = get_asset_id(Bytes32::from([4u8; 32]), id);
+ let asset_id_5 = get_asset_id(Bytes32::from([5u8; 32]), id);
assert_eq!(decimals(&instance_1, asset_id_1).await, None);
- set_decimals(&instance_1, asset_id_1, 9u8).await;
- assert_eq!(decimals(&instance_1, asset_id_1).await, Some(9u8));
+ let response = set_decimals(&instance_1, asset_id_1, decimals_1).await;
+ assert_eq!(decimals(&instance_1, asset_id_1).await, Some(decimals_1));
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetDecimalsEvent {
+ asset: asset_id_1,
+ decimals: decimals_1,
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
assert_eq!(decimals(&instance_1, asset_id_2).await, None);
- set_decimals(&instance_1, asset_id_2, 8u8).await;
- assert_eq!(decimals(&instance_1, asset_id_2).await, Some(8u8));
+ let response = set_decimals(&instance_1, asset_id_2, decimals_2).await;
+ assert_eq!(decimals(&instance_1, asset_id_2).await, Some(decimals_2));
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetDecimalsEvent {
+ asset: asset_id_2,
+ decimals: decimals_2,
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
- let asset_id_3 = get_asset_id(Bytes32::from([3u8; 32]), id);
assert_eq!(decimals(&instance_1, asset_id_3).await, None);
- set_decimals(&instance_1, asset_id_3, 7u8).await;
- assert_eq!(decimals(&instance_1, asset_id_3).await, Some(7u8));
+ let response = set_decimals(&instance_1, asset_id_3, decimals_3).await;
+ assert_eq!(decimals(&instance_1, asset_id_3).await, Some(decimals_3));
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetDecimalsEvent {
+ asset: asset_id_3,
+ decimals: decimals_3,
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
- let asset_id_4 = get_asset_id(Bytes32::from([4u8; 32]), id);
assert_eq!(decimals(&instance_1, asset_id_4).await, None);
- set_decimals(&instance_1, asset_id_4, 6u8).await;
- assert_eq!(decimals(&instance_1, asset_id_4).await, Some(6u8));
+ let response = set_decimals(&instance_1, asset_id_4, decimals_4).await;
+ assert_eq!(decimals(&instance_1, asset_id_4).await, Some(decimals_4));
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetDecimalsEvent {
+ asset: asset_id_4,
+ decimals: decimals_4,
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
- let asset_id_5 = get_asset_id(Bytes32::from([5u8; 32]), id);
assert_eq!(decimals(&instance_1, asset_id_5).await, None);
- set_decimals(&instance_1, asset_id_5, 5u8).await;
- assert_eq!(decimals(&instance_1, asset_id_5).await, Some(5u8));
+ let response = set_decimals(&instance_1, asset_id_5, decimals_5).await;
+ assert_eq!(decimals(&instance_1, asset_id_5).await, Some(decimals_5));
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetDecimalsEvent {
+ asset: asset_id_5,
+ decimals: decimals_5,
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
}
#[tokio::test]
- async fn does_not_overwrite_other_decimals() {
+ async fn does_not_overwrite_other_assets() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
let (asset_id_1, asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
- defaults(id, owner_wallet, other_wallet.clone());
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let decimals_1 = 9u8;
+ let decimals_2 = 8u8;
assert_eq!(decimals(&instance_1, asset_id_1).await, None);
- set_decimals(&instance_1, asset_id_1, 9u8).await;
- assert_eq!(decimals(&instance_1, asset_id_1).await, Some(9u8));
+ let response = set_decimals(&instance_1, asset_id_1, decimals_1).await;
+ assert_eq!(decimals(&instance_1, asset_id_1).await, Some(decimals_1));
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetDecimalsEvent {
+ asset: asset_id_1,
+ decimals: decimals_1,
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
assert_eq!(decimals(&instance_1, asset_id_2).await, None);
- set_decimals(&instance_1, asset_id_2, 8u8).await;
+ let response = set_decimals(&instance_1, asset_id_2, decimals_2).await;
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetDecimalsEvent {
+ asset: asset_id_2,
+ decimals: decimals_2,
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
- assert_eq!(decimals(&instance_1, asset_id_1).await, Some(9u8));
- assert_eq!(decimals(&instance_1, asset_id_2).await, Some(8u8));
+ assert_eq!(decimals(&instance_1, asset_id_1).await, Some(decimals_1));
+ assert_eq!(decimals(&instance_1, asset_id_2).await, Some(decimals_2));
}
}
diff --git a/tests/src/native_asset/tests/functions/set_metadata.rs b/tests/src/native_asset/tests/functions/set_metadata.rs
index 6b257ca1..bfde0d08 100644
--- a/tests/src/native_asset/tests/functions/set_metadata.rs
+++ b/tests/src/native_asset/tests/functions/set_metadata.rs
@@ -2,7 +2,7 @@ use crate::native_asset::tests::utils::{
interface::{metadata, set_metadata},
setup::{defaults, get_asset_id, setup, Metadata, SetMetadataEvent},
};
-use fuels::types::{Bytes, Bytes32, Identity};
+use fuels::types::{Bits256, Bytes, Bytes32, Identity};
mod success {
@@ -18,7 +18,13 @@ mod success {
assert_eq!(metadata(&instance_1, asset_id_1, key.clone()).await, None);
- let response = set_metadata(&instance_1, asset_id_1, key.clone(), metadata1.clone()).await;
+ let response = set_metadata(
+ &instance_1,
+ asset_id_1,
+ key.clone(),
+ Some(metadata1.clone()),
+ )
+ .await;
assert_eq!(
metadata(&instance_1, asset_id_1, key.clone()).await,
Some(metadata1.clone())
@@ -33,9 +39,48 @@ mod success {
*event,
SetMetadataEvent {
asset: asset_id_1,
+ metadata: Some(metadata1),
+ key: key,
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
+ }
+
+ #[tokio::test]
+ #[ignore]
+ async fn sets_none() {
+ let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
+ let (asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let metadata1 = Metadata::String(String::from("Fuel NFT Metadata"));
+ let key = String::from("key1");
+
+ set_metadata(
+ &instance_1,
+ asset_id_1,
+ key.clone(),
+ Some(metadata1.clone()),
+ )
+ .await;
+ assert_eq!(
+ metadata(&instance_1, asset_id_1, key.clone()).await,
+ Some(metadata1.clone())
+ );
+
+ let response = set_metadata(&instance_1, asset_id_1, key.clone(), None).await;
+ assert_eq!(metadata(&instance_1, asset_id_1, key.clone()).await, None);
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
+
+ assert_eq!(
+ *event,
+ SetMetadataEvent {
+ asset: asset_id_1,
+ metadata: None,
+ key: key,
sender: Identity::Address(owner_wallet.address().into()),
- metadata: metadata1,
- key: key
}
);
}
@@ -51,7 +96,13 @@ mod success {
let key = String::from("key1");
assert_eq!(metadata(&instance_1, asset_id_1, key.clone()).await, None);
- let response = set_metadata(&instance_1, asset_id_1, key.clone(), metadata1.clone()).await;
+ let response = set_metadata(
+ &instance_1,
+ asset_id_1,
+ key.clone(),
+ Some(metadata1.clone()),
+ )
+ .await;
assert_eq!(
metadata(&instance_1, asset_id_1, key.clone()).await,
Some(metadata1.clone())
@@ -66,14 +117,20 @@ mod success {
*event,
SetMetadataEvent {
asset: asset_id_1,
+ metadata: Some(metadata1),
+ key: key.clone(),
sender: Identity::Address(owner_wallet.address().into()),
- metadata: metadata1,
- key: key.clone()
}
);
assert_eq!(metadata(&instance_1, asset_id_2, key.clone()).await, None);
- let response = set_metadata(&instance_1, asset_id_2, key.clone(), metadata2.clone()).await;
+ let response = set_metadata(
+ &instance_1,
+ asset_id_2,
+ key.clone(),
+ Some(metadata2.clone()),
+ )
+ .await;
assert_eq!(
metadata(&instance_1, asset_id_2, key.clone()).await,
Some(metadata2.clone())
@@ -88,15 +145,21 @@ mod success {
*event,
SetMetadataEvent {
asset: asset_id_2,
+ metadata: Some(metadata2),
+ key: key.clone(),
sender: Identity::Address(owner_wallet.address().into()),
- metadata: metadata2,
- key: key.clone()
}
);
let asset_id_3 = get_asset_id(Bytes32::from([3u8; 32]), id);
assert_eq!(metadata(&instance_1, asset_id_3, key.clone()).await, None);
- let response = set_metadata(&instance_1, asset_id_3, key.clone(), metadata3.clone()).await;
+ let response = set_metadata(
+ &instance_1,
+ asset_id_3,
+ key.clone(),
+ Some(metadata3.clone()),
+ )
+ .await;
assert_eq!(
metadata(&instance_1, asset_id_3, key.clone()).await,
Some(metadata3.clone())
@@ -111,15 +174,15 @@ mod success {
*event,
SetMetadataEvent {
asset: asset_id_3,
+ metadata: Some(metadata3),
+ key: key,
sender: Identity::Address(owner_wallet.address().into()),
- metadata: metadata3,
- key: key
}
);
}
#[tokio::test]
- async fn does_not_overwrite_other_names() {
+ async fn does_not_overwrite_other_assets_with_same_key() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
let (asset_id_1, asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
defaults(id, owner_wallet.clone(), other_wallet.clone());
@@ -127,32 +190,42 @@ mod success {
let metadata2 = Metadata::String(String::from("Fuel NFT Metadata 2"));
let metadata3 = Metadata::String(String::from("Fuel NFT Metadata 3"));
let key = String::from("key1");
+ let asset_id_3 = get_asset_id(Bytes32::from([3u8; 32]), id);
assert_eq!(metadata(&instance_1, asset_id_1, key.clone()).await, None);
- let response = set_metadata(&instance_1, asset_id_1, key.clone(), metadata1.clone()).await;
+ let response = set_metadata(
+ &instance_1,
+ asset_id_1,
+ key.clone(),
+ Some(metadata1.clone()),
+ )
+ .await;
assert_eq!(
metadata(&instance_1, asset_id_1.clone(), key.clone()).await,
Some(metadata1.clone())
);
-
let log = response
.decode_logs_with_type::()
.unwrap();
let event = log.first().unwrap();
-
assert_eq!(
*event,
SetMetadataEvent {
asset: asset_id_1,
+ metadata: Some(metadata1.clone()),
+ key: key.clone(),
sender: Identity::Address(owner_wallet.address().into()),
- metadata: metadata1.clone(),
- key: key.clone()
}
);
assert_eq!(metadata(&instance_1, asset_id_2, key.clone()).await, None);
- let response = set_metadata(&instance_1, asset_id_2, key.clone(), metadata2.clone()).await;
-
+ let response = set_metadata(
+ &instance_1,
+ asset_id_2,
+ key.clone(),
+ Some(metadata2.clone()),
+ )
+ .await;
assert_eq!(
metadata(&instance_1, asset_id_1, key.clone()).await,
Some(metadata1.clone())
@@ -161,26 +234,28 @@ mod success {
metadata(&instance_1, asset_id_2, key.clone()).await,
Some(metadata2.clone())
);
-
let log = response
.decode_logs_with_type::()
.unwrap();
let event = log.first().unwrap();
-
assert_eq!(
*event,
SetMetadataEvent {
asset: asset_id_2,
+ metadata: Some(metadata2.clone()),
+ key: key.clone(),
sender: Identity::Address(owner_wallet.address().into()),
- metadata: metadata2.clone(),
- key: key.clone()
}
);
- let asset_id_3 = get_asset_id(Bytes32::from([3u8; 32]), id);
assert_eq!(metadata(&instance_1, asset_id_3, key.clone()).await, None);
- let response = set_metadata(&instance_1, asset_id_3, key.clone(), metadata3.clone()).await;
-
+ let response = set_metadata(
+ &instance_1,
+ asset_id_3,
+ key.clone(),
+ Some(metadata3.clone()),
+ )
+ .await;
assert_eq!(
metadata(&instance_1, asset_id_1, key.clone()).await,
Some(metadata1)
@@ -193,19 +268,17 @@ mod success {
metadata(&instance_1, asset_id_3, key.clone()).await,
Some(metadata3.clone())
);
-
let log = response
.decode_logs_with_type::()
.unwrap();
let event = log.first().unwrap();
-
assert_eq!(
*event,
SetMetadataEvent {
asset: asset_id_3,
+ metadata: Some(metadata3),
+ key: key,
sender: Identity::Address(owner_wallet.address().into()),
- metadata: metadata3,
- key: key
}
);
}
@@ -221,34 +294,46 @@ mod success {
Bytes::from_hex_str("0101010101010101010101010101010101010101010101010101010101010101")
.expect("failed to convert to bytes"),
);
+ let metadata4 = Metadata::B256(Bits256([1u8; 32]));
let key1 = String::from("key1");
let key2 = String::from("key2");
let key3 = String::from("key3");
+ let key4 = String::from("key4");
assert_eq!(metadata(&instance_1, asset_id_1, key1.clone()).await, None);
- let response = set_metadata(&instance_1, asset_id_1, key1.clone(), metadata1.clone()).await;
+ let response = set_metadata(
+ &instance_1,
+ asset_id_1,
+ key1.clone(),
+ Some(metadata1.clone()),
+ )
+ .await;
assert_eq!(
metadata(&instance_1, asset_id_1, key1.clone()).await,
Some(metadata1.clone())
);
-
let log = response
.decode_logs_with_type::()
.unwrap();
let event = log.first().unwrap();
-
assert_eq!(
*event,
SetMetadataEvent {
asset: asset_id_1,
+ metadata: Some(metadata1.clone()),
+ key: key1.clone(),
sender: Identity::Address(owner_wallet.address().into()),
- metadata: metadata1.clone(),
- key: key1.clone()
}
);
assert_eq!(metadata(&instance_1, asset_id_1, key2.clone()).await, None);
- let response = set_metadata(&instance_1, asset_id_1, key2.clone(), metadata2.clone()).await;
+ let response = set_metadata(
+ &instance_1,
+ asset_id_1,
+ key2.clone(),
+ Some(metadata2.clone()),
+ )
+ .await;
assert_eq!(
metadata(&instance_1, asset_id_1, key2.clone()).await,
Some(metadata2.clone())
@@ -257,50 +342,132 @@ mod success {
metadata(&instance_1, asset_id_1, key1.clone()).await,
Some(metadata1.clone())
);
-
let log = response
.decode_logs_with_type::()
.unwrap();
let event = log.first().unwrap();
-
assert_eq!(
*event,
SetMetadataEvent {
asset: asset_id_1,
+ metadata: Some(metadata2.clone()),
+ key: key2.clone(),
sender: Identity::Address(owner_wallet.address().into()),
- metadata: metadata2.clone(),
- key: key2.clone()
}
);
assert_eq!(metadata(&instance_1, asset_id_1, key3.clone()).await, None);
- let response = set_metadata(&instance_1, asset_id_1, key3.clone(), metadata3.clone()).await;
+ let response = set_metadata(
+ &instance_1,
+ asset_id_1,
+ key3.clone(),
+ Some(metadata3.clone()),
+ )
+ .await;
assert_eq!(
metadata(&instance_1, asset_id_1, key3.clone()).await,
Some(metadata3.clone())
);
assert_eq!(
metadata(&instance_1, asset_id_1, key2.clone()).await,
- Some(metadata2)
+ Some(metadata2.clone())
);
assert_eq!(
metadata(&instance_1, asset_id_1, key1.clone()).await,
- Some(metadata1)
+ Some(metadata1.clone())
);
-
let log = response
.decode_logs_with_type::()
.unwrap();
let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetMetadataEvent {
+ asset: asset_id_1,
+ metadata: Some(metadata3.clone()),
+ key: key3.clone(),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
+ assert_eq!(metadata(&instance_1, asset_id_1, key4.clone()).await, None);
+ let response = set_metadata(
+ &instance_1,
+ asset_id_1,
+ key4.clone(),
+ Some(metadata4.clone()),
+ )
+ .await;
+ assert_eq!(
+ metadata(&instance_1, asset_id_1, key4.clone()).await,
+ Some(metadata4.clone())
+ );
+ assert_eq!(
+ metadata(&instance_1, asset_id_1, key3).await,
+ Some(metadata3)
+ );
+ assert_eq!(
+ metadata(&instance_1, asset_id_1, key2).await,
+ Some(metadata2)
+ );
+ assert_eq!(
+ metadata(&instance_1, asset_id_1, key1).await,
+ Some(metadata1)
+ );
+ let log = response
+ .decode_logs_with_type::()
+ .unwrap();
+ let event = log.first().unwrap();
assert_eq!(
*event,
SetMetadataEvent {
asset: asset_id_1,
+ metadata: Some(metadata4),
+ key: key4,
sender: Identity::Address(owner_wallet.address().into()),
- metadata: metadata3,
- key: key3
}
);
}
}
+
+mod revert {
+
+ use super::*;
+
+ #[tokio::test]
+ #[should_panic(expected = "EmptyString")]
+ async fn when_empty_string() {
+ let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
+ let (asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let metadata1 = Metadata::String(String::from(""));
+ let key = String::from("key1");
+
+ set_metadata(
+ &instance_1,
+ asset_id_1,
+ key.clone(),
+ Some(metadata1.clone()),
+ )
+ .await;
+ }
+
+ #[tokio::test]
+ #[should_panic(expected = "EmptyBytes")]
+ async fn when_empty_bytes() {
+ let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
+ let (asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let metadata1 =
+ Metadata::Bytes(Bytes::from_hex_str("").expect("failed to convert to bytes"));
+ let key = String::from("key1");
+
+ set_metadata(
+ &instance_1,
+ asset_id_1,
+ key.clone(),
+ Some(metadata1.clone()),
+ )
+ .await;
+ }
+}
diff --git a/tests/src/native_asset/tests/functions/set_name.rs b/tests/src/native_asset/tests/functions/set_name.rs
index b7e45ba2..ab5552af 100644
--- a/tests/src/native_asset/tests/functions/set_name.rs
+++ b/tests/src/native_asset/tests/functions/set_name.rs
@@ -1,8 +1,8 @@
use crate::native_asset::tests::utils::{
interface::{name, set_name},
- setup::{defaults, get_asset_id, setup},
+ setup::{defaults, get_asset_id, setup, SetNameEvent},
};
-use fuels::types::Bytes32;
+use fuels::types::{Bytes32, Identity};
mod success {
@@ -12,14 +12,83 @@ mod success {
async fn sets_one_asset() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
let (asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
- defaults(id, owner_wallet, other_wallet.clone());
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let name_1 = String::from("Fuel Asset 1");
assert_eq!(name(&instance_1, asset_id_1).await, None);
- set_name(&instance_1, asset_id_1, String::from("Fuel Asset 1")).await;
+ let response = set_name(&instance_1, asset_id_1, Some(name_1.clone())).await;
+ assert_eq!(name(&instance_1, asset_id_1).await, Some(name_1.clone()));
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
assert_eq!(
- name(&instance_1, asset_id_1).await,
- Some(String::from("Fuel Asset 1"))
+ *event,
+ SetNameEvent {
+ asset: asset_id_1,
+ name: Some(name_1),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
+ }
+
+ // TODO: Renable when set_name() accepts an Option
+ #[tokio::test]
+ #[ignore]
+ async fn sets_none() {
+ let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
+ let (asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let name_1 = String::from("Fuel Asset 1");
+
+ set_name(&instance_1, asset_id_1, Some(name_1.clone())).await;
+ assert_eq!(name(&instance_1, asset_id_1).await, Some(name_1.clone()));
+
+ let response = set_name(&instance_1, asset_id_1, None).await;
+ assert_eq!(name(&instance_1, asset_id_1).await, None);
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetNameEvent {
+ asset: asset_id_1,
+ name: None,
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
+ }
+
+ #[tokio::test]
+ async fn sets_name_twice() {
+ let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
+ let (asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let name_1 = String::from("Fuel Asset 1");
+ let name_2 = String::from("Fuel Asset 2");
+
+ let response = set_name(&instance_1, asset_id_1, Some(name_1.clone())).await;
+ assert_eq!(name(&instance_1, asset_id_1).await, Some(name_1.clone()));
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetNameEvent {
+ asset: asset_id_1,
+ name: Some(name_1),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
+
+ let response = set_name(&instance_1, asset_id_1, Some(name_2.clone())).await;
+ assert_eq!(name(&instance_1, asset_id_1).await, Some(name_2.clone()));
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetNameEvent {
+ asset: asset_id_1,
+ name: Some(name_2),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
);
}
@@ -27,70 +96,139 @@ mod success {
async fn sets_multiple_assets() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
let (asset_id_1, asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
- defaults(id, owner_wallet, other_wallet.clone());
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let name_1 = String::from("Fuel Asset 1");
+ let name_2 = String::from("Fuel Asset 2");
+ let name_3 = String::from("Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3 Fuel Asset 3");
+ let name_4 = String::from("4");
+ let name_5 = String::from("Fuel Asset 1");
+ let asset_id_3 = get_asset_id(Bytes32::from([3u8; 32]), id);
+ let asset_id_4 = get_asset_id(Bytes32::from([4u8; 32]), id);
+ let asset_id_5 = get_asset_id(Bytes32::from([5u8; 32]), id);
assert_eq!(name(&instance_1, asset_id_1).await, None);
- set_name(&instance_1, asset_id_1, String::from("Fuel Asset 1")).await;
+ let response = set_name(&instance_1, asset_id_1, Some(name_1.clone())).await;
+ assert_eq!(name(&instance_1, asset_id_1).await, Some(name_1.clone()));
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
assert_eq!(
- name(&instance_1, asset_id_1).await,
- Some(String::from("Fuel Asset 1"))
+ *event,
+ SetNameEvent {
+ asset: asset_id_1,
+ name: Some(name_1),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
);
assert_eq!(name(&instance_1, asset_id_2).await, None);
- set_name(&instance_1, asset_id_2, String::from("Fuel Asset 2")).await;
+ let response = set_name(&instance_1, asset_id_2, Some(name_2.clone())).await;
+ assert_eq!(name(&instance_1, asset_id_2).await, Some(name_2.clone()));
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
assert_eq!(
- name(&instance_1, asset_id_2).await,
- Some(String::from("Fuel Asset 2"))
+ *event,
+ SetNameEvent {
+ asset: asset_id_2,
+ name: Some(name_2),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
);
- let asset_id_3 = get_asset_id(Bytes32::from([3u8; 32]), id);
assert_eq!(name(&instance_1, asset_id_3).await, None);
- set_name(&instance_1, asset_id_3, String::from("Fuel Asset 3")).await;
+ let response = set_name(&instance_1, asset_id_3, Some(name_3.clone())).await;
+ assert_eq!(name(&instance_1, asset_id_3).await, Some(name_3.clone()));
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
assert_eq!(
- name(&instance_1, asset_id_3).await,
- Some(String::from("Fuel Asset 3"))
+ *event,
+ SetNameEvent {
+ asset: asset_id_3,
+ name: Some(name_3),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
);
- let asset_id_4 = get_asset_id(Bytes32::from([4u8; 32]), id);
assert_eq!(name(&instance_1, asset_id_4).await, None);
- set_name(&instance_1, asset_id_4, String::from("Fuel Asset 4")).await;
+ let response = set_name(&instance_1, asset_id_4, Some(name_4.clone())).await;
+ assert_eq!(name(&instance_1, asset_id_4).await, Some(name_4.clone()));
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
assert_eq!(
- name(&instance_1, asset_id_4).await,
- Some(String::from("Fuel Asset 4"))
+ *event,
+ SetNameEvent {
+ asset: asset_id_4,
+ name: Some(name_4),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
);
- let asset_id_5 = get_asset_id(Bytes32::from([5u8; 32]), id);
assert_eq!(name(&instance_1, asset_id_5).await, None);
- set_name(&instance_1, asset_id_5, String::from("Fuel Asset 5")).await;
+ let response = set_name(&instance_1, asset_id_5, Some(name_5.clone())).await;
+ assert_eq!(name(&instance_1, asset_id_5).await, Some(name_5.clone()));
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
assert_eq!(
- name(&instance_1, asset_id_5).await,
- Some(String::from("Fuel Asset 5"))
+ *event,
+ SetNameEvent {
+ asset: asset_id_5,
+ name: Some(name_5),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
);
}
#[tokio::test]
- async fn does_not_overwrite_other_names() {
+ async fn does_not_overwrite_other_assets() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
let (asset_id_1, asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
- defaults(id, owner_wallet, other_wallet.clone());
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let name_1 = String::from("Fuel Asset 1");
+ let name_2 = String::from("Fuel Asset 2");
assert_eq!(name(&instance_1, asset_id_1).await, None);
- set_name(&instance_1, asset_id_1, String::from("Fuel Asset 1")).await;
+ let response = set_name(&instance_1, asset_id_1, Some(name_1.clone())).await;
+ assert_eq!(name(&instance_1, asset_id_1).await, Some(name_1.clone()));
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
assert_eq!(
- name(&instance_1, asset_id_1).await,
- Some(String::from("Fuel Asset 1"))
+ *event,
+ SetNameEvent {
+ asset: asset_id_1,
+ name: Some(name_1.clone()),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
);
assert_eq!(name(&instance_1, asset_id_2).await, None);
- set_name(&instance_1, asset_id_2, String::from("Fuel Asset 2")).await;
-
+ let response = set_name(&instance_1, asset_id_2, Some(name_2.clone())).await;
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
assert_eq!(
- name(&instance_1, asset_id_1).await,
- Some(String::from("Fuel Asset 1"))
- );
- assert_eq!(
- name(&instance_1, asset_id_2).await,
- Some(String::from("Fuel Asset 2"))
+ *event,
+ SetNameEvent {
+ asset: asset_id_2,
+ name: Some(name_2.clone()),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
);
+
+ assert_eq!(name(&instance_1, asset_id_1).await, Some(name_1));
+ assert_eq!(name(&instance_1, asset_id_2).await, Some(name_2));
+ }
+}
+
+mod revert {
+
+ use super::*;
+
+ #[tokio::test]
+ #[should_panic(expected = "EmptyString")]
+ async fn when_empty_string() {
+ let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
+ let (asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
+ defaults(id, owner_wallet, other_wallet);
+ let name_1 = String::from("");
+
+ set_name(&instance_1, asset_id_1, Some(name_1)).await;
}
}
diff --git a/tests/src/native_asset/tests/functions/set_symbol.rs b/tests/src/native_asset/tests/functions/set_symbol.rs
index b46c6bce..d65b2026 100644
--- a/tests/src/native_asset/tests/functions/set_symbol.rs
+++ b/tests/src/native_asset/tests/functions/set_symbol.rs
@@ -1,8 +1,8 @@
use crate::native_asset::tests::utils::{
interface::{set_symbol, symbol},
- setup::{defaults, get_asset_id, setup},
+ setup::{defaults, get_asset_id, setup, SetSymbolEvent},
};
-use fuels::types::Bytes32;
+use fuels::types::{Bytes32, Identity};
mod success {
@@ -12,14 +12,95 @@ mod success {
async fn sets_one_asset() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
let (asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
- defaults(id, owner_wallet, other_wallet.clone());
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let symbol_1 = String::from("FA1");
assert_eq!(symbol(&instance_1, asset_id_1).await, None);
- set_symbol(&instance_1, asset_id_1, String::from("FA1")).await;
+ let response = set_symbol(&instance_1, asset_id_1, Some(symbol_1.clone())).await;
assert_eq!(
symbol(&instance_1, asset_id_1).await,
- Some(String::from("FA1"))
+ Some(symbol_1.clone())
+ );
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetSymbolEvent {
+ asset: asset_id_1,
+ symbol: Some(symbol_1),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
+ }
+
+ // TODO: Renable when set_symbol() accepts an Option
+ #[tokio::test]
+ #[ignore]
+ async fn sets_none() {
+ let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
+ let (asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let symbol_1 = String::from("FA1");
+
+ set_symbol(&instance_1, asset_id_1, Some(symbol_1.clone())).await;
+ assert_eq!(
+ symbol(&instance_1, asset_id_1).await,
+ Some(symbol_1.clone())
+ );
+
+ let response = set_symbol(&instance_1, asset_id_1, None).await;
+ assert_eq!(symbol(&instance_1, asset_id_1).await, None);
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetSymbolEvent {
+ asset: asset_id_1,
+ symbol: None,
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
+ }
+
+ #[tokio::test]
+ async fn sets_symbol_twice() {
+ let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
+ let (asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let symbol_1 = String::from("FA1");
+ let symbol_2 = String::from("FA2");
+
+ let response = set_symbol(&instance_1, asset_id_1, Some(symbol_1.clone())).await;
+ assert_eq!(
+ symbol(&instance_1, asset_id_1).await,
+ Some(symbol_1.clone())
+ );
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetSymbolEvent {
+ asset: asset_id_1,
+ symbol: Some(symbol_1),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
+ );
+
+ let response = set_symbol(&instance_1, asset_id_1, Some(symbol_2.clone())).await;
+ assert_eq!(
+ symbol(&instance_1, asset_id_1).await,
+ Some(symbol_2.clone())
+ );
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetSymbolEvent {
+ asset: asset_id_1,
+ symbol: Some(symbol_2),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
);
}
@@ -27,70 +108,157 @@ mod success {
async fn sets_multiple_assets() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
let (asset_id_1, asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
- defaults(id, owner_wallet, other_wallet.clone());
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let symbol_1 = String::from("FA1");
+ let symbol_2 = String::from("FA2");
+ let symbol_3 = String::from("FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1");
+ let symbol_4 = String::from("F");
+ let symbol_5 = String::from("FA1");
+ let asset_id_3 = get_asset_id(Bytes32::from([3u8; 32]), id);
+ let asset_id_4 = get_asset_id(Bytes32::from([4u8; 32]), id);
+ let asset_id_5 = get_asset_id(Bytes32::from([5u8; 32]), id);
assert_eq!(symbol(&instance_1, asset_id_1).await, None);
- set_symbol(&instance_1, asset_id_1, String::from("FA1")).await;
+ let response = set_symbol(&instance_1, asset_id_1, Some(symbol_1.clone())).await;
assert_eq!(
symbol(&instance_1, asset_id_1).await,
- Some(String::from("FA1"))
+ Some(symbol_1.clone())
+ );
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetSymbolEvent {
+ asset: asset_id_1,
+ symbol: Some(symbol_1),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
);
assert_eq!(symbol(&instance_1, asset_id_2).await, None);
- set_symbol(&instance_1, asset_id_2, String::from("FA2")).await;
+ let response = set_symbol(&instance_1, asset_id_2, Some(symbol_2.clone())).await;
assert_eq!(
symbol(&instance_1, asset_id_2).await,
- Some(String::from("FA2"))
+ Some(symbol_2.clone())
+ );
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetSymbolEvent {
+ asset: asset_id_2,
+ symbol: Some(symbol_2),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
);
- let asset_id_3 = get_asset_id(Bytes32::from([3u8; 32]), id);
assert_eq!(symbol(&instance_1, asset_id_3).await, None);
- set_symbol(&instance_1, asset_id_3, String::from("FA3")).await;
+ let response = set_symbol(&instance_1, asset_id_3, Some(symbol_3.clone())).await;
assert_eq!(
symbol(&instance_1, asset_id_3).await,
- Some(String::from("FA3"))
+ Some(symbol_3.clone())
+ );
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetSymbolEvent {
+ asset: asset_id_3,
+ symbol: Some(symbol_3),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
);
- let asset_id_4 = get_asset_id(Bytes32::from([4u8; 32]), id);
assert_eq!(symbol(&instance_1, asset_id_4).await, None);
- set_symbol(&instance_1, asset_id_4, String::from("FA4")).await;
+ let response = set_symbol(&instance_1, asset_id_4, Some(symbol_4.clone())).await;
assert_eq!(
symbol(&instance_1, asset_id_4).await,
- Some(String::from("FA4"))
+ Some(symbol_4.clone())
+ );
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetSymbolEvent {
+ asset: asset_id_4,
+ symbol: Some(symbol_4),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
);
- let asset_id_5 = get_asset_id(Bytes32::from([5u8; 32]), id);
assert_eq!(symbol(&instance_1, asset_id_5).await, None);
- set_symbol(&instance_1, asset_id_5, String::from("FA5")).await;
+ let response = set_symbol(&instance_1, asset_id_5, Some(symbol_5.clone())).await;
assert_eq!(
symbol(&instance_1, asset_id_5).await,
- Some(String::from("FA5"))
+ Some(symbol_5.clone())
+ );
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
+ assert_eq!(
+ *event,
+ SetSymbolEvent {
+ asset: asset_id_5,
+ symbol: Some(symbol_5),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
);
}
#[tokio::test]
- async fn does_not_overwrite_other_symbols() {
+ async fn does_not_overwrite_other_assets() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
let (asset_id_1, asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
- defaults(id, owner_wallet, other_wallet.clone());
+ defaults(id, owner_wallet.clone(), other_wallet.clone());
+ let symbol_1 = String::from("FA1");
+ let symbol_2 = String::from("FA2");
assert_eq!(symbol(&instance_1, asset_id_1).await, None);
- set_symbol(&instance_1, asset_id_1, String::from("FA1")).await;
+ let response = set_symbol(&instance_1, asset_id_1, Some(symbol_1.clone())).await;
assert_eq!(
symbol(&instance_1, asset_id_1).await,
- Some(String::from("FA1"))
+ Some(symbol_1.clone())
);
-
- assert_eq!(symbol(&instance_1, asset_id_2).await, None);
- set_symbol(&instance_1, asset_id_2, String::from("FA2")).await;
-
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
assert_eq!(
- symbol(&instance_1, asset_id_1).await,
- Some(String::from("FA1"))
+ *event,
+ SetSymbolEvent {
+ asset: asset_id_1,
+ symbol: Some(symbol_1.clone()),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
);
+
+ assert_eq!(symbol(&instance_1, asset_id_2).await, None);
+ let response = set_symbol(&instance_1, asset_id_2, Some(symbol_2.clone())).await;
+ let log = response.decode_logs_with_type::().unwrap();
+ let event = log.first().unwrap();
assert_eq!(
- symbol(&instance_1, asset_id_2).await,
- Some(String::from("FA2"))
+ *event,
+ SetSymbolEvent {
+ asset: asset_id_2,
+ symbol: Some(symbol_2.clone()),
+ sender: Identity::Address(owner_wallet.address().into()),
+ }
);
+
+ assert_eq!(symbol(&instance_1, asset_id_1).await, Some(symbol_1));
+ assert_eq!(symbol(&instance_1, asset_id_2).await, Some(symbol_2));
+ }
+}
+
+mod revert {
+
+ use super::*;
+
+ #[tokio::test]
+ #[should_panic(expected = "EmptyString")]
+ async fn when_empty_string() {
+ let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
+ let (asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
+ defaults(id, owner_wallet, other_wallet);
+ let symbol_1 = String::from("");
+
+ set_symbol(&instance_1, asset_id_1, Some(symbol_1)).await;
}
}
diff --git a/tests/src/native_asset/tests/functions/symbol.rs b/tests/src/native_asset/tests/functions/symbol.rs
index b7a9eae8..1b27e473 100644
--- a/tests/src/native_asset/tests/functions/symbol.rs
+++ b/tests/src/native_asset/tests/functions/symbol.rs
@@ -9,88 +9,57 @@ mod success {
use super::*;
#[tokio::test]
- async fn one_asset() {
+ async fn get_none_symbol() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
let (asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
defaults(id, owner_wallet, other_wallet.clone());
assert_eq!(symbol(&instance_1, asset_id_1).await, None);
-
- set_symbol(&instance_1, asset_id_1, String::from("FA1")).await;
- assert_eq!(
- symbol(&instance_1, asset_id_1).await,
- Some(String::from("FA1"))
- );
}
#[tokio::test]
- async fn multiple_assets() {
+ async fn get_one_asset_symbol() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
- let (asset_id_1, asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
+ let (asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
defaults(id, owner_wallet, other_wallet.clone());
+ let symbol_1 = String::from("FA1");
assert_eq!(symbol(&instance_1, asset_id_1).await, None);
- set_symbol(&instance_1, asset_id_1, String::from("FA1")).await;
- assert_eq!(
- symbol(&instance_1, asset_id_1).await,
- Some(String::from("FA1"))
- );
-
- assert_eq!(symbol(&instance_1, asset_id_2).await, None);
- set_symbol(&instance_1, asset_id_2, String::from("FA2")).await;
- assert_eq!(
- symbol(&instance_1, asset_id_2).await,
- Some(String::from("FA2"))
- );
-
- let asset_id_3 = get_asset_id(Bytes32::from([3u8; 32]), id);
- assert_eq!(symbol(&instance_1, asset_id_3).await, None);
- set_symbol(&instance_1, asset_id_3, String::from("FA3")).await;
- assert_eq!(
- symbol(&instance_1, asset_id_3).await,
- Some(String::from("FA3"))
- );
-
- let asset_id_4 = get_asset_id(Bytes32::from([4u8; 32]), id);
- assert_eq!(symbol(&instance_1, asset_id_4).await, None);
- set_symbol(&instance_1, asset_id_4, String::from("FA4")).await;
- assert_eq!(
- symbol(&instance_1, asset_id_4).await,
- Some(String::from("FA4"))
- );
- let asset_id_5 = get_asset_id(Bytes32::from([5u8; 32]), id);
- assert_eq!(symbol(&instance_1, asset_id_5).await, None);
- set_symbol(&instance_1, asset_id_5, String::from("FA5")).await;
- assert_eq!(
- symbol(&instance_1, asset_id_5).await,
- Some(String::from("FA5"))
- );
+ set_symbol(&instance_1, asset_id_1, Some(symbol_1.clone())).await;
+ assert_eq!(symbol(&instance_1, asset_id_1).await, Some(symbol_1));
}
#[tokio::test]
- async fn does_not_overwrite_other_symbols() {
+ async fn get_multiple_assets_symbols() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
let (asset_id_1, asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
defaults(id, owner_wallet, other_wallet.clone());
+ let symbol_1 = String::from("FA1");
+ let symbol_2 = String::from("FA2");
+ let symbol_3 = String::from("FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1FA1");
+ let symbol_4 = String::from("F");
+ let symbol_5 = String::from("FA1");
+ let asset_id_3 = get_asset_id(Bytes32::from([3u8; 32]), id);
+ let asset_id_4 = get_asset_id(Bytes32::from([4u8; 32]), id);
+ let asset_id_5 = get_asset_id(Bytes32::from([5u8; 32]), id);
assert_eq!(symbol(&instance_1, asset_id_1).await, None);
- set_symbol(&instance_1, asset_id_1, String::from("FA1")).await;
- assert_eq!(
- symbol(&instance_1, asset_id_1).await,
- Some(String::from("FA1"))
- );
-
assert_eq!(symbol(&instance_1, asset_id_2).await, None);
- set_symbol(&instance_1, asset_id_2, String::from("FA2")).await;
+ assert_eq!(symbol(&instance_1, asset_id_3).await, None);
+ assert_eq!(symbol(&instance_1, asset_id_4).await, None);
+ assert_eq!(symbol(&instance_1, asset_id_5).await, None);
+
+ set_symbol(&instance_1, asset_id_1, Some(symbol_1.clone())).await;
+ set_symbol(&instance_1, asset_id_2, Some(symbol_2.clone())).await;
+ set_symbol(&instance_1, asset_id_3, Some(symbol_3.clone())).await;
+ set_symbol(&instance_1, asset_id_4, Some(symbol_4.clone())).await;
+ set_symbol(&instance_1, asset_id_5, Some(symbol_5.clone())).await;
- assert_eq!(
- symbol(&instance_1, asset_id_1).await,
- Some(String::from("FA1"))
- );
- assert_eq!(
- symbol(&instance_1, asset_id_2).await,
- Some(String::from("FA2"))
- );
+ assert_eq!(symbol(&instance_1, asset_id_1).await, Some(symbol_1));
+ assert_eq!(symbol(&instance_1, asset_id_2).await, Some(symbol_2));
+ assert_eq!(symbol(&instance_1, asset_id_3).await, Some(symbol_3));
+ assert_eq!(symbol(&instance_1, asset_id_4).await, Some(symbol_4));
+ assert_eq!(symbol(&instance_1, asset_id_5).await, Some(symbol_5));
}
}
diff --git a/tests/src/native_asset/tests/functions/total_assets.rs b/tests/src/native_asset/tests/functions/total_assets.rs
index a857da77..d3063348 100644
--- a/tests/src/native_asset/tests/functions/total_assets.rs
+++ b/tests/src/native_asset/tests/functions/total_assets.rs
@@ -16,7 +16,7 @@ mod success {
assert_eq!(total_assets(&instance_1).await, 0);
- mint(&instance_1, identity2, sub_id_1, 100).await;
+ mint(&instance_1, identity2, Some(sub_id_1), 100).await;
assert_eq!(total_assets(&instance_1).await, 1);
}
@@ -28,19 +28,31 @@ mod success {
assert_eq!(total_assets(&instance_1).await, 0);
- mint(&instance_1, identity2.clone(), sub_id_1, 100).await;
+ mint(&instance_1, identity2.clone(), Some(sub_id_1), 100).await;
assert_eq!(total_assets(&instance_1).await, 1);
- mint(&instance_1, identity2.clone(), sub_id_2, 200).await;
+ mint(&instance_1, identity2.clone(), Some(sub_id_2), 200).await;
assert_eq!(total_assets(&instance_1).await, 2);
- mint(&instance_1, identity2.clone(), Bits256([3u8; 32]), 300).await;
+ mint(
+ &instance_1,
+ identity2.clone(),
+ Some(Bits256([3u8; 32])),
+ 300,
+ )
+ .await;
assert_eq!(total_assets(&instance_1).await, 3);
- mint(&instance_1, identity2.clone(), Bits256([4u8; 32]), 400).await;
+ mint(
+ &instance_1,
+ identity2.clone(),
+ Some(Bits256([4u8; 32])),
+ 400,
+ )
+ .await;
assert_eq!(total_assets(&instance_1).await, 4);
- mint(&instance_1, identity2, Bits256([5u8; 32]), 200).await;
+ mint(&instance_1, identity2, Some(Bits256([5u8; 32])), 200).await;
assert_eq!(total_assets(&instance_1).await, 5);
}
@@ -52,13 +64,13 @@ mod success {
assert_eq!(total_assets(&instance_1).await, 0);
- mint(&instance_1, identity2.clone(), sub_id_1, 100).await;
+ mint(&instance_1, identity2.clone(), Some(sub_id_1), 100).await;
assert_eq!(total_assets(&instance_1).await, 1);
- mint(&instance_1, identity2.clone(), sub_id_1, 100).await;
+ mint(&instance_1, identity2.clone(), Some(sub_id_1), 100).await;
assert_eq!(total_assets(&instance_1).await, 1);
- mint(&instance_1, identity2.clone(), sub_id_1, 100).await;
+ mint(&instance_1, identity2.clone(), Some(sub_id_1), 100).await;
assert_eq!(total_assets(&instance_1).await, 1);
}
}
diff --git a/tests/src/native_asset/tests/functions/total_supply.rs b/tests/src/native_asset/tests/functions/total_supply.rs
index d08cc37e..70bc703c 100644
--- a/tests/src/native_asset/tests/functions/total_supply.rs
+++ b/tests/src/native_asset/tests/functions/total_supply.rs
@@ -15,7 +15,7 @@ mod success {
defaults(id, owner_wallet, other_wallet.clone());
assert_eq!(total_supply(&instance_1, asset_id_1).await, None);
- mint(&instance_1, identity2, sub_id_1, 100).await;
+ mint(&instance_1, identity2, Some(sub_id_1), 100).await;
assert_eq!(total_supply(&instance_1, asset_id_1).await, Some(100));
}
@@ -26,26 +26,38 @@ mod success {
defaults(id, owner_wallet, other_wallet.clone());
assert_eq!(total_supply(&instance_1, asset_id_1).await, None);
- mint(&instance_1, identity2.clone(), sub_id_1, 100).await;
+ mint(&instance_1, identity2.clone(), Some(sub_id_1), 100).await;
assert_eq!(total_supply(&instance_1, asset_id_1).await, Some(100));
assert_eq!(total_supply(&instance_1, asset_id_2).await, None);
- mint(&instance_1, identity2.clone(), sub_id_2, 200).await;
+ mint(&instance_1, identity2.clone(), Some(sub_id_2), 200).await;
assert_eq!(total_supply(&instance_1, asset_id_2).await, Some(200));
let asset_id_3 = get_asset_id(Bytes32::from([3u8; 32]), id);
assert_eq!(total_supply(&instance_1, asset_id_3).await, None);
- mint(&instance_1, identity2.clone(), Bits256([3u8; 32]), 300).await;
+ mint(
+ &instance_1,
+ identity2.clone(),
+ Some(Bits256([3u8; 32])),
+ 300,
+ )
+ .await;
assert_eq!(total_supply(&instance_1, asset_id_3).await, Some(300));
let asset_id_4 = get_asset_id(Bytes32::from([4u8; 32]), id);
assert_eq!(total_supply(&instance_1, asset_id_4).await, None);
- mint(&instance_1, identity2.clone(), Bits256([4u8; 32]), 400).await;
+ mint(
+ &instance_1,
+ identity2.clone(),
+ Some(Bits256([4u8; 32])),
+ 400,
+ )
+ .await;
assert_eq!(total_supply(&instance_1, asset_id_4).await, Some(400));
let asset_id_5 = get_asset_id(Bytes32::from([5u8; 32]), id);
assert_eq!(total_supply(&instance_1, asset_id_5).await, None);
- mint(&instance_1, identity2, Bits256([5u8; 32]), 500).await;
+ mint(&instance_1, identity2, Some(Bits256([5u8; 32])), 500).await;
assert_eq!(total_supply(&instance_1, asset_id_5).await, Some(500));
}
@@ -56,13 +68,13 @@ mod success {
defaults(id, owner_wallet, other_wallet.clone());
assert_eq!(total_supply(&instance_1, asset_id_1).await, None);
- mint(&instance_1, identity2.clone(), sub_id_1, 100).await;
+ mint(&instance_1, identity2.clone(), Some(sub_id_1), 100).await;
assert_eq!(total_supply(&instance_1, asset_id_1).await, Some(100));
- mint(&instance_1, identity2.clone(), sub_id_2, 200).await;
+ mint(&instance_1, identity2.clone(), Some(sub_id_2), 200).await;
assert_eq!(total_supply(&instance_1, asset_id_1).await, Some(100));
- mint(&instance_1, identity2.clone(), sub_id_2, 300).await;
+ mint(&instance_1, identity2.clone(), Some(sub_id_2), 300).await;
assert_eq!(total_supply(&instance_1, asset_id_1).await, Some(100));
}
@@ -73,7 +85,7 @@ mod success {
defaults(id, owner_wallet, other_wallet.clone());
assert_eq!(total_supply(&instance_1, asset_id_1).await, None);
- mint(&instance_1, identity2.clone(), sub_id_1, 100).await;
+ mint(&instance_1, identity2.clone(), Some(sub_id_1), 100).await;
assert_eq!(total_supply(&instance_1, asset_id_1).await, Some(100));
burn(&instance_2, asset_id_1, sub_id_1, 50).await;
diff --git a/tests/src/native_asset/tests/utils/interface.rs b/tests/src/native_asset/tests/utils/interface.rs
index d8dba435..caad919a 100644
--- a/tests/src/native_asset/tests/utils/interface.rs
+++ b/tests/src/native_asset/tests/utils/interface.rs
@@ -1,8 +1,8 @@
use crate::native_asset::tests::utils::setup::{AssetLib, Metadata};
use fuels::{
prelude::{AssetId, CallParameters, TxPolicies, WalletUnlocked},
- programs::{call_response::FuelCallResponse, call_utils::TxDependencyExtension},
- types::{Bits256, Identity},
+ programs::responses::CallResponse,
+ types::{transaction_builders::VariableOutputPolicy, Bits256, Identity},
};
pub(crate) async fn total_assets(contract: &AssetLib) -> u64 {
@@ -49,13 +49,13 @@ pub(crate) async fn decimals(contract: &AssetLib, asset: AssetId
pub(crate) async fn mint(
contract: &AssetLib,
recipient: Identity,
- sub_id: Bits256,
+ sub_id: Option,
amount: u64,
-) -> FuelCallResponse<()> {
+) -> CallResponse<()> {
contract
.methods()
.mint(recipient, sub_id, amount)
- .append_variable_outputs(1)
+ .with_variable_output_policy(VariableOutputPolicy::Exactly(1))
.call()
.await
.unwrap()
@@ -66,7 +66,7 @@ pub(crate) async fn burn(
asset_id: AssetId,
sub_id: Bits256,
amount: u64,
-) -> FuelCallResponse<()> {
+) -> CallResponse<()> {
let call_params = CallParameters::new(amount, asset_id, 1_000_000);
contract
@@ -83,11 +83,11 @@ pub(crate) async fn burn(
pub(crate) async fn set_name(
contract: &AssetLib,
asset: AssetId,
- name: String,
-) -> FuelCallResponse<()> {
+ name: Option,
+) -> CallResponse<()> {
contract
.methods()
- .set_name(asset, name)
+ .set_name(asset, name.unwrap())
.call()
.await
.unwrap()
@@ -96,11 +96,11 @@ pub(crate) async fn set_name(
pub(crate) async fn set_symbol(
contract: &AssetLib,
asset: AssetId,
- name: String,
-) -> FuelCallResponse<()> {
+ symbol: Option,
+) -> CallResponse<()> {
contract
.methods()
- .set_symbol(asset, name)
+ .set_symbol(asset, symbol.unwrap())
.call()
.await
.unwrap()
@@ -110,7 +110,7 @@ pub(crate) async fn set_decimals(
contract: &AssetLib,
asset: AssetId,
decimals: u8,
-) -> FuelCallResponse<()> {
+) -> CallResponse<()> {
contract
.methods()
.set_decimals(asset, decimals)
@@ -137,11 +137,11 @@ pub(crate) async fn set_metadata(
contract: &AssetLib,
asset: AssetId,
key: String,
- metadata: Metadata,
-) -> FuelCallResponse<()> {
+ metadata: Option,
+) -> CallResponse<()> {
contract
.methods()
- .set_metadata(asset, key, metadata)
+ .set_metadata(asset, key, metadata.unwrap())
.call()
.await
.unwrap()
diff --git a/tests/src/ownership/Forc.toml b/tests/src/ownership/Forc.toml
index b24ee3f3..98c47417 100644
--- a/tests/src/ownership/Forc.toml
+++ b/tests/src/ownership/Forc.toml
@@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "ownership_test"
[dependencies]
-standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.5.2" }
+standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.0" }
sway_libs = { path = "../../../libs" }
diff --git a/tests/src/ownership/tests/functions/owner.rs b/tests/src/ownership/tests/functions/owner.rs
index 19062760..b5c84830 100644
--- a/tests/src/ownership/tests/functions/owner.rs
+++ b/tests/src/ownership/tests/functions/owner.rs
@@ -1,7 +1,7 @@
use crate::ownership::tests::utils::{
abi_calls::{owner, renounce_ownership, set_ownership},
- abigen_bindings::ownership_lib_mod::State,
test_helpers::setup,
+ State,
};
use fuels::types::Identity;
diff --git a/tests/src/ownership/tests/functions/renounce_ownership.rs b/tests/src/ownership/tests/functions/renounce_ownership.rs
index adf35a77..2d266f7d 100644
--- a/tests/src/ownership/tests/functions/renounce_ownership.rs
+++ b/tests/src/ownership/tests/functions/renounce_ownership.rs
@@ -1,7 +1,7 @@
use crate::ownership::tests::utils::{
abi_calls::{owner, renounce_ownership, set_ownership},
- abigen_bindings::ownership_lib_mod::State,
test_helpers::setup,
+ State,
};
use fuels::types::Identity;
diff --git a/tests/src/ownership/tests/functions/set_ownership.rs b/tests/src/ownership/tests/functions/set_ownership.rs
index dd1dbb86..c8316e77 100644
--- a/tests/src/ownership/tests/functions/set_ownership.rs
+++ b/tests/src/ownership/tests/functions/set_ownership.rs
@@ -1,7 +1,7 @@
use crate::ownership::tests::utils::{
abi_calls::{owner, renounce_ownership, set_ownership},
- abigen_bindings::ownership_lib_mod::State,
test_helpers::setup,
+ State,
};
use fuels::types::Identity;
diff --git a/tests/src/ownership/tests/functions/transfer_ownership.rs b/tests/src/ownership/tests/functions/transfer_ownership.rs
index 053f9a2f..cb5479eb 100644
--- a/tests/src/ownership/tests/functions/transfer_ownership.rs
+++ b/tests/src/ownership/tests/functions/transfer_ownership.rs
@@ -1,7 +1,7 @@
use crate::ownership::tests::utils::{
abi_calls::{owner, set_ownership, transfer_ownership},
- abigen_bindings::ownership_lib_mod::State,
test_helpers::setup,
+ State,
};
use fuels::types::Identity;
diff --git a/tests/src/ownership/tests/utils/mod.rs b/tests/src/ownership/tests/utils/mod.rs
index 924097fd..48063914 100644
--- a/tests/src/ownership/tests/utils/mod.rs
+++ b/tests/src/ownership/tests/utils/mod.rs
@@ -3,7 +3,7 @@ use fuels::{
abigen, launch_custom_provider_and_get_wallets, Contract, LoadConfiguration,
StorageConfiguration, TxPolicies, WalletUnlocked, WalletsConfig,
},
- programs::call_response::FuelCallResponse,
+ programs::responses::CallResponse,
types::Identity,
};
@@ -22,7 +22,7 @@ pub mod abi_calls {
use super::*;
- pub async fn only_owner(contract: &OwnershipLib) -> FuelCallResponse<()> {
+ pub async fn only_owner(contract: &OwnershipLib) -> CallResponse<()> {
contract.methods().only_owner().call().await.unwrap()
}
@@ -30,9 +30,7 @@ pub mod abi_calls {
contract.methods().owner().call().await.unwrap().value
}
- pub async fn renounce_ownership(
- contract: &OwnershipLib,
- ) -> FuelCallResponse<()> {
+ pub async fn renounce_ownership(contract: &OwnershipLib) -> CallResponse<()> {
contract
.methods()
.renounce_ownership()
@@ -44,7 +42,7 @@ pub mod abi_calls {
pub async fn set_ownership(
contract: &OwnershipLib,
new_owner: Identity,
- ) -> FuelCallResponse<()> {
+ ) -> CallResponse<()> {
contract
.methods()
.set_ownership(new_owner)
@@ -56,7 +54,7 @@ pub mod abi_calls {
pub async fn transfer_ownership(
contract: &OwnershipLib,
new_owner: Identity,
- ) -> FuelCallResponse<()> {
+ ) -> CallResponse<()> {
contract
.methods()
.transfer_ownership(new_owner)
diff --git a/tests/src/upgradability/Forc.toml b/tests/src/upgradability/Forc.toml
index 02d03edb..d99cb1d1 100644
--- a/tests/src/upgradability/Forc.toml
+++ b/tests/src/upgradability/Forc.toml
@@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "upgradability_test"
[dependencies]
-standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.5.2" }
+standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.0" }
sway_libs = { path = "../../../libs" }
diff --git a/tests/src/upgradability/src/main.sw b/tests/src/upgradability/src/main.sw
index 275fb8ad..313b8b68 100644
--- a/tests/src/upgradability/src/main.sw
+++ b/tests/src/upgradability/src/main.sw
@@ -14,11 +14,21 @@ configurable {
INITIAL_OWNER: State = State::Uninitialized,
}
-#[namespace(SRC14)]
storage {
- // target is at sha256("storage_SRC14_0")
- target: Option = None,
- proxy_owner: State = State::Uninitialized,
+ SRC14 {
+ /// The [ContractId] of the target contract.
+ ///
+ /// # Additional Information
+ ///
+ /// `target` is stored at sha256("storage_SRC14_0")
+ target in 0x7bb458adc1d118713319a5baa00a2d049dd64d2916477d2688d76970c898cd55: Option = None,
+ /// The [State] of the proxy owner.
+ ///
+ /// # Additional Information
+ ///
+ /// `proxy_owner` is stored at sha256("storage_SRC14_1")
+ proxy_owner in 0xbb79927b15d9259ea316f2ecb2297d6cc8851888a98278c0a2e03e1a091ea754: State = State::Uninitialized,
+ },
}
abi UpgradableTest {
@@ -47,25 +57,25 @@ impl SRC14 for Contract {
impl SRC14Extension for Contract {
#[storage(read)]
fn proxy_owner() -> State {
- _proxy_owner(storage.proxy_owner)
+ _proxy_owner()
}
}
impl UpgradableTest for Contract {
#[storage(read)]
fn only_proxy_owner() {
- only_proxy_owner(storage.proxy_owner);
+ only_proxy_owner();
}
#[storage(write)]
fn set_proxy_owner(new_proxy_owner: State) {
- _set_proxy_owner(new_proxy_owner, storage.proxy_owner);
+ _set_proxy_owner(new_proxy_owner);
}
// Used to immediately set the storage variables as the configured constants
#[storage(write)]
fn initialize_proxy() {
- storage.target.write(INITIAL_TARGET);
- storage.proxy_owner.write(INITIAL_OWNER);
+ storage::SRC14.target.write(INITIAL_TARGET);
+ storage::SRC14.proxy_owner.write(INITIAL_OWNER);
}
}
diff --git a/tests/src/upgradability/tests/utils/mod.rs b/tests/src/upgradability/tests/utils/mod.rs
index 4b52c7fa..556364c1 100644
--- a/tests/src/upgradability/tests/utils/mod.rs
+++ b/tests/src/upgradability/tests/utils/mod.rs
@@ -3,7 +3,7 @@ use fuels::{
abigen, launch_custom_provider_and_get_wallets, Contract, ContractId, LoadConfiguration,
StorageConfiguration, TxPolicies, WalletUnlocked, WalletsConfig,
},
- programs::call_response::FuelCallResponse,
+ programs::responses::CallResponse,
};
// Load abi from json
@@ -24,7 +24,7 @@ pub mod abi_calls {
pub async fn set_proxy_target(
contract: &UpgradabilityLib,
new_target: ContractId,
- ) -> FuelCallResponse<()> {
+ ) -> CallResponse<()> {
contract
.methods()
.set_proxy_target(new_target)
@@ -35,26 +35,22 @@ pub mod abi_calls {
pub async fn proxy_target(
contract: &UpgradabilityLib,
- ) -> FuelCallResponse