From a58566009a364768640826fd78f0b84fe29b92cf Mon Sep 17 00:00:00 2001
From: Cameron Carstens <54727135+bitzoic@users.noreply.github.com>
Date: Mon, 13 Nov 2023 14:16:26 +0300
Subject: [PATCH] Bump Sway-Libs to Forc v0.47.0 and Sway-Standards v0.2.0
(#202)
## Type of change
- Improvement (refactoring, restructuring repository, cleaning tech
debt, ...)
## Changes
The following changes have been made:
- Updates the repo to forc v0.47.0
- Updates the repo to Sway-Standards v0.2.0
- Updates the repo to fuel-core v0.20.8
---
.github/workflows/ci.yml | 4 +-
README.md | 6 +--
libs/fixed_point/src/ifp128.sw | 12 ++---
libs/fixed_point/src/ifp256.sw | 12 ++---
libs/fixed_point/src/ifp64.sw | 12 ++---
libs/fixed_point/src/ufp128.sw | 8 ++--
libs/fixed_point/src/ufp32.sw | 7 ++-
libs/fixed_point/src/ufp64.sw | 7 ++-
libs/merkle_proof/src/binary_merkle_proof.sw | 5 +-
libs/ownership/Forc.toml | 2 +-
libs/ownership/src/ownable.sw | 18 ++++++--
libs/pausable/src/lib.sw | 11 +++--
libs/signed_integers/src/i128.sw | 36 +++++++++++----
libs/signed_integers/src/i16.sw | 36 +++++++++++----
libs/signed_integers/src/i256.sw | 36 +++++++++++----
libs/signed_integers/src/i32.sw | 36 +++++++++++----
libs/signed_integers/src/i64.sw | 36 +++++++++++----
libs/signed_integers/src/i8.sw | 36 +++++++++++----
libs/token/Forc.toml | 2 +-
.../fixed_point/ifp64_pow_test/src/main.sw | 12 ++---
tests/src/fixed_point/ufp128_test/src/main.sw | 8 ++--
.../fixed_point/ufp32_pow_test/src/main.sw | 12 ++---
.../fixed_point/ufp64_pow_test/src/main.sw | 12 ++---
tests/src/merkle_proof/src/main.sw | 15 +++++-
tests/src/ownership/Forc.toml | 2 +-
tests/src/ownership/src/main.sw | 16 +++----
.../reentrancy_attacker_contract/src/main.sw | 18 ++++++--
.../reentrancy_target_contract/src/main.sw | 20 ++++++--
.../signed_i128_twos_complement/src/main.sw | 30 ++++++++++--
.../signed_i16_twos_complement/src/main.sw | 30 ++++++++++--
.../signed_i256_twos_complement/src/main.sw | 40 +++++++++++++---
.../signed_i32_twos_complement/src/main.sw | 30 ++++++++++--
.../signed_integers/signed_i64/src/main.sw | 8 ++--
.../signed_i64_twos_complement/src/main.sw | 30 ++++++++++--
.../signed_i8_twos_complement/src/main.sw | 30 ++++++++++--
tests/src/token/Forc.toml | 6 +--
tests/src/token/src/main.sw | 46 +++++++++++++------
37 files changed, 494 insertions(+), 193 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index d7fb99c1..91660459 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -16,8 +16,8 @@ env:
CARGO_TERM_COLOR: always
REGISTRY: ghcr.io
RUST_VERSION: 1.71.1
- FORC_VERSION: 0.46.0
- CORE_VERSION: 0.20.3
+ FORC_VERSION: 0.47.0
+ CORE_VERSION: 0.20.8
PATH_TO_SCRIPTS: .github/scripts
jobs:
diff --git a/README.md b/README.md
index 30475f87..beb32add 100644
--- a/README.md
+++ b/README.md
@@ -9,8 +9,8 @@
-
-
+
+
@@ -82,7 +82,7 @@ cargo test
Any instructions related to using a specific library should be found within the README.md of that library.
> **Note**
-> All projects currently use `forc v0.46.0`, `fuels-rs v0.46.0` and `fuel-core 0.20.3`.
+> All projects currently use `forc v0.47.0`, `fuels-rs v0.46.0` and `fuel-core 0.20.8`.
## Contributing
diff --git a/libs/fixed_point/src/ifp128.sw b/libs/fixed_point/src/ifp128.sw
index 488d4b01..878146e6 100644
--- a/libs/fixed_point/src/ifp128.sw
+++ b/libs/fixed_point/src/ifp128.sw
@@ -492,20 +492,18 @@ impl Exponent for IFP128 {
impl Power for IFP128 {
/// Power function. x ^ exponent
- fn pow(self, exponent: Self) -> Self {
+ fn pow(self, exponent: u32) -> Self {
+ let ufp64_exponent = UFP64::from(exponent.as_u64());
let non_negative = if !self.non_negative {
// roots of negative numbers are complex numbers which we lack for now
- assert(exponent.underlying.floor() == exponent.underlying);
+ assert(ufp64_exponent.floor() == ufp64_exponent);
- let div_2 = exponent.underlying / UFP64::from(2);
+ let div_2 = ufp64_exponent / UFP64::from(2);
div_2.floor() == div_2
} else {
true
};
- let mut underlying = self.underlying.pow(exponent.underlying);
- if !exponent.non_negative {
- underlying = UFP64::recip(underlying);
- }
+ let mut underlying = self.underlying.pow(exponent);
Self {
underlying: underlying,
non_negative: non_negative,
diff --git a/libs/fixed_point/src/ifp256.sw b/libs/fixed_point/src/ifp256.sw
index 85bc7d7e..a0cde596 100644
--- a/libs/fixed_point/src/ifp256.sw
+++ b/libs/fixed_point/src/ifp256.sw
@@ -492,20 +492,18 @@ impl Exponent for IFP256 {
impl Power for IFP256 {
/// Power function. x ^ exponent
- fn pow(self, exponent: Self) -> Self {
+ fn pow(self, exponent: u32) -> Self {
+ let ufp128_exponent = UFP128::from((0, exponent.as_u64()));
let non_negative = if !self.non_negative {
// roots of negative numbers are complex numbers which we lack for now
- assert(exponent.underlying.floor() == exponent.underlying);
+ assert(ufp128_exponent.floor() == ufp128_exponent);
- let div_2 = exponent.underlying / UFP128::from((2, 0));
+ let div_2 = ufp128_exponent / UFP128::from((2, 0));
div_2.floor() == div_2
} else {
true
};
- let mut underlying = self.underlying.pow(exponent.underlying);
- if !exponent.non_negative {
- underlying = UFP128::recip(underlying);
- }
+ let mut underlying = self.underlying.pow(exponent);
Self {
underlying: underlying,
non_negative: non_negative,
diff --git a/libs/fixed_point/src/ifp64.sw b/libs/fixed_point/src/ifp64.sw
index e67e744f..34b6ca38 100644
--- a/libs/fixed_point/src/ifp64.sw
+++ b/libs/fixed_point/src/ifp64.sw
@@ -492,20 +492,18 @@ impl Exponent for IFP64 {
impl Power for IFP64 {
/// Power function. x ^ exponent
- fn pow(self, exponent: Self) -> Self {
+ fn pow(self, exponent: u32) -> Self {
+ let ufp32_exponent = UFP32::from(exponent);
let non_negative = if !self.non_negative {
// roots of negative numbers are complex numbers which we lack for now
- assert(exponent.underlying.floor() == exponent.underlying);
+ assert(ufp32_exponent.floor() == ufp32_exponent);
- let div_2 = exponent.underlying / UFP32::from(2u32);
+ let div_2 = ufp32_exponent / UFP32::from(2u32);
div_2.floor() == div_2
} else {
true
};
- let mut underlying = self.underlying.pow(exponent.underlying);
- if !exponent.non_negative {
- underlying = UFP32::recip(underlying);
- }
+ let mut underlying = self.underlying.pow(exponent);
Self {
underlying: underlying,
non_negative: non_negative,
diff --git a/libs/fixed_point/src/ufp128.sw b/libs/fixed_point/src/ufp128.sw
index d4b936ee..1562548e 100644
--- a/libs/fixed_point/src/ufp128.sw
+++ b/libs/fixed_point/src/ufp128.sw
@@ -385,12 +385,10 @@ impl Root for UFP128 {
}
impl Power for UFP128 {
- fn pow(self, exponent: Self) -> Self {
- let nominator_pow = self.value.pow(exponent.value);
- let u128_1 = U128::from((0, 1));
+ fn pow(self, exponent: u32) -> Self {
+ let nominator_pow = self.value.pow(exponent);
let u128_2 = U128::from((0, 2));
- let u128_64 = U128::from((0, 64));
- let two_pow_64_n_minus_1 = u128_2.pow(u128_64 * (exponent.value - u128_1));
+ let two_pow_64_n_minus_1 = u128_2.pow((64u32 * (exponent - 1u32)));
let nominator = nominator_pow / two_pow_64_n_minus_1;
Self::from((nominator.upper, nominator.lower))
}
diff --git a/libs/fixed_point/src/ufp32.sw b/libs/fixed_point/src/ufp32.sw
index eb274ced..a155a4cb 100644
--- a/libs/fixed_point/src/ufp32.sw
+++ b/libs/fixed_point/src/ufp32.sw
@@ -446,15 +446,14 @@ impl Exponent for UFP32 {
impl Power for UFP32 {
/// Power function. x ^ exponent
- fn pow(self, exponent: Self) -> Self {
+ fn pow(self, exponent: u32) -> Self {
let demoninator_power = UFP32::denominator();
- let exponent_int = exponent.value >> 16;
- let nominator_pow = self.value.pow(exponent_int);
+ let nominator_pow = self.value.pow(exponent);
// As we need to ensure the fixed point structure
// which means that the denominator is always 2 ^ 16
// we need to divide the nominator by 2 ^ (16 * exponent - 1)
// - 1 is the formula is due to denominator need to stay 2 ^ 16
- let nominator = nominator_pow >> 16 * (exponent_int - 1u32).as_u64();
+ let nominator = nominator_pow >> 16 * (exponent - 1u32).as_u64();
if nominator > u32::max() {
// panic on overflow
diff --git a/libs/fixed_point/src/ufp64.sw b/libs/fixed_point/src/ufp64.sw
index de16417a..b087aa92 100644
--- a/libs/fixed_point/src/ufp64.sw
+++ b/libs/fixed_point/src/ufp64.sw
@@ -446,15 +446,14 @@ impl Exponent for UFP64 {
impl Power for UFP64 {
/// Power function. x ^ exponent
- fn pow(self, exponent: Self) -> Self {
+ fn pow(self, exponent: u32) -> Self {
let demoninator_power = UFP64::denominator();
- let exponent_int = exponent.value >> 32;
- let nominator_pow = U128::from((0, self.value)).pow(U128::from((0, exponent_int)));
+ let nominator_pow = U128::from((0, self.value)).pow(exponent);
// As we need to ensure the fixed point structure
// which means that the denominator is always 2 ^ 32
// we need to delete the nominator by 2 ^ (32 * exponent - 1)
// - 1 is the formula is due to denominator need to stay 2 ^ 32
- let nominator = nominator_pow >> demoninator_power * (exponent_int - 1);
+ let nominator = nominator_pow >> demoninator_power * (exponent.as_u64() - 1);
if nominator.upper != 0 {
// panic on overflow
diff --git a/libs/merkle_proof/src/binary_merkle_proof.sw b/libs/merkle_proof/src/binary_merkle_proof.sw
index 80ef2546..3f219de6 100644
--- a/libs/merkle_proof/src/binary_merkle_proof.sw
+++ b/libs/merkle_proof/src/binary_merkle_proof.sw
@@ -171,7 +171,10 @@ pub fn process_proof(
proof: Vec,
) -> b256 {
let proof_length = proof.len();
- require((num_leaves > 1 && proof_length == path_length_from_key(key, num_leaves)) || (num_leaves <= 1 && proof_length == 0), ProofError::InvalidProofLength);
+ require(
+ (num_leaves > 1 && proof_length == path_length_from_key(key, num_leaves)) || (num_leaves <= 1 && proof_length == 0),
+ ProofError::InvalidProofLength,
+ );
require(key < num_leaves, ProofError::InvalidKey);
let mut digest = merkle_leaf;
diff --git a/libs/ownership/Forc.toml b/libs/ownership/Forc.toml
index 9b6e2cfa..ac97d820 100644
--- a/libs/ownership/Forc.toml
+++ b/libs/ownership/Forc.toml
@@ -5,4 +5,4 @@ license = "Apache-2.0"
name = "ownership"
[dependencies]
-src_5 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.1.0" }
+src_5 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.2.0" }
diff --git a/libs/ownership/src/ownable.sw b/libs/ownership/src/ownable.sw
index b3a0d272..1d17323d 100644
--- a/libs/ownership/src/ownable.sw
+++ b/libs/ownership/src/ownable.sw
@@ -6,7 +6,11 @@ pub mod events;
use errors::AccessError;
use events::{OwnershipRenounced, OwnershipSet, OwnershipTransferred};
use std::{auth::msg_sender, hash::sha256, storage::storage_api::{read, write}};
-use src_5::{Ownership, State};
+use src_5::State;
+
+pub struct Ownership {
+ state: State,
+}
impl Ownership {
/// Returns the `Ownership` struct in the `Uninitalized` state.
@@ -143,7 +147,11 @@ impl StorageKey {
/// ```
#[storage(read)]
pub fn only_owner(self) {
- require(self.owner() == State::Initialized(msg_sender().unwrap()), AccessError::NotOwner);
+ require(
+ self
+ .owner() == State::Initialized(msg_sender().unwrap()),
+ AccessError::NotOwner,
+ );
}
}
@@ -217,7 +225,11 @@ impl StorageKey {
/// ```
#[storage(read, write)]
pub fn set_ownership(self, new_owner: Identity) {
- require(self.owner() == State::Uninitialized, AccessError::CannotReinitialized);
+ require(
+ self
+ .owner() == State::Uninitialized,
+ AccessError::CannotReinitialized,
+ );
self.write(Ownership::initialized(new_owner));
diff --git a/libs/pausable/src/lib.sw b/libs/pausable/src/lib.sw
index c0f6b0e4..5e4e3462 100644
--- a/libs/pausable/src/lib.sw
+++ b/libs/pausable/src/lib.sw
@@ -152,7 +152,7 @@ pub fn _unpause() {
#[storage(read)]
pub fn _is_paused() -> bool {
let paused_key = StorageKey::new(PAUSABLE, 0, PAUSABLE);
- paused_key.read()
+ paused_key.try_read().unwrap_or(false)
}
/// Requires that the contract is in the paused state.
@@ -179,7 +179,12 @@ pub fn _is_paused() -> bool {
#[storage(read)]
pub fn require_paused() {
let paused_key = StorageKey::::new(PAUSABLE, 0, PAUSABLE);
- require(paused_key.read(), PauseError::NotPaused);
+ require(
+ paused_key
+ .try_read()
+ .unwrap_or(false),
+ PauseError::NotPaused,
+ );
}
/// Requires that the contract is in the unpaused state.
@@ -206,5 +211,5 @@ pub fn require_paused() {
#[storage(read)]
pub fn require_not_paused() {
let paused_key = StorageKey::::new(PAUSABLE, 0, PAUSABLE);
- require(!paused_key.read(), PauseError::Paused);
+ require(!paused_key.try_read().unwrap_or(false), PauseError::Paused);
}
diff --git a/libs/signed_integers/src/i128.sw b/libs/signed_integers/src/i128.sw
index 8a53ea33..7146f5fe 100644
--- a/libs/signed_integers/src/i128.sw
+++ b/libs/signed_integers/src/i128.sw
@@ -250,20 +250,32 @@ impl core::ops::Divide for I128 {
|| self.underlying == Self::indent())
&& divisor.underlying > Self::indent()
{
- res = Self::from_uint((self.underlying - Self::indent()) / (divisor.underlying - Self::indent()) + Self::indent());
+ res = Self::from_uint(
+ (self.underlying - Self::indent()) / (divisor
+ .underlying - Self::indent()) + Self::indent(),
+ );
} else if self.underlying < Self::indent()
&& divisor.underlying < Self::indent()
{
- res = Self::from_uint((Self::indent() - self.underlying) / (Self::indent() - divisor.underlying) + Self::indent());
+ res = Self::from_uint(
+ (Self::indent() - self.underlying) / (Self::indent() - divisor
+ .underlying) + Self::indent(),
+ );
} else if (self.underlying > Self::indent()
|| self.underlying == Self::indent())
&& divisor.underlying < Self::indent()
{
- res = Self::from_uint(Self::indent() - (self.underlying - Self::indent()) / (Self::indent() - divisor.underlying));
+ res = Self::from_uint(
+ Self::indent() - (self.underlying - Self::indent()) / (Self::indent() - divisor
+ .underlying),
+ );
} else if self.underlying < Self::indent()
&& divisor.underlying > Self::indent()
{
- res = Self::from_uint(Self::indent() - (Self::indent() - self.underlying) / (divisor.underlying - Self::indent()));
+ res = Self::from_uint(
+ Self::indent() - (Self::indent() - self.underlying) / (divisor
+ .underlying - Self::indent()),
+ );
}
res
}
@@ -278,21 +290,29 @@ impl core::ops::Multiply for I128 {
&& (other.underlying > Self::indent()
|| other.underlying == Self::indent())
{
- res = Self::from_uint((self.underlying - Self::indent()) * (other.underlying - Self::indent()) + Self::indent());
+ res = Self::from_uint(
+ (self.underlying - Self::indent()) * (other.underlying - Self::indent()) + Self::indent(),
+ );
} else if self.underlying < Self::indent()
&& other.underlying < Self::indent()
{
- res = Self::from_uint((Self::indent() - self.underlying) * (Self::indent() - other.underlying) + Self::indent());
+ res = Self::from_uint(
+ (Self::indent() - self.underlying) * (Self::indent() - other.underlying) + Self::indent(),
+ );
} else if (self.underlying > Self::indent()
|| self.underlying == Self::indent())
&& other.underlying < Self::indent()
{
- res = Self::from_uint(Self::indent() - (self.underlying - Self::indent()) * (Self::indent() - other.underlying));
+ res = Self::from_uint(
+ Self::indent() - (self.underlying - Self::indent()) * (Self::indent() - other.underlying),
+ );
} else if self.underlying < Self::indent()
&& (other.underlying > Self::indent()
|| other.underlying == Self::indent())
{
- res = Self::from_uint(Self::indent() - (other.underlying - Self::indent()) * (Self::indent() - self.underlying));
+ res = Self::from_uint(
+ Self::indent() - (other.underlying - Self::indent()) * (Self::indent() - self.underlying),
+ );
}
res
}
diff --git a/libs/signed_integers/src/i16.sw b/libs/signed_integers/src/i16.sw
index b269801f..5f5ab90a 100644
--- a/libs/signed_integers/src/i16.sw
+++ b/libs/signed_integers/src/i16.sw
@@ -237,19 +237,31 @@ impl core::ops::Divide for I16 {
if self.underlying >= Self::indent()
&& divisor.underlying > Self::indent()
{
- res = Self::from_uint((self.underlying - Self::indent()) / (divisor.underlying - Self::indent()) + Self::indent());
+ res = Self::from_uint(
+ (self.underlying - Self::indent()) / (divisor
+ .underlying - Self::indent()) + Self::indent(),
+ );
} else if self.underlying < Self::indent()
&& divisor.underlying < Self::indent()
{
- res = Self::from_uint((Self::indent() - self.underlying) / (Self::indent() - divisor.underlying) + Self::indent());
+ res = Self::from_uint(
+ (Self::indent() - self.underlying) / (Self::indent() - divisor
+ .underlying) + Self::indent(),
+ );
} else if self.underlying >= Self::indent()
&& divisor.underlying < Self::indent()
{
- res = Self::from_uint(Self::indent() - (self.underlying - Self::indent()) / (Self::indent() - divisor.underlying));
+ res = Self::from_uint(
+ Self::indent() - (self.underlying - Self::indent()) / (Self::indent() - divisor
+ .underlying),
+ );
} else if self.underlying < Self::indent()
&& divisor.underlying > Self::indent()
{
- res = Self::from_uint(Self::indent() - (Self::indent() - self.underlying) / (divisor.underlying - Self::indent()));
+ res = Self::from_uint(
+ Self::indent() - (Self::indent() - self.underlying) / (divisor
+ .underlying - Self::indent()),
+ );
}
res
}
@@ -262,19 +274,27 @@ impl core::ops::Multiply for I16 {
if self.underlying >= Self::indent()
&& other.underlying >= Self::indent()
{
- res = Self::from_uint((self.underlying - Self::indent()) * (other.underlying - Self::indent()) + Self::indent());
+ res = Self::from_uint(
+ (self.underlying - Self::indent()) * (other.underlying - Self::indent()) + Self::indent(),
+ );
} else if self.underlying < Self::indent()
&& other.underlying < Self::indent()
{
- res = Self::from_uint((Self::indent() - self.underlying) * (Self::indent() - other.underlying) + Self::indent());
+ res = Self::from_uint(
+ (Self::indent() - self.underlying) * (Self::indent() - other.underlying) + Self::indent(),
+ );
} else if self.underlying >= Self::indent()
&& other.underlying < Self::indent()
{
- res = Self::from_uint(Self::indent() - (self.underlying - Self::indent()) * (Self::indent() - other.underlying));
+ res = Self::from_uint(
+ Self::indent() - (self.underlying - Self::indent()) * (Self::indent() - other.underlying),
+ );
} else if self.underlying < Self::indent()
&& other.underlying >= Self::indent()
{
- res = Self::from_uint(Self::indent() - (other.underlying - Self::indent()) * (Self::indent() - self.underlying));
+ res = Self::from_uint(
+ Self::indent() - (other.underlying - Self::indent()) * (Self::indent() - self.underlying),
+ );
}
res
}
diff --git a/libs/signed_integers/src/i256.sw b/libs/signed_integers/src/i256.sw
index c0477c69..a8615260 100644
--- a/libs/signed_integers/src/i256.sw
+++ b/libs/signed_integers/src/i256.sw
@@ -249,20 +249,32 @@ impl core::ops::Divide for I256 {
let self_ge_indent = self.underlying > Self::indent() || self.underlying == Self::indent();
let divisor_gt_indent = divisor.underlying > Self::indent();
if self_ge_indent && divisor_gt_indent {
- res = Self::from_uint((self.underlying - Self::indent()) / (divisor.underlying - Self::indent()) + Self::indent());
+ res = Self::from_uint(
+ (self.underlying - Self::indent()) / (divisor
+ .underlying - Self::indent()) + Self::indent(),
+ );
} else if self.underlying < Self::indent()
&& divisor.underlying < Self::indent()
{
- res = Self::from_uint((Self::indent() - self.underlying) / (Self::indent() - divisor.underlying) + Self::indent());
+ res = Self::from_uint(
+ (Self::indent() - self.underlying) / (Self::indent() - divisor
+ .underlying) + Self::indent(),
+ );
} else if (self.underlying > Self::indent()
|| self.underlying == Self::indent())
&& divisor.underlying < Self::indent()
{
- res = Self::from_uint(Self::indent() - (self.underlying - Self::indent()) / (Self::indent() - divisor.underlying));
+ res = Self::from_uint(
+ Self::indent() - (self.underlying - Self::indent()) / (Self::indent() - divisor
+ .underlying),
+ );
} else if self.underlying < Self::indent()
&& divisor.underlying > Self::indent()
{
- res = Self::from_uint(Self::indent() - (Self::indent() - self.underlying) / (divisor.underlying - Self::indent()));
+ res = Self::from_uint(
+ Self::indent() - (Self::indent() - self.underlying) / (divisor
+ .underlying - Self::indent()),
+ );
}
res
}
@@ -277,21 +289,29 @@ impl core::ops::Multiply for I256 {
&& (other.underlying > Self::indent()
|| other.underlying == Self::indent())
{
- res = Self::from_uint((self.underlying - Self::indent()) * (other.underlying - Self::indent()) + Self::indent());
+ res = Self::from_uint(
+ (self.underlying - Self::indent()) * (other.underlying - Self::indent()) + Self::indent(),
+ );
} else if self.underlying < Self::indent()
&& other.underlying < Self::indent()
{
- res = Self::from_uint((Self::indent() - self.underlying) * (Self::indent() - other.underlying) + Self::indent());
+ res = Self::from_uint(
+ (Self::indent() - self.underlying) * (Self::indent() - other.underlying) + Self::indent(),
+ );
} else if (self.underlying > Self::indent()
|| self.underlying == Self::indent())
&& other.underlying < Self::indent()
{
- res = Self::from_uint(Self::indent() - (self.underlying - Self::indent()) * (Self::indent() - other.underlying));
+ res = Self::from_uint(
+ Self::indent() - (self.underlying - Self::indent()) * (Self::indent() - other.underlying),
+ );
} else if self.underlying < Self::indent()
&& (other.underlying > Self::indent()
|| other.underlying == Self::indent())
{
- res = Self::from_uint(Self::indent() - (other.underlying - Self::indent()) * (Self::indent() - self.underlying));
+ res = Self::from_uint(
+ Self::indent() - (other.underlying - Self::indent()) * (Self::indent() - self.underlying),
+ );
}
res
}
diff --git a/libs/signed_integers/src/i32.sw b/libs/signed_integers/src/i32.sw
index d2efe449..f12f89c3 100644
--- a/libs/signed_integers/src/i32.sw
+++ b/libs/signed_integers/src/i32.sw
@@ -268,19 +268,27 @@ impl core::ops::Multiply for I32 {
if self.underlying >= Self::indent()
&& other.underlying >= Self::indent()
{
- res = Self::from_uint((self.underlying - Self::indent()) * (other.underlying - Self::indent()) + Self::indent());
+ res = Self::from_uint(
+ (self.underlying - Self::indent()) * (other.underlying - Self::indent()) + Self::indent(),
+ );
} else if self.underlying < Self::indent()
&& other.underlying < Self::indent()
{
- res = Self::from_uint((Self::indent() - self.underlying) * (Self::indent() - other.underlying) + Self::indent());
+ res = Self::from_uint(
+ (Self::indent() - self.underlying) * (Self::indent() - other.underlying) + Self::indent(),
+ );
} else if self.underlying >= Self::indent()
&& other.underlying < Self::indent()
{
- res = Self::from_uint(Self::indent() - (self.underlying - Self::indent()) * (Self::indent() - other.underlying));
+ res = Self::from_uint(
+ Self::indent() - (self.underlying - Self::indent()) * (Self::indent() - other.underlying),
+ );
} else if self.underlying < Self::indent()
&& other.underlying >= Self::indent()
{
- res = Self::from_uint(Self::indent() - (other.underlying - Self::indent()) * (Self::indent() - self.underlying));
+ res = Self::from_uint(
+ Self::indent() - (other.underlying - Self::indent()) * (Self::indent() - self.underlying),
+ );
}
res
}
@@ -294,19 +302,31 @@ impl core::ops::Divide for I32 {
if self.underlying >= Self::indent()
&& divisor.underlying > Self::indent()
{
- res = Self::from_uint((self.underlying - Self::indent()) / (divisor.underlying - Self::indent()) + Self::indent());
+ res = Self::from_uint(
+ (self.underlying - Self::indent()) / (divisor
+ .underlying - Self::indent()) + Self::indent(),
+ );
} else if self.underlying < Self::indent()
&& divisor.underlying < Self::indent()
{
- res = Self::from_uint((Self::indent() - self.underlying) / (Self::indent() - divisor.underlying) + Self::indent());
+ res = Self::from_uint(
+ (Self::indent() - self.underlying) / (Self::indent() - divisor
+ .underlying) + Self::indent(),
+ );
} else if self.underlying >= Self::indent()
&& divisor.underlying < Self::indent()
{
- res = Self::from_uint(Self::indent() - (self.underlying - Self::indent()) / (Self::indent() - divisor.underlying));
+ res = Self::from_uint(
+ Self::indent() - (self.underlying - Self::indent()) / (Self::indent() - divisor
+ .underlying),
+ );
} else if self.underlying < Self::indent()
&& divisor.underlying > Self::indent()
{
- res = Self::from_uint(Self::indent() - (Self::indent() - self.underlying) / (divisor.underlying - Self::indent()));
+ res = Self::from_uint(
+ Self::indent() - (Self::indent() - self.underlying) / (divisor
+ .underlying - Self::indent()),
+ );
}
res
}
diff --git a/libs/signed_integers/src/i64.sw b/libs/signed_integers/src/i64.sw
index b88fd26a..7c58f4b1 100644
--- a/libs/signed_integers/src/i64.sw
+++ b/libs/signed_integers/src/i64.sw
@@ -269,19 +269,27 @@ impl core::ops::Multiply for I64 {
if self.underlying >= Self::indent()
&& other.underlying >= Self::indent()
{
- res = Self::from_uint((self.underlying - Self::indent()) * (other.underlying - Self::indent()) + Self::indent());
+ res = Self::from_uint(
+ (self.underlying - Self::indent()) * (other.underlying - Self::indent()) + Self::indent(),
+ );
} else if self.underlying < Self::indent()
&& other.underlying < Self::indent()
{
- res = Self::from_uint((Self::indent() - self.underlying) * (Self::indent() - other.underlying) + Self::indent());
+ res = Self::from_uint(
+ (Self::indent() - self.underlying) * (Self::indent() - other.underlying) + Self::indent(),
+ );
} else if self.underlying >= Self::indent()
&& other.underlying < Self::indent()
{
- res = Self::from_uint(Self::indent() - (self.underlying - Self::indent()) * (Self::indent() - other.underlying));
+ res = Self::from_uint(
+ Self::indent() - (self.underlying - Self::indent()) * (Self::indent() - other.underlying),
+ );
} else if self.underlying < Self::indent()
&& other.underlying >= Self::indent()
{
- res = Self::from_uint(Self::indent() - (other.underlying - Self::indent()) * (Self::indent() - self.underlying));
+ res = Self::from_uint(
+ Self::indent() - (other.underlying - Self::indent()) * (Self::indent() - self.underlying),
+ );
}
res
}
@@ -295,19 +303,31 @@ impl core::ops::Divide for I64 {
if self.underlying >= Self::indent()
&& divisor.underlying > Self::indent()
{
- res = Self::from_uint((self.underlying - Self::indent()) / (divisor.underlying - Self::indent()) + Self::indent());
+ res = Self::from_uint(
+ (self.underlying - Self::indent()) / (divisor
+ .underlying - Self::indent()) + Self::indent(),
+ );
} else if self.underlying < Self::indent()
&& divisor.underlying < Self::indent()
{
- res = Self::from_uint((Self::indent() - self.underlying) / (Self::indent() - divisor.underlying) + Self::indent());
+ res = Self::from_uint(
+ (Self::indent() - self.underlying) / (Self::indent() - divisor
+ .underlying) + Self::indent(),
+ );
} else if self.underlying >= Self::indent()
&& divisor.underlying < Self::indent()
{
- res = Self::from_uint(Self::indent() - (self.underlying - Self::indent()) / (Self::indent() - divisor.underlying));
+ res = Self::from_uint(
+ Self::indent() - (self.underlying - Self::indent()) / (Self::indent() - divisor
+ .underlying),
+ );
} else if self.underlying < Self::indent()
&& divisor.underlying > Self::indent()
{
- res = Self::from_uint(Self::indent() - (Self::indent() - self.underlying) / (divisor.underlying - Self::indent()));
+ res = Self::from_uint(
+ Self::indent() - (Self::indent() - self.underlying) / (divisor
+ .underlying - Self::indent()),
+ );
}
res
}
diff --git a/libs/signed_integers/src/i8.sw b/libs/signed_integers/src/i8.sw
index 477ed25a..60b61479 100644
--- a/libs/signed_integers/src/i8.sw
+++ b/libs/signed_integers/src/i8.sw
@@ -236,19 +236,31 @@ impl core::ops::Divide for I8 {
if self.underlying >= Self::indent()
&& divisor.underlying > Self::indent()
{
- res = Self::from_uint((self.underlying - Self::indent()) / (divisor.underlying - Self::indent()) + Self::indent());
+ res = Self::from_uint(
+ (self.underlying - Self::indent()) / (divisor
+ .underlying - Self::indent()) + Self::indent(),
+ );
} else if self.underlying < Self::indent()
&& divisor.underlying < Self::indent()
{
- res = Self::from_uint((Self::indent() - self.underlying) / (Self::indent() - divisor.underlying) + Self::indent());
+ res = Self::from_uint(
+ (Self::indent() - self.underlying) / (Self::indent() - divisor
+ .underlying) + Self::indent(),
+ );
} else if self.underlying >= Self::indent()
&& divisor.underlying < Self::indent()
{
- res = Self::from_uint(Self::indent() - (self.underlying - Self::indent()) / (Self::indent() - divisor.underlying));
+ res = Self::from_uint(
+ Self::indent() - (self.underlying - Self::indent()) / (Self::indent() - divisor
+ .underlying),
+ );
} else if self.underlying < Self::indent()
&& divisor.underlying > Self::indent()
{
- res = Self::from_uint(Self::indent() - (Self::indent() - self.underlying) / (divisor.underlying - Self::indent()));
+ res = Self::from_uint(
+ Self::indent() - (Self::indent() - self.underlying) / (divisor
+ .underlying - Self::indent()),
+ );
}
res
}
@@ -261,19 +273,27 @@ impl core::ops::Multiply for I8 {
if self.underlying >= Self::indent()
&& other.underlying >= Self::indent()
{
- res = Self::from_uint((self.underlying - Self::indent()) * (other.underlying - Self::indent()) + Self::indent());
+ res = Self::from_uint(
+ (self.underlying - Self::indent()) * (other.underlying - Self::indent()) + Self::indent(),
+ );
} else if self.underlying < Self::indent()
&& other.underlying < Self::indent()
{
- res = Self::from_uint((Self::indent() - self.underlying) * (Self::indent() - other.underlying) + Self::indent());
+ res = Self::from_uint(
+ (Self::indent() - self.underlying) * (Self::indent() - other.underlying) + Self::indent(),
+ );
} else if self.underlying >= Self::indent()
&& other.underlying < Self::indent()
{
- res = Self::from_uint(Self::indent() - (self.underlying - Self::indent()) * (Self::indent() - other.underlying));
+ res = Self::from_uint(
+ Self::indent() - (self.underlying - Self::indent()) * (Self::indent() - other.underlying),
+ );
} else if self.underlying < Self::indent()
&& other.underlying >= Self::indent()
{
- res = Self::from_uint(Self::indent() - (other.underlying - Self::indent()) * (Self::indent() - self.underlying));
+ res = Self::from_uint(
+ Self::indent() - (other.underlying - Self::indent()) * (Self::indent() - self.underlying),
+ );
}
res
}
diff --git a/libs/token/Forc.toml b/libs/token/Forc.toml
index a7df4a8a..998475b9 100644
--- a/libs/token/Forc.toml
+++ b/libs/token/Forc.toml
@@ -5,4 +5,4 @@ license = "Apache-2.0"
name = "token"
[dependencies]
-src_7 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.1.2" }
+src_7 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.2.0" }
diff --git a/tests/src/fixed_point/ifp64_pow_test/src/main.sw b/tests/src/fixed_point/ifp64_pow_test/src/main.sw
index d96969a5..b0c4b0e4 100644
--- a/tests/src/fixed_point/ifp64_pow_test/src/main.sw
+++ b/tests/src/fixed_point/ifp64_pow_test/src/main.sw
@@ -5,25 +5,23 @@ use std::assert::assert;
fn main() -> bool {
let one = IFP64::from_uint(1u32);
- let ifp64_1000 = IFP64::from_uint(1u32);
- let mut res = one.pow(ifp64_1000);
+ let mut res = one.pow(1u32);
assert(one == res);
let two = IFP64::from_uint(2u32);
- let three = IFP64::from_uint(3u32);
- res = two.pow(three);
+ res = two.pow(3u32);
assert(IFP64::from_uint(8u32) == res);
let ufp_64_11 = IFP64::from_uint(11u32);
- res = ufp_64_11.pow(two);
+ res = ufp_64_11.pow(2u32);
assert(IFP64::from_uint(121u32) == res);
let five = IFP64::from_uint(5u32);
- res = five.pow(three);
+ res = five.pow(3u32);
assert(IFP64::from_uint(125u32) == res);
let seven = IFP64::from_uint(7u32);
- res = seven.pow(two);
+ res = seven.pow(2u32);
assert(IFP64::from_uint(49u32) == res);
true
diff --git a/tests/src/fixed_point/ufp128_test/src/main.sw b/tests/src/fixed_point/ufp128_test/src/main.sw
index ee90a3bd..f29ceb4b 100644
--- a/tests/src/fixed_point/ufp128_test/src/main.sw
+++ b/tests/src/fixed_point/ufp128_test/src/main.sw
@@ -29,9 +29,11 @@ fn main() -> bool {
value: U128::from((1, 3)),
};
res = UFP128::recip(value);
- assert(UFP128 {
- value: U128::from((0, 18446744073709551613)),
- } == res);
+ assert(
+ UFP128 {
+ value: U128::from((0, 18446744073709551613)),
+ } == res,
+ );
// trunc
let mut value = UFP128 {
diff --git a/tests/src/fixed_point/ufp32_pow_test/src/main.sw b/tests/src/fixed_point/ufp32_pow_test/src/main.sw
index 627854bd..b07b15fe 100644
--- a/tests/src/fixed_point/ufp32_pow_test/src/main.sw
+++ b/tests/src/fixed_point/ufp32_pow_test/src/main.sw
@@ -5,25 +5,23 @@ use std::assert::assert;
fn main() -> bool {
let one = UFP32::from_uint(1);
- let ufp32_1000 = UFP32::from_uint(1);
- let mut res = one.pow(ufp32_1000);
+ let mut res = one.pow(1u32);
assert(one == res);
let two = UFP32::from_uint(2);
- let three = UFP32::from_uint(3);
- res = two.pow(three);
+ res = two.pow(3u32);
assert(UFP32::from_uint(8) == res);
let ufp_64_11 = UFP32::from_uint(11);
- res = ufp_64_11.pow(two);
+ res = ufp_64_11.pow(2u32);
assert(UFP32::from_uint(121) == res);
let five = UFP32::from_uint(5);
- res = five.pow(three);
+ res = five.pow(3u32);
assert(UFP32::from_uint(125) == res);
let seven = UFP32::from_uint(7);
- res = seven.pow(two);
+ res = seven.pow(2u32);
assert(UFP32::from_uint(49) == res);
true
diff --git a/tests/src/fixed_point/ufp64_pow_test/src/main.sw b/tests/src/fixed_point/ufp64_pow_test/src/main.sw
index b9122cbe..6f8e2d51 100644
--- a/tests/src/fixed_point/ufp64_pow_test/src/main.sw
+++ b/tests/src/fixed_point/ufp64_pow_test/src/main.sw
@@ -5,25 +5,23 @@ use std::assert::assert;
fn main() -> bool {
let one = UFP64::from_uint(1);
- let ufp64_1000 = UFP64::from_uint(1);
- let mut res = one.pow(ufp64_1000);
+ let mut res = one.pow(1u32);
assert(one == res);
let two = UFP64::from_uint(2);
- let three = UFP64::from_uint(3);
- res = two.pow(three);
+ res = two.pow(3u32);
assert(UFP64::from_uint(8) == res);
let ufp_64_11 = UFP64::from_uint(11);
- res = ufp_64_11.pow(two);
+ res = ufp_64_11.pow(2u32);
assert(UFP64::from_uint(121) == res);
let five = UFP64::from_uint(5);
- res = five.pow(three);
+ res = five.pow(3u32);
assert(UFP64::from_uint(125) == res);
let seven = UFP64::from_uint(7);
- res = seven.pow(two);
+ res = seven.pow(2u32);
assert(UFP64::from_uint(49) == res);
true
diff --git a/tests/src/merkle_proof/src/main.sw b/tests/src/merkle_proof/src/main.sw
index 256e3ed4..d605f31e 100644
--- a/tests/src/merkle_proof/src/main.sw
+++ b/tests/src/merkle_proof/src/main.sw
@@ -5,8 +5,19 @@ use merkle_proof::binary_merkle_proof::{leaf_digest, node_digest, process_proof,
abi MerkleProofTest {
fn leaf_digest(data: b256) -> b256;
fn node_digest(left: b256, right: b256) -> b256;
- fn process_proof(key: u64, merkle_leaf: b256, num_leaves: u64, proof: Vec) -> b256;
- fn verify_proof(key: u64, merkle_leaf: b256, merkle_root: b256, num_leaves: u64, proof: Vec) -> bool;
+ fn process_proof(
+ key: u64,
+ merkle_leaf: b256,
+ num_leaves: u64,
+ proof: Vec,
+ ) -> b256;
+ fn verify_proof(
+ key: u64,
+ merkle_leaf: b256,
+ merkle_root: b256,
+ num_leaves: u64,
+ proof: Vec,
+ ) -> bool;
}
impl MerkleProofTest for Contract {
diff --git a/tests/src/ownership/Forc.toml b/tests/src/ownership/Forc.toml
index 88a2f14d..6ed0d787 100644
--- a/tests/src/ownership/Forc.toml
+++ b/tests/src/ownership/Forc.toml
@@ -6,4 +6,4 @@ name = "ownership_test"
[dependencies]
ownership = { path = "../../../libs/ownership" }
-src_5 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.1.0" }
+src_5 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.2.0" }
diff --git a/tests/src/ownership/src/main.sw b/tests/src/ownership/src/main.sw
index 946c5e89..faa3b03f 100644
--- a/tests/src/ownership/src/main.sw
+++ b/tests/src/ownership/src/main.sw
@@ -1,7 +1,7 @@
contract;
use ownership::*;
-use src_5::{Ownership, State};
+use src_5::{SRC5, State};
storage {
owner: Ownership = Ownership::uninitialized(),
@@ -10,8 +10,6 @@ storage {
abi OwnableTest {
#[storage(read)]
fn only_owner();
- #[storage(read)]
- fn owner() -> State;
#[storage(read, write)]
fn renounce_ownership();
#[storage(read, write)]
@@ -20,15 +18,17 @@ abi OwnableTest {
fn transfer_ownership(new_owner: Identity);
}
-impl OwnableTest for Contract {
+impl SRC5 for Contract {
#[storage(read)]
- fn only_owner() {
- storage.owner.only_owner();
+ fn owner() -> State {
+ storage.owner.owner()
}
+}
+impl OwnableTest for Contract {
#[storage(read)]
- fn owner() -> State {
- storage.owner.owner()
+ fn only_owner() {
+ storage.owner.only_owner();
}
#[storage(read, write)]
diff --git a/tests/src/reentrancy/reentrancy_attacker_contract/src/main.sw b/tests/src/reentrancy/reentrancy_attacker_contract/src/main.sw
index 70302271..fa2cd7ea 100644
--- a/tests/src/reentrancy/reentrancy_attacker_contract/src/main.sw
+++ b/tests/src/reentrancy/reentrancy_attacker_contract/src/main.sw
@@ -44,21 +44,31 @@ impl Attacker for Contract {
}
fn evil_callback_1() {
- assert(abi(Attacker, contract_id().value).launch_attack(get_msg_sender_id_or_panic()));
+ assert(
+ abi(Attacker, contract_id()
+ .value)
+ .launch_attack(get_msg_sender_id_or_panic()),
+ );
}
fn evil_callback_2() {
- abi(Attacker, contract_id().value).launch_thwarted_attack_1(get_msg_sender_id_or_panic());
+ abi(Attacker, contract_id()
+ .value)
+ .launch_thwarted_attack_1(get_msg_sender_id_or_panic());
}
fn evil_callback_3() {
- abi(Attacker, contract_id().value).launch_thwarted_attack_2(get_msg_sender_id_or_panic());
+ abi(Attacker, contract_id()
+ .value)
+ .launch_thwarted_attack_2(get_msg_sender_id_or_panic());
}
#[storage(read)]
fn evil_callback_4() {
let helper = storage.helper.read();
- abi(AttackHelper, helper.value).attempt_cross_contract_reentrancy(storage.target_id.read());
+ abi(AttackHelper, helper
+ .value)
+ .attempt_cross_contract_reentrancy(storage.target_id.read());
}
fn innocent_callback() {}
diff --git a/tests/src/reentrancy/reentrancy_target_contract/src/main.sw b/tests/src/reentrancy/reentrancy_target_contract/src/main.sw
index 0d03ba67..1babdce1 100644
--- a/tests/src/reentrancy/reentrancy_target_contract/src/main.sw
+++ b/tests/src/reentrancy/reentrancy_target_contract/src/main.sw
@@ -20,7 +20,9 @@ impl Target for Contract {
true
} else {
// this call transfers control to the attacker contract, allowing it to execute arbitrary code.
- abi(Attacker, get_msg_sender_id_or_panic().value).evil_callback_1();
+ abi(Attacker, get_msg_sender_id_or_panic()
+ .value)
+ .evil_callback_1();
false
}
}
@@ -30,7 +32,9 @@ impl Target for Contract {
reentrancy_guard();
// this call transfers control to the attacker contract, allowing it to execute arbitrary code.
- abi(Attacker, get_msg_sender_id_or_panic().value).evil_callback_2();
+ abi(Attacker, get_msg_sender_id_or_panic()
+ .value)
+ .evil_callback_2();
}
fn cross_function_reentrance_denied() {
@@ -38,11 +42,15 @@ impl Target for Contract {
reentrancy_guard();
// this call transfers control to the attacker contract, allowing it to execute arbitrary code.
- abi(Attacker, get_msg_sender_id_or_panic().value).evil_callback_3();
+ abi(Attacker, get_msg_sender_id_or_panic()
+ .value)
+ .evil_callback_3();
}
fn intra_contract_call() {
- abi(Target, contract_id().value).cross_function_reentrance_denied();
+ abi(Target, contract_id()
+ .value)
+ .cross_function_reentrance_denied();
}
fn guarded_function_is_callable() {
@@ -54,6 +62,8 @@ impl Target for Contract {
// panic if reentrancy detected
reentrancy_guard();
// this call transfers control to the attacker contract, allowing it to execute arbitrary code.
- abi(Attacker, get_msg_sender_id_or_panic().value).evil_callback_4();
+ abi(Attacker, get_msg_sender_id_or_panic()
+ .value)
+ .evil_callback_4();
}
}
diff --git a/tests/src/signed_integers/signed_i128_twos_complement/src/main.sw b/tests/src/signed_integers/signed_i128_twos_complement/src/main.sw
index 07ccea6a..f15a4543 100644
--- a/tests/src/signed_integers/signed_i128_twos_complement/src/main.sw
+++ b/tests/src/signed_integers/signed_i128_twos_complement/src/main.sw
@@ -13,19 +13,39 @@ fn main() -> bool {
assert(res.twos_complement() == I128::from(U128::from((0, 10))));
res = I128::neg_from(U128::from((0, 5)));
- assert(res.twos_complement().underlying - u_one + res.underlying == U128::max());
+ assert(
+ res
+ .twos_complement()
+ .underlying - u_one + res.underlying == U128::max(),
+ );
res = I128::neg_from(U128::from((0, 27)));
- assert(res.twos_complement().underlying - u_one + res.underlying == U128::max());
+ assert(
+ res
+ .twos_complement()
+ .underlying - u_one + res.underlying == U128::max(),
+ );
res = I128::neg_from(U128::from((0, 110)));
- assert(res.twos_complement().underlying - u_one + res.underlying == U128::max());
+ assert(
+ res
+ .twos_complement()
+ .underlying - u_one + res.underlying == U128::max(),
+ );
res = I128::neg_from(U128::from((0, 93)));
- assert(res.twos_complement().underlying - u_one + res.underlying == U128::max());
+ assert(
+ res
+ .twos_complement()
+ .underlying - u_one + res.underlying == U128::max(),
+ );
res = I128::neg_from(U128::from((0, 78)));
- assert(res.twos_complement().underlying - u_one + res.underlying == U128::max());
+ assert(
+ res
+ .twos_complement()
+ .underlying - u_one + res.underlying == U128::max(),
+ );
true
}
diff --git a/tests/src/signed_integers/signed_i16_twos_complement/src/main.sw b/tests/src/signed_integers/signed_i16_twos_complement/src/main.sw
index 66581f58..eb44d7d5 100644
--- a/tests/src/signed_integers/signed_i16_twos_complement/src/main.sw
+++ b/tests/src/signed_integers/signed_i16_twos_complement/src/main.sw
@@ -11,19 +11,39 @@ fn main() -> bool {
assert(res.twos_complement() == I16::from(10u16));
res = I16::neg_from(5);
- assert(res.twos_complement().underlying + res.underlying == u16::max() + 1);
+ assert(
+ res
+ .twos_complement()
+ .underlying + res.underlying == u16::max() + 1,
+ );
res = I16::neg_from(27u16);
- assert(res.twos_complement().underlying + res.underlying == u16::max() + 1);
+ assert(
+ res
+ .twos_complement()
+ .underlying + res.underlying == u16::max() + 1,
+ );
res = I16::neg_from(110u16);
- assert(res.twos_complement().underlying + res.underlying == u16::max() + 1);
+ assert(
+ res
+ .twos_complement()
+ .underlying + res.underlying == u16::max() + 1,
+ );
res = I16::neg_from(93u16);
- assert(res.twos_complement().underlying + res.underlying == u16::max() + 1);
+ assert(
+ res
+ .twos_complement()
+ .underlying + res.underlying == u16::max() + 1,
+ );
res = I16::neg_from(78u16);
- assert(res.twos_complement().underlying + res.underlying == u16::max() + 1);
+ assert(
+ res
+ .twos_complement()
+ .underlying + res.underlying == u16::max() + 1,
+ );
true
}
diff --git a/tests/src/signed_integers/signed_i256_twos_complement/src/main.sw b/tests/src/signed_integers/signed_i256_twos_complement/src/main.sw
index f1e20f36..54b48f6f 100644
--- a/tests/src/signed_integers/signed_i256_twos_complement/src/main.sw
+++ b/tests/src/signed_integers/signed_i256_twos_complement/src/main.sw
@@ -7,25 +7,51 @@ fn main() -> bool {
let u_one = U256::from((0, 0, 0, 1));
let one = I256::from(u_one);
let mut res = one + I256::from(U256::from((0, 0, 0, 1)));
- assert(res.twos_complement() == I256::from(U256::from((0, 0, 0, 2))));
+ assert(
+ res
+ .twos_complement() == I256::from(U256::from((0, 0, 0, 2))),
+ );
res = I256::from(U256::from((0, 0, 0, 10)));
- assert(res.twos_complement() == I256::from(U256::from((0, 0, 0, 10))));
+ assert(
+ res
+ .twos_complement() == I256::from(U256::from((0, 0, 0, 10))),
+ );
res = I256::neg_from(U256::from((0, 0, 0, 5)));
- assert(res.twos_complement().underlying - u_one + res.underlying == U256::max());
+ assert(
+ res
+ .twos_complement()
+ .underlying - u_one + res.underlying == U256::max(),
+ );
res = I256::neg_from(U256::from((0, 0, 0, 27)));
- assert(res.twos_complement().underlying - u_one + res.underlying == U256::max());
+ assert(
+ res
+ .twos_complement()
+ .underlying - u_one + res.underlying == U256::max(),
+ );
res = I256::neg_from(U256::from((0, 0, 0, 110)));
- assert(res.twos_complement().underlying - u_one + res.underlying == U256::max());
+ assert(
+ res
+ .twos_complement()
+ .underlying - u_one + res.underlying == U256::max(),
+ );
res = I256::neg_from(U256::from((0, 0, 0, 93)));
- assert(res.twos_complement().underlying - u_one + res.underlying == U256::max());
+ assert(
+ res
+ .twos_complement()
+ .underlying - u_one + res.underlying == U256::max(),
+ );
res = I256::neg_from(U256::from((0, 0, 0, 78)));
- assert(res.twos_complement().underlying - u_one + res.underlying == U256::max());
+ assert(
+ res
+ .twos_complement()
+ .underlying - u_one + res.underlying == U256::max(),
+ );
true
}
diff --git a/tests/src/signed_integers/signed_i32_twos_complement/src/main.sw b/tests/src/signed_integers/signed_i32_twos_complement/src/main.sw
index 222a5d76..ed91317a 100644
--- a/tests/src/signed_integers/signed_i32_twos_complement/src/main.sw
+++ b/tests/src/signed_integers/signed_i32_twos_complement/src/main.sw
@@ -11,19 +11,39 @@ fn main() -> bool {
assert(res.twos_complement() == I32::from(10u32));
res = I32::neg_from(5);
- assert(res.twos_complement().underlying + res.underlying == u32::max() + 1);
+ assert(
+ res
+ .twos_complement()
+ .underlying + res.underlying == u32::max() + 1,
+ );
res = I32::neg_from(27u32);
- assert(res.twos_complement().underlying + res.underlying == u32::max() + 1);
+ assert(
+ res
+ .twos_complement()
+ .underlying + res.underlying == u32::max() + 1,
+ );
res = I32::neg_from(110u32);
- assert(res.twos_complement().underlying + res.underlying == u32::max() + 1);
+ assert(
+ res
+ .twos_complement()
+ .underlying + res.underlying == u32::max() + 1,
+ );
res = I32::neg_from(93u32);
- assert(res.twos_complement().underlying + res.underlying == u32::max() + 1);
+ assert(
+ res
+ .twos_complement()
+ .underlying + res.underlying == u32::max() + 1,
+ );
res = I32::neg_from(78u32);
- assert(res.twos_complement().underlying + res.underlying == u32::max() + 1);
+ assert(
+ res
+ .twos_complement()
+ .underlying + res.underlying == u32::max() + 1,
+ );
true
}
diff --git a/tests/src/signed_integers/signed_i64/src/main.sw b/tests/src/signed_integers/signed_i64/src/main.sw
index 1bfe3b6c..6c49e3ed 100644
--- a/tests/src/signed_integers/signed_i64/src/main.sw
+++ b/tests/src/signed_integers/signed_i64/src/main.sw
@@ -8,9 +8,11 @@ fn main() -> bool {
assert(res == I64::from(2u64));
res = I64::from(10u64) - I64::from(11u64);
- assert(res == I64 {
- underlying: 9223372036854775807u64,
- });
+ assert(
+ res == I64 {
+ underlying: 9223372036854775807u64,
+ },
+ );
res = I64::from(10u64) * I64::neg_from(1);
assert(res == I64::neg_from(10));
diff --git a/tests/src/signed_integers/signed_i64_twos_complement/src/main.sw b/tests/src/signed_integers/signed_i64_twos_complement/src/main.sw
index d28398f3..dd105416 100644
--- a/tests/src/signed_integers/signed_i64_twos_complement/src/main.sw
+++ b/tests/src/signed_integers/signed_i64_twos_complement/src/main.sw
@@ -11,19 +11,39 @@ fn main() -> bool {
assert(res.twos_complement() == I64::from(10));
res = I64::neg_from(5);
- assert(res.twos_complement().underlying + res.underlying == u64::max() + 1);
+ assert(
+ res
+ .twos_complement()
+ .underlying + res.underlying == u64::max() + 1,
+ );
res = I64::neg_from(27);
- assert(res.twos_complement().underlying + res.underlying == u64::max() + 1);
+ assert(
+ res
+ .twos_complement()
+ .underlying + res.underlying == u64::max() + 1,
+ );
res = I64::neg_from(110);
- assert(res.twos_complement().underlying + res.underlying == u64::max() + 1);
+ assert(
+ res
+ .twos_complement()
+ .underlying + res.underlying == u64::max() + 1,
+ );
res = I64::neg_from(93);
- assert(res.twos_complement().underlying + res.underlying == u64::max() + 1);
+ assert(
+ res
+ .twos_complement()
+ .underlying + res.underlying == u64::max() + 1,
+ );
res = I64::neg_from(78);
- assert(res.twos_complement().underlying + res.underlying == u64::max() + 1);
+ assert(
+ res
+ .twos_complement()
+ .underlying + res.underlying == u64::max() + 1,
+ );
true
}
diff --git a/tests/src/signed_integers/signed_i8_twos_complement/src/main.sw b/tests/src/signed_integers/signed_i8_twos_complement/src/main.sw
index 0f5178b3..4b52b0aa 100644
--- a/tests/src/signed_integers/signed_i8_twos_complement/src/main.sw
+++ b/tests/src/signed_integers/signed_i8_twos_complement/src/main.sw
@@ -11,19 +11,39 @@ fn main() -> bool {
assert(res.twos_complement() == I8::from(10u8));
res = I8::neg_from(5);
- assert(res.twos_complement().underlying + res.underlying == u8::max() + 1);
+ assert(
+ res
+ .twos_complement()
+ .underlying + res.underlying == u8::max() + 1,
+ );
res = I8::neg_from(27u8);
- assert(res.twos_complement().underlying + res.underlying == u8::max() + 1);
+ assert(
+ res
+ .twos_complement()
+ .underlying + res.underlying == u8::max() + 1,
+ );
res = I8::neg_from(110u8);
- assert(res.twos_complement().underlying + res.underlying == u8::max() + 1);
+ assert(
+ res
+ .twos_complement()
+ .underlying + res.underlying == u8::max() + 1,
+ );
res = I8::neg_from(93u8);
- assert(res.twos_complement().underlying + res.underlying == u8::max() + 1);
+ assert(
+ res
+ .twos_complement()
+ .underlying + res.underlying == u8::max() + 1,
+ );
res = I8::neg_from(78u8);
- assert(res.twos_complement().underlying + res.underlying == u8::max() + 1);
+ assert(
+ res
+ .twos_complement()
+ .underlying + res.underlying == u8::max() + 1,
+ );
true
}
diff --git a/tests/src/token/Forc.toml b/tests/src/token/Forc.toml
index 325fa696..eb8a6cbd 100644
--- a/tests/src/token/Forc.toml
+++ b/tests/src/token/Forc.toml
@@ -5,7 +5,7 @@ license = "Apache-2.0"
name = "token_test"
[dependencies]
-src_20 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.1.1" }
-src_3 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.1.1" }
-src_7 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.1.2" }
+src_20 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.2.0" }
+src_3 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.2.0" }
+src_7 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.2.0" }
token = { path = "../../../libs/token" }
diff --git a/tests/src/token/src/main.sw b/tests/src/token/src/main.sw
index 9fb63249..593b2704 100644
--- a/tests/src/token/src/main.sw
+++ b/tests/src/token/src/main.sw
@@ -2,7 +2,7 @@ contract;
use src_20::SRC20;
use src_3::SRC3;
-use src_7::{SRC7, Metadata};
+use src_7::{Metadata, SRC7};
use token::{
base::{
_decimals,
@@ -15,17 +15,13 @@ use token::{
_total_supply,
SetTokenAttributes,
},
+ metadata::*,
mint::{
_burn,
_mint,
},
- metadata::*,
-};
-use std::{
- hash::Hash,
- storage::storage_string::*,
- string::String
};
+use std::{hash::Hash, storage::storage_string::*, string::String};
storage {
total_assets: u64 = 0,
@@ -66,7 +62,15 @@ impl SRC20 for Contract {
impl SRC3 for Contract {
#[storage(read, write)]
fn mint(recipient: Identity, sub_id: SubId, amount: u64) {
- _mint(storage.total_assets, storage.total_supply, recipient, sub_id, amount);
+ _mint(
+ storage
+ .total_assets,
+ storage
+ .total_supply,
+ recipient,
+ sub_id,
+ amount,
+ );
}
#[storage(read, write)]
@@ -149,7 +153,7 @@ fn test_total_supply() {
#[test]
fn test_name() {
use std::constants::ZERO_B256;
-
+
let src20_abi = abi(SRC20, CONTRACT_ID);
let attributes_abi = abi(SetTokenAttributes, CONTRACT_ID);
@@ -161,7 +165,13 @@ fn test_name() {
assert(src20_abi.name(asset_id).is_none());
attributes_abi.set_name(asset_id, name);
- assert(src20_abi.name(asset_id).unwrap().as_bytes() == name.as_bytes());
+ assert(
+ src20_abi
+ .name(asset_id)
+ .unwrap()
+ .as_bytes() == name
+ .as_bytes(),
+ );
}
#[test]
@@ -179,7 +189,13 @@ fn test_symbol() {
assert(src20_abi.symbol(asset_id).is_none());
attributes_abi.set_symbol(asset_id, symbol);
- assert(src20_abi.symbol(asset_id).unwrap().as_bytes() == symbol.as_bytes());
+ assert(
+ src20_abi
+ .symbol(asset_id)
+ .unwrap()
+ .as_bytes() == symbol
+ .as_bytes(),
+ );
}
#[test]
@@ -311,7 +327,7 @@ fn test_set_metadata_b256() {
let src7_abi = abi(SRC7, CONTRACT_ID);
let set_metadata_abi = abi(SetTokenMetadata, CONTRACT_ID);
let key = String::from_ascii_str("my_key");
-
+
set_metadata_abi.set_metadata(asset_id, key, metadata);
let returned_metadata = src7_abi.metadata(asset_id, key);
@@ -329,7 +345,7 @@ fn test_set_metadata_u64() {
let src7_abi = abi(SRC7, CONTRACT_ID);
let set_metadata_abi = abi(SetTokenMetadata, CONTRACT_ID);
let key = String::from_ascii_str("my_key");
-
+
set_metadata_abi.set_metadata(asset_id, key, metadata);
let returned_metadata = src7_abi.metadata(asset_id, key);
@@ -347,7 +363,7 @@ fn test_set_metadata_string() {
let src7_abi = abi(SRC7, CONTRACT_ID);
let set_metadata_abi = abi(SetTokenMetadata, CONTRACT_ID);
let key = String::from_ascii_str("my_key");
-
+
set_metadata_abi.set_metadata(asset_id, key, metadata);
let returned_metadata = src7_abi.metadata(asset_id, key);
@@ -365,7 +381,7 @@ fn test_set_metadata_bytes() {
let src7_abi = abi(SRC7, CONTRACT_ID);
let set_metadata_abi = abi(SetTokenMetadata, CONTRACT_ID);
let key = String::from_ascii_str("my_key");
-
+
set_metadata_abi.set_metadata(asset_id, key, metadata);
let returned_metadata = src7_abi.metadata(asset_id, key);