From 1758a6f730118d988f58c3976a1662043bc5da37 Mon Sep 17 00:00:00 2001 From: bitzoic Date: Fri, 10 Nov 2023 12:57:55 +0300 Subject: [PATCH] Run formatter --- libs/merkle_proof/src/binary_merkle_proof.sw | 5 +- libs/ownership/src/ownable.sw | 12 ++++- 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 +++++++++++---- tests/src/fixed_point/ufp128_test/src/main.sw | 8 ++-- tests/src/merkle_proof/src/main.sw | 15 +++++- .../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/src/main.sw | 46 +++++++++++++------ 20 files changed, 423 insertions(+), 115 deletions(-) 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/src/ownable.sw b/libs/ownership/src/ownable.sw index b3a0d272..3ce2d030 100644 --- a/libs/ownership/src/ownable.sw +++ b/libs/ownership/src/ownable.sw @@ -143,7 +143,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 +221,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/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/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/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/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/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);